--- loncom/homework/default_homework.lcpm 2005/11/16 23:17:39 1.105 +++ loncom/homework/default_homework.lcpm 2006/06/30 21:24:27 1.108 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run() # -# $Id: default_homework.lcpm,v 1.105 2005/11/16 23:17:39 albertel Exp $ +# $Id: default_homework.lcpm,v 1.108 2006/06/30 21:24:27 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -117,10 +117,11 @@ sub caparesponse_check { if ( $answer eq ($answer *1.0)) { $type = 2; } else { $type = 3; } } else { - if ($type eq 'cs') { $type = 4; } + if ($type eq 'cs') { $type = 4; } elsif ($type eq 'ci') { $type = 3 } elsif ($type eq 'mc') { $type = 5; } elsif ($type eq 'fml') { $type = 8; } + elsif ($type eq 'math') { $type = 9; } elsif ($type eq 'subj') { $type = 7; } elsif ($type eq 'float') { $type = 2; } elsif ($type eq 'int') { $type = 1; } @@ -149,13 +150,17 @@ sub caparesponse_check { ($sig_ubound,$sig_lbound)=&LONCAPA_INTERNAL_get_sigrange($sig); my $reterror=""; - my $result = &caparesponse_capa_check_answer($response,$answer,$type, + my $result; + if ($type eq '9') { + $result = &maxima_check(&maxima_cas_formula_fix($response),&maxima_cas_formula_fix($answer),\$reterror); + } else { + $result = &caparesponse_capa_check_answer(&capa_formula_fix($response),&capa_formula_fix($answer),$type, $tol_type,$tol, $sig_lbound,$sig_ubound, $ans_fmt,$unit,$calc,$id_list, $points,$external::randomseed, \$reterror); - + } if ($result == '1') { $result='EXACT_ANS'; } elsif ($result == '2') { $result='APPROX_ANS'; } elsif ($result == '3') { $result='SIG_FAIL'; } @@ -179,6 +184,23 @@ sub caparesponse_check { return ("$result:\nRetError $reterror:\nAnswer $answer:\nResponse $response:\n type-$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$unit|\n$message",$reterror); } +sub maxima_cas_formula_fix { + my ($expression)=@_; + return &implicit_multiplication($expression); +} + +sub capa_formula_fix { + my ($expression)=@_; + return &implicit_multiplication($expression); +} + +sub implicit_multiplication { + my ($expression)=@_; + $expression=~s/\s+/\*/g; + $expression=~s/(\d)([a-zA-Z\(])/$1\*$2/g; + $expression=~s/\)(\w)/\)\*$1/g; + return $expression; +} sub caparesponse_check_list { my $response=$LONCAPA::CAPAresponse_args{'response'}; @@ -210,7 +232,7 @@ sub caparesponse_check_list { $result.="Final final response :$responselist['-1']:$unit:\n"; $unit=~s/\s//; - my ($awards, @msgs); + my ($awards, @msgs, $i); foreach my $thisanswer (@LONCAPA::CAPAresponse_answer) { my ($msg,$aresult); $result.="trying answer :$thisanswer:\n"; @@ -231,6 +253,7 @@ sub caparesponse_check_list { $awards.="$temp,"; $result.=$aresult; push(@msgs,$msg); + $i++; } chop($awards); return ("$awards:\n$result",@msgs);