grisette-0.11.0.0: Symbolic evaluation as a library
Copyright(c) Sirui Lu 2021-2023
LicenseBSD-3-Clause (see the LICENSE file)
Maintainersiruilu@cs.washington.edu
StabilityExperimental
PortabilityGHC only
Safe HaskellTrustworthy
LanguageHaskell2010

Grisette.Internal.Core.Data.Class.CEGISSolver

Description

 
Synopsis

Note for the examples

The examples assumes that the z3 solver is available in PATH.

Generic CEGIS interface

data VerifierResult cex exception Source #

The response from a verifier.

Constructors

CEGISVerifierFoundCex cex 
CEGISVerifierNoCex Bool

True indicates that the verifier is sure that there is no counter-example, while False indicates that the verifier is not sure, but it cannot find a counter-example.

CEGISVerifierException exception 

Instances

Instances details
(Lift cex, Lift exception) => Lift (VerifierResult cex exception :: Type) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Methods

lift :: Quote m => VerifierResult cex exception -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => VerifierResult cex exception -> Code m (VerifierResult cex exception) #

(NFData cex, NFData exception) => NFData (VerifierResult cex exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Methods

rnf :: VerifierResult cex exception -> () #

Generic (VerifierResult cex exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Associated Types

type Rep (VerifierResult cex exception) 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

type Rep (VerifierResult cex exception) = D1 ('MetaData "VerifierResult" "Grisette.Internal.Core.Data.Class.CEGISSolver" "grisette-0.11.0.0-HndeEPlDvvDHSETLw6O8c" 'False) (C1 ('MetaCons "CEGISVerifierFoundCex" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 cex)) :+: (C1 ('MetaCons "CEGISVerifierNoCex" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)) :+: C1 ('MetaCons "CEGISVerifierException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 exception))))

Methods

from :: VerifierResult cex exception -> Rep (VerifierResult cex exception) x #

to :: Rep (VerifierResult cex exception) x -> VerifierResult cex exception #

(Show cex, Show exception) => Show (VerifierResult cex exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Methods

showsPrec :: Int -> VerifierResult cex exception -> ShowS #

show :: VerifierResult cex exception -> String #

showList :: [VerifierResult cex exception] -> ShowS #

(Eq cex, Eq exception) => Eq (VerifierResult cex exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Methods

(==) :: VerifierResult cex exception -> VerifierResult cex exception -> Bool #

(/=) :: VerifierResult cex exception -> VerifierResult cex exception -> Bool #

(PPrint cex, PPrint exception) => PPrint (VerifierResult cex exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Methods

pformat :: VerifierResult cex exception -> Doc ann Source #

pformatPrec :: Int -> VerifierResult cex exception -> Doc ann Source #

pformatList :: [VerifierResult cex exception] -> Doc ann Source #

(Hashable cex, Hashable exception) => Hashable (VerifierResult cex exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Methods

hashWithSalt :: Int -> VerifierResult cex exception -> Int #

hash :: VerifierResult cex exception -> Int #

type Rep (VerifierResult cex exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

type Rep (VerifierResult cex exception) = D1 ('MetaData "VerifierResult" "Grisette.Internal.Core.Data.Class.CEGISSolver" "grisette-0.11.0.0-HndeEPlDvvDHSETLw6O8c" 'False) (C1 ('MetaCons "CEGISVerifierFoundCex" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 cex)) :+: (C1 ('MetaCons "CEGISVerifierNoCex" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)) :+: C1 ('MetaCons "CEGISVerifierException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 exception))))

type SynthesisConstraintFun cex = cex -> IO SymBool Source #

Build the synthesizer constraint from the verfication result. The first argument will be guaranteed to be distinct during each invocation of the function in the CEGIS algorithm, so it can be used to instantiate the identifiers for fresh variables.

type VerifierFun cex exception = Model -> IO (VerifierResult cex exception) Source #

The verifier.

data CEGISResult exception Source #

The result of the CEGIS procedure.

Instances

Instances details
Lift exception => Lift (CEGISResult exception :: Type) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Methods

lift :: Quote m => CEGISResult exception -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => CEGISResult exception -> Code m (CEGISResult exception) #

Serial exception => Binary (CEGISResult exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Methods

put :: CEGISResult exception -> Put #

get :: Get (CEGISResult exception) #

putList :: [CEGISResult exception] -> Put #

Serial exception => Serial (CEGISResult exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Methods

serialize :: MonadPut m => CEGISResult exception -> m () #

deserialize :: MonadGet m => m (CEGISResult exception) #

Serial exception => Serialize (CEGISResult exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Methods

put :: Putter (CEGISResult exception) #

get :: Get (CEGISResult exception) #

NFData exception => NFData (CEGISResult exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Methods

rnf :: CEGISResult exception -> () #

Generic (CEGISResult exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Associated Types

type Rep (CEGISResult exception) 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

type Rep (CEGISResult exception) = D1 ('MetaData "CEGISResult" "Grisette.Internal.Core.Data.Class.CEGISSolver" "grisette-0.11.0.0-HndeEPlDvvDHSETLw6O8c" 'False) (C1 ('MetaCons "CEGISSuccess" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Model)) :+: (C1 ('MetaCons "CEGISVerifierFailure" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 exception)) :+: C1 ('MetaCons "CEGISSolverFailure" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SolvingFailure))))

Methods

from :: CEGISResult exception -> Rep (CEGISResult exception) x #

to :: Rep (CEGISResult exception) x -> CEGISResult exception #

Show exception => Show (CEGISResult exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Methods

showsPrec :: Int -> CEGISResult exception -> ShowS #

show :: CEGISResult exception -> String #

showList :: [CEGISResult exception] -> ShowS #

Eq exception => Eq (CEGISResult exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Methods

(==) :: CEGISResult exception -> CEGISResult exception -> Bool #

(/=) :: CEGISResult exception -> CEGISResult exception -> Bool #

Hashable exception => Hashable (CEGISResult exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Methods

hashWithSalt :: Int -> CEGISResult exception -> Int #

hash :: CEGISResult exception -> Int #

type Rep (CEGISResult exception) Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

type Rep (CEGISResult exception) = D1 ('MetaData "CEGISResult" "Grisette.Internal.Core.Data.Class.CEGISSolver" "grisette-0.11.0.0-HndeEPlDvvDHSETLw6O8c" 'False) (C1 ('MetaCons "CEGISSuccess" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Model)) :+: (C1 ('MetaCons "CEGISVerifierFailure" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 exception)) :+: C1 ('MetaCons "CEGISSolverFailure" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SolvingFailure))))

solverGenericCEGIS Source #

Arguments

:: Solver handle 
=> handle

Configuration of the solver.

-> Bool

Whether we should rerun the passed verifiers if any other verifier found a counter-example.

-> SymBool

The initial synthesis constraint.

-> SynthesisConstraintFun input

Synthesis constraint from counter-examples

-> [VerifierFun input exception]

The verifier functions.

-> IO ([input], CEGISResult exception) 

Generic CEGIS procedure. See genericCEGIS for more details.

The difference from genericCEGIS is that this function accepts a solver handle for the synthesizer, instead of a solver configuration.

solverGenericCEGISWithRefinement Source #

Arguments

:: Solver handle 
=> handle

Configuration of the solver.

-> Bool

Whether we should rerun the passed verifiers if any other verifier found a counter-example.

-> SymBool

The initial synthesis constraint.

-> SynthesisConstraintFun input

Synthesis constraint from counter-examples

-> Maybe RefinementConditionFun

Refinement condition generator.

-> [VerifierFun input exception]

The verifier functions.

-> IO ([input], CEGISResult exception) 

Generic CEGIS procedure with refinement. See genericCEGISWithRefinement for more details.

The difference from genericCEGISWithRefinement is that this function accepts a solver handle for the synthesizer, instead of a solver configuration.

genericCEGIS Source #

Arguments

:: ConfigurableSolver config handle 
=> config

Configuration of the solver.

-> Bool

Whether we should rerun the passed verifiers if any other verifier found a counter-example.

-> SymBool

The initial synthesis constraint.

-> SynthesisConstraintFun input

Synthesis constraint from counter-examples

-> [VerifierFun input exception]

The verifier functions.

-> IO ([input], CEGISResult exception) 

Generic CEGIS procedure.

The CEGIS procedure will try to find a model that satisfies the initial synthesis constraint, and satisfies all the inputs generated by the verifier.

genericCEGISWithRefinement Source #

Arguments

:: ConfigurableSolver config handle 
=> config

Configuration of the solver.

-> Bool

Whether we should rerun the passed verifiers if any other verifier found a counter-example.

-> SymBool

The initial synthesis constraint.

-> SynthesisConstraintFun input

Synthesis constraint from counter-examples

-> Maybe RefinementConditionFun

Refinement condition generator.

-> [VerifierFun input exception]

The verifier functions.

-> IO ([input], CEGISResult exception) 

Generic CEGIS procedure.

The CEGIS procedure will try to find a model that satisfies the initial synthesis constraint, and satisfies all the inputs generated by the verifier.

CEGIS interfaces with pre/post conditions

data CEGISCondition Source #

The condition for CEGIS to solve.

The first argument is the pre-condition, and the second argument is the post-condition.

The CEGIS procedures would try to find a model for the formula

\[ \forall P. (\exists I. \mathrm{pre}(P, I)) \wedge (\forall I. \mathrm{pre}(P, I)\implies \mathrm{post}(P, I)) \]

In program synthesis tasks, \(P\) is the symbolic constants in the symbolic program, and \(I\) is the input. The pre-condition is used to restrict the search space of the program. The procedure would only return programs that meets the pre-conditions on every possible inputs, and there are at least one possible input. The post-condition is used to specify the desired program behaviors.

Instances

Instances details
Generic CEGISCondition Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Associated Types

type Rep CEGISCondition 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

type Rep CEGISCondition = D1 ('MetaData "CEGISCondition" "Grisette.Internal.Core.Data.Class.CEGISSolver" "grisette-0.11.0.0-HndeEPlDvvDHSETLw6O8c" 'False) (C1 ('MetaCons "CEGISCondition" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SymBool) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SymBool)))
EvalSym CEGISCondition Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

Mergeable CEGISCondition Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

SimpleMergeable CEGISCondition Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

type Rep CEGISCondition Source # 
Instance details

Defined in Grisette.Internal.Core.Data.Class.CEGISSolver

type Rep CEGISCondition = D1 ('MetaData "CEGISCondition" "Grisette.Internal.Core.Data.Class.CEGISSolver" "grisette-0.11.0.0-HndeEPlDvvDHSETLw6O8c" 'False) (C1 ('MetaCons "CEGISCondition" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SymBool) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SymBool)))

cegisPostCond :: SymBool -> CEGISCondition Source #

Construct a CEGIS condition with only a post-condition. The pre-condition would be set to true, meaning that all programs in the program space are allowed.

cegisPrePost :: SymBool -> SymBool -> CEGISCondition Source #

Construct a CEGIS condition with both pre- and post-conditions.

solverCegisMultiInputs Source #

Arguments

:: (EvalSym input, ExtractSym input, Solver handle) 
=> handle 
-> handle 
-> [input]

Initial symbolic inputs. The solver will try to find a program that works on all the inputs representable by these inputs (see CEGISCondition).

-> (input -> CEGISCondition)

The condition for the solver to solve. All the symbolic constants that are not in the inputs will be considered as part of the symbolic program.

-> IO ([input], CEGISResult SolvingFailure)

The counter-examples generated during the CEGIS loop, and the model found by the solver.

CEGIS with multiple (possibly symbolic) inputs. See cegisMultiInputs for more details.

The difference from cegisMultiInputs is that this function accepts two solver handles, one for the synthesizer and one for the verifier.

The synthesizer solver will **not** be reset, while the verifier solver will be reset after each iteration.

solverCegis Source #

Arguments

:: (Solver handle, EvalSym inputs, ExtractSym inputs, SymEq inputs) 
=> handle

The synthesizer solver handle

-> handle

The verifier solver handle

-> inputs

Initial symbolic inputs. The solver will try to find a program that works on all the inputs representable by it (see CEGISCondition).

-> (inputs -> CEGISCondition)

The condition for the solver to solve. All the symbolic constants that are not in the inputs will be considered as part of the symbolic program.

-> IO ([inputs], CEGISResult SolvingFailure)

The counter-examples generated during the CEGIS loop, and the model found by the solver.

CEGIS with a single symbolic input to represent a set of inputs. See cegis for more details.

The difference from cegis is that this function accepts two solver handles, one for the synthesizer and one for the verifier.

The synthesizer solver will **not** be reset, while the verifier solver will be reset after each iteration.

solverCegisExcept :: forall t (u :: Type -> Type) e v inputs handle. (UnionWithExcept t u e v, PlainUnion u, Functor u, EvalSym inputs, ExtractSym inputs, Solver handle, SymEq inputs) => handle -> handle -> inputs -> (Either e v -> CEGISCondition) -> (inputs -> t) -> IO ([inputs], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, using a single symbolic input to represent a set of inputs. See cegisExcept for more details.

The difference from cegisExcept is that this function accepts two solver handles, one for the synthesizer and one for the verifier.

The synthesizer solver will **not** be reset, while the verifier solver will be reset after each iteration.

solverCegisExceptStdVC :: forall t (u :: Type -> Type) inputs handle. (UnionWithExcept t u VerificationConditions (), PlainUnion u, Monad u, EvalSym inputs, ExtractSym inputs, Solver handle, SymEq inputs) => handle -> handle -> inputs -> (inputs -> t) -> IO ([inputs], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, using a single symbolic input to represent a set of inputs. See cegisExceptStdVC for more details.

The difference from cegisExceptStdVC is that this function accepts two solver handles, one for the synthesizer and one for the verifier.

The synthesizer solver will **not** be reset, while the verifier solver will be reset after each iteration.

solverCegisExceptVC :: (UnionWithExcept t u e v, PlainUnion u, Monad u, EvalSym inputs, ExtractSym inputs, Solver handle, SymEq inputs) => handle -> handle -> inputs -> (Either e v -> u (Either VerificationConditions ())) -> (inputs -> t) -> IO ([inputs], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, using a single symbolic input to represent a set of inputs.

The errors should be translated to assertion or assumption violations.

The difference from cegisExceptVC is that this function accepts two solver handles, one for the synthesizer and one for the verifier.

The synthesizer solver will **not** be reset, while the verifier solver will be reset after each iteration.

solverCegisExceptMultiInputs :: forall handle inputs t (u :: Type -> Type) e v. (Solver handle, EvalSym inputs, ExtractSym inputs, UnionWithExcept t u e v, PlainUnion u, Monad u) => handle -> handle -> [inputs] -> (Either e v -> CEGISCondition) -> (inputs -> t) -> IO ([inputs], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, using multiple (possibly symbolic) inputs to represent a set of inputs.

The difference from cegisExceptMultiInputs is that this function accepts two solver handles, one for the synthesizer and one for the verifier.

The synthesizer solver will **not** be reset, while the verifier solver will be reset after each iteration.

solverCegisExceptStdVCMultiInputs :: forall handle inputs t (u :: Type -> Type). (Solver handle, EvalSym inputs, ExtractSym inputs, UnionWithExcept t u VerificationConditions (), PlainUnion u, Monad u) => handle -> handle -> [inputs] -> (inputs -> t) -> IO ([inputs], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, using multiple (possibly symbolic) inputs to represent a set of inputs. See cegisExceptStdVCMultiInputs for more details.

The difference from cegisExceptStdVCMultiInputs is that this function accepts two solver handles, one for the synthesizer and one for the verifier.

The synthesizer solver will **not** be reset, while the verifier solver will be reset after each iteration.

solverCegisExceptVCMultiInputs :: (Solver handle, EvalSym inputs, ExtractSym inputs, UnionWithExcept t u e v, PlainUnion u, Monad u) => handle -> handle -> [inputs] -> (Either e v -> u (Either VerificationConditions ())) -> (inputs -> t) -> IO ([inputs], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, using multiple (possibly symbolic) inputs to represent a set of inputs.

The errors should be translated to assertion or assumption violations.

The difference from cegisExceptVCMultiInputs is that this function accepts two solver handles, one for the synthesizer and one for the verifier.

The synthesizer solver will **not** be reset, while the verifier solver will be reset after each iteration.

solverCegisForAll Source #

Arguments

:: (ExtractSym forallInput, Solver handle) 
=> handle 
-> handle 
-> forallInput

A symbolic value. All the symbolic constants in the value are treated as for-all variables.

-> CEGISCondition 
-> IO ([Model], CEGISResult SolvingFailure)

First output are the counter-examples for all the for-all variables, and the second output is the model for all other variables if CEGIS succeeds.

CEGIS with a single symbolic input to represent a set of inputs. See cegisForAll for more details.

The difference from cegisForAll is that this function accepts two solver handles, one for the synthesizer and one for the verifier.

The synthesizer solver will **not** be reset, while the verifier solver will be reset after each iteration.

solverCegisForAllExcept :: forall t (u :: Type -> Type) e v inputs handle. (UnionWithExcept t u e v, PlainUnion u, Functor u, EvalSym inputs, ExtractSym inputs, Solver handle, SymEq inputs) => handle -> handle -> inputs -> (Either e v -> CEGISCondition) -> t -> IO ([Model], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, with a forall variable.

See cegisForAllExcept, cegisForAll and cegisExcept.

The difference from cegisForAllExcept is that this function accepts two solver handles, one for the synthesizer and one for the verifier.

The synthesizer solver will **not** be reset, while the verifier solver will be reset after each iteration.

solverCegisForAllExceptStdVC :: forall t (u :: Type -> Type) inputs handle. (UnionWithExcept t u VerificationConditions (), PlainUnion u, Monad u, EvalSym inputs, ExtractSym inputs, Solver handle, SymEq inputs) => handle -> handle -> inputs -> t -> IO ([Model], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, with a forall variable.

See cegisForAllExceptStdVC cegisForAll and cegisExceptStdVC.

The difference from cegisForAllExceptStdVC is that this function accepts two solver handles, one for the synthesizer and one for the verifier.

The synthesizer solver will **not** be reset, while the verifier solver will be reset after each iteration.

solverCegisForAllExceptVC :: (UnionWithExcept t u e v, PlainUnion u, Monad u, EvalSym inputs, ExtractSym inputs, Solver handle, SymEq inputs) => handle -> handle -> inputs -> (Either e v -> u (Either VerificationConditions ())) -> t -> IO ([Model], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, with a forall variable.

See cegisForAllExceptVC cegisForAll and cegisExceptVC.

The difference from cegisForAllExceptVC is that this function accepts two solver handles, one for the synthesizer and one for the verifier.

The synthesizer solver will **not** be reset, while the verifier solver will be reset after each iteration.

cegisMultiInputs Source #

Arguments

:: (EvalSym input, ExtractSym input, ConfigurableSolver config handle) 
=> config

The configuration of the solver

-> [input]

Initial symbolic inputs. The solver will try to find a program that works on all the inputs representable by these inputs (see CEGISCondition).

-> (input -> CEGISCondition)

The condition for the solver to solve. All the symbolic constants that are not in the inputs will be considered as part of the symbolic program.

-> IO ([input], CEGISResult SolvingFailure)

The counter-examples generated during the CEGIS loop, and the model found by the solver.

CEGIS with multiple (possibly symbolic) inputs. Solves the following formula (see CEGISCondition for details).

\[ \forall P. (\exists I\in\mathrm{inputs}. \mathrm{pre}(P, I)) \wedge (\forall I\in\mathrm{inputs}. \mathrm{pre}(P, I)\implies \mathrm{post}(P, I)) \]

For simpler queries, where the inputs are representable by a single symbolic value, you may want to use cegis or cegisExcept instead. We have an example for the cegis call.

cegis Source #

Arguments

:: (ConfigurableSolver config handle, EvalSym inputs, ExtractSym inputs, SymEq inputs) 
=> config

The configuration of the solver

-> inputs

Initial symbolic inputs. The solver will try to find a program that works on all the inputs representable by it (see CEGISCondition).

-> (inputs -> CEGISCondition)

The condition for the solver to solve. All the symbolic constants that are not in the inputs will be considered as part of the symbolic program.

-> IO ([inputs], CEGISResult SolvingFailure)

The counter-examples generated during the CEGIS loop, and the model found by the solver.

CEGIS with a single symbolic input to represent a set of inputs.

The following example tries to find the value of c such that for all positive x, x * c && c -2. The c .> -2 clause is used to make the solution unique.

>>> let [x,c] = ["x","c"] :: [SymInteger]
>>> cegis z3 x (\x -> cegisPrePost (x .> 0) (x * c .< 0 .&& c .> -2))
(...,CEGISSuccess (Model {c -> -1 :: Integer}))

cegisExcept :: forall t (u :: Type -> Type) e v inputs config handle. (UnionWithExcept t u e v, PlainUnion u, Functor u, EvalSym inputs, ExtractSym inputs, ConfigurableSolver config handle, SymEq inputs) => config -> inputs -> (Either e v -> CEGISCondition) -> (inputs -> t) -> IO ([inputs], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, using a single symbolic input to represent a set of inputs.

cegisExcept is particularly useful when custom error types are used. With cegisExcept, you define how the errors are interpreted to the CEGIS conditions after the symbolic evaluation. This could increase the readability and modularity of the code.

The following example tries to find the value of c such that for all positive x, x * c && c -2. The c .> -2 assertion is used to make the solution unique.

>>> let [x,c] = ["x","c"] :: [SymInteger]
>>> import Control.Monad.Except
>>> :{
  res :: SymInteger -> ExceptT VerificationConditions Union ()
  res x = do
    symAssume $ x .> 0
    symAssert $ x * c .< 0
    symAssert $ c .> -2
:}
>>> :{
  translation (Left AssumptionViolation) = cegisPrePost (con False) (con True)
  translation (Left AssertionViolation) = cegisPostCond (con False)
  translation _ = cegisPostCond (con True)
:}
>>> cegisExcept z3 x translation res
([...],CEGISSuccess (Model {c -> -1 :: Integer}))

cegisExceptStdVC :: forall t (u :: Type -> Type) inputs config handle. (UnionWithExcept t u VerificationConditions (), PlainUnion u, Monad u, EvalSym inputs, ExtractSym inputs, ConfigurableSolver config handle, SymEq inputs) => config -> inputs -> (inputs -> t) -> IO ([inputs], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, using a single symbolic input to represent a set of inputs. This function saves the efforts to implement the translation function for the standard error type VerificationConditions, and the standard result type ().

This function translates assumption violations to failed pre-conditions, and translates assertion violations to failed post-conditions. The () result will not fail any conditions.

The following example tries to find the value of c such that for all positive x, x * c && c -2. The c .> -2 assertion is used to make the solution unique.

>>> let [x,c] = ["x","c"] :: [SymInteger]
>>> import Control.Monad.Except
>>> :{
  res :: SymInteger -> ExceptT VerificationConditions Union ()
  res x = do
    symAssume $ x .> 0
    symAssert $ x * c .< 0
    symAssert $ c .> -2
:}
>>> cegisExceptStdVC z3 x res
([...],CEGISSuccess (Model {c -> -1 :: Integer}))

cegisExceptVC :: (UnionWithExcept t u e v, PlainUnion u, Monad u, EvalSym inputs, ExtractSym inputs, ConfigurableSolver config handle, SymEq inputs) => config -> inputs -> (Either e v -> u (Either VerificationConditions ())) -> (inputs -> t) -> IO ([inputs], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, using a single symbolic input to represent a set of inputs.

The errors should be translated to assertion or assumption violations.

cegisExceptMultiInputs :: forall config handle inputs t (u :: Type -> Type) e v. (ConfigurableSolver config handle, EvalSym inputs, ExtractSym inputs, UnionWithExcept t u e v, PlainUnion u, Monad u) => config -> [inputs] -> (Either e v -> CEGISCondition) -> (inputs -> t) -> IO ([inputs], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, using multiple (possibly symbolic) inputs to represent a set of inputs.

cegisExceptStdVCMultiInputs :: forall config handle inputs t (u :: Type -> Type). (ConfigurableSolver config handle, EvalSym inputs, ExtractSym inputs, UnionWithExcept t u VerificationConditions (), PlainUnion u, Monad u) => config -> [inputs] -> (inputs -> t) -> IO ([inputs], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, using multiple (possibly symbolic) inputs to represent a set of inputs. This function saves the efforts to implement the translation function for the standard error type VerificationConditions, and the standard result type ().

This function translates assumption violations to failed pre-conditions, and translates assertion violations to failed post-conditions. The () result will not fail any conditions.

cegisExceptVCMultiInputs :: (ConfigurableSolver config handle, EvalSym inputs, ExtractSym inputs, UnionWithExcept t u e v, PlainUnion u, Monad u) => config -> [inputs] -> (Either e v -> u (Either VerificationConditions ())) -> (inputs -> t) -> IO ([inputs], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, using multiple (possibly symbolic) inputs to represent a set of inputs.

The errors should be translated to assertion or assumption violations.

cegisForAll Source #

Arguments

:: (ExtractSym forallInput, ConfigurableSolver config handle) 
=> config 
-> forallInput

A symbolic value. All the symbolic constants in the value are treated as for-all variables.

-> CEGISCondition 
-> IO ([Model], CEGISResult SolvingFailure)

First output are the counter-examples for all the for-all variables, and the second output is the model for all other variables if CEGIS succeeds.

CEGIS with a single symbolic input to represent a set of inputs.

The following example tries to find the value of c such that for all positive x, x * c && c -2. The c .> -2 clause is used to make the solution unique.

>>> let [x,c] = ["x","c"] :: [SymInteger]
>>> cegisForAll z3 x $ cegisPrePost (x .> 0) (x * c .< 0 .&& c .> -2)
(...,CEGISSuccess (Model {c -> -1 :: Integer}))

cegisForAllExcept :: forall t (u :: Type -> Type) e v inputs config handle. (UnionWithExcept t u e v, PlainUnion u, Functor u, EvalSym inputs, ExtractSym inputs, ConfigurableSolver config handle, SymEq inputs) => config -> inputs -> (Either e v -> CEGISCondition) -> t -> IO ([Model], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, with a forall variable.

See cegisForAll and cegisExcept.

cegisForAllExceptStdVC :: forall t (u :: Type -> Type) inputs config handle. (UnionWithExcept t u VerificationConditions (), PlainUnion u, Monad u, EvalSym inputs, ExtractSym inputs, ConfigurableSolver config handle, SymEq inputs) => config -> inputs -> t -> IO ([Model], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, with a forall variable.

See cegisForAll and cegisExceptStdVC.

cegisForAllExceptVC :: (UnionWithExcept t u e v, PlainUnion u, Monad u, EvalSym inputs, ExtractSym inputs, ConfigurableSolver config handle, SymEq inputs) => config -> inputs -> (Either e v -> u (Either VerificationConditions ())) -> t -> IO ([Model], CEGISResult SolvingFailure) Source #

CEGIS for symbolic programs with error handling, with a forall variable.

See cegisForAll and cegisExceptVC.