{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE Trustworthy #-}
module Grisette.Core.Data.Class.CEGISSolver
(
CEGISSolver (..),
CEGISCondition (..),
cegisPostCond,
cegisPrePost,
cegis,
cegisExcept,
cegisExceptStdVC,
cegisExceptVC,
cegisExceptMultiInputs,
cegisExceptStdVCMultiInputs,
cegisExceptVCMultiInputs,
)
where
import GHC.Generics
import Generics.Deriving
import Grisette.Core.Control.Exception
import Grisette.Core.Data.Class.Bool
import Grisette.Core.Data.Class.Evaluate
import Grisette.Core.Data.Class.ExtractSymbolics
import Grisette.Core.Data.Class.Mergeable
import Grisette.Core.Data.Class.SimpleMergeable
import Grisette.Core.Data.Class.Solvable
import Grisette.Core.Data.Class.Solver
import Grisette.IR.SymPrim.Data.Prim.Model
import Grisette.IR.SymPrim.Data.SymPrim
data CEGISCondition = CEGISCondition SymBool SymBool deriving (forall x. Rep CEGISCondition x -> CEGISCondition
forall x. CEGISCondition -> Rep CEGISCondition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CEGISCondition x -> CEGISCondition
$cfrom :: forall x. CEGISCondition -> Rep CEGISCondition x
Generic)
cegisPostCond :: SymBool -> CEGISCondition
cegisPostCond :: SymBool -> CEGISCondition
cegisPostCond = SymBool -> SymBool -> CEGISCondition
CEGISCondition (forall c t. Solvable c t => c -> t
con Bool
True)
cegisPrePost :: SymBool -> SymBool -> CEGISCondition
cegisPrePost :: SymBool -> SymBool -> CEGISCondition
cegisPrePost = SymBool -> SymBool -> CEGISCondition
CEGISCondition
deriving via (Default CEGISCondition) instance Mergeable CEGISCondition
deriving via (Default CEGISCondition) instance SimpleMergeable CEGISCondition
class
CEGISSolver config failure
| config -> failure
where
cegisMultiInputs ::
(EvaluateSym inputs, ExtractSymbolics inputs) =>
config ->
[inputs] ->
(inputs -> CEGISCondition) ->
IO ([inputs], Either failure Model)
cegis ::
( CEGISSolver config failure,
EvaluateSym inputs,
ExtractSymbolics inputs
) =>
config ->
inputs ->
CEGISCondition ->
IO ([inputs], Either failure Model)
cegis :: forall config failure inputs.
(CEGISSolver config failure, EvaluateSym inputs,
ExtractSymbolics inputs) =>
config
-> inputs -> CEGISCondition -> IO ([inputs], Either failure Model)
cegis config
config inputs
inputs CEGISCondition
cond = forall config failure inputs.
(CEGISSolver config failure, EvaluateSym inputs,
ExtractSymbolics inputs) =>
config
-> [inputs]
-> (inputs -> CEGISCondition)
-> IO ([inputs], Either failure Model)
cegisMultiInputs config
config [inputs
inputs] (forall a b. a -> b -> a
const CEGISCondition
cond)
cegisExceptMultiInputs ::
( CEGISSolver config failure,
EvaluateSym inputs,
ExtractSymbolics inputs,
UnionWithExcept t u e v,
UnionPrjOp u,
Monad u
) =>
config ->
[inputs] ->
(Either e v -> CEGISCondition) ->
(inputs -> t) ->
IO ([inputs], Either failure Model)
cegisExceptMultiInputs :: forall config failure inputs t (u :: * -> *) e v.
(CEGISSolver config failure, EvaluateSym inputs,
ExtractSymbolics inputs, UnionWithExcept t u e v, UnionPrjOp u,
Monad u) =>
config
-> [inputs]
-> (Either e v -> CEGISCondition)
-> (inputs -> t)
-> IO ([inputs], Either failure Model)
cegisExceptMultiInputs config
config [inputs]
cexes Either e v -> CEGISCondition
interpretFun inputs -> t
f =
forall config failure inputs.
(CEGISSolver config failure, EvaluateSym inputs,
ExtractSymbolics inputs) =>
config
-> [inputs]
-> (inputs -> CEGISCondition)
-> IO ([inputs], Either failure Model)
cegisMultiInputs config
config [inputs]
cexes (forall bool (u :: * -> *) a.
(SimpleMergeable a, UnionLike u, UnionPrjOp u) =>
u a -> a
simpleMerge forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either e v -> CEGISCondition
interpretFun forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t (u :: * -> *) e v.
UnionWithExcept t u e v =>
t -> u (Either e v)
extractUnionExcept forall b c a. (b -> c) -> (a -> b) -> a -> c
. inputs -> t
f)
cegisExceptVCMultiInputs ::
( CEGISSolver config failure,
EvaluateSym inputs,
ExtractSymbolics inputs,
UnionWithExcept t u e v,
UnionPrjOp u,
Monad u
) =>
config ->
[inputs] ->
(Either e v -> u (Either VerificationConditions ())) ->
(inputs -> t) ->
IO ([inputs], Either failure Model)
cegisExceptVCMultiInputs :: forall config failure inputs t (u :: * -> *) e v.
(CEGISSolver config failure, EvaluateSym inputs,
ExtractSymbolics inputs, UnionWithExcept t u e v, UnionPrjOp u,
Monad u) =>
config
-> [inputs]
-> (Either e v -> u (Either VerificationConditions ()))
-> (inputs -> t)
-> IO ([inputs], Either failure Model)
cegisExceptVCMultiInputs config
config [inputs]
cexes Either e v -> u (Either VerificationConditions ())
interpretFun inputs -> t
f =
forall config failure inputs.
(CEGISSolver config failure, EvaluateSym inputs,
ExtractSymbolics inputs) =>
config
-> [inputs]
-> (inputs -> CEGISCondition)
-> IO ([inputs], Either failure Model)
cegisMultiInputs
config
config
[inputs]
cexes
( \inputs
v ->
forall bool (u :: * -> *) a.
(SimpleMergeable a, UnionLike u, UnionPrjOp u) =>
u a -> a
simpleMerge
( ( \case
Left VerificationConditions
AssumptionViolation -> SymBool -> SymBool -> CEGISCondition
cegisPrePost (forall c t. Solvable c t => c -> t
con Bool
False) (forall c t. Solvable c t => c -> t
con Bool
True)
Left VerificationConditions
AssertionViolation -> SymBool -> CEGISCondition
cegisPostCond (forall c t. Solvable c t => c -> t
con Bool
False)
Either VerificationConditions ()
_ -> SymBool -> CEGISCondition
cegisPostCond (forall c t. Solvable c t => c -> t
con Bool
True)
)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall t (u :: * -> *) e v.
UnionWithExcept t u e v =>
t -> u (Either e v)
extractUnionExcept (inputs -> t
f inputs
v) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Either e v -> u (Either VerificationConditions ())
interpretFun)
)
)
cegisExceptStdVCMultiInputs ::
( CEGISSolver config failure,
EvaluateSym inputs,
ExtractSymbolics inputs,
UnionWithExcept t u VerificationConditions (),
UnionPrjOp u,
Monad u
) =>
config ->
[inputs] ->
(inputs -> t) ->
IO ([inputs], Either failure Model)
cegisExceptStdVCMultiInputs :: forall config failure inputs t (u :: * -> *).
(CEGISSolver config failure, EvaluateSym inputs,
ExtractSymbolics inputs,
UnionWithExcept t u VerificationConditions (), UnionPrjOp u,
Monad u) =>
config
-> [inputs] -> (inputs -> t) -> IO ([inputs], Either failure Model)
cegisExceptStdVCMultiInputs config
config [inputs]
cexes =
forall config failure inputs t (u :: * -> *) e v.
(CEGISSolver config failure, EvaluateSym inputs,
ExtractSymbolics inputs, UnionWithExcept t u e v, UnionPrjOp u,
Monad u) =>
config
-> [inputs]
-> (Either e v -> u (Either VerificationConditions ()))
-> (inputs -> t)
-> IO ([inputs], Either failure Model)
cegisExceptVCMultiInputs config
config [inputs]
cexes forall (m :: * -> *) a. Monad m => a -> m a
return
cegisExcept ::
( UnionWithExcept t u e v,
UnionPrjOp u,
Functor u,
EvaluateSym inputs,
ExtractSymbolics inputs,
CEGISSolver config failure
) =>
config ->
inputs ->
(Either e v -> CEGISCondition) ->
t ->
IO ([inputs], Either failure Model)
cegisExcept :: forall t (u :: * -> *) e v inputs config failure.
(UnionWithExcept t u e v, UnionPrjOp u, Functor u,
EvaluateSym inputs, ExtractSymbolics inputs,
CEGISSolver config failure) =>
config
-> inputs
-> (Either e v -> CEGISCondition)
-> t
-> IO ([inputs], Either failure Model)
cegisExcept config
config inputs
inputs Either e v -> CEGISCondition
f t
v = forall config failure inputs.
(CEGISSolver config failure, EvaluateSym inputs,
ExtractSymbolics inputs) =>
config
-> inputs -> CEGISCondition -> IO ([inputs], Either failure Model)
cegis config
config inputs
inputs forall a b. (a -> b) -> a -> b
$ forall bool (u :: * -> *) a.
(SimpleMergeable a, UnionLike u, UnionPrjOp u) =>
u a -> a
simpleMerge forall a b. (a -> b) -> a -> b
$ Either e v -> CEGISCondition
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall t (u :: * -> *) e v.
UnionWithExcept t u e v =>
t -> u (Either e v)
extractUnionExcept t
v
cegisExceptVC ::
( UnionWithExcept t u e v,
UnionPrjOp u,
Monad u,
EvaluateSym inputs,
ExtractSymbolics inputs,
CEGISSolver config failure
) =>
config ->
inputs ->
(Either e v -> u (Either VerificationConditions ())) ->
t ->
IO ([inputs], Either failure Model)
cegisExceptVC :: forall t (u :: * -> *) e v inputs config failure.
(UnionWithExcept t u e v, UnionPrjOp u, Monad u,
EvaluateSym inputs, ExtractSymbolics inputs,
CEGISSolver config failure) =>
config
-> inputs
-> (Either e v -> u (Either VerificationConditions ()))
-> t
-> IO ([inputs], Either failure Model)
cegisExceptVC config
config inputs
inputs Either e v -> u (Either VerificationConditions ())
f t
v =
forall config failure inputs.
(CEGISSolver config failure, EvaluateSym inputs,
ExtractSymbolics inputs) =>
config
-> inputs -> CEGISCondition -> IO ([inputs], Either failure Model)
cegis config
config inputs
inputs forall a b. (a -> b) -> a -> b
$
forall bool (u :: * -> *) a.
(SimpleMergeable a, UnionLike u, UnionPrjOp u) =>
u a -> a
simpleMerge forall a b. (a -> b) -> a -> b
$
( \case
Left VerificationConditions
AssumptionViolation -> SymBool -> SymBool -> CEGISCondition
cegisPrePost (forall c t. Solvable c t => c -> t
con Bool
False) (forall c t. Solvable c t => c -> t
con Bool
True)
Left VerificationConditions
AssertionViolation -> SymBool -> CEGISCondition
cegisPostCond (forall c t. Solvable c t => c -> t
con Bool
False)
Either VerificationConditions ()
_ -> SymBool -> CEGISCondition
cegisPostCond (forall c t. Solvable c t => c -> t
con Bool
True)
)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall t (u :: * -> *) e v.
UnionWithExcept t u e v =>
t -> u (Either e v)
extractUnionExcept t
v forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Either e v -> u (Either VerificationConditions ())
f)
cegisExceptStdVC ::
( UnionWithExcept t u VerificationConditions (),
UnionPrjOp u,
Monad u,
EvaluateSym inputs,
ExtractSymbolics inputs,
CEGISSolver config failure
) =>
config ->
inputs ->
t ->
IO ([inputs], Either failure Model)
cegisExceptStdVC :: forall t (u :: * -> *) inputs config failure.
(UnionWithExcept t u VerificationConditions (), UnionPrjOp u,
Monad u, EvaluateSym inputs, ExtractSymbolics inputs,
CEGISSolver config failure) =>
config -> inputs -> t -> IO ([inputs], Either failure Model)
cegisExceptStdVC config
config inputs
inputs = forall t (u :: * -> *) e v inputs config failure.
(UnionWithExcept t u e v, UnionPrjOp u, Monad u,
EvaluateSym inputs, ExtractSymbolics inputs,
CEGISSolver config failure) =>
config
-> inputs
-> (Either e v -> u (Either VerificationConditions ()))
-> t
-> IO ([inputs], Either failure Model)
cegisExceptVC config
config inputs
inputs forall (m :: * -> *) a. Monad m => a -> m a
return