Skip to content

Instantly share code, notes, and snippets.

@dimpase

dimpase/gist:4992965

Created Feb 20, 2013
Embed
What would you like to do?
A bit of CA in Haskell. The hardest part was to figure out nf, to ensure strict evaluation.
module Main where
import Math.CommutativeAlgebra.Polynomial
import Math.Algebras.VectorSpace -- for nf
main =
print (adder 10000000 d e)
where
[x,y] = map glexvar ["x","y"]
a = 4*x^2 + 3*x + 2
b = 5*x^2 + 6*x + 7
c = 8*x^2 + 9*x + 10
d = a*y^2 + b*y + c
e = d
adder n v u = adder' n u
where
adder' 0 acc = acc
adder' n acc = adder' (n-1) (nf (acc+v))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment