Skip to content

Instantly share code, notes, and snippets.

@dimpase
Created February 20, 2013 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimpase/4992965 to your computer and use it in GitHub Desktop.
Save dimpase/4992965 to your computer and use it in GitHub Desktop.
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