[<<][meta][>>][..]

Mon Feb 15 10:31:12 CET 2010

## Nesting the Term type

Point: try complex or normal numbers on top of the Term type.
The Haskell Complex type can't be used in a straightforward manner:
Term (Complex Double)
just gives complex versions of the operations, and
Complex (Term Double)
doesn't seem to work because the following instances are not defined:
instance (Real a) => Real (Term a)
instance (RealFrac a) => RealFrac (Term a)
instance (RealFloat a) => RealFloat (Term a)
Defining them makes it possible to use complex operations like this:
test1 = compileNodes [realPart c, imagPart c] where
c = a * b
a = var "ar" :+ var "ai"
b = var "br" :+ var "bi"
This gives:
([r3,r6],
[(r0,(mul ar br)),
(r1,(mul ai bi)),
(r2,(negate r1)),
(r3,(add r0 r2)),
(r4,(mul ar bi)),
(r5,(mul ai br)),
(r6,(add r4 r5))])
Reductions also work:
test2 = compileNodes [realPart c, imagPart c] where
c = a * b
a = var "ar" :+ 0
b = var "br" :+ var "bi"
gives:
([r0,r1],
[(r0,(mul ar br)),
(r1,(mul ar bi))])

[Reply][About]

[<<][meta][>>][..]