## Miscellaneous

### Periodic Formulas and cmp

by Spyro Roubos -
Number of replies: 1
Is there a way of comparing formulas mod (number)?

Example:

DOCUMENT();

# Load whatever macros you need for the problem
loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"PGunion.pl", # Union College macros
#"PGcourse.pl", # Customization file for the course

);

Context("Complex");
Context()->variables->add(k=>'Real');

$c = Formula("pi/2 + 2pik"); # ->with(period=>"2pi") here does nothing.$c->{test_points} = [[1,0.1]]; #test the student formula against the
#correct one evaluated at z = 1, k = 0.1

# I've tried doing [[1, Real(0.1)->with(period=>"2pi")]],
# but this doesn't change the checker either.

ANS($c->cmp); # ANS($c->with(period=>"2pi")->cmp); doesn't change the checker
ENDDOCUMENT();
--------------------------------------------------

Is there a separate cmp-mod function that I'm supposed to use in the MathObjects?
In reply to Spyro Roubos

### Re: Periodic Formulas and cmp

by Davide Cervone -
There is a discussion at
    http://wwrk.maa.org/moodle/mod/forum/discuss.php?d=1888

that describes several ways to do this.

I've also just entered changes in the CVS repository so that Formula("z")->with(period=>2*pi) will match z, z+2pi, z-2pi and so on.

Note that you do not include 2pi k in this approach. If you want to require the students to include this in their answers, see the discussion listed above. If you go with one of the last two solutions on that page, note that it is now eaier to obtain the value of the parameter a than it was when I wrote that example. Before removing the parameter, you can do

    \$a = Context()->variables->get('a')->{value};

to obtain the value of the parameter as it was set for the equality check. This prevents having to obtain it by dividing the difference of the correct and student answers by 2pi.

Davide