## WeBWorK Problems

### Specifying occurrences of character in answer ### Re: Specifying occurrences of character in answer

by Bruce Yoshiwara -
Number of replies: 6
Hi Alex,

I'm not yet able to get bizarroArithmetic to check anything yet. Whatever the student inputs, I get the message that WeBWorK can't generate enough valid points for comparison.

In my first attempt, I trimmed out what I believed should make no difference to the error, and here's what's left.

##DESCRIPTION
## Algebra problem: Rational exponents--incubation time vs mass of egg
##ENDDESCRIPTION

## DBsubject(Algebra)
## DBchapter(Functions)
## Date('2/4/2018')
## Author('Yoshiwara')
## Institution('')
## TitleText1('Modeling, Functions, and Graphs')
## EditionText1('5')
## AuthorText1('Yoshiwara')
## Section1('3.4')
## Problem1('43')

########################################################################
DOCUMENT();

"PGstandard.pl",
"PGunion.pl",
"imageChoice.pl",
"PGML.pl",
"bizarroArithmetic.pl",
);

Context()->flags->set(reduceConstants=>0);
Context()->flags->set(limits=>[1,2000]);

$f = "-x^(1/3) / (x^(5/3)) ";$f_display = " \dfrac{ - x^{1/3}}{ x^{5/3} }";
$g = Formula(" -1/x^{4/3} " ); Context()->operators->set( '**' => {class => 'bizarro::BOP::power', isCommand => 1, perl=>undef}, '^' => {class => 'bizarro::BOP::power', isCommand => 1, perl=>undef}, ); Context()->flags->set(bizarroPow=>1); BEGIN_PGML a. [ [$f_display] =][__________]
END_PGML
ANS($g -> cmp()); ENDDOCUMENT(); In reply to Bruce Yoshiwara ### Re: Specifying occurrences of character in answer by Alex Jordan - Hi Bruce, Well, your timing is interesting. I see that behavior too, and something is broken. Meanwhile, an instructor here is writing that a batch of problems that use bizarroArithmetic suddenly no longer work (after years of behaving well). With the last upgrade of WW, there was a lot of "perl warnings cleanup". Right now I suspect something about that hurt bizarro. Tonight I will investigate, and hopefully have it all sorted out by the end of the weekend. Point is, bizarro is supposed to work as you've tried and I outlined. And it has worked that way for a while up until seemingly recently. So hang tight. Alex In reply to Alex Jordan ### Re: Specifying occurrences of character in answer by Alex Jordan - OK, I think I still have a different issue to track down regarding local faculty reporting a problem. But the issue with your example is the sequence you are executing the commands. This block: Context()->operators->set( '**' => {class => 'bizarro::BOP::power', isCommand => 1, perl=>undef}, '^' => {class => 'bizarro::BOP::power', isCommand => 1, perl=>undef}, ); Needs to happen before you define any Math Objects for the context. In this case,$g.

Now, as it turns out (and I often forget when dealing with bizarro), since your problem is about exponents, it is the other relevant things that should get bizarro treatment. In this case, division. Here is what I believe to be a working version of your example. Again, note that I moved the operator settings up earlier. And I've included the custom answer checker. Also I changed the macros you loaded to what I would go with, but maybe you need the originals for what goes on with the full version of the problem.

##DESCRIPTION
## Algebra problem: Rational exponents--incubation time vs mass of egg
##ENDDESCRIPTION

## DBsubject(Algebra)
## DBchapter(Functions)
## Date('2/4/2018')
## Author('Yoshiwara')
## Institution('')
## TitleText1('Modeling, Functions, and Graphs')
## EditionText1('5')
## AuthorText1('Yoshiwara')
## Section1('3.4')
## Problem1('43')

########################################################################
DOCUMENT();

"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"bizarroArithmetic.pl",
);

TEXT(beginproblem());

Context("Numeric");
Context()->flags->set(reduceConstants=>0);
Context()->flags->set(limits=>[1,10]);
Context()->operators->set(
'/' => {class => 'bizarro::BOP::divide', isCommand => 1},
);

$f = "-x^(1/3) / (x^(5/3)) ";$f_display = " \dfrac{ - x^{1/3}}{ x^{5/3} }";
$g = Formula(" -1/x^(4/3) " ); BEGIN_PGML a. [ [$f_display] =][__________]
END_PGML

ANS($g -> 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(bizarroDiv=>1);
delete $correct->{test_values}; delete$student->{test_values};
my $OK = (($correct == $student) or ($student == $correct)); Context()->flags->set(bizarroDiv=>0); Value::Error("Your answer is correct, but please simplify it further") unless$OK;
return $OK; })); ENDDOCUMENT(); If you are writing this in PTX source, you wnat to put the following in your pg-code element at the end:$evaluator = $g -> 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(bizarroDiv=>1);
delete $correct->{test_values}; delete$student->{test_values};
my $OK = (($correct == $student) or ($student == $correct)); Context()->flags->set(bizarroDiv=>0); Value::Error("Your answer is correct, but please simplify it further") unless$OK;
return $OK; }); And then in the statement, where you put the answer blank, put it like: var name="$g" evaluator="$evaluator" width="15" (with surrounding tag marks which I omit here because this forum eats them up and I don't know how to escape that here.) In reply to Alex Jordan ### Re: Specifying occurrences of character in answer by Bruce Yoshiwara - Hello Alex, Thanks! Actually, the instructions (which I hadn't include in my pared-down example) asks for an expression with only positive exponents, so I'll be working on how to disallow the answer -x^(-4/3). But now that you've corrected the order of commands, I can experiment with how answers will be graded with different settings. Cheers. Bruce In reply to Bruce Yoshiwara ### Re: Specifying occurrences of character in answer by Alex Jordan - I think what I posted will do that. Suppose the answer was actually 1/x^4 to simplify the following explanation. Ans suppose 5 is a test point. It will compute a different value for 5^(-4) than for 1/5^4. In the first, you will get the actual decimal value of 0.0016. For the second when bizarro division is on, it first will reduce to 1/625, but then bizarro division will make some decimal that is not equal to 0.0016. Since x^(-4) is equal to 1/x^4 for regular arithmetic, a submitted answer of x^(-4) passes the first bar in the answer checker. Since x^(-4) is not equal to 1/x^4 for bizarro arithmetic, a submitted answer of x^(-4) does not pass the second bar, and you get a special feedback message that the answer is numerically correct, but not in the required form. Meanwhile, a submitted answer of 1/x^4 passes both bars. You might get "correct" results for things like 1/((x^-4)^(-1)) though, and at the moment I think you have to live with that. Unfortunately just turning on bizarro ^ in addition to / will not help. The bizarro operations are a consistent field structure on R. So if you have both bizarro ^ and bizarro / turned on, then 1/x is equal to x^(-1). But you could alter the custom checker to just turn on one, then try again with the other. And to get credit, the expression would have to pass three filters instead of just the two in the demonstration. In reply to Alex Jordan ### Re: Specifying occurrences of character in answer by Bruce Yoshiwara - Hi Alex, Thanks so much for your time. I feel a bit guilty to report that when I (believe I had) copied your code and tested it, it accepted -x^(-4/3) as correct. So I did turn on the Pow switches, and -x^(-4/3) is now rejected. So I'm happy with what I've now have, but apparently you wouldn't expect it to behave differently from what you provided. Anyway, here's what I now have (which seems to work). DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "PGML.pl", "bizarroArithmetic.pl", ); TEXT(beginproblem()); Context("Numeric"); Context()->flags->set(reduceConstants=>0); Context()->flags->set(limits=>[1,10]); Context()->operators->set( '/' => {class => 'bizarro::BOP::divide', isCommand => 1}, '**' => {class => 'bizarro::BOP::power', isCommand => 1, perl=>undef}, '^' => {class => 'bizarro::BOP::power', isCommand => 1, perl=>undef}, ); #Context()->flags->set(bizarroPow=>1);$f = "-x^(1/3) / (x^(5/3)) ";
$f_display = " \dfrac{ - x^{1/3}}{ x^{5/3} }";$g = Formula(" -1/x^(4/3) " );

BEGIN_PGML

THIS PROBLEM IS NOT TO BE ASSIGNED.

Simplify by applying the laws of exponents. Write your answers with positive exponents only.
a.
[ [$f_display] =][__________] END_PGML ANS($g -> 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(bizarroDiv=>1,bizarroPow=>1); delete$correct->{test_values};
delete $student->{test_values}; my$OK = (($correct ==$student) or ($student ==$correct));
Context()->flags->set(bizarroDiv=>0,bizarroPow=>1);
Value::Error("Your answer is equivalent, but please use the proper format") unless $OK; return$OK;
}));

ENDDOCUMENT(); 