Haskell does not have any clever way to short-circuit evaluation of LCM for
arbitrary precision Integer type.

LCM is defined as follows:

lcm _ 0         =  0
lcm 0 _         =  0
lcm x y         =  abs ((x `quot` (gcd x y)) * y)

And GCD is implemented straightforwardly using Euclid algorithm:

gcd x y         =  gcd' (abs x) (abs y)
                   where gcd' a 0  =  a
                         gcd' a b  =  gcd' b (a `rem` b)

I think this has something to do with the way extended integers are
implemented in J.

-- Eugene

On Sun, Mar 10, 2019 at 10:50 PM Raul Miller <rauldmil...@gmail.com> wrote:

> On Sunday, March 10, 2019, james faure <james.fa...@epitech.eu> wrote:
>
> > For reference, the haskell implementation doesn't have any special magic
> > to it, besides the lazy list handling:
>
>
> I was suggesting that the Haskell compiler might have enough number theory
> implemented to discard the irrelevant duplicate factors from that sequence.
>
> Of course, it also might not be that smart...
>
> But what you posted here doesn’t seem to say much about either possibility?
>
> —
> Raul
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to