image=0
n=$counter

F=f\left(x\right)\,\,=\,\,
Fa=f'\left(x\right)\,\,=\,\,
R=$level

!if $level=0
    R=$counter
!endif
	
pm=!randitem +,-
mp=!randitem +,-
keuze=!randitem 1,2
s=!randitem -1,1

!if $questiontype=0
    # freestyle
    ss=!record 7 of lang/remarks.$taal
    question$n=$ss
    exotext=!record 25 of lang/remarks.$taal
    sometext=!record 26 of lang/remarks.$taal
    exotext=<p><a onmouseover="return escape('$sometext')">$exotext
    helptext=$empty
    a=!randitem 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
    b=!randitem 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16    
    c=!randitem 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
    d=!randitem 2,3,4,5,6,7,8   
    e=!randitem 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16    
    a=$[$s*$a]
    !if $R = 1 
	!if $keuze=1
	    sin=!randitem sin,cos,tan
    	    functie=$a*$sin(x)
    	    formula$n=$F $a\cdot \$sin \left( x \right)
	!else
	    sin=!randitem sin,tan
    	    functie=$a*$sin(x) $pm $b*cos(x)
    	    formula$n=$F $a\cdot \$sin \left( x \right) $pm $b\cdot \cos \left( x \right)
	!endif
        !goto READY
    !endif 
    !if $R = 2
	!if $keuze=1 
    	    sin=!randitem sin,cos,tan
    	    functie=$a*$sin(x^$b)
    	    formula$n=$F $a\cdot\$sin\left( x^{$b} \right)
	!else
    	    sin=tan
    	    functie=$a*$sin($b*x)
    	    formula$n=$F $a\cdot\$sin\left( $b x \right)
	!endif
        !goto READY
    !endif
    !if $R = 3 
	sin=!randitem sin,cos,tan
	!if $keuze=1
    	    functie=$a*x^$d*$sin($b*x)
    	    formula$n=$F $a\cdot x^{$d} \cdot \$sin\left($b  x \right)
	!else
    	    functie=$b^x*$sin(x)
    	    formula$n=$F $b^{x} \cdot \$sin\left(x \right)
	!endif
        !goto READY
    !endif
    !if $R > 3 
	sin=!randitem sin,cos
	!if $keuze=1
    	    functie=$sin($a*x)/($b*x)
    	    formula$n=$F \frac {\$sin \left($a x \right)}{$b \cdot x}
	!else
    	    functie=$sin(x)/($b*x)
    	    formula$n=$F \frac {\$sin \left(x \right)}{$b \cdot x}
	!endif
    !endif
    :READY	
    sommen=!exec maxima diff($functie ,x);        
    answer$n=!line 1 of $sommen
    !if $sin=tan
	checkfile=exos/checkfile3.proc
    !else
	checkfile=exos/checkfile2.proc
    !endif	
    !if sec isin $(answer$n)
	answer$n=!replace internal sec by 1/cos in $(answer$n)
    !endif
    texanswer$n=!texmath $(answer$n)
    texanswer$n=!replace internal log by ln in $(texanswer$n)
    texanswer$n=$Fa $(texanswer$n)
 !exit
!endif

!if $questiontype isin 1,2
    checkfile=$checkdir/multiplechoice.proc
    !if $questiontype=2
	rr=!record 15 of lang/remarks.$taal
    !else
	rr=!record 16 of lang/remarks.$taal
    !endif
    exotext=$rr
    ss=!record 7 of lang/remarks.$taal
    question$n=$ss
    math=1
    plot=0
    draw=0
    image=0
    multiimage=0
    aa=!shuffle 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
    b=!randitem 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16    
    c=!randitem 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
    d=!randitem 2,3,4,5,6,7,8   
    e=!randitem 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16    
    total=$empty
    !if $options <4 or $options>8
	options=4
    !endif
    answer$n=!randint 1,$options	
    # We need to address maxima differently...
    # the combined simultaneus feeding of 4 questions in this type of "goniometry" 
    # results in a lot of trouble
    # so we start maxima 4 times ... hopefully multiexec works fine
    !if $R = 1 
	!for p=1 to $options
	    a=!item $p of $aa
	    a=$[$s*$a]
	    !if $keuze=1
		sin=!randitem sin,cos,tan
    		functie=$a*$sin(x)
		!if $p=$(answer$n)
    		    formula$n=$F $a\cdot \$sin \left( x \right)
		!endif
	    !else
		sin=!randitem sin,tan
    		functie=$a*$sin(x) $pm $b*cos(x)
		!if $p=$(answer$n)
    		    formula$n=$F $a\cdot \$sin \left( x \right) $pm $b\cdot \cos \left( x \right)
		!endif
	    !endif
	    ex=!exec maxima diff($functie,x);
	    !if sec isin $ex
		ex=!replace internal sec by 1/cos in $ex
	    !endif
	    !if log isin $ex
		ex=!replace internal log by ln in $ex
	    !endif
	    ex=!texmath $ex
	    ex$p=f'(x)\,\,=\,\, $ex
	!next p
	s=$(answer$n)
	texanswer$n=$(ex$s)
      !exit
    !endif 
    !if $R = 2
	!for p=1 to $options
	    a=!item $p of $aa
	    a=$[$s*$a]
	    !if $keuze=1 
    		sin=!randitem sin,cos,tan
    		functie=$b*$sin(x^$a)
		!if $p=$(answer$n)
    		    formula$n=$F $b\cdot\$sin\left( x^{$a} \right)
		!endif
	    !else
    		sin=!randitem sin,tan
    		functie=$b*$sin($a*x)
		!if $p=$(answer$n)
    		    formula$n=$F $b\cdot\$sin\left( $a x \right)
		!endif
	    !endif
	    ex=!exec maxima diff($functie,x);
	    !if sec isin $ex
		ex=!replace internal sec by 1/cos in $ex
	    !endif
	    !if log isin $ex
		ex=!replace internal log by ln in $ex
	    !endif
	    ex=!texmath $ex
	    ex$p=f'(x)\,\,=\,\, $ex
    	!next p
	s=$(answer$n)
	texanswer$n=$(ex$s)
        !exit
    !endif
    !if $R = 3 
	!for p=1 to $options
	    a=!item $p of $aa
	    a=$[$s*$a]
	    sin=!randitem sin,cos,tan
	    !if $keuze=1
    		functie=$a*x^$d*$sin($b*x)
		!if $p=$(answer$n)
    		    formula$n=$F $a\cdot x^{$d} \cdot \$sin\left($b  x \right)
		!endif
	    !else
    		functie=$a^x*$sin(x)
		!if $p=$(answer$n)
    		    formula$n=$F $a^{x} \cdot \$sin\left(x \right)
		!endif
	    !endif
	    ex=!exec maxima diff($functie,x);
	    !if sec isin $ex
		ex=!replace internal sec by 1/cos in $ex
	    !endif
	    !if log isin $ex
		ex=!replace internal log by ln in $ex
	    !endif
	    ex=!texmath $ex
	    ex$p=f'(x)\,\,=\,\, $ex
        !next p
	s=$(answer$n)
	texanswer$n=$(ex$s)
        !exit
    !endif
    !if $R > 3 
	!for p=1 to $options
	    a=!item $p of $aa
	    a=$[$s*$a]
	    sin=!randitem sin,cos
	    !if $keuze=1
    		functie=$sin($a*x)/($b*x)
		!if $p=$(answer$n)
    		    formula$n=$F \frac {\$sin \left($a x \right)}{$b \cdot x}
		!endif
	    !else
    		functie=$sin(x)/($a*x)
		!if $p=$(answer$n)
    		    formula$n=$F \frac {\$sin \left(x \right)}{$a \cdot x}
		!endif
	    !endif
	    ex=!exec maxima diff($functie,x);
	    !if sec isin $ex
		ex=!replace internal sec by 1/cos in $ex
	    !endif
	    !if log isin $ex
		ex=!replace internal log by ln in $ex
	    !endif
	    ex=!texmath $ex
	    ex$p=f'(x)\,\,=\,\, $ex
        !next p
	s=$(answer$n)
	texanswer$n=$(ex$s)
    !endif
 !exit
!endif
