tag:blogger.com,1999:blog-5195188167565410449.post5561495038359270686..comments2018-01-09T12:18:36.360+00:00Comments on Haskell for Maths: Commutative Algebra in Haskell, part 1DavidAhttp://www.blogger.com/profile/16359932006803389458noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-5195188167565410449.post-49463726895605702892014-03-03T16:12:13.084+00:002014-03-03T16:12:13.084+00:00IMHO monomials should go to a hashtable, and then ...IMHO monomials should go to a hashtable, and then coefficients of monomials are cheap to maintain.<br />Otherwise, an efficient way certainly would be something akin to what garbage collectors do, as nf is really a sort of garbage collection here. dimpasehttps://www.blogger.com/profile/14596969929730094920noreply@blogger.comtag:blogger.com,1999:blog-5195188167565410449.post-46396544270037682802014-02-08T15:14:30.140+00:002014-02-08T15:14:30.140+00:00Hmm, now that I look, it seems like I could. The c...Hmm, now that I look, it seems like I could. The code currently says:<br />instance (Eq k, Num k, Eq b, Ord b, Show b, Algebra k b) => Num (Vect k b) where<br /> x+y = x <+> y<br /> x*y = mult (x `te` y)<br /> ...<br />I see that I have required Ord b, so it looks like I could do nf here.<br /><br />Perhaps my thought was that this may not always be the most efficient way to proceed.DavidAhttps://www.blogger.com/profile/16359932006803389458noreply@blogger.comtag:blogger.com,1999:blog-5195188167565410449.post-56238130831861132372014-02-05T17:01:16.586+00:002014-02-05T17:01:16.586+00:00sorry, missed your reply... Could you elaborate wh...sorry, missed your reply... Could you elaborate why Ord can't be assumed?dimpasehttps://www.blogger.com/profile/14596969929730094920noreply@blogger.comtag:blogger.com,1999:blog-5195188167565410449.post-36117108060061133092013-02-23T20:38:54.042+00:002013-02-23T20:38:54.042+00:00Hmm - thanks for pointing this out. So the reason ...Hmm - thanks for pointing this out. So the reason you need the nf calls is to force it to gather together like terms - e.g. to rewrite x+x as 2x. Without that, then you'll get more and more terms over time. But now that you mention it, it's also possible that I could improve the code by putting in some strictness annotations or seq calls.<br />The reason by the way that I can't put the nf call inside the implementations of (+) and (*) is because I can't assume an Ord instance for monomials in the definition of Algebra. But perhaps Haskell has a way round that now.DavidAhttps://www.blogger.com/profile/16359932006803389458noreply@blogger.comtag:blogger.com,1999:blog-5195188167565410449.post-36651804671505872902013-02-20T04:52:59.269+00:002013-02-20T04:52:59.269+00:00It was tricky for me to figure out that for strict...It was tricky for me to figure out that for strict evaluation of polynomials, one needs to use nf from Math.Algebras.VectorSpace.<br /><br />Without nf, things like https://gist.github.com/dimpase/4992965<br />blow up the stack.dimpasehttps://www.blogger.com/profile/14596969929730094920noreply@blogger.com