WeBWorK Problems

Error: you can only use '/' between (non-negative) integers

Error: you can only use '/' between (non-negative) integers

by Lukas Fredriksson -
Number of replies: 2

Hi, in one of my problems I get an error code saying that / can only be used between (non-negative) integers, code listed below with error message as well.
It throws an error when the variable I at row 22 is negative and is used in division on row 38 and 50. I've tried doing abs() and there is no error.

This problem started occurring after we upgraded from 2.15 to 2.17, tried it on a system with 2.15 installed and got no errors. There seems to be something wrong with pg on my system but it's the latest version and 'npm install' does what it's supposed to do.

This problem is rather old, is there anything deprecated in how we load the macros and/or what macros we use?

1 DOCUMENT(); 2 3 # Load whatever macros you need for the problem 4 loadMacros("PG.pl", 5 "PGbasicmacros.pl", 6 "PGchoicemacros.pl", 7 "PGanswermacros.pl", 8 "PGauxiliaryFunctions.pl", 9 "PGgraphmacros.pl", 10 ); 11 12 install_problem_grader(~~&std_problem_grader); 13 14 $A=random(2,6,1); 15 $B=random(2,10,4); 16 $C=random(2,6,1); 17 $D=random(3,11,4); 18 $E=random(2,6,1); 19 $F=random(2,6,1); 20 $G=$A*$B*$E+$C*$D*$F; 21 $H=$A*$F+$C*$E; 22 $I=$E**2*$B-$F**2*$D; 23 $J=$B*$D; 24 25 BEGIN_TEXT 26 $I 27 Skriv uttrycket \(\frac{$A\sqrt{$B}-$C\sqrt{$D}}{$E\sqrt{$B}+$F\sqrt{$D}}\) 28 på formen \(K+L\sqrt{$J}\), där \(K\) och \(L\) är rationella tal. 29 30 $PAR 31 32 \( K = \) \{ans_rule(20) \} 33 34 END_TEXT 35 36 $gcd =gcd($G,$I); 37 $G2=$G/$gcd; 38 $I2=$I/$gcd; 39 $ans = "$G2/$I2"; 40 &ANS(num_cmp($ans,mode=>'frac')); 41 42 BEGIN_TEXT 43 44 \( L = \) \{ans_rule(20) \} 45 46 END_TEXT 47 48 $gcd2 =gcd($H,$I); 49 $H2=$H/$gcd2; 50 $I2=$I/$gcd2; 51 $ans = "-$H2/$I2"; 52 &ANS(num_cmp($ans,mode=>'frac')); 53 54 ENDDOCUMENT();
1. ERROR caught by Translator while processing problem file:tmpEdit/talR1.pg
ERRORS from evaluating PG file: 
You can only use '/' between (non-negative) integers; see position 3 of formula at line 419 of [PG]/macros/PGnumericevaluators.pl Died within main::NUM_CMP called at line 419 of [PG]/macros/PGnumericevaluators.pl from within main::num_cmp called at line 40 of (eval 986)

In reply to Lukas Fredriksson

Re: Error: you can only use '/' between (non-negative) integers

by Danny Glin -
I can't specifically say if something changed between 2.15 and 2.17, but it looks like the "mode=>'frac'" option doesn't allow division by a negative number. It appears that that option may no longer do what was originally intended, since even with it set I can enter a decimal as an answer, and the correct answer is shown as a decimal.

num_cmp and its relatives are legacy methods which are not being actively maintained, so it's not surprising that things are not behaving entirely as expected. Here is some documentation on more recent methods for fraction answers, though this is still a little outdated since it does not use PGML.
In reply to Danny Glin

Re: Error: you can only use '/' between (non-negative) integers

by Lukas Fredriksson -

You are correct that removing "mode=>'frac'" actually solved this issue.

We have a lot of old problems that may or may not end up causing issues and it would take a very long time to rewrite / check them all. Do you know if there is any way to test if the problem is working from the terminal? If so, I could just let it run through all our problems (on a test server) with different seeds to see if any of our problems need updating.