[LON-CAPA-cvs] cvs: rat / lonuserstate.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Fri, 05 May 2006 15:50:21 -0000
albertel Fri May 5 11:50:21 2006 EDT
Modified files:
/rat lonuserstate.pm
Log:
- expression factoring was not correctly testing for the second test to succeed and get a valid subexpression
Index: rat/lonuserstate.pm
diff -u rat/lonuserstate.pm:1.108 rat/lonuserstate.pm:1.109
--- rat/lonuserstate.pm:1.108 Thu Apr 27 19:36:10 2006
+++ rat/lonuserstate.pm Fri May 5 11:50:20 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Construct and maintain state and binary representation of course for user
#
-# $Id: lonuserstate.pm,v 1.108 2006/04/27 23:36:10 albertel Exp $
+# $Id: lonuserstate.pm,v 1.109 2006/05/05 15:50:20 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -413,16 +413,18 @@
foreach my $key (keys(%hash)) {
if ($key=~/^conditions/) {
my $expr=$hash{$key};
+ # try to find and factor out common sub-expressions
foreach my $sub ($expr=~m/(\(\([_\.\d]+(?:\&[_\.\d]+)+\)(?:\|\([_\.\d]+(?:\&[_\.\d]+)+\))+\))/g) {
my $orig=$sub;
- $sub=~/\(\(([_\.\d]+\&(:?[_\.\d]+\&)*)(?:[_\.\d]+\&*)+\)(?:\|\(\1(?:[_\.\d]+\&*)+\))+\)/;
- my $factor=$1;
- $sub=~s/$factor//g;
+
+ my ($factor) = ($sub=~/\(\(([_\.\d]+\&(:?[_\.\d]+\&)*)(?:[_\.\d]+\&*)+\)(?:\|\(\1(?:[_\.\d]+\&*)+\))+\)/);
+ next if (!defined($factor));
+
+ $sub=~s/\Q$factor\E//g;
$sub=~s/^\(/\($factor\(/;
$sub.=')';
$sub=simplify($sub);
- $orig=~s/(\W)/\\$1/g;
- $expr=~s/$orig/$sub/;
+ $expr=~s/\Q$orig\E/$sub/;
}
$hash{$key}=$expr;
unless (defined($captured{$expr})) {