[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: numerator? denominator?
Thus spake George:
> On Sun, Feb 06, 2000 at 12:13:04PM -0500, Nils Barth wrote:
> > Thus spake George:
> > > On Fri, Feb 04, 2000 at 09:31:07PM -0500, Nils Barth wrote:
> > > > Thanks George!
> > >
> > > BTW: I saw you in the libs calculating mod by using the '/' operator. But
> > > there is in fact a '%' operator that calculates mod. The 'mod' operator did
> > > modular math on a full expression. I dunno how soon I'll implement it again,
> > > there are some issues with it and the precalculation of constants.
> >
> > OIC, I got confused.
> > It's been corrected.
> > (so `mod' was something like: (2 == 5 mod 3) etc.?)
>
> Yes, the 'mod' operator was basically something that would take an entire
> expression and evaluate it under mod n. the % operator just takes the left
> side already evaluated and then mods it just like any other operator.
>
> The way it worked was that it first modded any arguments (except for say
> power in which it modded only the left argument) and then did the operation
> and moded the result. I need to figure out how to do the precalculation in a
> different way because now operations with constant number arguments are
> evaluated first.
Okay.
Actually, if you're working on that -anyhow-, you might want to
implement fast exponentiation. Basically, exponentiation mod n can be
done very quickly, so if
a^b mod n
were computed internally mod n, it would be MUCH faster than
a^b % n
i.e., first do a^b, then mod is slow.
To see the relevant algorithm, see:
dr-genius/lib/number_theory/misc.gel
function PowerMod
It's not a big deal if this isn't built-in (heck, m9a (=mathematica)
doesn't have it built-in), but it would be more elegant.
--
-nils