There's more than one way to do things PerlMonks

### Re^5: Algorithm for cancelling common factors between two lists of multiplicands

by tmoertel (Chaplain)
 on Aug 11, 2005 at 05:04 UTC ( #482850=note: print w/replies, xml ) Need Help??

The last two digits of the Math::Pari implementation's result seem to be off:
```+8.070604647867604097576877675243109941729476950993498765160880e-7030
8.070604647867604097576877675243109941729e-7030
8.070604647867604097576877668E-7030  <-- Math::Pari
^^
Can you increase the implementation's precision? Or is that the limit?

Cheers,
Tom

• Comment on Re^5: Algorithm for cancelling common factors between two lists of multiplicands

Replies are listed 'Best First'.
Re^6: Algorithm for cancelling common factors between two lists of multiplicands
by BrowserUk (Patriarch) on Aug 11, 2005 at 05:57 UTC

The precision is setable, but I had left at the default.

Increasing the precision to the point where it match or suppassed the accuracy of your Haskell code (a setting of 58), doubled the time it took to a gnat's under 50 ms:

```[ 6:46:43.79] P:\test>MP-FET.pl
8.070604647867604097576877675243109941729476950993498765160880911582E-
+7030
1 trial  of _default ( 49.865ms total), 49.865ms/trial

BTW: Could you explain something for me? In this:

```cancel (x:xs) (y:ys)
| x == y    = cancel xs ys
| x < y     = let (xs', ys') = cancel xs (y:ys) in (x:xs', ys')
| otherwise = let (xs', ys') = cancel (x:xs) ys in (xs', y:ys')
cancel xs ys    = (xs, ys)

I understand how it cancels between the lists, but I am confused about when it would pattern match against the second definition?

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
The pattern (_:_) will not match an empty list [], so the first definition will match only when both input lists are non-empty. If one or both of the inputs are empty, the second definition will match.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://482850]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2023-12-04 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
What's your preferred 'use VERSION' for new CPAN modules in 2023?

Results (23 votes). Check out past polls.

Notices?