On Tue, Feb 21, 2012 at 04:15:25PM +0100, Ralf Hemmecke wrote:
>> Thank you. I knew of the optimization of this kind.
>> It is difficult for a Haskeller to believe in the necessity of such
>> loops. When I try this, it takes much more time of me to develop a code
>> of this kind.
>
> Honestly, when I first read your h function, I had hard times to
> decipher it. Fortunately, I learnt about this pattern during a Haskell
> course last semester.
>
> Anyway, for me the loop variant is still easier to read. Nevertheless
> there are certainly some advantages in a purely functional language.
> I've seen some program transformation code that automatically turns a
> naively programmed O(n^2) code into O(n) code.
>
One even _cannot_ write such loops in Haskell, because these reassignments
in a loop are non-functional. `do' and `reapeat' are not possible
(except a particular area of the monadic IO, where they are mimiked).
Once my friend, a mathematician, asked me to compute in DoCon the
value of det(mM) == 0 for a certain concrete
mM :: Matrix Polynomial([x,y,z], Rational).
He wrote that he uses Maple, the intermediate polynomials occur large,
and Maple computes this example long and runs out of the memory
(and he is experienced in using CA).
So, I put the data directly and naively in DoCon and ran det mM == 0.
It has returned False in a couple of seconds, unexpectedly.
I started to investigate.
This was because Haskell computes lazily. det mM belongs to Q[x,y,z],
and it has occured so that the leading monomial in this example is found
fast (and it is non-zero). The polynomial representation in DoCon is so
that all the rest monomials go to the tail, and this is visible even for
the GHC compiler. Zero polynomial means the empty list. The lazy
interpreter stopped immediately at this point of computation, because
it was syntactically visible that the result of (== 0) does not depend on
this tail!
Regards,
------
Sergei
[email protected]
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en.