]> git.unchartedbackwaters.co.uk Git - francis/lta.git/commitdiff
Minor code clean-ups.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Fri, 12 Apr 2013 19:35:18 +0000 (20:35 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Fri, 12 Apr 2013 19:35:18 +0000 (20:35 +0100)
LTA/Symbolic.hs

index c0e04d05cf97e78bedb7e35bb53e951ca9c96d73..d05f5f6c36399785fc16fc2821de176ed7a03a5e 100644 (file)
@@ -71,7 +71,7 @@ instance PairSeqLike (PairSeq ProductTag Expr) where
          let localMultiplier = multiplier * coeff in
            case (expr, localMultiplier) of
              (Product childSeq, _) -> mergeTerms oldSeq localMultiplier childSeq
-             (a, b) -> case evalPow a b of
+             (a, b) -> case a `evalPow` b of
                Just n -> transformOverall oldSeq (* n)
                Nothing -> addPair oldSeq (a, b)
 
@@ -129,7 +129,7 @@ normalise :: (PairSeqLike (PairSeq t c), Eq c, Num c) => PairSeq t c -> PairSeq
 normalise = removeZeros . flatten . extractMultipliers
 
 isZero :: (Num e, Eq e) => e -> Bool
-isZero n = n == 0
+isZero = (== 0)
 
 extractMultiplier :: Expr -> (Expr, Literal)
 extractMultiplier (Literal literal) = (1, literal)
@@ -143,7 +143,7 @@ extractMultiplier (Sum (PairSeq coeff terms)) =
 extractMultiplier e = (e, 1)
 
 pow :: Expr -> Expr -> Expr
-pow a b = simplify $ Product $ PairSeq 1 (Map.singleton a b)
+pow a b = simplify . Product $ empty `addPair` (a, b)
 
 evalPow :: Expr -> Expr -> Maybe Literal
 evalPow (Literal a) (Literal b) = evalPow' a b where
@@ -179,17 +179,17 @@ instance Num Literal where
 instance Num Expr where
   (+) n 0 = n
   (+) 0 n = n
-  (+) a b = simplify $ Sum $ empty `addPair` (a, 1) `addPair` (b, 1)
+  (+) a b = simplify . Sum $ empty `addPair` (a, 1) `addPair` (b, 1)
   (*) _ 0 = 0
   (*) 0 _ = 0
   (*) 1 n = n
   (*) n 1 = n
-  (*) a b = simplify $ Product $ empty `addPair` (a, 1) `addPair` (b, 1)
+  (*) a b = simplify . Product $ empty `addPair` (a, 1) `addPair` (b, 1)
   abs = UnaryFunction Abs
   fromInteger = Literal . fromInteger
-  negate a = simplify $ Sum $ empty `addPair` (a, -1)
+  negate a = simplify . Sum $ empty `addPair` (a, -1)
   signum = UnaryFunction Signum
 
 instance Fractional Expr where
-  (/) a b = simplify $ Product $ empty `addPair` (a, 1) `addPair` (b, -1)
+  (/) a b = simplify . Product $ empty `addPair` (a, 1) `addPair` (b, -1)
   fromRational = Literal . RationalLiteral