
# Types: 1. choose picture from equation. 2. choose equation from picture.

!if $atype<3
 type=$atype
!else
 type=!randitem 1,2
!endif

st=!randitem $style
file=defs/$st
n=!recordcnt $file
n=!randint 1,$n
rec=!record $n of $file
randata=!line 1 of $rec
choices=!line 2 to -1 of $rec
choices=!trim $choices
present=!linecnt $choices
signs=!randitem +-,-+
!distribute chars $signs into sign1,sign2
choices=!replace +- by $sign1 in $choices
choices=!replace -+ by $sign2 in $choices

!reset plotf, ineq
!distribute items <>,>< into lg,gl
!for i=1 to $present
 d=!line $i of $choices
 d=!translate ; to $\
$ in $d
 n=!linecnt $d
 !distribute lines $d into in,p1,p2,p3,p4,p5,p6
 !reset pl
 !for j=1 to $n-1
  pl=!append item $(p$j) notitle lt $curvecolor to $pl
 !next j
 !if $lg isin $in or $gl isin $in
  !distribute chars <> into ineq1,ineq2
  i1=!replace <> by $ineq1 in $in
  i1=!replace >< by $ineq2 in $i1
  i2=!replace <> by $ineq2 in $in
  i2=!replace >< by $ineq1 in $i2
  ineq=!append item $i1, $i2 to $ineq
  plotf=!append line $pl\
$pl to $plotf
 !else
  ineq=!append item $in to $ineq
  plotf=!append line $pl to $plotf
 !endif
!next i
present=!itemcnt $ineq
ineq=!tolower $ineq
ineq=!mathsubst conjugate=conj in $ineq

ineqtex=!rawmath $ineq
ineqtex=!texmath $ineqtex
ineqtex=!mathsubst im={\rm Im} in $ineqtex
ineqtex=!mathsubst re={\rm Re} in $ineqtex
ineqtex=!replace internal and by {\rm \ \ $name_and\ \ } in $ineqtex
ineqtex=!replace internal or by {\rm \ \ $name_or\ \ } in $ineqtex
ineqtex=!replace internal < by \le $ in $ineqtex
ineqtex=!replace internal > by \ge $ in $ineqtex

ineqpari=!mathsubst im=imag in $ineq
ineqpari=!mathsubst re=real in $ineqpari
ineqpari=!mathsubst and=&& in $ineqpari
ineqpari=!mathsubst or=|| in $ineqpari
sh=!shuffle $present
good=!randint 1,$present
goodf=!positionof item $good in $sh
plotf=!lines $sh of $plotf
ineqtex=!items $sh of $ineqtex
ineqpari=!items $sh of $ineqpari
!distribute items $ineqpari into ipari1,ipari2,ipari3,ipari4,ipari5,ipari6,ipari7,ipari8,ipari9,ipari10
askcnt=$[min(6,$present)]
!distribute item &&,|| into p_and,p_or
pari_precision=4
pari_header=

!for t=1 to $present
 pari_header=$pari_header\
  {\
   grid$t(r)=for(m=0,3*r,y=-$range+$range*m/(1.5*r)+0.0001;\
    for(n=0,2*r,x=-$range+$range*(n+0.5*(m%2))/r+0.0001;\
     z=x+i*y; if($(ipari$t),print1(x," ",y,";"))\
    );\
   );\
  }
!next t

!if $type=1
 datasrc=grid$goodf(15)
!else
 src=
 !for i=1 to $askcnt
  src=$src;grid$i(9);print1(";;");
 !next i
 datasrc=$src
!endif

status=waiting

