PREP 2015 Question Authoring - Archived

how to use ContextFraction properly?

Re: how to use ContextFraction properly?

by Davide Cervone -
Number of replies: 0
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