WeBWorK Problems

context::Fraction::Real

context::Fraction::Real

by Bruce Yoshiwara -
Number of replies: 4
I'm trying to have students reduce a rational expression in two variables.

The CofIdaho RationalExpEvaluator seems to work OK, but I get error messages when I select the "Show correct answers" box and check answers, whether or not I have input correct answers.

Code:
...

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"contextFraction.pl",
"CofIdaho_macros.pl",
);

$ans8 = Compute("(-b^2)/(5a)");
ANS(RationalExpEvaluator($ans8,["a","b"]));

------------
and I get the warning:

Error messages

Can't locate object method "make" via package "context::Fraction::Real" (perhaps you forgot to load "context::Fraction::Real"?) at /opt/webwork/pg/lib/Parser/Number.pm line 66.
Call stack

The information below can help locate the source of the problem.

in Parser::Number::string called at line 287 of /opt/webwork/pg/lib/Parser/BOP.pm
in Parser::BOP::string called at line 189 of /opt/webwork/pg/lib/Parser/UOP.pm
in Parser::UOP::string called at line 287 of /opt/webwork/pg/lib/Parser/BOP.pm
in Parser::BOP::string called at line 670 of /opt/webwork/pg/lib/Parser.pm
in Parser::string called at line 921 of /opt/webwork/pg/lib/Value.pm
in Value::stringify called at line 1844 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator.pm
in WeBWorK::ContentGenerator::nbsp called at line 264 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm
in WeBWorK::ContentGenerator::Problem::attemptResults called at line 975 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm
in WeBWorK::ContentGenerator::Problem::body called at line 152 of /opt/webwork/webwork2/lib/WeBWorK/Template.pm
in WeBWorK::Template::template called at line 491 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator.pm
in WeBWorK::ContentGenerator::content called at line 195 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator.pm
in WeBWorK::ContentGenerator::go called at line 353 of /opt/webwork/webwork2/lib/WeBWorK.pm
Request information

Method POST
URI /webwork2/pierce_math115/Lesson08.1SkillsA/4/
HTTP Headers
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.3
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1036 Safari/532.5
Accept application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Connection keep-alive
Referer http://www.xyzhomework.com/webwork2/pierce_math115/Lesson08.1SkillsA/4/?effectiveUser=yoshiwbw&displayMode=images&editMode=savedFile&edit_level=0&status_message=%3Cdiv%20class%3D%22ResultsWithoutError%22%3ESaved%20to%20file%20'%5BTMPL%5D%2FsetModLesson08.1SkillsA%2FProblems7-12.pg'.%3C%2Fdiv%3E&key=2t7AVdavzqVyX9TdWK5wwUGHkSjqex4l&sourceFilePath=setModLesson08.1SkillsA/Problems7-12.pg&user=yoshiwbw&problemSeed=2214
Content-Length 2336
Accept-Encoding gzip,deflate,sdch
Origin http://www.xyzhomework.com
Cache-Control max-age=0
Content-Type multipart/form-data; boundary=----WebKitFormBoundaryRQoQU4RYxtMXLXsK
Accept-Language en-US,en;q=0.8
Host www.xyzhomework.com

Any suggestions?
Thanks.
Bruce
In reply to Bruce Yoshiwara

Re: context::Fraction::Real

by Robin Cruz -

Hi, Bruce,

I used the code you sent in a test problem and cannot get the error you describe.  I'm thinking that the problem is that the RationalExpEvaluator macro was not written explicitly to work with MathObjects.  This is something I plan to change this summer, but that doesn't help you now.  Did you change the context in the problem?  Would you send me more of the problem's code so that I can run exactly what you are running?

--rac

In reply to Robin Cruz

Re: context::Fraction::Real

by Bruce Yoshiwara -
OK, the code is included below (including stuff I know is extraneous).

When I input the correct answer, WeBWorK marks it as correct. Only when I ask to "Show Correct Answers" do I get the error messages. (And I get the warnings on two different WeBWorK servers: Rochester and xyzhomework.com.)

##DESCRIPTION
## Pierce Modular Math 115 Answers
##ENDDESCRIPTION

##KEYWORDS('algebra')

## DBsubject('Elementary Algebra')
## DBchapter('')
## DBsection('')
## Date('Spring 2010')
## Author('B Yoshiwara')
## Institution('Los Angeles Pierce College')
## TitleText1('Modular Math 115')
## EditionText1('1')
## AuthorText1('K. Yoshiwara')
## Section1('8.1')
## Problem1('7-12')

########################################################################

DOCUMENT();

loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"contextFraction.pl",
"CofIdaho_macros.pl",
);

# Print problem number and point value (weight) for the problem
TEXT(beginproblem());

# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;

##############################################################
#
# Setup
Context("Fraction");
Context()->variables->are(x=>'Real',a=>'Real',b=>'Real');
$ans8 = Compute("(-b^2)/(5a)");

##############################################################
#
# Text
Context()->texStrings;
BEGIN_TEXT

Enter answers in the answer boxes, using parentheses as appropriate.
$BR
Use the Preview Answers button to verify that you've entered what you intended.

$BR
8: \{ans_rule(10)\}
END_TEXT
Context()->normalStrings;

##############################################################
#
# Answers
ANS(RationalExpEvaluator($ans8,["a","b"]));
ENDDOCUMENT();
In reply to Bruce Yoshiwara

Re: context::Fraction::Real

by Davide Cervone -
The problem is that RationalExpEvaluator() expects you to pass it a string, but you are passing it a MathObject (a Faction object). RationalExpEvaluator() stores what you pass it as the correct answer, which is supposed to be a string (not an object). Eventually, that string gets used to form the correct answer column of the results table at the top of the page. Now when you use a MathObject instead of a string, the MathObject is eventually turned into a sting ("stringified", as they say) when the table is formed. But the part of the code that makes the table is not within the problem itself, and no longer has access to the problems environment, and since that is where the parserFraction.pl was loaded, the code that defines the Fraction object is no longer available. That is where the error message is coming from.

One solution is to use

    ANS(RationalExpEvaluator($ans8->string,["a","b"])); 
to force the answer back to a string before passing it to RationalExpEvaluator(). That makes sure the stringification is done within the problem itself, where the Fraction MathObejct class is defined.

I've looked through the RationalExpEvaluator(), and frankly I wouldn't use it (no offense intended to the authors). It has a number of serious weaknesses and limitations. For example, try entering -(b^2/5)/a for the answer to your problem above.

What is really needed is a rational-function MathObject context. This could probably be made from the LimitedPolynomal context fairly easily by extending the division operator to accept polynomial values. I'll have to look into that.

Davide

In reply to Bruce Yoshiwara

Re: context::Fraction::Real

by Davide Cervone -
OK, I've put together two new contexts that might be useful to you. One is a PolynomialFactors context in which you can enter products of powers of polynomials (and nothing else), and the other is a RationalFunction context, in which you can only enter rational functions (or optionally products and powers of them). These are in the files contextPolynomialFactors.pl and contextRationalFunciton.pl in the macros directory (you will need to use CVS to check out the new files).

These are not heavily tested, but seem to work for me. They are based on the LimitedPolynomial context, which has been around for a while, and so has been tested more thoroughly. You will need to check out the latest version of that, too.

Read the comments at the top of the file for details. You may want to set the strictQuotients flag to disallow products of rational functions if you want.

Anyway, hope that helps. It's something I've been meaning to do for a while.

Davide