Rev 6079 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 338 | schaersvoo | 1 | # this file expects a reply$n and returns a modulescore |
| 2 | # the student answer should be a simplified version of the question |
||
| 3 | # the answer should be checked on litteral retyping the correct answer |
||
| 4 | # a varlist should be provided: |
||
| 5 | # varlist=x |
||
| 6 | # varlist=x,y,z |
||
| 7 | # a verbatim original of the question should be provided |
||
| 8 | # var1=the original math construct (e.g non latex,preferably rawmath) |
||
| 6079 | schaersvoo | 9 | # letop geen variabele "t" gebruiken...gaat mis vermoedelijk via de "t" in "sqrt" -> sqrT() -> sqr() -> () |
| 338 | schaersvoo | 10 | # for instance: the simplify \frac{4x^{3}}{2x^{\frac{-1}{2}}} |
| 11 | # varlist=x |
||
| 12 | # var1=4*x^3/(2*x^(-1/2)) |
||
| 3688 | schaersvoo | 13 | # 1/2011 added !exec toascii $param1,$param2... |
| 338 | schaersvoo | 14 | |
| 362 | schaersvoo | 15 | goback=0 |
| 16 | errortext=$empty |
||
| 338 | schaersvoo | 17 | |
| 18 | !if $wims_user=supervisor |
||
| 19 | !if $varlist=$empty |
||
| 5807 | schaersvoo | 20 | errortext=YOU SHOULD DECLARE : <br />varlist=x or varlist=yield |
| 338 | schaersvoo | 21 | goback=1 |
| 22 | !exit |
||
| 23 | !endif |
||
| 24 | !if $var1=$empty |
||
| 5807 | schaersvoo | 25 | errortext=YOU SHOULD DECLARE A $$var1 = a rawmath formula of the question<br />\ |
| 26 | for instance: the simplify \frac{4x^{3}}{2x^{\frac{-1}{2}}}<br />\ |
||
| 27 | varlist=x<br />\ |
||
| 338 | schaersvoo | 28 | var1=4*x^3/(2*x^(-1/2)) |
| 29 | goback=1 |
||
| 30 | !exit |
||
| 31 | !endif |
||
| 32 | !endif |
||
| 33 | |||
| 34 | n=$counter |
||
| 35 | |||
| 36 | test=!wordcnt $(reply$n) |
||
| 37 | !if $test=0 |
||
| 38 | goback=1 |
||
| 39 | maxscore=$[$P9*$maxscore] |
||
| 40 | errortext=!record 37 of $remarkdir/commonremarks.$taal |
||
| 41 | !exit |
||
| 42 | !endif |
||
| 43 | |||
| 44 | !if ? isin $(reply$n) |
||
| 45 | remark$n=$NOK |
||
| 46 | goback=0 |
||
| 47 | maxscore=0 |
||
| 48 | !exit |
||
| 49 | !endif |
||
| 50 | |||
| 51 | |||
| 52 | AAA=!nospace $(reply$n) |
||
| 53 | AAA=!rawmath $AAA |
||
| 54 | AAA=!lower $AAA |
||
| 55 | AAA=!rawmath $AAA |
||
| 56 | var=!lower $varlist |
||
| 57 | va=!varlist $AAA |
||
| 58 | testvar=$empty |
||
| 59 | !for i in $va |
||
| 718 | schaersvoo | 60 | it=!charcnt $i |
| 61 | !if $it=1 |
||
| 62 | # exclude sqrt,log... |
||
| 63 | !if $i notin $var |
||
| 64 | testvar=!append line <b>$i</b> to $testvar |
||
| 65 | !endif |
||
| 338 | schaersvoo | 66 | !endif |
| 67 | !next i |
||
| 68 | |||
| 69 | !if $testvar!=$empty |
||
| 70 | ex=!record 77 of $remarkdir/commonremarks.$taal |
||
| 71 | !if $teaching=1 |
||
| 837 | schaersvoo | 72 | maxscore=$[$P9*$maxscore] |
| 338 | schaersvoo | 73 | goback=1 |
| 837 | schaersvoo | 74 | errortext=$ex |
| 75 | #var=$var va=$va AAA=$AAA testvar=$testvar |
||
| 338 | schaersvoo | 76 | !else |
| 5807 | schaersvoo | 77 | remark$n=$NOK<br />$ex |
| 338 | schaersvoo | 78 | maxscore=0 |
| 79 | goback=0 |
||
| 80 | !endif |
||
| 81 | !exit |
||
| 82 | !endif |
||
| 83 | |||
| 84 | !for i in $var |
||
| 85 | !if $i notin $AAA |
||
| 86 | testvar=$i |
||
| 87 | ex=!record 32 of $remarkdir/commonremarks.$taal |
||
| 88 | !if $teaching=1 |
||
| 89 | goback=1 |
||
| 90 | errortext=$ex |
||
| 91 | # heavy pentalty... |
||
| 837 | schaersvoo | 92 | maxscore=$[$P9*$maxscore] |
| 338 | schaersvoo | 93 | !else |
| 5807 | schaersvoo | 94 | remark$n=$NOK<br />$ex |
| 837 | schaersvoo | 95 | goback=0 |
| 96 | maxscore=0 |
||
| 338 | schaersvoo | 97 | !endif |
| 98 | !exit |
||
| 99 | !else |
||
| 100 | I=!toupper $i |
||
| 101 | AAA=!replace internal $i by $I in $AAA |
||
| 102 | !endif |
||
| 103 | !next i |
||
| 104 | |||
| 837 | schaersvoo | 105 | # check on scientific notation 3e+12 3*10^12 |
| 338 | schaersvoo | 106 | AAA=!nospace $AAA |
| 107 | !if x10 isin $AAA |
||
| 108 | ex=!record 68 of $remarkdir/commonremarks.$taal |
||
| 109 | maxscore=$[$P1*$maxscore] |
||
| 110 | !if $teaching=1 |
||
| 111 | goback=1 |
||
| 112 | errortext=$ex |
||
| 113 | !exit |
||
| 114 | !else |
||
| 115 | AAA=!replace internal x10 by *10 in $AAA |
||
| 116 | !if $extra=$empty |
||
| 117 | extra=$ex |
||
| 118 | !else |
||
| 5807 | schaersvoo | 119 | extra=!append line $ <br />$ex $ to $extra |
| 338 | schaersvoo | 120 | !endif |
| 121 | !endif |
||
| 122 | !endif |
||
| 123 | test=!replace [0-9]e[0-9] by @ in $AAA |
||
| 124 | !if @ isin $test |
||
| 125 | maxscore=$[$P1*$maxscore] |
||
| 126 | testvar1=!replace internal e by e+ in $AAA |
||
| 5857 | schaersvoo | 127 | testvar1=<span style="color:green">$testvar1</span> |
| 128 | testvar2=<br /><span style="color:red">$AAA</span> |
||
| 338 | schaersvoo | 129 | errortext=!record 16 of $remarkdir/commonremarks.$taal |
| 130 | goback=1 |
||
| 131 | !exit |
||
| 132 | !endif |
||
| 133 | |||
| 134 | AAA=!replace internal ** by ^ in $AAA |
||
| 135 | AAA=!replace internal e+ by *10^ in $AAA |
||
| 136 | AAA=!replace internal e- by *10^- in $AAA |
||
| 137 | |||
| 138 | !for p=1 to 3 |
||
| 139 | AAA=!replace internal ** by * in $AAA |
||
| 140 | !next p |
||
| 141 | |||
| 142 | t=!char 1 of $AAA |
||
| 143 | !if $t=* |
||
| 144 | AAA=!char 2 to -1 of $AAA |
||
| 145 | !endif |
||
| 146 | |||
| 147 | |||
| 148 | #check for sin etc |
||
| 837 | schaersvoo | 149 | !for p in sqrt,log,sin,ln,cos,tan,sec,abs,*i,i*,+i,i+,-i,i- |
| 150 | !if $p isin $AAA |
||
| 151 | I=!toupper $p |
||
| 152 | AAA=!replace internal $p by $I in $AAA |
||
| 338 | schaersvoo | 153 | !endif |
| 837 | schaersvoo | 154 | !next p |
| 718 | schaersvoo | 155 | AAA=!replace [a-z\~\!\@\#\$\%\&\_\|\=\"\'\:\;\{\}] by $empty in $AAA |
| 338 | schaersvoo | 156 | AAA=!lower $AAA |
| 157 | AAA=!nospace $AAA |
||
| 158 | AAA=!rawmath $AAA |
||
| 159 | |||
| 160 | # check for 4*11*n^3 instead of 44*n^3 and x*x*x |
||
| 161 | # attention to 6*4*10^3 --> 6@4#3 --> 6@4 meaning can be simplified further |
||
| 162 | # and 4*10^ will be ignored |
||
| 163 | test=!replace [\*][0-9]*[\^] by # in $AAA |
||
| 164 | test=!replace internal * by @ in $test |
||
| 165 | !if @ isin $test |
||
| 166 | things=0,1,2,3,4,5,6,7,8,9 |
||
| 167 | t=!positionof char @ in $test |
||
| 168 | !if $t != $empty |
||
| 169 | !for p in $t |
||
| 170 | d1=!char $[$p-1] of $test |
||
| 171 | d2=!char $[$p+1] of $test |
||
| 172 | !if ($d1 isin $things) and ($d2 isin $things) |
||
| 173 | testvar=$AAA |
||
| 174 | errortext=!record 74 of $remarkdir/commonremarks.$taal |
||
| 175 | !if $teaching=1 |
||
| 176 | maxscore=$[$P4*$maxscore] |
||
| 177 | !else |
||
| 178 | maxscore=$[$P8*$maxscore] |
||
| 179 | !endif |
||
| 180 | goback=1 |
||
| 181 | !exit |
||
| 182 | !endif |
||
| 183 | !next p |
||
| 184 | !for p in $t |
||
| 185 | d1=!char $[$p-1] of $test |
||
| 186 | d2=!char $[$p+1] of $test |
||
| 187 | !if $d1=$d2 |
||
| 188 | !if ($d1 isin $varlist) and ($d2 isin $varlist) |
||
| 189 | testvar=$AAA |
||
| 190 | errortext=!record 74 of $remarkdir/commonremarks.$taal |
||
| 191 | !if $teaching=1 |
||
| 192 | maxscore=$[$P4*$maxscore] |
||
| 193 | !else |
||
| 194 | maxscore=$[$P8*$maxscore] |
||
| 195 | !endif |
||
| 196 | goback=1 |
||
| 197 | !exit |
||
| 198 | !endif |
||
| 199 | !endif |
||
| 200 | !next p |
||
| 201 | !endif |
||
| 202 | !endif |
||
| 203 | |||
| 204 | # check on literal copying of the exo, this is important because |
||
| 205 | # we use pari to check if the reply is the same as the answer |
||
| 206 | a1=$AAA |
||
| 207 | o1=!lower $var1 |
||
| 208 | o1=!rawmath $o1 |
||
| 209 | o1=!nospace $o1 |
||
| 210 | c1=!lower $(answer$n) |
||
| 211 | c1=!rawmath $c1 |
||
| 212 | c1=!nospace $c1 |
||
| 213 | |||
| 3688 | schaersvoo | 214 | |
| 338 | schaersvoo | 215 | !if $c1!=$o1 |
| 216 | !if $o1 issametext $a1 |
||
| 217 | ex=!record 73 of $remarkdir/commonremarks.$taal |
||
| 218 | !if $teaching=1 |
||
| 219 | goback=1 |
||
| 220 | errortext=$ex |
||
| 221 | maxscore=$[$P5*$maxscore] |
||
| 222 | !else |
||
| 223 | # this answer will be wrong !!! no consideration |
||
| 5807 | schaersvoo | 224 | remark$n=$NOK<br />$ex |
| 338 | schaersvoo | 225 | goback=0 |
| 226 | maxscore=0 |
||
| 227 | !endif |
||
| 228 | !exit |
||
| 229 | !endif |
||
| 230 | !endif |
||
| 231 | |||
| 232 | |||
| 6041 | schaersvoo | 233 | c2=!replace [\(\)\~\`\!\@\#\$\%\&\_\|\=\+\"\'\:\;\?\-] by $empty in $c1 |
| 234 | o2=!replace [\(\)\~\`\!\@\#\$\%\&\_\|\=\+\"\'\:\;\?\-] by $empty in $o1 |
||
| 338 | schaersvoo | 235 | o2=!nospace $o2 |
| 236 | c2=!nospace $c2 |
||
| 237 | !if $o2!=$c2 |
||
| 6041 | schaersvoo | 238 | a2=!replace [\(\)\~\`\!\@\#\$\%\&\_\|\=\+\"\'\:\;\?\-] by $empty in $a1 |
| 338 | schaersvoo | 239 | a2=!nospace $a2 |
| 240 | !if $o2 issametext $a2 |
||
| 241 | ex=!record 73 of $remarkdir/commonremarks.$taal |
||
| 242 | !if $teaching=1 |
||
| 243 | goback=1 |
||
| 244 | errortext=$ex |
||
| 245 | maxscore=$[$P5*$maxscore] |
||
| 246 | !else |
||
| 247 | # this answer will be wrong !!! no consideration |
||
| 5807 | schaersvoo | 248 | remark$n=$NOK<br />$ex |
| 338 | schaersvoo | 249 | goback=0 |
| 250 | maxscore=0 |
||
| 251 | !endif |
||
| 252 | !exit |
||
| 253 | !endif |
||
| 254 | !endif |
||
| 255 | |||
| 3688 | schaersvoo | 256 | tot=!exec toascii $o2,$c2,$a2 |
| 3690 | schaersvoo | 257 | o3=!item 1 of $tot |
| 258 | c3=!item 2 of $tot |
||
| 3688 | schaersvoo | 259 | !ifval $o3!=$c3 |
| 3690 | schaersvoo | 260 | a3=!item 3 of $tot |
| 3688 | schaersvoo | 261 | !ifval $a3=$o3 |
| 262 | ex=!record 73 of $remarkdir/commonremarks.$taal |
||
| 263 | !if $teaching=1 |
||
| 264 | goback=1 |
||
| 265 | errortext=$ex |
||
| 266 | maxscore=$[$P5*$maxscore] |
||
| 267 | !else |
||
| 268 | # this answer will be wrong !!! no consideration |
||
| 5807 | schaersvoo | 269 | remark$n=$NOK<br />$ex |
| 3688 | schaersvoo | 270 | goback=0 |
| 271 | maxscore=0 |
||
| 338 | schaersvoo | 272 | !endif |
| 3688 | schaersvoo | 273 | !exit |
| 338 | schaersvoo | 274 | !endif |
| 275 | !endif |
||
| 276 | |||
| 277 | # now AAA=y^5/3 |
||
| 278 | A=!lower $AAA |
||
| 279 | G=!lower $(answer$n) |
||
| 280 | var=!lower $varlist |
||
| 281 | !for p in $varlist |
||
| 837 | schaersvoo | 282 | num=!randint 10,100 |
| 283 | A=!replace internal $p by ($num) in $A |
||
| 284 | G=!replace internal $p by ($num) in $G |
||
| 338 | schaersvoo | 285 | !next p |
| 837 | schaersvoo | 286 | Ac=$[$A] |
| 287 | Gc=$[$G] |
||
| 288 | !if NaN notin $Ac$Gc |
||
| 289 | !if $Ac=$Gc |
||
| 290 | t3=1 |
||
| 291 | !else |
||
| 292 | !if $Ac=$[-1*$Gc] |
||
| 293 | ex=!record 27 of $remarkdir/commonremarks.$taal |
||
| 294 | t3=0.5 |
||
| 295 | !if $extra=$empty |
||
| 296 | extra=$ex |
||
| 297 | !else |
||
| 5807 | schaersvoo | 298 | extra=!append line $ $ex <br /> $ to $extra |
| 837 | schaersvoo | 299 | !endif |
| 300 | !else |
||
| 301 | Ac=!replace internal - by + in $A |
||
| 302 | Ac=$[$Ac] |
||
| 303 | !if $Ac=$Gc or $Ac=$[-1*$Gc] |
||
| 304 | ex=!record 27 of $remarkdir/commonremarks.$taal |
||
| 305 | t3=0.3 |
||
| 306 | !if $extra=$empty |
||
| 307 | extra=$ex |
||
| 308 | !else |
||
| 5807 | schaersvoo | 309 | extra=!append line $ $ex <br /> $ to $extra |
| 837 | schaersvoo | 310 | !endif |
| 311 | !else |
||
| 312 | t3=0 |
||
| 313 | !endif |
||
| 314 | !endif |
||
| 315 | !endif |
||
| 316 | !else |
||
| 317 | t3=1 |
||
| 318 | !endif |
||
| 338 | schaersvoo | 319 | # very expensive but te only way to compare "variables in powers" like x^a |
| 320 | tot=!exec maxima if rationalize(expand(float($AAA))) = rationalize(expand(float($(answer$n)))) then 1 else 0 ;\ |
||
| 837 | schaersvoo | 321 | if ratsimp($AAA) = ratsimp($(answer$n)) then 1 else 0 ;\ |
| 718 | schaersvoo | 322 | expand($AAA);\ |
| 338 | schaersvoo | 323 | ratsimp($AAA); |
| 324 | |||
| 837 | schaersvoo | 325 | |
| 338 | schaersvoo | 326 | !if $wims_exec_error != $empty |
| 327 | testvar=$(reply$n) |
||
| 328 | maxscore=$[$P4*$maxscore] |
||
| 329 | goback=1 |
||
| 330 | errortext=!record 26 of $remarkdir/commonremarks.$taal |
||
| 5857 | schaersvoo | 331 | !exit |
| 338 | schaersvoo | 332 | !endif |
| 333 | |||
| 837 | schaersvoo | 334 | t1=!line 1 of $tot |
| 335 | t2=!line 2 of $tot |
||
| 336 | !if $[$t1+$t2]>0 |
||
| 337 | tt=1 |
||
| 338 | t3=1 |
||
| 339 | #hmmm... sometimes substitution mysteriously goes wrong ?? |
||
| 340 | !else |
||
| 341 | tt=0 |
||
| 342 | !endif |
||
| 343 | |||
| 338 | schaersvoo | 344 | # check if the answer can be simplified further on variable level? |
| 718 | schaersvoo | 345 | a1=!line 3 of $tot |
| 346 | a2=!line 4 of $tot |
||
| 837 | schaersvoo | 347 | !if $tt=1 |
| 348 | # answer is technically correct |
||
| 7477 | schaersvoo | 349 | simpler1=0 |
| 837 | schaersvoo | 350 | !for p in $varlist |
| 351 | c1=!positionof char $p in $AAA |
||
| 352 | c3=!positionof char $p in $a2 |
||
| 353 | c1=!itemcnt $c1 |
||
| 354 | c3=!itemcnt $c3 |
||
| 7477 | schaersvoo | 355 | !if $[$c3-$c1]<0 |
| 356 | !increase simpler1 |
||
| 837 | schaersvoo | 357 | !endif |
| 358 | !next p |
||
| 7477 | schaersvoo | 359 | simpler2=0 |
| 360 | !for p in $varlist |
||
| 361 | c1=!positionof char $p in $AAA |
||
| 362 | c3=!positionof char $p in $a1 |
||
| 363 | c1=!itemcnt $c1 |
||
| 364 | c3=!itemcnt $c3 |
||
| 365 | !if $[$c3-$c1]<0 |
||
| 366 | !increase simpler2 |
||
| 367 | !endif |
||
| 368 | !next p |
||
| 369 | !if $simpler1>0 and $simpler2>0 |
||
| 837 | schaersvoo | 370 | # can the answer be further simplified on variable level? |
| 371 | ex=!record 74 of $remarkdir/commonremarks.$taal |
||
| 372 | testvar=<em>$AAA</em> |
||
| 373 | !if $teaching=1 |
||
| 374 | goback=1 |
||
| 375 | errortext=$ex |
||
| 376 | maxscore=$[$P7*$maxscore] |
||
| 377 | !else |
||
| 378 | # this answer will be wrong !!! no consideration |
||
| 5807 | schaersvoo | 379 | remark$n=$NOK<br />$ex |
| 837 | schaersvoo | 380 | goback=0 |
| 381 | maxscore=0 |
||
| 382 | !endif |
||
| 383 | !exit |
||
| 338 | schaersvoo | 384 | !endif |
| 385 | |||
| 837 | schaersvoo | 386 | # in some cases we can "check" if the correct student answer (a fraction) can be written simpler... |
| 338 | schaersvoo | 387 | !if / isin $AAA and / isin $(answer$n) |
| 388 | a=!replace internal / by , in $AAA |
||
| 389 | at=!itemcnt $a |
||
| 390 | g=!replace internal / by , in $(answer$n) |
||
| 391 | gt=!itemcnt $g |
||
| 392 | !if $at=2 and $gt=2 |
||
| 393 | a1=!item 1 of $a |
||
| 394 | a2=!item 2 of $a |
||
| 395 | g1=!item 1 of $g |
||
| 396 | g2=!item 2 of $g |
||
| 397 | rep1=0 |
||
| 398 | rep2=0 |
||
| 399 | !for p in $varlist |
||
| 400 | !if $p isin $a1 and $p isin $g1 |
||
| 837 | schaersvoo | 401 | a1=!replace internal $p by (10) in $a1 |
| 402 | g1=!replace internal $p by (10) in $g1 |
||
| 338 | schaersvoo | 403 | rep1=1 |
| 404 | !endif |
||
| 405 | !if $p isin $a2 and $p isin $g2 |
||
| 406 | rep2=1 |
||
| 837 | schaersvoo | 407 | a2=!replace internal $p by (11) in $a2 |
| 408 | g2=!replace internal $p by (11) in $g2 |
||
| 338 | schaersvoo | 409 | !endif |
| 410 | !next p |
||
| 411 | !if $rep1=1 and $rep2=1 |
||
| 837 | schaersvoo | 412 | a1=$[abs($a1)] |
| 413 | g1=$[abs($g1)] |
||
| 414 | a2=$[abs($a2)] |
||
| 415 | g2=$[abs($g2)] |
||
| 416 | !if NaN notin $a1$a2$g1$g2 |
||
| 417 | !if $a1 != $g1 or $a2 != $g2 |
||
| 418 | ex=!record 74 of $remarkdir/commonremarks.$taal |
||
| 419 | maxscore=$[$P6*$maxscore] |
||
| 420 | !if $extra=$empty |
||
| 421 | extra=$ex |
||
| 422 | !else |
||
| 5807 | schaersvoo | 423 | extra=!append line $ <br />$ex $ to $extra |
| 837 | schaersvoo | 424 | !endif |
| 425 | !endif |
||
| 338 | schaersvoo | 426 | !endif |
| 427 | !endif |
||
| 837 | schaersvoo | 428 | !else |
| 429 | !if $at > $gt |
||
| 430 | ex=!record 74 of $remarkdir/commonremarks.$taal |
||
| 431 | maxscore=$[$maxscore*$P9] |
||
| 432 | !if $extra=$empty |
||
| 433 | extra=$ex |
||
| 434 | !else |
||
| 5807 | schaersvoo | 435 | extra=!append line $ <br />$ex $ to $extra |
| 837 | schaersvoo | 436 | !endif |
| 437 | !endif |
||
| 338 | schaersvoo | 438 | !endif |
| 439 | !endif |
||
| 837 | schaersvoo | 440 | !endif |
| 441 | |||
| 442 | score=$[(9*$tt+$t3)/10] |
||
| 443 | maxscore=$[$maxscore*$score] |
||
| 444 | modulescore=$[$modulescore + $maxscore] |
||
| 445 | |||
| 1094 | schaersvoo | 446 | !if $maxscore=1 |
| 837 | schaersvoo | 447 | remark$n=$OK |
| 338 | schaersvoo | 448 | !else |
| 1094 | schaersvoo | 449 | !if $maxscore>0.5 |
| 837 | schaersvoo | 450 | remark$n=$BOK |
| 451 | !else |
||
| 452 | remark$n=$NOK |
||
| 338 | schaersvoo | 453 | !endif |
| 837 | schaersvoo | 454 | !endif |
| 455 | |||
| 456 | !if $extra != $empty |
||
| 5807 | schaersvoo | 457 | remark$n=!append line $ <br /> $extra $ to $(remark$n) |
| 338 | schaersvoo | 458 | !endif |
| 459 | goback=0 |
||
| 460 | !exit |