Eliminate (:==) completely.

This commit is contained in:
Iavor S. Diatchki 2014-11-03 10:02:08 -08:00
parent 20e8d89c66
commit 7154d09f23

View File

@ -11,15 +11,18 @@ import qualified Control.Applicative as A
test = test =
do print (ppExpr expr) do -- print (ppExpr expr)
mapM_ (print . ppProp) mapM_ (print . ppProp)
$ crySimpSteps $ return
$ cryDefined expr $ crySimplify
$ expr
where where
a : b : c : d : _ = map (Var . Name) [ 0 .. ] a : b : c : d : _ = map (Var . Name) [ 0 .. ]
expr = Div a b expr = a :== zero
rest = Min (a :* b) (inf :* (inf :* (c :+ d))) rest = Div a b
: Min (a :* b) (inf :* (inf :* (c :+ d)))
: []
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -366,16 +369,18 @@ cryIsFin expr =
-- | Simplify @t :== 0@ or @t :==: 0@. -- | Simplify @t :== 0@ or @t :==: 0@.
-- Assumes defined input. -- Assumes defined input.
cryIs0 :: Bool -> Expr -> Maybe Prop cryIs0 :: Bool -> Expr -> Maybe Prop
cryIs0 useFinite ty = cryIs0 useFinite expr =
case ty of case expr of
K Inf -> Just PFalse K Inf -> Just PFalse
K (Nat n) -> Just (if n == 0 then PTrue else PFalse) K (Nat n) -> Just (if n == 0 then PTrue else PFalse)
Var _ -> Nothing Var _ | useFinite -> Nothing
| otherwise -> Just (Fin expr :&& expr :==: zero)
t1 :+ t2 -> Just (eq t1 zero :&& eq t2 zero) t1 :+ t2 -> Just (eq t1 zero :&& eq t2 zero)
t1 :- t2 -> Just (eq t1 t2) t1 :- t2 -> Just (eq t1 t2)
t1 :* t2 -> Just (eq t1 zero :|| eq t2 zero) t1 :* t2 -> Just (eq t1 zero :|| eq t2 zero)
Div t1 t2 -> Just (gt t2 t1) Div t1 t2 -> Just (gt t2 t1)
Mod _ _ -> (`eq` zero) `fmap` crySimpExpr ty Mod _ _ | useFinite -> (:==: zero) `fmap` crySimpExpr expr
| otherwise -> Just (cryNatOp (:==:) expr zero)
-- or: Just (t2 `Divides` t1) -- or: Just (t2 `Divides` t1)
t1 :^^ t2 -> Just (eq t1 zero :&& gt t2 zero) t1 :^^ t2 -> Just (eq t1 zero :&& gt t2 zero)
Min t1 t2 -> Just (eq t1 zero :|| eq t2 zero) Min t1 t2 -> Just (eq t1 zero :|| eq t2 zero)