Proof/Haskell: Difference between revisions
Content added Content deleted
Underscore (talk | contribs) (I am a math major, hear me roar.) |
No edit summary |
||
Line 88: | Line 88: | ||
subst :: IntExpr -> Equals -> Proof IntExpr |
subst :: IntExpr -> Equals -> Proof IntExpr |
||
{- A convenience function used internally. -} |
{- A convenience function used internally. -} |
||
subst a (a' :== b) |
subst a (a' :== b) | a == a' = return b |
||
⚫ | |||
then return b |
|||
⚫ | |||
{- All the remaining functions are rules of inference, which allow |
{- All the remaining functions are rules of inference, which allow |
||
Line 108: | Line 107: | ||
{- If a = A, b = B, ..., z = Z, |
{- If a = A, b = B, ..., z = Z, |
||
then a + b + ... + z = A + B + ... + Z. -} |
then a + b + ... + z = A + B + ... + Z. -} |
||
equalTerms sum@(Sum l) eqs |
equalTerms sum@(Sum l) eqs |
||
| length l == length eqs = zipWithM subst l eqs >>= return . (sum :==) . Sum |
|||
failf2 "equalTerms: %s and %s have different lengths" l eqs |
| otherwise = failf2 "equalTerms: %s and %s have different lengths" l eqs |
||
zipWithM subst l eqs >>= return . (sum :==) . Sum |
|||
containsFactor :: IntExpr -> IntExpr -> Proof Divides |
containsFactor :: IntExpr -> IntExpr -> Proof Divides |
||
{- If p == a*b, |
{- If p == a*b, |
||
then a | p. -} |
then a | p. -} |
||
expr@(Product l) `containsFactor` x |
expr@(Product l) `containsFactor` x |
||
| x `elem` l = return $ x :| expr |
|||
| otherwise = failf2 "containsFactor: %s not found in %s" x expr |
|||
y `containsFactor` _ = failf "containsFactor: %s not a product" y |
y `containsFactor` _ = failf "containsFactor: %s not a product" y |
||