We are trying to extend the idea to the ^ operator for questions like

- simplify 12^8 * 12^5 (where we expect 12^13, and do not want to accept all of the digits that come from carrying out the exponentiation)
- factor the integer 12 (where we'd have the answer be OneOf(Formula("2^2*3"), Formula("2*2*3")) and the bizarro arithmetic would recognize "6*2" and "4*3" as different.)

syntax error at (eval 7261) line 6, near "**("

If you think you may be able to offer an explanation or a fix, please download the attached .pl file and try the problem below. Everything should function well until you try submitting an answer.

# WeBWorK problem written by Chris Hughes, 2013

# Portland Community College

#

# Template:

# Simplify the following expression

# x^m * x^n

#

# We use an INTEGER value for x on the interval [2,20]

#

# This problem chooes m and n to be POSITIVE

#

# Last edited: Carl Yao 6/28/13

#

# ENDDESCRIPTION

## DBsubject('Algebra')

## DBchapter('Polynomial and Rational Functions')

## DBsection('Polynomial Functions')

## KEYWORDS('multiply','exponent','simplify')

## DBCCSS('8.EE.1')

## TitleText1('')

## EditionText1('')

## AuthorText1('')

## Section1('')

## Problem1('')

## Author('Chris Hughes')

## Institution('PCC')

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

DOCUMENT();

loadMacros(

"PGstandard.pl",

"MathObjects.pl",

"PGML.pl",

# "PCCmacros.pl",

"contextLimitedPolynomial.pl",

"answerHints.pl",

"parserBizarroArithmeticTest.pl",

);

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

Context("LimitedPolynomial-Strict");

# m and n are the exponents

$mybase=random(9,20,1);

$m=random(1,20,1);

$n=random(2,20,1);

# myvar is the variable- could be x, y, z, ..., anything in PCCmacros.pl

$myvar = "x";

# custom error message

Context()->{error}{msg}{"A variable can appear only once in each term of a polynomial"}

= "Your answer must be fully simplified";

# quick reduction check (if $m or $n is 1)

$myvar1 = Formula("$myvar^$m")->reduce->substitute(x=>$mybase);

$myvar2 = Formula("$myvar^$n")->reduce->substitute(x=>$mybase);

$total = $m+$n;

$ans = Formula("$myvar^($total)");

Context("Numeric"); # since these problems have *numeric* bases

Context()->flags->set(formatStudentAnswer=>'parsed',reduceConstants=>0); # this line stops 9^3 being computed, and leaves it as 9^3

Context()->operators->undefine('*','/','+','-'); # forbid operators in the answer

# need to do the substitution in NUMERIC context

$myvar1 = $myvar1->substitute(x=>$mybase);

$myvar2 = $myvar2->substitute(x=>$mybase);

$ans = $ans->substitute(x=>$mybase);

$ans = Compute($ans);

Context()->operators->set(

'^' => {class => 'my::BOP::power', isCommand => 1}, # override ^

'**' => {class => 'my::BOP::power', isCommand => 1}, # override **

);

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

TEXT(beginproblem());

BEGIN_PGML

Use the properties of exponents to simplify the following

[`[$myvar1]\cdot[$myvar2]`]

[______]

END_PGML

$wrong=$m*$n;

ANS($ans -> cmp(checker=>sub{

my ( $correct, $student, $ansHash ) = @_;

return 0 if $ansHash->{isPreview} || $correct != $student;

$student = $ansHash->{student_formula};

$correct = $correct->{original_formula} if defined $correct->{original_formula};

$student = Formula("$student"); $correct = Formula("$correct");

return 0 unless ($correct == $student);

Context()->flags->set(bizarroPow=>1);

Value->Error("Use exponents to simplify rather than actually evaluating") unless ($correct == $student);

Context()->flags->set(bizarroPow=>0);

return 1;

}) ->

withPostFilter(AnswerHints(

[Compute("$mybase^($wrong)")] =>

"When multiplying terms with the same base, you do not multiply the exponents.")));

BEGIN_PGML_SOLUTION

We _add_ the exponents as follows

[`\begin{aligned}

[$mybase]^{[$m]}\cdot [$mybase]^{[$n]}&=[$mybase]^{[$m]+[$n]}\\

&=[$mybase]^{[$total]}

\end{aligned}`]

END_PGML_SOLUTION

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

ENDDOCUMENT();