WeBWorK Problems

lcm and gcd in contexts

lcm and gcd in contexts

by Kenneth Appel -
Number of replies: 4
Davide,
I have seen you use lcm and gcd from your generalized parser in a tricky situation. What do I need to get them for simpler use. For example I tried
$a1=random(2,4,2);
$a2=random(1,3,2)+$a1;
$b1=random(6,8,2);
$b2=random(1,5,4)+$b1;
$c1=random(6,10,2);
$c2=lcm($a,$b);
and this did not work. What is the proper way to do this?
Ken
In reply to Kenneth Appel

Re: lcm and gcd in contexts

by Davide Cervone -
The lcm() and gcd() functions (along with reduce() and some others) are in PGauxiliaryFunctions.pl, so you ned to use loadMacros() to load that file first.

Alternatively, there are copies in context::Fraction so if you have loaded contextFraction.pl, you can use context::Fraction::lcm() or context::Fraction::gcd() instead.

Davide
In reply to Davide Cervone

Re: lcm and gcd in contexts

by Michael Gage -
Loading PGstandard.pl will also automatically load PGauxiliaryFunctions.pl along with some other commonly used macro packages.
In reply to Michael Gage

Re: lcm and gcd in contexts

by Kenneth Appel -
Mike, Davide,
Is it possible that Davide has added something to PGauxiliaryFunctions.pl since it was
included in PGstandard.pl. I had written the
problem with PGstandard.pl on my macro list and
it did not respond to lcm. When I added
PGauxiliaryFunctions.pl it did recognize lcm.
Ken
In reply to Kenneth Appel

Re: lcm and gcd in contexts

by Davide Cervone -
No, I haven't changed PGstandard.pl since it has gone into the pg/macros directory. Make sure you don't have duplicate copies of it somewhere in the macros path. Perhaps you have been getting the wrong copy?

Davide