!set n=$counter
mytexsize=+2
F=f\left(x\right)\,\,=\,\,
Fa=f'\left(x\right)\,\,=\,\,
R=$level
!if $level=0
    R=$counter
!endif    
cols=20
rows=3
pm=!randitem +,-
mp=!randitem +,-
keuze=!randitem 1,2
!if $questiontype=0
    #freestyle
    plaatje=0
    checkfile=exos/checkfile2.proc
    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
    c=!randitem 2,4,6,8,10,12,14,16
    d=!randitem 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16    
    e=!randitem 2,3,4,5 
    f=!randitem 6,7,8,9 
    s=!randitem 1,-1
    a=$[$s*$a]  
    !if $b=$d
	b=$[$b+1]
    !endif	
    !if $R = 1
	!if $keuze=1
    	    functie=$a*sqrt(x) $pm $c
    	    formula$n=$F $a\cdot \sqrt x $pm $c
	!else
    	    functie=$a*x^$b $pm $c*sqrt(x) 
    	    formula$n=$F $a\cdot x^$b $pm $c\sqrt x 
	!endif
	!goto READY
    !endif
    !if $R = 2 	
	!if $keuze=1
	    c=$[$s*$c]
    	    functie=$c*x*sqrt(x) $pm $d*x
    	    formula$n=$F $c\cdot x\sqrt x $pm $d\cdot x
	!else
    	    functie=$a*x^$b $pm $c*x^$e*sqrt(x) 
    	    formula$n=$F $a\cdot x^$b $pm $c\cdot x^$e \cdot \sqrt x 
	!endif
	!goto READY
    !endif
    !if $R>2
	ss=!record 8 of lang/remarks.$taal
	question$n=$ss
	exotext=<img src=$module_dir/gifs/wortelhelp.gif>
	mytexsize=+5
	!if $R = 3 
	    !if $keuze=1
    		functie=$a*x^(1/$f) $pm $d
    		formula$n=$F $a\cdot \root $f \of{x} $pm $d
	    !else
    		functie=$a*x^$b $pm $f*x^($e/$f)
    		formula$n=$F $a\cdot x^$b $pm $f\cdot \root $f \of{x^$e}}
	    !endif
	    !goto READY
	!endif
	!if $R > 3 
	    !if $keuze=1
    		functie=$a*x^$e*x^(1/$f) $pm $d
		formula$n=$F $a\cdot x^$e\cdot \root $f \of{x} $pm $d
	    !else
		g=!randitem 2,4,8
		functie=$a*x^$b $pm $f/(x^($e/$f))
		formula$n=$F $a\cdot x^$b $pm \frac{$f}{\root $f \of{x^$e}}
	    !endif
	!endif
    !endif
    :READY
    # pari does not work with roots: maxima has to do it
    sommen=!exec maxima diff($functie ,x);
    answer$n=!line 1 of $sommen
    texanswer$n=!texmath $(answer$n)
    texanswer$n=$Fa $(texanswer$n)
 !exit
!endif

!if $questiontype isin 1,2
    # multiple choice
    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
    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
    c=!randitem 2,4,6,8,10,12,14,16
    d=!randitem 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16    
    e=!randitem 2,3,4,5 
    f=!randitem 6,7,8,9 
    s=!randitem 1,-1
    a=$[$s*$a]  
    !if $b=$d
	b=$[$b+1]
    !endif
    # limit the multiple choice options reasonable
    !if $options<4 or $options>8
	options=4
    !endif
    total=$empty
    answer$n=!randint 1,$options	
    !if $R = 1
	!for p=1 to $options
	    !if $keuze=1
    		functie=$a*sqrt(x) $pm $c
		!if $p=$(answer$n)
    		    formula$n=$F $a\cdot \sqrt x $pm $c
		!endif
	    !else
    		functie=$a*x^$b $pm $c*sqrt(x)
		!if $p=$(answer$n) 
    		    formula$n=$F $a\cdot x^$b $pm $c\sqrt x 
		!endif
	    !endif
	    total=!append line diff($functie ,x); to $total
	!next p
	!goto READY2
    !endif
    !if $R = 2 	
	!for p=1 to $options
	    !if $keuze=1
		c=$[$s*$c]
    		functie=$c*x*sqrt(x) $pm $d*x
		!if $p=$(answer$n)
    		    formula$n=$F $c\cdot x\sqrt x $pm $d\cdot x
		!endif
	    !else
    		functie=$a*x^$b $pm $c*x^$e*sqrt(x) 
		!if $p=$(answer$n)
    		    formula$n=$F $a\cdot x^$b $pm $c\cdot x^$e \cdot \sqrt x 
		!endif
	    !endif
	    total=!append line diff($functie ,x); to $total
	!next p
	!goto READY2
    !endif
    !if $R>2
	ss=!record 28 of lang/remarks.$taal
	question$n=$ss
	mytexsize=+5
	!if $R = 3 
	    !for p=1 to $options
		!if $keuze=1
    		    functie=$a*x^(1/$f) $pm $d
		    !if $p=$(answer$n)
    			formula$n=$F $a\cdot \root $f \of{x} $pm $d
		    !endif
		!else
    		    functie=$a*x^$b $pm $f*x^($e/$f)
		    !if $p=$(answer$n)
    			formula$n=$F $a\cdot x^$b $pm $f\cdot \root $f \of{x^$e}}
		    !endif
		!endif
		total=!append line diff($functie ,x); to $total
	    !next p
	    !goto READY2
	!endif
	!if $R > 3 
	    !for p=1 to $options
		!if $keuze=1
    		    functie=$a*x^$e*x^(1/$f) $pm $d
		    !if $p=$(answer$n)
			formula$n=$F $a\cdot x^$e\cdot \root $f \of{x} $pm $d
		    !endif
		!else
		    #NAKIJKEN
		    g=!randitem 2,4,8
		    functie=$a*x^$b $pm $f/(x^($e/$f))
		    !if $p=$(answer$n)
			formula$n=$F $a\cdot x^$b $pm \frac{$f}{\root $f \of{x^$e}}
		    !endif
		!endif
		total=!append line diff($functie ,x); to $total
	    !next p
	!endif
    !endif
    :READY2
    sommen=!exec maxima $total
    !for p=1 to $options
	ex=!line $p of $sommen
        ex=!texmath $ex
        ex$p=f'(x)\,\,=\,\, $ex
    !next p
    s=$(answer$n)
    texanswer$n=$(ex$s)
!endif
