image=0
n=$counter
F=f(x)\,\,=\,\,
Fa=f'(x)\,\,=\,\,
mytexsize=+2
R=$level
!if $level=0
    R=$counter
!endif    
    
pm=!randitem +,-
mp=!randitem +,-
s=!randitem 1,-1
keuze=!randitem 1,2
!if $questiontype=0
    # freestyle
    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
    b=!randitem 2,3,4,5,6,7,8,9,10    
    c=!randitem 3,4,5
    d=!randitem 2,3,4,5,6  
    e=!randitem 2,3,4,5,6
    f=!randitem 2,3,4,5
    f=$[$f*$s]
    !if $R = 1 
	!if $keuze=1
    	    functie=($a*x^$e $pm $b*x)^($f)
    	    formula$n=$F  \left( $a \cdot x^{$e} $pm $b\cdot x\right)^{$f}
	!else
    	    functie=log($a*x^$e $pm $b*x)
    	    formula$n=$F  \ln \left( $a \cdot x^{$e} $pm $b\cdot x \right)
	!endif
	!goto READY
    !endif
    !if $R = 2
	!if $keuze=1 
    	    functie=sqrt($a*x^($d) $pm $b)
    	    formula$n=$F \sqrt \left($a\cdot x^{$d} $pm $b \right)
	!else
    	    functie=($a*x^($d) $pm $b)^(1/$c)
    	    formula$n=$F \root $c\of {\left($a\cdot x^{$d} $pm $b\right)}
	!endif
	!goto READY
    !endif
    !if $R = 3
	!if $keuze=1 
    	    functie=(x^$a)*(e^($b*x^($d)))
    	    formula$n=$F  x^{$a} \cdot e^{($b\cdot x^{$d})}
	!else
    	    functie=(x^$a)*(log($b*x^($d)))
    	    formula$n=$F  x^{$a} \cdot \ln \left($b\cdot x^{$d}\right)
	!endif
	!goto READY
    !endif
    !if $R > 3 
	!if $keuze=1 
	    functie=(e^($b*x^($d)))/(x^$a)
            formula$n=$F  \frac {e^{($b\cdot x^{$d})}}{ x^{$a}}
        !else
            functie=($b^x)/(sqrt($a*x))
            formula$n=$F \frac{$b^{x}}{\sqrt{$a\cdot x}}
        !endif
    !endif
    :READY
    sommen=!exec maxima factor(diff($functie ,x)); 
    answer$n=!line 1 of $sommen	
    answer$n=!replace internal log by ln in $(answer$n)
    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
    # multiplechoice
    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
    multiimage=0
    image=0
    aa=!shuffle 2,3,4,5,6,7,8,9,10
    bb=!shuffle 2,3,4,5,6,7,8,9,10    
    c=!randitem 3,4,5
    d=!randitem 2,3,4,5,6  
    e=!randitem 2,3,4,5,6
    f=!randitem 2,3,4,5
    f=$[$f*$s]
    !if $options<3 or $options>8
	options=4
    !endif
    total=$empty
    answer$n=!randint 1,$options
    !if $R = 1
	!for p=1 to $options
	    a=!item $p of $aa
	    b=!item $p of $bb
	    !if $keuze=1
    		functie=($a*x^$e $pm $b*x)^($f)
		!if $p=$(answer$n)
    		    formula$n=$F  \left( $a \cdot x^{$e} $pm $b\cdot x\right)^{$f}
		!endif
	    !else
    		functie=log($a*x^$e $pm $b*x)
		!if $p=$(answer$n)
    	    	    formula$n=$F  \ln \left( $a \cdot x^{$e} $pm $b\cdot x \right)
		!endif
	    !endif
	    total=!append line factor(diff($functie ,x)); to $total
	!next p
      !goto READY2
    !endif
    !if $R = 2
	!for p=1 to $options
	    a=!item $p of $aa
	    b=!item $p of $bb
	    !if $keuze=1 
    		functie=sqrt($a*x^($d) $pm $b)
		!if $p=$(answer$n)
    		    formula$n=$F \sqrt \left($a\cdot x^{$d} $pm $b \right)
		!endif
	    !else
    		functie=($a*x^($d) $pm $b)^(1/$c)
		!if $p=$(answer$n)
    		    formula$n=$F \root $c\of {\left($a\cdot x^{$d} $pm $b\right)}
		!endif
	    !endif
	    total=!append line factor(diff($functie ,x)); to $total
	!next p
      !goto READY2
    !endif
    !if $R = 3
	!for p=1 to $options
	    a=!item $p of $aa
	    b=!item $p of $bb
	    !if $keuze=1 
    		functie=(x^$a)*(e^($b*x^($d)))
		!if $p=$(answer$n)
    		    formula$n=$F  x^{$a} \cdot e^{($b\cdot x^{$d})}
		!endif
	    !else
    		functie=(x^$a)*(log($b*x^($d)))
		!if $p=$(answer$n)
    		    formula$n=$F  x^{$a} \cdot \ln \left($b\cdot x^{$d}\right)
		!endif
	    !endif
	    total=!append line factor(diff($functie ,x)); to $total
	!next p
      !goto READY2
    !endif
    !if $R > 3 
	!for p=1 to $options
	    a=!item $p of $aa
	    b=!item $p of $bb
	    !if $keuze=1 
		functie=(e^($b*x^($d)))/(x^$a)
		!if $p=$(answer$n)
        	    formula$n=$F  \frac {e^{($b\cdot x^{$d})}}{ x^{$a}}
		!endif
    	    !else
        	functie=($b^x)/(sqrt($a*x))
		!if $p=$(answer$n)
        	    formula$n=$F \frac{$b^{x}}{\sqrt{$a\cdot x}}
		!endif
    	    !endif
	    total=!append line factor(diff($functie ,x)); to $total
	!next p
    !endif
    :READY2
    sommen=!exec maxima $total
    !for p=1 to $options
	ex=!line $p of $sommen
	ex=!replace internal log by ln in $ex
	ex=!texmath $ex
	ex$p=f'(x)\,\,=\,\, $ex
    !next p
    s=$(answer$n)
    texanswer$n=$(ex$s)
 !exit
!endif
