## PREP 2015 Question Authoring - Archived

### how to use ContextFraction properly?

by Valerio De Angelis -
Number of replies: 1
The code below works and does what I want, but I have the feeling that there is a better way to do it. I do not want decimals in the solution, but the only way I could do that was to define two different objects, $ans to check the answer and$sol to display the solution without decimals. If I use ContextFraction for $ans (that is used by the answer checker), the system does not recognize the correct answer and returns "incorrect". Is there a way to use contextFraction for the object that goes in the answer checker? Thanks for any help. DOCUMENT(); loadMacros("PGstandard.pl", "MathObjects.pl", "contextFraction.pl", "PGcourse.pl", "PGML.pl"); Context("Point");$a=random(2,9,1);
$b=non_zero_random(-8,8,2);$c=random(3,9,2);
$d=non_zero_random(-9,9,1); Context()->variables->add(r=>'Real',s=>'Real');$ans=Compute("($d/$a-$b r/$a-$c s/$a, r, s)");
Context("Fraction-NoDecimals");
$sol=Compute("($d/$a-$b r/$a-$c s/$a, r, s)"); TEXT(beginproblem()); BEGIN_PGML Find the solution set of the linear equation, using [x_1] and [x_2] as free variables. [[$a] x_1+[$b]x_2+[$c]x_3 = [$d]] [S=][_________________]{$ans}

END_PGML

BEGIN_PGML_SOLUTION

[S= [$sol]] END_PGML_SOLUTION ENDDOCUMENT() In reply to Valerio De Angelis ### Re: how to use ContextFraction properly? by Davide Cervone - It looks like you really only need to prevent decimals from being entered, which does not actually require the Fraction context. You just need to turn on the "no-fraction" feature in the Point context: Context("Point"); Parser::Number::NoDecimals();  The alternative would be to use the Fraction-NoDecimals context and enable points in that context: Context("Fraction-NoDecimals"); Context()->parens->set("(" => {type=>"Point"});  Either approach works. There are a couple of comments I'd make about other aspects of the problem. First, how are the students supposed to know to use the variables r and s in their answers? You should probably include that in your statement somewhere. Second you ask for a set, but your answer is a formula returning a point. It might be good for you to include the braces for the set around your answer blank, so that they are filling in its contents. Here is one version of the central part of your problem with these rewrites: Context("Point"); Context()->variables->add(r=>'Real',s=>'Real'); Parser::Number::NoDecimals();$a=random(2,9,1);
$b=non_zero_random(-8,8,2);$c=random(3,9,2);
$d=non_zero_random(-9,9,1);$ans = Compute("($d/$a-$b r/$a-$c s/$a, r, s)");

TEXT(beginproblem());

BEGIN_PGML

Find the solution set of the following linear equation, using [x_1] and [x_2] as the
free variables [r] and [s].

[[$a] x_1+[$b]x_2+[$c]x_3 = [$d]]

[S= \{] [_________________]{\$ans} [\}]

END_PGML