[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm lonmaxima.pm response.pm /homework/caparesponse caparesponse.pm
www
lon-capa-cvs@mail.lon-capa.org
Fri, 15 Dec 2006 22:11:46 -0000
www Fri Dec 15 17:11:46 2006 EDT
Modified files:
/loncom/homework default_homework.lcpm lonmaxima.pm response.pm
/loncom/homework/caparesponse caparesponse.pm
Log:
Make formula fix work with <mathresponse>
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.122 loncom/homework/default_homework.lcpm:1.123
--- loncom/homework/default_homework.lcpm:1.122 Fri Dec 15 16:15:42 2006
+++ loncom/homework/default_homework.lcpm Fri Dec 15 17:11:43 2006
@@ -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.122 2006/12/15 21:15:42 www Exp $
+# $Id: default_homework.lcpm,v 1.123 2006/12/15 22:11:43 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -256,38 +256,6 @@
return ($result,$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)=@_;
-# Escape scientific notation, so 3e8 does not become 3*e*8
-# 3e8 -> 3&8; 3e-8 -> 3&-8; 3E+8 -> e&+8
- $expression=~s/(\d+)e([\+\-]*\d+)/$1\&\($2\)/gsi;
-# 3x10^8 -> 3&8; 3*10^-8 -> 3&-8
- $expression=~s/(\d+)(?:x|\*)10(?:\^|\*\*)([\+\-]*\d+)/$1\&\($2\)/gsi;
-# Fill in multiplication signs
-# a b -> a*b;3 b -> 3*b;3 4 -> 3*4
- $expression=~s/(\w)\s+(\w)/$1\*$2/gs;
-# )( -> )*(; ) ( -> )*(
- $expression=~s/\)\s*\(/\)\*\(/gs;
-# 3a -> 3*a; 3( -> 3*(; 3 ( -> 3*(; 3A -> 3*A
- $expression=~s/(\d)\s*([a-zA-Z\(])/$1\*$2/gs;
-# a ( -> a*(
- $expression=~s/(\w)\s+\(/$1\*\(/gs;
-# )a -> )*a; )3 -> )*3; ) 3 -> )*3
- $expression=~s/\)\s*(\w)/\)\*$1/gs;
-# 3&8 -> 3e8; 3&-4 -> 3e-4
- $expression=~s/(\d+)\&\(([\+\-]*\d+)\)/$1e$2/gs;
- return $expression;
-}
sub caparesponse_check_list {
my $responses=$LONCAPA::CAPAresponse_args{'response'};
Index: loncom/homework/lonmaxima.pm
diff -u loncom/homework/lonmaxima.pm:1.8 loncom/homework/lonmaxima.pm:1.9
--- loncom/homework/lonmaxima.pm:1.8 Fri Dec 15 16:10:13 2006
+++ loncom/homework/lonmaxima.pm Fri Dec 15 17:11:43 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Interface routines to MAXIMA CAS
#
-# $Id: lonmaxima.pm,v 1.8 2006/12/15 21:10:13 www Exp $
+# $Id: lonmaxima.pm,v 1.9 2006/12/15 22:11:43 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,6 +31,7 @@
use strict;
use IO::Socket;
use Apache::lonnet;
+use Apache::response();
use LONCAPA;
sub connect {
@@ -78,13 +79,18 @@
return $reply;
}
+sub maxima_cas_formula_fix {
+ my ($expression)=@_;
+ return &Apache::response::implicit_multiplication($expression);
+}
+
sub maxima_run {
my ($script,$submission,$argument) = @_;
my $socket=&connect();
my $fullscript='';
my $submission_index=1;
foreach my $submission_component (split(/\s*\,\s*/,$submission)) {
- $fullscript.="RESPONSE[$submission_index]:$submission_component;\n";
+ $fullscript.="RESPONSE[$submission_index]:".&maxima_cas_formula_fix($submission_component).";\n";
$submission_index++;
}
my $argument_index=1;
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.155 loncom/homework/response.pm:1.156
--- loncom/homework/response.pm:1.155 Fri Dec 15 16:10:13 2006
+++ loncom/homework/response.pm Fri Dec 15 17:11:43 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# various response type definitons response definition
#
-# $Id: response.pm,v 1.155 2006/12/15 21:10:13 www Exp $
+# $Id: response.pm,v 1.156 2006/12/15 22:11:43 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -535,6 +535,28 @@
return $result;
}
+sub implicit_multiplication {
+ my ($expression)=@_;
+# Escape scientific notation, so 3e8 does not become 3*e*8
+# 3e8 -> 3&8; 3e-8 -> 3&-8; 3E+8 -> e&+8
+ $expression=~s/(\d+)e([\+\-]*\d+)/$1\&\($2\)/gsi;
+# 3x10^8 -> 3&8; 3*10^-8 -> 3&-8
+ $expression=~s/(\d+)(?:x|\*)10(?:\^|\*\*)([\+\-]*\d+)/$1\&\($2\)/gsi;
+# Fill in multiplication signs
+# a b -> a*b;3 b -> 3*b;3 4 -> 3*4
+ $expression=~s/(\w)\s+(\w)/$1\*$2/gs;
+# )( -> )*(; ) ( -> )*(
+ $expression=~s/\)\s*\(/\)\*\(/gs;
+# 3a -> 3*a; 3( -> 3*(; 3 ( -> 3*(; 3A -> 3*A
+ $expression=~s/(\d)\s*([a-zA-Z\(])/$1\*$2/gs;
+# a ( -> a*(
+ $expression=~s/(\w)\s+\(/$1\*\(/gs;
+# )a -> )*a; )3 -> )*3; ) 3 -> )*3
+ $expression=~s/\)\s*(\w)/\)\*$1/gs;
+# 3&8 -> 3e8; 3&-4 -> 3e-4
+ $expression=~s/(\d+)\&\(([\+\-]*\d+)\)/$1e$2/gs;
+ return $expression;
+}
sub start_answer {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.201 loncom/homework/caparesponse/caparesponse.pm:1.202
--- loncom/homework/caparesponse/caparesponse.pm:1.201 Wed Dec 13 23:59:51 2006
+++ loncom/homework/caparesponse/caparesponse.pm Fri Dec 15 17:11:43 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# caparesponse definition
#
-# $Id: caparesponse.pm,v 1.201 2006/12/14 04:59:51 albertel Exp $
+# $Id: caparesponse.pm,v 1.202 2006/12/15 22:11:43 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -33,6 +33,7 @@
use Apache::lonmaxima();
use Apache::lonlocal;
use Apache::lonnet;
+use Apache::response();
use Storable qw(dclone);
BEGIN {
@@ -372,6 +373,11 @@
}
}
+sub capa_formula_fix {
+ my ($expression)=@_;
+ return &Apache::response::implicit_multiplication($expression);
+}
+
sub end_numericalresponse {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $increment=1;
@@ -385,6 +391,8 @@
my $safehole = new Safe::Hole;
$safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
$safehole->wrap(\&Apache::lonmaxima::maxima_check,$safeeval,'&maxima_check');
+ $safehole->wrap(\&Apache::lonmaxima::maxima_cas_formula_fix,$safeeval,'&maxima_cas_formula_fix');
+ $safehole->wrap(\&capa_formula_fix,$safeeval,'&capa_formula_fix');
if (scalar(@$tagstack)) { $tag=$$tagstack[-1]; }
if ( $target eq 'grade' && &Apache::response::submitted() ) {