
eqs=!trim $eqs
eqs=!nonempty lines $eqs
!if $eqs=$empty
 error=empty_data
 !exit
!endif
eqcnt=!linecnt $eqs

diagnostics=good
Eq=
eqlist=
!for i=1 to $eqcnt
 eq$i=!line $i of $eqs
 e_=!trim $(eq$i)
 e_=!char 1 to $eqlim of $e_
 e_=!lower $e_
 e_=!rawmath $e_
 e_=!translate , to . in $e_
 e_=!translate = to , in $e_
 n_=!itemcnt $e_
 !if $n_!=2
  error=not_equation
  !exit
 !endif
 !distribute items $e_ into f_,g_
 !default g_=0
 eq$i=$f_-($g_)
 Eq=$Eq+($(eq$i))
 eqlist=!append item $(eq$i) to $eqlist
!next i

!if . isin $Eq or / isin $Eq or ^ isin $Eq
 error=not_integer
 !exit
!endif
v_=!varlist $Eq
v_=!listunion $varnames and $v_
n_=!itemcnt $v_
!if $n_>$spacedim
  error=illegal_var
  !exit
!endif

!for v in $varnames
 Eq=!mathsubst $v=t in $Eq
!next v
pari_header=eqlist=[$eqlist];varlist=[$varnames];\
	eqcoeff=matrix($eqcnt,$spacedim,m,n,polcoeff(eqlist[m],1,varlist[n]));\
	eqrank=matrank(eqcoeff);

r=!random -10,10
lintest=!exec pari print(poldegree($Eq))\
	print(subst($Eq-Pol($Eq,t),t,$r))\
	print(eqrank)
!distribute lines $lintest into deg, rest, eqrank
rest=!trim $rest
!if $rest=$empty or rank isin $eqrank or $eqrank=$empty
 error=bad_data
 !exit
!endif
!ifval $rest!=0 or $deg>1
 error=non_linear
 !exit
!endif
!ifval $eqrank<$codim
 diagnostics=bigdim
 !exit
!endif

!for i=1 to $eqcnt
 e_=$(eq$i)
 !for p=1 to $objdim+1
  E_=$e_
  !for v in $varnames
   E_=!mathsubst $v=($($(v)_$p)) in $E_
  !next v
  E_=$[$E_]
  !if NaN isin $E_ or Inf isin $E_
   error=bad_data
   !exit
  !endif
  !ifval $E_!=0
   diagnostics=bad $p
   !exit
  !endif
 !next p
!next i

!if $diagnostics=good and $eqcnt>$codim
 diagnostics=redundant
!endif
