tag:blogger.com,1999:blog-5195188167565410449.post1294793580226717866..comments2016-09-19T07:11:19.884+01:00Comments on Haskell for Maths: The free vector space on a type, part 2DavidAhttp://www.blogger.com/profile/16359932006803389458noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5195188167565410449.post-83890345349867820352011-01-16T20:44:36.555+00:002011-01-16T20:44:36.555+00:00Why call nf?
As you say, it probably depends what ...Why call nf?<br />As you say, it probably depends what we're doing. I'm thinking of the normal form as the true identity of the vector, so I feel we definitely need to call nf at the end of any extended calculation (before "show"). In addition, with the current Eq instance, we need to call nf before (==).<br />It's not strictly necessary to call nf after every step in a calculation, but I suspect it will often be more efficient to do so.<br />As a simple example, consider the following:<br />> let f = \b -> case b of E 1 -> e1 <+> e2; E 2 -> e2 <+> (-1) *> e1<br />> e1 >>= f >>= f >>= f >>= f<br />e1+e2-e1+e2-e1-e2-e1+e2-e1-e2+e1-e2-e1-e2-e1+e2<br />> nf it<br />-4e1DavidAhttps://www.blogger.com/profile/16359932006803389458noreply@blogger.comtag:blogger.com,1999:blog-5195188167565410449.post-58625535809855908172011-01-11T13:23:30.884+00:002011-01-11T13:23:30.884+00:00So, why exactly will we really need to keep on cal...So, why exactly will we really need to keep on calling nf here? I can see two reasons immediately this might be the case:<br />1. We're really computing (>>=) as a list concatenation for the terms rather than doing any sort of summation at all in this step. This is potentially a valid thing to do — I know Afra Zomorodian has used something like that to speed up Gröbner basis style computations of persistent homology… But in my experience, you'll want to know that you'll be doing enough of the right kinds of operations for this to pay off.<br />2. We're worrying about applying subsequent lifted functions to “too many” basis elements. This seems like laziness should “magically” take care of, as long as we take a coefficient known to be 0 to be sufficient reason not to look at (as in forcing strictness for) its corresponding basis element.michiexilehttps://www.blogger.com/profile/00008302080954798496noreply@blogger.com