WeBWorK Main Forum

Error with adding string to context after upgrade to WW 2.16

Error with adding string to context after upgrade to WW 2.16

by Bianca Sosnovski -
Number of replies: 1

Hi everyone,

I just updated our WW server from 2.15 to 2.16. My colleague contacted me saying that a problem that worked just fine is now not rendering  by the system. 

Is there anything that changed with the upgrade that would cause the error with the PG code?

I may be wrong but lines 124 and 125 of the code, which are indicated in the error message, don't seem to be needed. So after commenting them, the problem is rendered when seen it individually on a page of the assignment. Though it is still doesn't show in the Hmwk Set Editor view of the instructor.

screenshot

I really would like to know why it is now having issues. Is there anything to be adjusted after the upgrade?

Thank you.

-------

WeBWorK Error

WeBWorK has encountered a software error while attempting to process this problem. It is likely that there is an error in the problem itself. If you are a student, report this error message to your professor to have it corrected. If you are a professor, please consult the error output below for more information.

Error messages

ERRORS from evaluating PG file:
Alias 'R' doesn't exist for string 'All real numbers' at line 124 of (eval 3075)

Error details

        Problem11
1. ERROR caught by Translator while processing problem file:MA119/ES/BeforeTest1Graph1.pg
****************
ERRORS from evaluating PG file: 
Alias 'R' doesn't exist for string 'All real numbers' at line 124 of (eval 3075)
****************
------Input Read 1 ##DESCRIPTION 2 ## Introduction to Functions 3 ## 4 ##ENDDESCRIPTION 5 ## DBsubject(Algebra) 6 ## DBchapter(Functions) 7 ## DBsection(Domain and range) 8 ## Institution(The College of Idaho) 9 ## Author(RA Cruz) 10 ## MLTleader(1) 11 ## MLT(algebra_functions_domain_range_graph_linear) 12 ## Level(2) 13 ## MO(1) 14 ## TitleText1('Essentials of Intermediate Algebra') 15 ## AuthorText1('Blitzer') 16 ## EditionText1('1') 17 ## Section1('2.1') 18 ## Problem1('') 19 ## KEYWORDS('functions') 20 ## Date: 2007/09 updated 2013/08 -rac 21 22 DOCUMENT(); # This should be the first executable line in the problem. 23 24 loadMacros( 25 "PGstandard.pl", 26 "MathObjects.pl", 27 "contextLimitedNumeric.pl", 28 "contextInequalities.pl", 29 "answerHints.pl", 30 "PGgraphmacros.pl", 31 "PGchoicemacros.pl" 32 ); 33 34 TEXT(beginproblem()); 35 36 ###################################### 37 # Setup 38 39 Context("Numeric"); 40 41 #--------Define the function----------- 42 43 @xnum = (random(-5,-3,1),random(3,5,1)); #Stay in the grid 44 @ynum = (random(-5,-3,1),random(3,5,1)); 45 46 $m = ($ynum[1] - $ynum[0])/($xnum[1] - $xnum[0]); 47 $b = $ynum[0] - $m * $xnum[0]; 48 49 $f = Formula("$m * x + $b"); 50 51 @interval = ("[$xnum[0],$xnum[1])","($xnum[0],$xnum[1]]"); 52 $n = random(0,1,1); 53 54 #------------Define the graph----------------------- 55 $refreshCachedImages=1; 56 57 $choose = random(0,2,1); 58 @colors = ("blue", "red", "green"); 59 $rc = $colors[$choose]; #Pick a random color 60 61 $xmin = -6; 62 $ymin = -6; 63 $xmax = 6; 64 $ymax = 6; 65 66 $graph = init_graph($xmin,$ymin,$xmax,$ymax, 67 'axes'=>[0,0],'grid'=>[$xmax-$xmin,$ymax-$ymin]); 68 $graph->lb('reset'); 69 add_functions( $graph,"$f for x in $interval[$n] using color:$rc and weight:3" ); 70 71 $graph->lb( new Label($xmin+1,$ymax-.5, "y = f(x)",'black','center') ); 72 73 $i = 0; # Number the axes 74 do { 75 $xtick = $i + $xmin + 1; 76 if ($xtick!=0) {$graph->lb( new Label($xtick,0, "$xtick",'black','center') );} 77 $i =$i+1; 78 } while ($i<($xmax-$xmin)-1); 79 80 $i = 0; 81 do { 82 $ytick = $i +$ymin + 1; 83 if ($ytick!=0) {$graph->lb( new Label(-.2,$ytick+.1, "$ytick",'black','center') );} 84 $i =$i+1; 85 } while ($i<($ymax-$ymin)-1); 86 87 #------------Pick the points--------------- 88 89 @n = (random($xnum[0]+1,$xnum[1]-1,1), $xnum[$n]); 90 @slice = NchooseK(2,2); 91 @input = @n[@slice]; 92 @answer = ($f->eval(x=>$input[0]), $f->eval(x=>$input[1])); 93 94 ###################################### 95 # Main text 96 # Note: tex_size=>n is for the size on the hardcopy: 600=60% 97 98 BEGIN_TEXT 99 $BCENTER 100 \{ image( insertGraph($graph), 101 width=>400,height=>400,tex_size=>600 ) \} 102 $ECENTER 103 $BR 104 Use the graph of \(y=f(x)\) given above to find: 105 $PAR 106 a) \( f($input[0]) \) = \{ans_rule(10)\} 107 $PAR 108 b) \( f($input[1]) \) = \{ans_rule(10)\} 109 $PAR 110 $BR 111 Write your answers in interval notation 112 $BR 113 c) The domain: \{ans_rule(20)\} 114 $PAR 115 d) The range: \{ans_rule(20)\} 116 END_TEXT 117 118 ###################################### 119 # Answers 120 121 $showPartialCorrectAnswers = 1; 122 123 Context("LimitedNumeric"); 124 Context()->strings->add("No solution"=>{alias=>"DNE"}, 125 "All real numbers"=>{alias=>"R"}); 126 127 #---Part a)-------------------------- 128 $ans_a = Real($answer[0])->with(tolerance=>0.15, tolType=>'absolute'); 129 ANS($ans_a->cmp(ignoreStrings => 1)); 130 131 #---Part b)-------------------------- 132 $ans_b = Real($answer[1])->with(tolerance=>0.15, tolType=>'absolute'); 133 ANS($ans_b->cmp(ignoreStrings => 1)); 134 135 #---Part c)-------------------------- 136 Context("Inequalities"); 137 Context()->variables->add(y=>'Real'); 138 Context()->strings->add("All real numbers"=>{},"R"=>{alias=>"All real numbers"}); 139 140 @domain = ("$xnum[0] <= x < $xnum[1]", "$xnum[0] < x <= $xnum[1]"); 141 $ans_c = Compute($domain[$n]); 142 ANS($ans_c->cmp->withPostFilter(AnswerHints( 143 sub { 144 my ($correct,$student,$ans) = @_; 145 return $student =~ /y/; 146 } => ["Use the variable $BITALIC x $EITALIC for the domain of a function.", 147 checkCorrect => 1, 148 score => 0] 149 ))); 150 151 #---Part d)-------------------------- 152 $ran1 = $f->eval(x=>$xnum[0]); 153 $ran2 = $f->eval(x=>$xnum[1]); 154 if ($ran2<$ran1) { 155 $ran2 = $ran1; 156 $ran1 = $f->eval(x=>$xnum[1]); 157 } 158 @range = ("$ran1 <= y < $ran2", "$ran1 < y <= $ran2"); 159 $ans_d = Compute($range[$n]); 160 ANS($ans_d->cmp->withPostFilter(AnswerHints( 161 sub { 162 my ($correct,$student,$ans) = @_; 163 return $student =~ /x/; 164 } => ["Use the variable $BITALIC y $EITALIC for the range of a function.", 165 checkCorrect => 1, 166 score => 0] 167 ))); 168 169 ###################################### 170 # Solutions 171 172 Context()->texStrings; 173 SOLUTION(EV3(<<'END_SOLUTION')); 174 $PAR SOLUTION $PAR 175 $BR 176 a) \( f($input[0]) = $ans_a\) 177 $BR 178 b) \( f($input[1]) = $ans_b \) 179 $BR 180 c) The domain: \($ans_c\) 181 $BR 182 d) The range: \($ans_d\) 183 END_SOLUTION 184 Context()->normalStrings; 185 186 187 ; 188 ENDDOCUMENT();

In reply to Bianca Sosnovski

Re: Error with adding string to context after upgrade to WW 2.16

by Davide Cervone -
Is there anything that changed with the upgrade that would cause the error with the PG code?

Yes. The Context now checks that an alias points to an exiting entry in the context and provides a warning if not (the warning you are seeing). Note that the R constant is only defined in the Interval context (and related ones), but the alias to it is being made in the LImitedNumeric context. It does not exist in that context, which leads to the error you are seeing. And even if you were in the Interval context, this still would not work, since the R in that context is a constant (tied to the interval (-infinity, infinity)), not a string, so your problem would still generate this error.

In the LimitedNumeric context, you could do

Context()->strings->add("All Real Numbers" => {}, R => {alias => "All Real Numbers"});
which would resolve the problem, and would show R as All Real Numbers in student and correct answers.

This is what is done for the Inequalities context for answers (c) and (d). Unfortunately, it is not correct there, since R is already defined as a constant, so you are generating a second definition for the string (it does override the earlier definition in this case). But you don't really want R to be a string in this case, as R can be used in expressions like R - {0}, which will cause an error if you redefine R in this way.

Instead, you should make All Real Numbers be a *constant* not a string. Unfortunately, constant don't usually allow spaces in their names, so you would need to modify the name pattern first:

Context("Inequalities");
Context()->constants->{namePattern} = qr/.+/;   # allow anything as a name
Context()->constants->add("All Real Numbers" => {alias => "R"});

Note that the problem says you are to use interval notation (like [1,infinity)), but the problem's answer hints filters require the answer to use inequalities, not intervals, which could cause confusion. Also, the context you are using allows interval notation to be entered, but then marks it incorrect since it is not an inequality. You might consider using the Inequalities-Only context instead, which will give a better error message when intervals are used. Of course, you should reword the problem to indicate the inequalities are to be used, not intervals.

The Inequalities-Only context does not have R defined, so you would need to use

Context()->strings->add("All Real Numbers" => {}, R => {alias => "All Real Numbers"});
again in this case.