Skip to content

Commit

Permalink
Merge pull request #408 from openwebwork/PG-2.15
Browse files Browse the repository at this point in the history
PG-2.15
  • Loading branch information
mgage authored Oct 6, 2019
2 parents dfef4c6 + 0d73e68 commit cc7277d
Show file tree
Hide file tree
Showing 57 changed files with 31,520 additions and 1,041 deletions.
4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$PG_VERSION ='PG-2.14';
$PG_COPYRIGHT_YEARS = '1996-2018';
$PG_VERSION ='2.15';
$PG_COPYRIGHT_YEARS = '1996-2019';

1;
26 changes: 13 additions & 13 deletions lib/AnswerHash.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
manipulation methods. More of these may be added as it
becomes necessary.
Useage: $rh_ans = new AnswerHash;
Usage: $rh_ans = new AnswerHash;
AnswerEvaluator -- this class organizes the construction of
answer evaluator subroutines which check the
Expand All @@ -37,7 +37,7 @@
thus greatly reducing the programming and maintenance
required for constructing answer evaluators.
Useage: $ans_eval = new AnswerEvaluator;
Usage: $ans_eval = new AnswerEvaluator;
=cut

Expand Down Expand Up @@ -203,14 +203,14 @@ sub setKeys {

=head4 data
Useage: $rh_ans->data('foo'); set $rh_ans->{student_ans} = 'foo';
Usage: $rh_ans->data('foo'); set $rh_ans->{student_ans} = 'foo';
$student_input = $rh_ans->data(); retrieve value of $rh_ans->{student_ans}
synonym for input
=head4 input
Useage: $rh_ans->input('foo') sets $rh_ans->{student_ans} = 'foo';
Usage: $rh_ans->input('foo') sets $rh_ans->{student_ans} = 'foo';
$student_input = $rh_ans->input();
synonym for data
Expand All @@ -231,7 +231,7 @@ sub input { #$rh_ans->input('foo') is a synonym for $rh_ans->{student_ans}='

=head4 input
Useage: $rh_ans->score(1)
Usage: $rh_ans->score(1)
$score = $rh_ans->score();
Retrieve or set $rh_ans->{score}, the student's score on the problem.
Expand Down Expand Up @@ -266,7 +266,7 @@ sub stringify_hash {

=head4 throw_error
Useage: $rh_ans->throw_error("FLAG", "message");
Usage: $rh_ans->throw_error("FLAG", "message");
FLAG is a distinctive word that describes the type of error.
Examples are EVAL for an evaluation error or "SYNTAX" for a syntax error.
Expand All @@ -279,7 +279,7 @@ sub stringify_hash {
=head4 catch_error
Useage: $rh_ans->catch_error("FLAG2");
Usage: $rh_ans->catch_error("FLAG2");
Returns true (1) if $rh_ans->{error_flag} equals "FLAG2", otherwise it returns
false (empty string).
Expand All @@ -288,7 +288,7 @@ sub stringify_hash {
=head4 clear_error
Useage: $rh_ans->clear_error("FLAG2");
Usage: $rh_ans->clear_error("FLAG2");
If $rh_ans->{error_flag} equals "FLAG2" then the {error_flag} entry is set to
the empty string as is the entry {error_message}
Expand All @@ -297,7 +297,7 @@ sub stringify_hash {
=head4 error_message
Useage: $flag = $rh_ans -> error_flag();
Usage: $flag = $rh_ans -> error_flag();
$message = $rh_ans -> error_message();
Expand Down Expand Up @@ -352,7 +352,7 @@ sub error_message {
# =head4 pretty_print
#
#
# Useage: $rh_ans -> pretty_print();
# Usage: $rh_ans -> pretty_print();
#
#
# Returns a string containing a representation of the AnswerHash as an HTML table.
Expand Down Expand Up @@ -396,7 +396,7 @@ sub error_message {

=head4 OR
Useage: $rh_ans->OR($rh_ans2);
Usage: $rh_ans->OR($rh_ans2);
Returns a new AnswerHash whose score is the maximum of the scores in $rh_ans and $rh_ans2.
The correct answers for the two hashes are combined with "OR".
Expand All @@ -408,7 +408,7 @@ sub error_message {
=head4 AND
Useage: $rh_ans->AND($rh_ans2);
Usage: $rh_ans->AND($rh_ans2);
Returns a new AnswerHash whose score is the minimum of the scores in $rh_ans and $rh_ans2.
The correct answers for the two hashes are combined with "AND".
Expand Down Expand Up @@ -817,7 +817,7 @@ sub rh_ans {
A filter is a subroutine which takes one AnswerHash as an input, followed by
a hash of options.
Useage: filter($ans_hash, option1 =>value1, option2=> value2 );
Usage: filter($ans_hash, option1 =>value1, option2=> value2 );
The filter performs some operations on the input AnswerHash and returns an
Expand Down
7 changes: 3 additions & 4 deletions lib/Matrix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,8 @@ sub new_from_col_vecs

sub cp { # MEG makes new copies of complex number
my $z = shift;
return $z unless ref($z);
my $w = Complex1::cplx($z->Re,$z->Im);
return $w;
return $z unless ref($z) eq 'Complex1';
Complex1::cplx($z->Re,$z->Im);
}

=head4
Expand Down Expand Up @@ -600,4 +599,4 @@ sub decompose_LR



1;
1;
4 changes: 3 additions & 1 deletion lib/PGalias.pm
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ sub initialize {
$self->{externalGif2PngPath} = $envir->{externalGif2PngPath};
$self->{courseID} = $envir->{courseName};
$self->{problemSeed} = $envir->{problemSeed};
$self->{problemUUID} = $envir->{problemUUID}//0;

$self->{appletPath} = $self->{envir}->{pgDirectories}->{appletPath};
#
Expand All @@ -117,7 +118,8 @@ sub initialize {
$self->{courseID},
'set'.$self->{setNumber},
'prob'.$self->{probNum},
$self->{problemSeed}
$self->{problemSeed},
$self->{problemUUID},
);

##################################
Expand Down
8 changes: 6 additions & 2 deletions lib/PGcore.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ use Tie::IxHash;
use WeBWorK::Debug;
use MIME::Base64();
use PGUtil();

use Encode qw(encode_utf8 decode_utf8);
use utf8;
binmode(STDOUT, ":utf8");
##################################
# PGcore object
##################################
Expand Down Expand Up @@ -565,13 +567,15 @@ sub PG_restricted_eval {
sub decode_base64 ($) {
my $self = shift;
my $str = shift;
MIME::Base64::decode_base64($str);
$str = MIME::Base64::decode_base64($str);
decode_utf8($str);
}

sub encode_base64 ($;$) {
my $self = shift;
my $str = shift;
my $option = shift;
$str = encode_utf8($str);
MIME::Base64::encode_base64($str);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/PGloadfiles.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ our $debugON =0;

package PGloadfiles;
use strict;
#use Encode(qw(encode decode));
use Exporter;
use PGcore;
use WeBWorK::PG::Translator;
Expand Down Expand Up @@ -232,8 +233,9 @@ sub compile_file {
local($/);
$/ = undef; # allows us to treat the file as a single line

open(MACROFILE, "<$filePath") || die "Cannot open file: $filePath";
open(MACROFILE, "<:raw", $filePath) || die "Cannot open file: $filePath";
my $string = 'BEGIN {push @__eval__, __FILE__};' . "\n" . <MACROFILE>;
utf8::decode($string); # can't yet use :encoding(UTF-8)
#warn "compiling $string";
my ($result,$error,$fullerror) = $self->PG_macro_file_eval($string);
eval ('$main::__files__->{pop @main::__eval__} = $filePath'); #used to keep track of which file is being evaluated.
Expand Down
4 changes: 2 additions & 2 deletions lib/Parser/Context/Default.pm
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ $functions = {
'asinh' => {class => 'Parser::Function::hyperbolic', TeX => '\sinh^{-1}'},
'acosh' => {class => 'Parser::Function::hyperbolic', TeX => '\cosh^{-1}'},
'atanh' => {class => 'Parser::Function::hyperbolic', TeX => '\tanh^{-1}'},
'asech' => {class => 'Parser::Function::hyperbolic', TeX => '\mathop{\rm sech}^{-1}'},
'acsch' => {class => 'Parser::Function::hyperbolic', TeX => '\mathop{\rm csch}^{-1}'},
'asech' => {class => 'Parser::Function::hyperbolic', TeX => '\mathop{\rm sech}\nolimits^{-1}'},
'acsch' => {class => 'Parser::Function::hyperbolic', TeX => '\mathop{\rm csch}\nolimits^{-1}'},
'acoth' => {class => 'Parser::Function::hyperbolic', TeX => '\coth^{-1}'},

'ln' => {class => 'Parser::Function::numeric', inverse => 'exp',
Expand Down
2 changes: 1 addition & 1 deletion lib/Parser/Function.pm
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ sub TeX {
my @pstr = (); my $fn_precedence = $fn->{precedence};
$fn_precedence = $fn->{parenPrecedence} if $fn->{parenPrecedence};
$fn = $self->{def};
my $name = '\mathop{\rm '.$self->{name}.'}';
my $name = '\mathop{\rm '.$self->{name}.'}\nolimits';
$name = $fn->{TeX} if defined($fn->{TeX});
foreach my $x (@{$self->{params}}) {push(@pstr,$x->TeX)}
if ($fn->{braceTeX}) {$TeX = $name.'{'.join(',',@pstr).'}'}
Expand Down
20 changes: 19 additions & 1 deletion lib/Units.pm
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ our %known_units = ('m' => {
'factor' => 86400,
's' => 1
},
'month' => {
'factor' => 60*60*24*30,
's' => 1
},
'months' => {
'factor' => 60*60*24*30,
's' => 1
},
'mo' => {
'factor' => 60*60*24*30,
's' => 1
},
'yr' => {
'factor' => 31557600,
's' => 1
Expand Down Expand Up @@ -283,7 +295,7 @@ our %known_units = ('m' => {
'm' => 1
},
'parsec' => {
'factor' => 30.857E15,
'factor' => 3.08567758149137E16, #30.857E15,
'm' => 1
},
# VOLUME
Expand Down Expand Up @@ -441,6 +453,12 @@ our %known_units = ('m' => {
'kg' => 1,
's' => -2
},
'lbs' => {
'factor' => 4.4482216152605,
'm' => 1,
'kg' => 1,
's' => -2
},
'ton' => {
'factor' => 8900,
'm' => 1,
Expand Down
17 changes: 11 additions & 6 deletions lib/Value/Matrix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ sub numberMatrix { #internal
my @M = (); my $isFormula = 0;
foreach my $x (@_) {
$x = Value::makeValue($x,context=>$context);
Value::Error("Matrix row entries must be numbers") unless Value::isNumber($x);
Value::Error("Matrix row entries must be numbers: $x ") unless _isNumber($x);
push(@M,$x); $isFormula = 1 if Value::isFormula($x);
}
return $self->formula([@M]) if $isFormula;
Expand Down Expand Up @@ -249,7 +249,7 @@ sub isRow {
}

#
# See if the matrix is an Indenity matrix
# See if the matrix is an Identity matrix
#
sub isOne {
my $self = shift;
Expand All @@ -275,6 +275,11 @@ sub isZero {
return 1;
}

sub _isNumber {
my $n = shift;
return Value::isNumber($n) || Value::classMatch($n, 'Fraction');
}

#
# Make arbitrary data into a matrix, if possible
#
Expand Down Expand Up @@ -327,7 +332,7 @@ sub mult {
#
# Constant multiplication
#
if (Value::isNumber($r)) {
if (_isNumber($r)) {
my @coords = ();
foreach my $x (@{$l->data}) {push(@coords,$x*$r)}
return $self->make(@coords);
Expand Down Expand Up @@ -365,7 +370,7 @@ sub mult {
sub div {
my ($l,$r,$flag) = @_; my $self = $l;
Value::Error("Can't divide by a Matrix") if $flag;
Value::Error("Matrices can only be divided by Numbers") unless Value::isNumber($r);
Value::Error("Matrices can only be divided by Numbers") unless _isNumber($r);
Value::Error("Division by zero") if $r == 0;
my @coords = ();
foreach my $x (@{$l->data}) {push(@coords,$x/$r)}
Expand All @@ -377,11 +382,11 @@ sub power {
Value::Error("Can't use Matrices in exponents") if $flag;
Value::Error("Only square matrices can be raised to a power") unless $l->isSquare;
$r = Value::makeValue($r,context=>$context);
if ($r->isNumber && $r =~ m/^-\d+$/) {
if (_isNumber($r) && $r =~ m/^-\d+$/) {
$l = $l->inverse; $r = -$r;
$self->Error("Matrix is not invertible") unless defined($l);
}
Value::Error("Matrix powers must be non-negative integers") unless $r->isNumber && $r =~ m/^\d+$/;
Value::Error("Matrix powers must be non-negative integers") unless _isNumber($r) && $r =~ m/^\d+$/;
return $context->Package("Matrix")->I($l->length,$context) if $r == 0;
my $M = $l; foreach my $i (2..$r) {$M = $M*$l}
return $M;
Expand Down
24 changes: 23 additions & 1 deletion lib/Value/String.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ sub new {
return $s;
}

sub make {
my $self = shift;
my $s = $self->SUPER::make(@_);
my $def = $self->context->strings->get($s->{data}[0]);
$s->{caseSensitive} = 1 if $def->{caseSensitive};
return $s;
}

#
# Return the appropriate data.
#
Expand Down Expand Up @@ -72,7 +80,21 @@ sub compare {
#
# Mark a string to be display verbatim
#
sub verb {shift; return "\\verb".chr(0x85).(shift).chr(0x85)}
sub verb {
shift;
my $s = shift;
$s =~ s/\r/ /g;
# different verbatim delimiters because in general 0xD would be nicest,
# but browsers want to change that to 0xA
# eval() needed because this .pm file loaded outside the safe compartment,
# and eval() runs it inside the safe compartment, where problem context is in place.
my $d = eval ('main::MODES(HTML => chr(0x1F), TeX => chr(0xD), PTX=> chr(0xD))');
return "{\\verb$d$s$d}";
# Note this does not handle \n in the input string
# A future effort to address that should concurrently
# handle it similarly for HTML output.
# And something similar should be done for the ArbitraryString context
}

#
# Put normal strings into \text{} and others into \verb
Expand Down
2 changes: 1 addition & 1 deletion lib/Value/Union.pm
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ sub reduce {
foreach my $x ($self->value) {
if ($x->type eq 'Set') {push(@singletons,$x->value)}
elsif ($x->{data}[0] == $x->{data}[1]) {push(@singletons,$x->{data}[0])}
else {push(@intervals,$x->copy)}
else {push(@intervals,$x->inherit)}
}
my @union = (); my @set = (); my $prevX;
@intervals = (CORE::sort {$a <=> $b} @intervals);
Expand Down
Loading

0 comments on commit cc7277d

Please sign in to comment.