Skip to content

adding match for And #2435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions kore/src/Kore/Step/Axiom/Matcher.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ matchOne
matchOne pair =
( matchVariable pair
<|> matchEqualHeads pair
<|> matchAnd pair
<|> matchExists pair
<|> matchForall pair
<|> matchApplication pair
Expand Down Expand Up @@ -443,6 +444,15 @@ matchDefined (Pair term1 term2)
| Defined_ def2 <- term2 = push (Pair term1 def2)
| otherwise = empty

matchAnd
:: (MatchingVariable variable, MonadSimplify simplifier)
=> Pair (TermLike variable)
-> MaybeT (MatcherT variable simplifier) ()
matchAnd (Pair term1 term2)
| And_ _ conj1 conj2 <- term1 =
push (Pair conj1 term2) >> push (Pair conj2 term2)
| otherwise = empty

-- * Implementation

type MatchingVariable variable = InternalVariable variable
Expand Down
27 changes: 27 additions & 0 deletions kore/test/Test/Kore/Step/Axiom/Matcher.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Test.Kore.Step.Axiom.Matcher
, test_matching_Exists
, test_matching_Forall
, test_matching_Equals
, test_matching_And
, test_matcherOverloading
, match
, MatchResult
Expand Down Expand Up @@ -778,6 +779,32 @@ test_matching_Pair =
[(inject xInt, mkElemVar zInt), (inject yInt, mkElemVar zInt)]
]

test_matching_And :: [TestTree]
test_matching_And =
[ matches "and(x, x) matches x"
(mkAnd (mkElemVar xInt) (mkElemVar xInt))
(mkElemVar xInt)
[]
, matches "and(x, y) matches y"
(mkAnd (mkElemVar xInt) (mkElemVar yInt))
(mkElemVar yInt)
[(inject xInt, mkElemVar yInt)]
, matches "and(y, x) matches y"
(mkAnd (mkElemVar yInt) (mkElemVar xInt))
(mkElemVar yInt)
[(inject xInt, mkElemVar yInt)]
, matches "and(x, y) matches z"
(mkAnd (mkElemVar xInt) (mkElemVar yInt))
(mkElemVar zInt)
[(inject xInt, mkElemVar zInt), (inject yInt, mkElemVar zInt)]
, doesn'tMatch "and(x, 1) does not match 2"
(mkAnd (mkElemVar xInt) (mkInt 1))
(mkInt 2)
, doesn'tMatch "and(1, x) does not match 2"
(mkAnd (mkInt 1) (mkElemVar xInt))
(mkInt 2)
]

mkPair
:: TermLike RewritingVariableName
-> TermLike RewritingVariableName
Expand Down