Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d8ca961
Add Kore.Internal.Substitution.retractAssignment
ttuegel Jun 14, 2021
fe4f054
[REF] Push MultiAnd change down into simplifyPredicate
ttuegel Apr 28, 2021
19a210a
Update golden files
ttuegel Apr 30, 2021
8a8b8f3
Clean up simplifyPredicates
ttuegel May 6, 2021
a19dcda
[REF] Insert indirection before simplifyPredicateTODO
ttuegel May 6, 2021
8ddb897
Factor out Kore.Step.Simplification.Predicate
ttuegel May 6, 2021
aa449de
Add failing tests
ttuegel May 6, 2021
2a7a1f0
Use Kore.Internal.From
ttuegel May 14, 2021
93725c6
Materialize Nix expressions
invalid-email-address May 14, 2021
abae992
Add docs/simplify-predicate.md
ttuegel May 18, 2021
2fb5ae2
Distinguish normalization from simplification
ttuegel May 18, 2021
fcd95cb
Format with fourmolu
invalid-email-address May 18, 2021
95a9a8f
Run unification tests through OrPattern
ttuegel May 18, 2021
d665053
Keep predicates in disjunctive normal form
ttuegel May 18, 2021
3573e34
Normalized \bottom
ttuegel May 18, 2021
96e9957
Normalize \top
ttuegel May 18, 2021
edb3f67
Implement fromNot for Predicate
ttuegel May 18, 2021
745e50a
MultiOr: Add traverseOr
ttuegel May 19, 2021
2b12a7a
Move distributeAnd to MultiAnd
ttuegel May 19, 2021
a460f91
AndPredicates: Use scatter
ttuegel May 19, 2021
79e71af
MultiAnd: Add traverseOr and traverseOrAnd
ttuegel May 19, 2021
6651698
[RED] Simplify Not predicates
ttuegel May 19, 2021
6a4a8dc
Fix (some) Not simplifier tests
ttuegel May 20, 2021
4c5f6cb
Simplify double negation
ttuegel May 20, 2021
904c53b
RewriteStep: Update tests
ttuegel May 20, 2021
c880d3d
Recursively mark predicates simplified
ttuegel May 21, 2021
64f6e8b
assertEquivalentPatterns: Give a useful error message
ttuegel May 21, 2021
bd5d33e
Ignore simplification side condition in Predicate simplifier
ttuegel May 21, 2021
ce118ca
Implement Implies simplification
ttuegel May 21, 2021
af66ad3
assertBidirectionalEqualityResult: Add HasCallStack
ttuegel May 24, 2021
a7b4921
Predicate: Add missing newline
ttuegel May 24, 2021
2c7bbff
Simplify Iff
ttuegel May 24, 2021
1effc46
Predicate: Move markSimplified down
ttuegel May 25, 2021
10577b9
Clarify recursive nature of normalization
ttuegel May 26, 2021
daf8be2
Send substitutions to SMT solver
ttuegel May 26, 2021
79b7b39
CheckRequiresError: Include negated implication
ttuegel May 26, 2021
2daa50f
test: make golden
ttuegel May 27, 2021
aa36397
Predicate.simplify: Mark simplified patterns in delegates
ttuegel Jun 1, 2021
4866c43
Refactor and add documentation
ttuegel Jun 2, 2021
5f8c1b6
Format with fourmolu
invalid-email-address Jun 8, 2021
6a6323e
Clean up simplifyImplies
ttuegel Jun 14, 2021
0728d69
Remove special cases of simplifyIff
ttuegel Jun 14, 2021
c2bfbd4
Clean up simplifyImplies and simplifyIff
ttuegel Jun 14, 2021
a7f0699
simplifyPredicates: Revert toward master
ttuegel Jun 16, 2021
5ebb22f
Merge branch 'master' into overhaul-predicate
ttuegel Jun 16, 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
2 changes: 2 additions & 0 deletions kore/kore.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ library
Kore.Step.Simplification.Overloading
Kore.Step.Simplification.OverloadSimplifier
Kore.Step.Simplification.Pattern
Kore.Step.Simplification.Predicate
Kore.Step.Simplification.Rewrites
Kore.Step.Simplification.Rule
Kore.Step.Simplification.SetVariable
Expand Down Expand Up @@ -751,6 +752,7 @@ test-suite kore-test
Test.Kore.Step.Simplification.Or
Test.Kore.Step.Simplification.OrPattern
Test.Kore.Step.Simplification.Overloading
Test.Kore.Step.Simplification.Predicate
Test.Kore.Step.Simplification.Pattern
Test.Kore.Step.Simplification.Rule
Test.Kore.Step.Simplification.StringLiteral
Expand Down
25 changes: 18 additions & 7 deletions kore/src/Kore/Equation/Application.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ import Kore.Internal.Condition (
Condition,
)
import qualified Kore.Internal.Condition as Condition
import Kore.Internal.OrCondition (
OrCondition,
)
import qualified Kore.Internal.OrCondition as OrCondition
import Kore.Internal.OrPattern (
OrPattern,
Expand Down Expand Up @@ -382,16 +385,17 @@ checkRequires sideCondition predicate requires =
where
simplifyCondition = Simplifier.simplifyCondition sideCondition

assertBottom orCondition
| isBottom orCondition = done
| otherwise = requiresNotMet
assertBottom negatedImplication
| isBottom negatedImplication = done
| otherwise = requiresNotMet negatedImplication
done = return ()
requiresNotMet =
requiresNotMet negatedImplication =
throwE
CheckRequiresError
{ matchPredicate = predicate
, equationRequires = requires
, sideCondition
, negatedImplication
}

-- Pair a configuration with sideCondition for evaluation by the solver.
Expand Down Expand Up @@ -530,6 +534,7 @@ data CheckRequiresError variable = CheckRequiresError
{ matchPredicate :: !(Predicate variable)
, equationRequires :: !(Predicate variable)
, sideCondition :: !(SideCondition variable)
, negatedImplication :: !(OrCondition variable)
}
deriving stock (Eq, Ord, Show)
deriving stock (GHC.Generic)
Expand All @@ -539,16 +544,22 @@ data CheckRequiresError variable = CheckRequiresError
instance Pretty (CheckRequiresError RewritingVariableName) where
pretty checkRequiresError =
Pretty.vsep
[ "could not infer the equation requirement:"
[ "Could not infer the equation requirement:"
, Pretty.indent 4 (pretty equationRequires)
, "and the matching requirement:"
, Pretty.indent 4 (pretty matchPredicate)
, "from the side condition:"
, Pretty.indent 4 (pretty sideCondition)
, "The negated implication is:"
, Pretty.indent 4 (pretty negatedImplication)
]
where
CheckRequiresError{matchPredicate, equationRequires, sideCondition} =
checkRequiresError
CheckRequiresError
{ matchPredicate
, equationRequires
, sideCondition
, negatedImplication
} = checkRequiresError

-- * Logging

Expand Down
37 changes: 37 additions & 0 deletions kore/src/Kore/Internal/MultiAnd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ module Kore.Internal.MultiAnd (
singleton,
map,
traverse,
distributeAnd,
traverseOr,
traverseOrAnd,
) where

import qualified Data.Functor.Foldable as Recursive
Expand All @@ -35,6 +38,10 @@ import Kore.Attribute.Pattern.FreeVariables (
import Kore.Internal.Condition (
Condition,
)
import Kore.Internal.MultiOr (
MultiOr,
)
import qualified Kore.Internal.MultiOr as MultiOr
import Kore.Internal.Predicate (
Predicate,
getMultiAndPredicate,
Expand All @@ -49,6 +56,7 @@ import Kore.Internal.Variable
import Kore.TopBottom (
TopBottom (..),
)
import qualified Logic
import Prelude.Kore hiding (
map,
traverse,
Expand Down Expand Up @@ -251,3 +259,32 @@ traverse ::
f (MultiAnd child2)
traverse f = fmap make . Traversable.traverse f . toList
{-# INLINE traverse #-}

distributeAnd ::
Ord term =>
TopBottom term =>
MultiAnd (MultiOr term) ->
MultiOr (MultiAnd term)
distributeAnd multiAnd =
MultiOr.observeAll $ traverse Logic.scatter multiAnd
{-# INLINE distributeAnd #-}

traverseOr ::
Ord child2 =>
TopBottom child2 =>
Applicative f =>
(child1 -> f (MultiOr child2)) ->
MultiAnd child1 ->
f (MultiOr (MultiAnd child2))
traverseOr f = fmap distributeAnd . traverse f
{-# INLINE traverseOr #-}

traverseOrAnd ::
Ord child2 =>
TopBottom child2 =>
Applicative f =>
(child1 -> f (MultiOr (MultiAnd child2))) ->
MultiOr (MultiAnd child1) ->
f (MultiOr (MultiAnd child2))
traverseOrAnd f = MultiOr.traverseOr (fmap (MultiOr.map fold) . traverseOr f)
{-# INLINE traverseOrAnd #-}
28 changes: 12 additions & 16 deletions kore/src/Kore/Internal/MultiOr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module Kore.Internal.MultiOr (
bottom,
filterOr,
flatten,
distributeAnd,
distributeApplication,
gather,
observeAllT,
Expand All @@ -26,6 +25,7 @@ module Kore.Internal.MultiOr (
singleton,
map,
traverse,
traverseOr,

-- * Re-exports
Alternative (..),
Expand All @@ -43,10 +43,6 @@ import GHC.Exts (
import qualified GHC.Generics as GHC
import qualified Generics.SOP as SOP
import Kore.Debug
import Kore.Internal.MultiAnd (
MultiAnd,
)
import qualified Kore.Internal.MultiAnd as MultiAnd
import Kore.Syntax.Application (
Application (..),
)
Expand Down Expand Up @@ -162,17 +158,6 @@ singleton term
| isBottom term = MultiOr []
| otherwise = MultiOr [term]

distributeAnd ::
Ord term =>
TopBottom term =>
MultiAnd (MultiOr term) ->
MultiOr (MultiAnd term)
distributeAnd =
foldr (crossProductGeneric and') (singleton MultiAnd.top)
where
and' term ma =
MultiAnd.singleton term <> ma

distributeApplication ::
Ord head =>
Ord term =>
Expand Down Expand Up @@ -343,3 +328,14 @@ traverse ::
f (MultiOr child2)
traverse f = fmap make . Traversable.traverse f . toList
{-# INLINE traverse #-}

-- | Traverse a @MultiOr@ using an action that returns a disjunction.
traverseOr ::
Ord child2 =>
TopBottom child2 =>
Applicative f =>
(child1 -> f (MultiOr child2)) ->
MultiOr child1 ->
f (MultiOr child2)
traverseOr f = fmap fold . traverse f
{-# INLINE traverseOr #-}
4 changes: 4 additions & 0 deletions kore/src/Kore/Internal/Predicate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ instance From (Iff () child) (PredicateF variable child) where
from = IffF
{-# INLINE from #-}

instance From (Not () child) (PredicateF variable child) where
from = NotF
{-# INLINE from #-}

newtype Predicate variable = Predicate
{ getPredicate ::
Cofree (PredicateF variable) (PredicatePattern variable)
Expand Down
16 changes: 16 additions & 0 deletions kore/src/Kore/Internal/Substitution.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Kore.Internal.Substitution (
assignedVariable,
assignedTerm,
mapAssignedTerm,
retractAssignment,
singleSubstitutionToPredicate,
UnwrappedSubstitution,
mkUnwrappedSubstitution,
Expand Down Expand Up @@ -68,6 +69,7 @@ import qualified Kore.Attribute.Pattern.Simplified as Attribute (
import Kore.Debug
import Kore.Internal.Predicate (
Predicate,
pattern PredicateEquals,
)
import qualified Kore.Internal.Predicate as Predicate
import qualified Kore.Internal.SideCondition.SideCondition as SideCondition (
Expand Down Expand Up @@ -155,6 +157,20 @@ mkUnwrappedSubstitution ::
[Assignment variable]
mkUnwrappedSubstitution = fmap (uncurry assign)

{- | Extract an 'Assignment' from a 'Predicate' of the proper form.

Returns 'Nothing' if the 'Predicate' is not in the correct form.
-}
retractAssignment ::
InternalVariable variable =>
Predicate variable ->
Maybe (Assignment variable)
retractAssignment (PredicateEquals (Var_ var) term) =
Just (assign var term)
retractAssignment (PredicateEquals term (Var_ var)) =
Just (assign var term)
retractAssignment _ = Nothing

{- | @Substitution@ represents a collection @[xᵢ=φᵢ]@ of substitutions.

Individual substitutions are a pair of type
Expand Down
5 changes: 4 additions & 1 deletion kore/src/Kore/Step/SMT/Evaluator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import qualified Kore.Attribute.Symbol as Attribute (
import Kore.IndexedModule.MetadataTools (
SmtMetadataTools,
)
import qualified Kore.Internal.Condition as Condition
import Kore.Internal.Conditional (
Conditional,
)
Expand Down Expand Up @@ -120,7 +121,9 @@ instance
where
evaluate (sideCondition, conditional) =
assert (Conditional.isNormalized conditional) $
evaluate (sideCondition, Conditional.predicate conditional)
evaluate (sideCondition, Condition.toPredicate condition)
where
condition = Conditional.withoutTerm conditional

-- | Removes all branches refuted by an external SMT solver.
filterBranch ::
Expand Down
6 changes: 3 additions & 3 deletions kore/src/Kore/Step/Simplification/AndPredicates.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import qualified Kore.Internal.Condition as Condition
import Kore.Internal.MultiAnd (
MultiAnd,
)
import qualified Kore.Internal.MultiAnd as MultiAnd
import qualified Kore.Internal.MultiOr as MultiOr
import Kore.Internal.OrCondition (
OrCondition,
Expand All @@ -38,10 +39,9 @@ simplifyEvaluatedMultiPredicate ::
SideCondition RewritingVariableName ->
MultiAnd (OrCondition RewritingVariableName) ->
simplifier (OrCondition RewritingVariableName)
simplifyEvaluatedMultiPredicate sideCondition predicates = do
let crossProduct = MultiOr.distributeAnd predicates
simplifyEvaluatedMultiPredicate sideCondition predicates =
MultiOr.observeAllT $ do
element <- LogicT.scatter crossProduct
element <- MultiAnd.traverse LogicT.scatter predicates
andConditions element
where
andConditions predicates' =
Expand Down
Loading