Skip to content

Keep set of defined terms in SideCondition #2354

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 61 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
ef7e6a2
Add HashMap to SideCondition
ana-pantilie Dec 7, 2020
acd2db2
Rename assumptions to replacements
ana-pantilie Dec 7, 2020
a5f33ef
Use simplifyConjunctionWithAssumptions to construct and combine SideC…
ana-pantilie Dec 8, 2020
4ff1717
Hlint
ana-pantilie Dec 8, 2020
3a9367c
Use to and from SideCondition to simplify Condition
ana-pantilie Dec 14, 2020
4675f21
Merge remote-tracking branch 'ana-pantilie/substitution-map-in-sideco…
ana-pantilie Dec 15, 2020
2316fe4
Use Changed in simplifyConjunctions again
ana-pantilie Dec 16, 2020
aab235e
Merge branch 'master' into replacement-map-in-sidecondition
ana-pantilie Dec 16, 2020
a0548d4
Use replacements when simplifying terms, with exception
ana-pantilie Dec 17, 2020
e94747f
Regenerate golden
ana-pantilie Dec 17, 2020
0615cd6
Comment out failing test, TODO fix
ana-pantilie Dec 17, 2020
50cf56a
Merge branch 'replacement-map-in-sidecondition' of github.com:kframew…
ana-pantilie Dec 17, 2020
d9a2efd
Simplify Pattern with SideCondition in only special cases
ana-pantilie Dec 18, 2020
75d5de7
Use simplify instead of simplifyTopConfiguration
ana-pantilie Dec 18, 2020
3ea5720
Modify test which describes possibly wrong behavior
ana-pantilie Dec 18, 2020
99e47e0
Merge remote-tracking branch 'origin/master' into replacement-map-in-…
ana-pantilie Dec 18, 2020
2239a98
Merge branch 'master' into replacement-map-in-sidecondition
ana-pantilie Dec 21, 2020
8427101
Fixed onepath test
ana-pantilie Dec 21, 2020
6e5da94
TermLike.simplify unit tests; simplify with all replacements
ana-pantilie Dec 21, 2020
2d32ce3
Remove unused imports
ana-pantilie Dec 22, 2020
bb0deb2
Add Pretty instance for SideCondition
ana-pantilie Dec 22, 2020
fc82465
Add documentation
ana-pantilie Dec 22, 2020
d0d5a92
Add strictness to fields
ana-pantilie Dec 22, 2020
be0eff9
Add strict language pragma
ana-pantilie Jan 6, 2021
ff4667b
Make lazy binding
ana-pantilie Jan 7, 2021
319a6ca
Merge branch 'master' into replacement-map-in-sidecondition
ana-pantilie Jan 7, 2021
82678f7
Address review comments
ana-pantilie Jan 8, 2021
f8626e1
Clean-up
ana-pantilie Jan 8, 2021
f2da9d1
Update kore/src/Kore/Step/Simplification/Condition.hs
ana-pantilie Jan 8, 2021
b892e8f
Update Debug.hs
ana-pantilie Jan 8, 2021
45ac029
Merge branch 'master' into replacement-map-in-sidecondition
ana-pantilie Jan 8, 2021
d43d564
Modify simplification in checkImplication
ana-pantilie Jan 8, 2021
9864a29
Merge branch 'replacement-map-in-sidecondition' of github.com:kframew…
ana-pantilie Jan 8, 2021
c8f1282
unifyKequalsEq should apply for both \and and \equals
ana-pantilie Jan 12, 2021
14338ee
Tests for KEqual unification
ana-pantilie Jan 13, 2021
f53f318
Merge branch 'unify-kequals-both' into replacement-map-in-sidecondition
ana-pantilie Jan 14, 2021
e3d7b75
Merge remote-tracking branch 'origin/master' into replacement-map-in-…
ana-pantilie Jan 14, 2021
b02e458
Merge remote-tracking branch 'origin/master' into replacement-map-in-…
ana-pantilie Jan 16, 2021
8eb3a7c
Add a HashSet of defined TermLikes to SideCondition
ana-pantilie Jan 19, 2021
edff82c
Draft, incomplete implementation of assumeDefined
ana-pantilie Jan 20, 2021
9199f2e
Implement assumeDefined for assoc comm collections
ana-pantilie Jan 21, 2021
cdedaa8
Fix
ana-pantilie Jan 21, 2021
9d44720
Fixes and tests for generateNormalizedAcs
ana-pantilie Jan 21, 2021
294b729
Tests and fixes
ana-pantilie Jan 21, 2021
6095fae
Keep term and predicate replacements together as terms
ana-pantilie Jan 21, 2021
907817f
Merge branch 'master' into replacement-map-in-sidecondition
ana-pantilie Jan 21, 2021
3d92b8c
Merge branch 'master' into replacement-map-in-sidecondition
ana-pantilie Jan 21, 2021
3a98848
Remove double import
ana-pantilie Jan 22, 2021
bfb6080
generateNormalizedAcs: clean-up
ana-pantilie Jan 26, 2021
3f80f88
Finish isDefined, add tests and clean-up
ana-pantilie Jan 27, 2021
d7536b7
Merge remote-tracking branch 'origin/replacement-map-in-sidecondition…
ana-pantilie Jan 27, 2021
756cde3
Merge remote-tracking branch 'origin/master' into defined-terms-in-si…
ana-pantilie Jan 29, 2021
f478491
Major test clean-up, include set tests
ana-pantilie Jan 29, 2021
d180df7
Fix functional application case, add tests
ana-pantilie Jan 29, 2021
93f2a81
Review: remove TopBottom instance, toPredicate includes defined terms
ana-pantilie Feb 2, 2021
848ff05
Review: redundant case and freeVariables
ana-pantilie Feb 2, 2021
4e09391
Do not add collection to defined, special case for singletons
ana-pantilie Feb 3, 2021
76b7856
Refactor newly added tests
ana-pantilie Feb 3, 2021
9daf33c
Merge branch 'master' into defined-terms-in-sidecondition
ana-pantilie Feb 3, 2021
3900cc3
Fix conflicts with master
ana-pantilie Feb 3, 2021
ba60e3b
Refactor and clean-up CeilSimplifier
ana-pantilie Feb 3, 2021
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
16 changes: 16 additions & 0 deletions kore/src/Debug.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ import Data.HashMap.Strict
( HashMap
)
import qualified Data.HashMap.Strict as HashMap
import Data.HashSet
( HashSet
)
import qualified Data.HashSet as HashSet
import Data.Int
import Data.Map.Strict
( Map
Expand Down Expand Up @@ -346,6 +350,11 @@ instance Debug a => Debug (Set a) where
(parens (precOut >= 10) . Pretty.sep)
["Data.Set.fromList", debug (Set.toList as)]

instance Debug a => Debug (HashSet a) where
debugPrec as precOut =
(parens (precOut >= 10) . Pretty.sep)
["Data.HashSet.fromList", debug (HashSet.toList as)]

instance Debug a => Debug (Seq a) where
debugPrec as precOut =
(parens (precOut >= 10) . Pretty.sep)
Expand Down Expand Up @@ -620,6 +629,13 @@ instance (Debug a, Diff a) => Diff (Set a) where
wrapFromList diff' precOut =
parens (precOut >= 10) $ "Data.Set.fromList" <+> diff' 10

instance (Debug a, Diff a) => Diff (HashSet a) where
diffPrec as bs =
fmap wrapFromList $ diffPrec (HashSet.toList as) (HashSet.toList bs)
where
wrapFromList diff' precOut =
parens (precOut >= 10) $ "Data.HashSet.fromList" <+> diff' 10

instance Diff ExitCode

instance (Debug a, Debug b, Diff a, Diff b) => Diff (Either a b)
Expand Down
238 changes: 106 additions & 132 deletions kore/src/Kore/Builtin/AssocComm/CeilSimplifier.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@ import Prelude.Kore
import Control.Error
( MaybeT
)
import qualified Control.Lens as Lens
import Control.Monad
( zipWithM
)
import Control.Monad.Reader
( MonadReader
)
import qualified Control.Monad.Reader as Reader
import qualified Data.List as List
import qualified Data.Bifunctor as Bifunctor
import qualified Data.Map.Strict as Map

import Kore.Attribute.Pattern.FreeVariables
Expand Down Expand Up @@ -175,6 +171,8 @@ generalizeMapElement freeVariables' element =
newBuiltinAssocCommCeilSimplifier
:: forall normalized variable simplifier
. InternalVariable variable
=> Ord (Element normalized (TermLike variable))
=> Ord (Value normalized (TermLike variable))
=> MonadReader (SideCondition variable) simplifier
=> MonadSimplify simplifier
=> Traversable (Value normalized)
Expand All @@ -188,112 +186,95 @@ newBuiltinAssocCommCeilSimplifier mkBuiltin mkNotMember =
CeilSimplifier $ \Ceil { ceilChild } -> do
let internalAc@InternalAc { builtinAcChild } = ceilChild
sideCondition <- Reader.ask
let normalizedAc :: NormalizedAc normalized Key (TermLike variable)
normalizedAc = unwrapAc builtinAcChild
NormalizedAc
{ elementsWithVariables = abstractElements
, concreteElements
, opaque
}
= normalizedAc

let defineOpaquePair
:: TermLike variable
-> TermLike variable
-> MultiAnd (OrCondition variable)
defineOpaquePair opaque1 opaque2 =
internalAc
{ builtinAcChild =
wrapAc
emptyNormalizedAc { opaque = [opaque1, opaque2] }
}
& mkBuiltin
& makeCeilPredicate
-- TODO (thomas.tuegel): Do not mark this simplified.
-- Marking here may prevent user-defined axioms from applying.
-- At present, we wouldn't apply such an axiom, anyway.
& Predicate.markSimplifiedMaybeConditional Nothing
& OrCondition.fromPredicate
& MultiAnd.singleton

defineOpaquePairs
:: TermLike variable
-> [TermLike variable]
-> MultiAnd (OrCondition variable)
defineOpaquePairs this others =
foldMap (defineOpaquePair this) others

definedOpaquePairs :: MultiAnd (OrCondition variable)
definedOpaquePairs =
mconcat
$ zipWith defineOpaquePairs opaque
$ tail $ List.tails opaque

let abstractKeys, concreteKeys
:: [TermLike variable]
abstractValues, concreteValues, allValues
:: [Value normalized (TermLike variable)]
(abstractKeys, abstractValues) =
unzip (unwrapElement <$> abstractElements)
concreteKeys = from @Key <$> Map.keys concreteElements
concreteValues = Map.elems concreteElements
allValues = concreteValues <> abstractValues

let makeEvaluateTerm, defineAbstractKey, defineOpaque
:: TermLike variable -> MaybeT simplifier (OrCondition variable)
makeEvaluateTerm = makeEvaluateTermCeil sideCondition
defineAbstractKey = makeEvaluateTerm
defineOpaque = makeEvaluateTerm

defineValue
:: Value normalized (TermLike variable)
-> MaybeT simplifier (MultiAnd (OrCondition variable))
defineValue = foldlM worker mempty
where
worker multiAnd termLike = do
evaluated <- makeEvaluateTerm termLike
return (multiAnd <> MultiAnd.singleton evaluated)

TermLike.assertConstructorLikeKeys concreteKeys $ return ()

-- concreteKeys are defined by assumption
definedKeys <- traverse defineAbstractKey abstractKeys
definedOpaque <- traverse defineOpaque opaque
definedValues <- traverse defineValue allValues
-- concreteKeys are distinct by assumption
distinctConcreteKeys <-
traverse (flip distinctKey concreteKeys) abstractKeys
distinctAbstractKeys <-
zipWithM distinctKey
abstractKeys
(tail $ List.tails abstractKeys)
let conditions :: MultiAnd (OrCondition variable)
conditions =
mconcat
[ MultiAnd.make definedKeys
, MultiAnd.make definedOpaque
, mconcat definedValues
, mconcat distinctConcreteKeys
, mconcat distinctAbstractKeys
, foldMap (notMembers normalizedAc) opaque
, definedOpaquePairs
]

let symbolicKeys = getSymbolicKeysOfAc builtinAcChild
symbolicValues = getSymbolicValuesOfAc builtinAcChild
concreteValues = getConcreteValuesOfAc builtinAcChild
opaqueElements = opaque . unwrapAc $ builtinAcChild
definedKeysAndOpaque <-
traverse
(makeEvaluateTermCeil sideCondition)
(symbolicKeys <> opaqueElements)
& fmap MultiAnd.make
definedValues <-
traverse
(defineValue sideCondition)
(symbolicValues <> concreteValues)
& fmap mconcat
definedSubCollections <-
definePairWiseElements mkBuiltin mkNotMember internalAc
. generatePairWiseElements
$ builtinAcChild
let conditions =
definedKeysAndOpaque
<> definedValues
<> definedSubCollections
And.simplifyEvaluatedMultiPredicate sideCondition conditions
where
defineValue
:: SideCondition variable
-> Value normalized (TermLike variable)
-> MaybeT simplifier (MultiAnd (OrCondition variable))
defineValue sideCondition = foldlM worker mempty
where
worker multiAnd termLike = do
evaluated <- makeEvaluateTermCeil sideCondition termLike
return (multiAnd <> MultiAnd.singleton evaluated)

distinctKey
:: TermLike variable
-> [TermLike variable]
-> MaybeT simplifier (MultiAnd (OrCondition variable))
distinctKey thisKey otherKeys =
MultiAnd.make <$> traverse (notEquals thisKey) otherKeys
definePairWiseElements
:: forall variable normalized simplifier
. MonadSimplify simplifier
=> InternalVariable variable
=> MonadReader (SideCondition variable) simplifier
=> AcWrapper normalized
=> MkBuiltinAssocComm normalized variable
-> MkNotMember normalized variable
-> InternalAc Key normalized (TermLike variable)
-> PairWiseElements normalized Key (TermLike variable)
-> MaybeT simplifier (MultiAnd (OrCondition variable))
definePairWiseElements mkBuiltin mkNotMember internalAc pairWiseElements = do
definedKeyPairs <-
traverse
distinctKey
(symbolicKeyPairs <> symbolicConcreteKeyPairs)
& fmap MultiAnd.make
let definedElementOpaquePairs =
foldMap
notMember
(symbolicOpaquePairs <> concreteOpaquePairs')
definedOpaquePairs =
foldMap defineOpaquePair opaquePairs
return . fold $
[ definedKeyPairs
, definedElementOpaquePairs
, definedOpaquePairs
]
where
PairWiseElements
{ symbolicPairs
, opaquePairs
, symbolicConcretePairs
, symbolicOpaquePairs
, concreteOpaquePairs
} = pairWiseElements
symbolicKeyPairs =
Bifunctor.bimap
(fst . unwrapElement)
(fst . unwrapElement)
<$> symbolicPairs
symbolicConcreteKeyPairs =
Bifunctor.bimap
(fst . unwrapElement)
(from @Key @(TermLike variable) . fst)
<$> symbolicConcretePairs
concreteOpaquePairs' =
Bifunctor.first
wrapConcreteElement
<$> concreteOpaquePairs

notEquals
:: TermLike variable
-> TermLike variable
-> MaybeT simplifier (OrCondition variable)
notEquals t1 t2 = do
distinctKey
:: (TermLike variable, TermLike variable)
-> MaybeT simplifier (OrCondition variable)
distinctKey (t1, t2) = do
sideCondition <- Reader.ask
Equals.makeEvaluateTermsToPredicate tMin tMax sideCondition
>>= Not.simplifyEvaluatedPredicate
Expand All @@ -302,37 +283,30 @@ newBuiltinAssocCommCeilSimplifier mkBuiltin mkNotMember =
(tMin, tMax) = minMax t1 t2

notMember
:: TermLike variable
-> Element normalized (TermLike variable)
:: (Element normalized (TermLike variable), TermLike variable)
-> MultiAnd (OrCondition variable)
notMember termLike element =
notMember (element, termLike) =
mkNotMember element termLike
& OrCondition.fromPredicate
& MultiAnd.singleton

notMembers
:: NormalizedAc normalized Key (TermLike variable)
-> TermLike variable
defineOpaquePair
:: (TermLike variable, TermLike variable)
-> MultiAnd (OrCondition variable)
notMembers normalizedAc termLike =
Lens.foldMapOf foldElements (notMember termLike) normalizedAc

foldElements
:: AcWrapper collection
=> InternalVariable variable
=> Lens.Fold
(NormalizedAc collection Key (TermLike variable))
(Element collection (TermLike variable))
foldElements =
Lens.folding $ \normalizedAc ->
let
concreteElements' =
concreteElements normalizedAc
& Map.toList
& map wrapConcreteElement
symbolicElements' = elementsWithVariables normalizedAc
in
concreteElements' <> symbolicElements'
defineOpaquePair (opaque1, opaque2) =
internalAc
{ builtinAcChild =
wrapAc
emptyNormalizedAc { opaque = [opaque1, opaque2] }
}
& mkBuiltin
& makeCeilPredicate
-- TODO (thomas.tuegel): Do not mark this simplified.
-- Marking here may prevent user-defined axioms from applying.
-- At present, we wouldn't apply such an axiom, anyway.
& Predicate.markSimplifiedMaybeConditional Nothing
& OrCondition.fromPredicate
& MultiAnd.singleton

fromElement
:: AcWrapper normalized
Expand Down
56 changes: 56 additions & 0 deletions kore/src/Kore/Internal/NormalizedAc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module Kore.Internal.NormalizedAc
, normalizedAcConstructorLike
, normalizedAcFunctional
, unparseInternalAc
, PairWiseElements (..)
, generatePairWiseElements
) where

import Prelude.Kore
Expand All @@ -39,6 +41,9 @@ import Control.Lens.Iso
import Data.Kind
( Type
)
import Data.List.Extra
( nubOrdBy
)
import Data.Map.Strict
( Map
)
Expand Down Expand Up @@ -489,3 +494,54 @@ normalizedAcConstructorLike ac@(NormalizedAc _ _ _) =
pairIsConstructorLike (key, value) =
assertConstructorLike "" key $ isConstructorLike value
_ -> ConstructorLike Nothing

-- | 'PairWiseElements' is a representation of the elements of all subcollections
-- necessary for proving the definedness of a collection.
data PairWiseElements normalized key child =
PairWiseElements
{ symbolicPairs
:: [(Element normalized child, Element normalized child)]
, concretePairs
:: [((key, Value normalized child), (key, Value normalized child))]
, opaquePairs
:: [(child, child)]
, symbolicConcretePairs
:: [(Element normalized child, (key, Value normalized child))]
, symbolicOpaquePairs
:: [(Element normalized child, child)]
, concreteOpaquePairs
:: [((key, Value normalized child), child)]
}

-- | Generates the 'PairWiseElements' for a 'AcWrapper' collection.
generatePairWiseElements
:: AcWrapper normalized
=> Ord key
=> Ord child
=> Ord (Element normalized child)
=> Ord (Value normalized child)
=> normalized key child
-> PairWiseElements normalized key child
generatePairWiseElements (unwrapAc -> normalized) =
PairWiseElements
{ symbolicPairs = pairWiseElemsOfSameType symbolicElems
, concretePairs = pairWiseElemsOfSameType concreteElems
, opaquePairs = pairWiseElemsOfSameType opaqueElems
, symbolicConcretePairs =
(,) <$> symbolicElems <*> concreteElems
, symbolicOpaquePairs =
(,) <$> symbolicElems <*> opaqueElems
, concreteOpaquePairs =
(,) <$> concreteElems <*> opaqueElems
}
where
symbolicElems = elementsWithVariables normalized
concreteElems = Map.toList . concreteElements $ normalized
opaqueElems = opaque normalized
pairWiseElemsOfSameType elems =
[ (x, y) | x <- elems, y <- elems, x /= y ]
& nubOrdBy applyComm
applyComm p1 p2
| p1 == p2 = EQ
| swap p1 == p2 = EQ
| otherwise = compare p1 p2
Loading