11{- HLINT ignore "Use all" -}
2+ {-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
3+ {-# HLINT ignore "Use any" #-}
24module Cardano.ReCon.LTL.Lang.HomogeneousFormula (
35 HomogeneousFormula (.. )
46 , toFormula
@@ -37,6 +39,8 @@ data HomogeneousFormula event ty =
3739 ----------- Event property ----------
3840 | PropForall PropVarIdentifier (HomogeneousFormula event ty )
3941 | PropForallN PropVarIdentifier (Set PropValue ) (HomogeneousFormula event ty )
42+ | PropExists PropVarIdentifier (HomogeneousFormula event ty )
43+ | PropExistsN PropVarIdentifier (Set PropValue ) (HomogeneousFormula event ty )
4044 | PropEq (Relevance event ty ) PropTerm PropValue deriving (Show , Eq , Ord )
4145 -------------------------------------
4246
@@ -50,6 +54,8 @@ toFormula Top = F.Top
5054toFormula (PropEq e a b) = F. PropEq e a b
5155toFormula (PropForall x phi) = F. PropForall x (toFormula phi)
5256toFormula (PropForallN x dom phi) = F. PropForallN x dom (toFormula phi)
57+ toFormula (PropExists x phi) = F. PropExists x (toFormula phi)
58+ toFormula (PropExistsN x dom phi) = F. PropExistsN x dom (toFormula phi)
5359
5460valuesAccum :: Set PropValue -> PropVarIdentifier -> HomogeneousFormula event ty -> Set PropValue
5561valuesAccum acc x (Or phi psi) = valuesAccum (valuesAccum acc x phi) x psi
@@ -65,6 +71,10 @@ valuesAccum acc x (PropForall x' phi) | x /= x' = valuesAccum acc x phi
6571valuesAccum acc _ (PropForall _ _) = acc
6672valuesAccum acc x (PropForallN x' _ phi) | x /= x' = valuesAccum acc x phi
6773valuesAccum acc _ (PropForallN {}) = acc
74+ valuesAccum acc x (PropExists x' phi) | x /= x' = valuesAccum acc x phi
75+ valuesAccum acc _ (PropExists _ _) = acc
76+ valuesAccum acc x (PropExistsN x' _ phi) | x /= x' = valuesAccum acc x phi
77+ valuesAccum acc _ (PropExistsN {}) = acc
6878
6979-- | Set of values the given prop var can take in the formula.
7080values :: PropVarIdentifier -> HomogeneousFormula event ty -> Set PropValue
@@ -88,6 +98,10 @@ substHomogeneousFormula v x (PropForall x' phi) | x /= x' = PropForall x' (subst
8898substHomogeneousFormula _ _ (PropForall x' phi) = PropForall x' phi
8999substHomogeneousFormula v x (PropForallN x' dom phi) | x /= x' = PropForallN x' dom (substHomogeneousFormula v x phi)
90100substHomogeneousFormula _ _ (PropForallN x' dom phi) = PropForallN x' dom phi
101+ substHomogeneousFormula v x (PropExists x' phi) | x /= x' = PropExists x' (substHomogeneousFormula v x phi)
102+ substHomogeneousFormula _ _ (PropExists x' phi) = PropExists x' phi
103+ substHomogeneousFormula v x (PropExistsN x' dom phi) | x /= x' = PropExistsN x' dom (substHomogeneousFormula v x phi)
104+ substHomogeneousFormula _ _ (PropExistsN x' dom phi) = PropExistsN x' dom phi
91105
92106-- | Evaluate the `HomogeneousFormula` onto `Bool`.
93107-- This is the "interesting" part of the iso: `HomogeneousFormula` ≅ `Bool`
@@ -112,6 +126,18 @@ eval (PropForallN x dom phi) =
112126 Set. toList dom <&> \ v ->
113127 eval (substHomogeneousFormula (Val v) x phi)
114128 )
129+ -- ⟦∃x. φ⟧ <=> φ[☐/x] ∨ φ[v₁ / x] ∨ ... ∨ φ[vₖ / x] where v₁...vₖ is the set of values in φ which x can take.
130+ eval (PropExists x phi) = eval (substHomogeneousFormula Placeholder x phi) ||
131+ Prelude. or (
132+ Set. toList (values x phi) <&> \ v ->
133+ eval (substHomogeneousFormula (Val v) x phi)
134+ )
135+ -- ⟦∃(x ∈ v₁...vₖ). φ⟧ <=> φ[v₁ / x] ∨ ... ∨ φ[vₖ / x]
136+ eval (PropExistsN x dom phi) =
137+ Prelude. or (
138+ Set. toList dom <&> \ v ->
139+ eval (substHomogeneousFormula (Val v) x phi)
140+ )
115141
116142-- | This is the "easy" part of the iso: `HomogeneousFormula` ≅ `Bool`
117143quote :: Bool -> HomogeneousFormula event ty
@@ -144,6 +170,8 @@ retract = go Set.empty where
144170 go _ (F. PropEq _ (Var _) _) = Nothing
145171 go bound (F. PropForall x phi) = PropForall x <$> go (Set. insert x bound) phi
146172 go bound (F. PropForallN x dom phi) = PropForallN x dom <$> go (Set. insert x bound) phi
173+ go bound (F. PropExists x phi) = PropExists x <$> go (Set. insert x bound) phi
174+ go bound (F. PropExistsN x dom phi) = PropExistsN x dom <$> go (Set. insert x bound) phi
147175
148176normaliseHomogeneous :: Formula event ty -> Maybe (Formula event ty )
149177normaliseHomogeneous phi =
0 commit comments