--- rat/lonuserstate.pm 2006/04/27 23:36:10 1.108 +++ rat/lonuserstate.pm 2006/05/05 15:50:20 1.109 @@ -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 @@ sub accinit { 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})) {