]> git.unchartedbackwaters.co.uk Git - francis/lta.git/commitdiff
Add negate implementation for Literal and Expr.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Fri, 12 Apr 2013 15:39:53 +0000 (16:39 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Fri, 12 Apr 2013 15:39:53 +0000 (16:39 +0100)
LTA/Symbolic.hs

index e14b09cbc73ade8c66cb302c806d54668bb90c07..a46846a9d34647d9b2ce0a1abd9d6598baea8273 100644 (file)
@@ -163,9 +163,11 @@ instance Num Literal where
   (*) (FloatLiteral a) (RationalLiteral b) = FloatLiteral $ a * (fromRational b)
   abs (RationalLiteral a) = RationalLiteral $ abs a
   abs (FloatLiteral a) = FloatLiteral $ abs a
+  fromInteger = RationalLiteral . fromInteger
+  negate (FloatLiteral a) = FloatLiteral $ - a
+  negate (RationalLiteral a) = RationalLiteral $ - a
   signum (RationalLiteral a) = RationalLiteral $ signum a
   signum (FloatLiteral a) = FloatLiteral $ signum a
-  fromInteger = RationalLiteral . fromInteger
 
 -- The special cases for multiplication by 1 are needed as a base case to avoid
 -- infinite recursion when simplifying products.
@@ -178,6 +180,7 @@ instance Num Expr where
   (*) 1 n = n
   (*) n 1 = n
   (*) a b = simplify $ Product $ empty `addPair` (a, 1) `addPair` (b, 1)
-  fromInteger = Literal . fromInteger
   abs = UnaryFunction Abs
+  fromInteger = Literal . fromInteger
+  negate a = simplify $ Sum $ empty `addPair` (a, -1)
   signum = UnaryFunction Signum