-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add saturation test mentioned in egg's #60 discussion
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{-# LANGUAGE DeriveTraversable #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module T2 where | ||
|
||
-- Tests whether this saturates just like mwillsey claims that it does in egg! | ||
|
||
import Prelude hiding (not) | ||
|
||
import Test.Tasty.HUnit | ||
import Data.Deriving | ||
import Data.Equality.Matching | ||
import Data.Equality.Analysis | ||
import Data.Equality.Language | ||
import Data.Equality.Extraction | ||
import Data.Equality.Saturation | ||
|
||
data Lang a = And a a | ||
| Or a a | ||
| Not a | ||
| ToElim a | ||
| Sym Int | ||
deriving (Functor, Foldable, Traversable) | ||
|
||
deriveEq1 ''Lang | ||
deriveOrd1 ''Lang | ||
deriveShow1 ''Lang | ||
|
||
instance Analysis Lang where | ||
type Domain Lang = () | ||
makeA _ _ = () | ||
joinA = (<>) | ||
|
||
instance Language Lang | ||
|
||
x, y :: Pattern Lang | ||
x = "x" | ||
y = "y" | ||
not :: Pattern Lang -> Pattern Lang | ||
not = pat . Not | ||
|
||
rules :: [Rewrite Lang] | ||
rules = | ||
[ pat (x `And` y) := not (pat (not x `Or` not y)) | ||
, pat (x `Or` y) := not (pat (not x `And` not y)) | ||
, not (not x) := pat (ToElim x) | ||
, pat (ToElim x) := x | ||
] | ||
|
||
main :: IO () | ||
main = do | ||
fst (equalitySaturation (Fix $ (Fix $ Not $ Fix $ Sym 0) `And` (Fix $ Not $ Fix $ Sym 1)) rules depthCost) @?= Fix (Not $ Fix $ (Fix $ Sym 0) `Or` (Fix $ Sym 1)) | ||
pure () | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters