I have a problem that I am working on that uses RadioButtons. What I am looking for is a way to have the 5 options in my RadioButtons be reduced formulas with simplified randomized fractions. I have something that is currently sort of working, but it has an issue that it isn't simplifying all the formulas the same. For some reason, with $m=-1 or -2 then the formula displays with an extra set of parenthesis as y=(-1)x+b. Below is the current code and a picture of the issue I'm seeing. Any ideas? I have tried many different ways to create such a multiple choice question but I am not having much luck, this has been teh closest luck I've had but I'd be open to any suggestions for a way to code such a problem. Thanks!

DOCUMENT();

loadMacros(

"PGstandard.pl",

"PGML.pl",

"MathObjects.pl",

"PGgraphmacros.pl",

"parserRadioButtons.pl",

"PGcourse.pl",

"PG.pl",

"parserAssignment.pl",

"PGbasicmacros.pl",

"PGchoicemacros.pl",

"PGanswermacros.pl",

"MathObjects.pl",

"contextFraction.pl",

);

TEXT(beginproblem());

Context("Fraction")->variables->are(x=>"Real",y=>"Real");

parser::Assignment->Allow;

parser::Assignment->Function("f");

$mt = list_random(2,-2,1,-1);

$mb = list_random(1,2,3);

$m = Fraction("$mt/$mb");

$b = non_zero_random(-4,4,1);

Context()->noreduce('(-x)-y','(-x)+y');

$f1 = Formula("y=$m*x+$b")->reduce;

$f2 = Formula("y=$m*x-$b")->reduce;

$f3 = Formula("y=4*x+$m")->reduce;

$f4 = Formula("y=x+5")->reduce;

$f5 = Formula("y=$m*x+$m")->reduce;

$gr = init_graph(-6,-6,6,6,

axes=>[0,0],

grid=>[12,12],

size=>[600,600]

);

$gr -> lb('reset'); # remove default labels

# axes labels

$gr->lb( new Label(5.5,0,'x', 'black', 'center', 'bottom','large'));

$gr->lb( new Label(0.1,5.5,"y", 'black', 'left', 'middle'));

# axes labels

foreach my $i (-10..10) {

$gr->lb( new Label($i,0, $i, 'black', 'center', 'top', 'giant'));

$gr->lb( new Label(-0.1,$i, $i, 'black', 'right', 'middle'));

}

add_functions($gr, "$m*x+$b for x in <-10,10> using color:blue and weight:3");

# Set up possible answers

$showPartialCorrectAnswers = 0;

$mc = RadioButtons(

[ [" `$f1`", " `$f2` ", " `$f3` ", "`$f4` ", " `$f5` "] ], 1 );

BEGIN_PGML

What is the equation for the function shown?

>>[@ image(insertGraph($gr), width=>300, height=>300), @]*<<

END_PGML

BEGIN_TEXT

$BR

\{ $mc->buttons() \}

END_TEXT

$showPartialCorrectAnswers = 0;

ANS( $mc->cmp() );

ENDDOCUMENT();