
diagnostics=good
Eq=
eqlist=
!for i=1 to $spacedim
 e_=!trim $(eq$i)
 !if $e_=$empty
  error=empty_data
  !exit
 !endif
 e_=!char 1 to $eqlim of $e_
 e_=!lower $e_
 e_=!rawmath $e_
 eq$i=$e_
 Eq=$Eq+($e_)
 eqlist=!append item $e_ to $eqlist
!next i

!if $integer=1
 !if . isin $Eq or , isin $Eq or / isin $Eq or ^ isin $Eq
  error=not_integer
  !exit
 !endif
!endif
v_=!varlist $Eq
v_=!listunion $parmnames and $v_
n_=!itemcnt $v_
!if $n_>$objdim
  error=illegal_var
  !exit
!endif

pts=!translate $\
$ to ; in $points
pari_header=eqlist=bestappr([$eqlist],10^10); varlist=[$parmnames];\
	origin=eqlist; for(i=1,$objdim,origin=subst(origin,varlist[i],0));\
	eqmat=matrix($objdim,$spacedim,m,n,eqlist[n]-origin[n]);\
	id=matid($objdim);\
	for(m=1,$objdim,for(n=1,$objdim,eqmat[m,]=subst(eqmat[m,],varlist[n],id[m,n])));\
	points=[$pts]; for(n=1,$objdim+1,points[n,]=points[n,]-origin);

!for v in $parmnames
 Eq=!mathsubst $v=t in $Eq
!next v
r=!random -10,10
lintest=!exec pari print(poldegree($Eq))\
	print(subst($Eq-Pol($Eq,t),t,$r))\
	print(matrank(eqmat))\
	print(matrank(concat(eqmat~,points~)))\
	for(n=1,$objdim+1,print(matrank(concat(eqmat~,points[n,]~)),", "))
	
!distribute lines $lintest into deg, rest, rank1, rank2, ranks
rest=!trim $rest
!if $rest=$empty or rest isin $rest or rank isin $rank1$rank2
 error=bad_data
 !exit
!endif
!ifval $rest!=0 or $deg>1
 error=non_linear
 !exit
!endif

!if $rank2>$rank1
 !for p=1 to $objdim+1
  l_=!item $p of $ranks
  !if $l_>$rank1
   diagnostics=bad $p
   !exit
  !endif
 !next p
!endif

