sbv-13.1: SMT Based Verification: Symbolic Haskell theorem prover using SMT solving.
Copyright(c) Levent Erkok
LicenseBSD3
Maintainererkokl@gmail.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Documentation.SBV.Examples.Puzzles.U2Bridge

Description

The famous U2 bridge crossing puzzle: http://www.braingle.com/brainteasers/515/u2.html

Synopsis

Modeling the puzzle

data U2Member Source #

U2 band members.

Constructors

Bono 
Edge 
Adam 
Larry 

Instances

Instances details
Arbitrary U2Member Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Show U2Member Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

SymVal U2Member Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

HasKind U2Member Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

EnumSymbolic U2Member Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

SatModel U2Member Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

parseCVs :: [CV] -> Maybe (U2Member, [CV]) Source #

cvtModel :: (U2Member -> Maybe b) -> Maybe (U2Member, [CV]) -> Maybe (b, [CV]) Source #

OrdSymbolic (SBV U2Member) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

HasInductionSchema (Forall ta U2Member -> SBool) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

inductionSchema :: (Forall ta U2Member -> SBool) -> ProofObj Source #

SymVal extraT => HasInductionSchema (Forall ta U2Member -> Forall extraS extraT -> SBool) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

inductionSchema :: (Forall ta U2Member -> Forall extraS extraT -> SBool) -> ProofObj Source #

(SymVal extraT1, SymVal extraT2) => HasInductionSchema (Forall ta U2Member -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> SBool) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

inductionSchema :: (Forall ta U2Member -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> SBool) -> ProofObj Source #

(SymVal extraT1, SymVal extraT2, SymVal extraT3) => HasInductionSchema (Forall ta U2Member -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> SBool) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

inductionSchema :: (Forall ta U2Member -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> SBool) -> ProofObj Source #

(SymVal extraT1, SymVal extraT2, SymVal extraT3, SymVal extraT4) => HasInductionSchema (Forall ta U2Member -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> Forall extraS4 extraT4 -> SBool) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

inductionSchema :: (Forall ta U2Member -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> Forall extraS4 extraT4 -> SBool) -> ProofObj Source #

(SymVal extraT1, SymVal extraT2, SymVal extraT3, SymVal extraT4, SymVal extraT5) => HasInductionSchema (Forall ta U2Member -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> Forall extraS4 extraT4 -> Forall extraS5 extraT5 -> SBool) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

inductionSchema :: (Forall ta U2Member -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> Forall extraS4 extraT4 -> Forall extraS5 extraT5 -> SBool) -> ProofObj Source #

cv2U2Member :: String -> [CV] -> U2Member Source #

Conversion from SMT values to U2Member values.

_undefiner_U2Member :: a Source #

Autogenerated definition to avoid unused-variable warnings from GHC.

type SU2Member = SBV U2Member Source #

Symbolic version of the type U2Member.

sBono :: SBV U2Member Source #

Symbolic version of the constructor Bono.

sEdge :: SBV U2Member Source #

Symbolic version of the constructor Edge.

sAdam :: SBV U2Member Source #

Symbolic version of the constructor Adam.

sLarry :: SBV U2Member Source #

Symbolic version of the constructor Larry.

isBono :: SBV U2Member -> SBool Source #

Field recognizer predicate.

isEdge :: SBV U2Member -> SBool Source #

Field recognizer predicate.

isAdam :: SBV U2Member -> SBool Source #

Field recognizer predicate.

isLarry :: SBV U2Member -> SBool Source #

Field recognizer predicate.

sCaseU2Member :: Mergeable result => SBV U2Member -> result -> result -> result -> result -> result Source #

Case analyzer for the type U2Member.

type Time = Word32 Source #

Model time using 32 bits

type STime = SBV Time Source #

Symbolic variant for time

crossTime :: U2Member -> Time Source #

Crossing times for each member of the band

sCrossTime :: SU2Member -> STime Source #

The symbolic variant.. The duplication is unfortunate.

data Location Source #

Location of the flash

Constructors

Here 
There 

Instances

Instances details
Arbitrary Location Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Bounded Location Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Enum Location Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Show Location Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Eq Location Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

SymVal Location Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

HasKind Location Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

EnumSymbolic Location Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

SatModel Location Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

parseCVs :: [CV] -> Maybe (Location, [CV]) Source #

cvtModel :: (Location -> Maybe b) -> Maybe (Location, [CV]) -> Maybe (b, [CV]) Source #

OrdSymbolic (SBV Location) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

HasInductionSchema (Forall ta Location -> SBool) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

inductionSchema :: (Forall ta Location -> SBool) -> ProofObj Source #

SymVal extraT => HasInductionSchema (Forall ta Location -> Forall extraS extraT -> SBool) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

inductionSchema :: (Forall ta Location -> Forall extraS extraT -> SBool) -> ProofObj Source #

(SymVal extraT1, SymVal extraT2) => HasInductionSchema (Forall ta Location -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> SBool) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

inductionSchema :: (Forall ta Location -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> SBool) -> ProofObj Source #

(SymVal extraT1, SymVal extraT2, SymVal extraT3) => HasInductionSchema (Forall ta Location -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> SBool) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

inductionSchema :: (Forall ta Location -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> SBool) -> ProofObj Source #

(SymVal extraT1, SymVal extraT2, SymVal extraT3, SymVal extraT4) => HasInductionSchema (Forall ta Location -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> Forall extraS4 extraT4 -> SBool) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

inductionSchema :: (Forall ta Location -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> Forall extraS4 extraT4 -> SBool) -> ProofObj Source #

(SymVal extraT1, SymVal extraT2, SymVal extraT3, SymVal extraT4, SymVal extraT5) => HasInductionSchema (Forall ta Location -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> Forall extraS4 extraT4 -> Forall extraS5 extraT5 -> SBool) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

inductionSchema :: (Forall ta Location -> Forall extraS1 extraT1 -> Forall extraS2 extraT2 -> Forall extraS3 extraT3 -> Forall extraS4 extraT4 -> Forall extraS5 extraT5 -> SBool) -> ProofObj Source #

cv2Location :: String -> [CV] -> Location Source #

Conversion from SMT values to Location values.

_undefiner_Location :: a Source #

Autogenerated definition to avoid unused-variable warnings from GHC.

type SLocation = SBV Location Source #

Symbolic version of the type Location.

sHere :: SBV Location Source #

Symbolic version of the constructor Here.

sThere :: SBV Location Source #

Symbolic version of the constructor There.

isHere :: SBV Location -> SBool Source #

Field recognizer predicate.

isThere :: SBV Location -> SBool Source #

Field recognizer predicate.

sCaseLocation :: Mergeable result => SBV Location -> result -> result -> result Source #

Case analyzer for the type Location.

data Status Source #

The status of the puzzle after each move

This type is equipped with an automatically derived Mergeable instance because each field is Mergeable. A Generic instance must also be derived for this to work, and the DeriveAnyClass language extension must be enabled. The derived Mergeable instance simply walks down the structure field by field and merges each one. An equivalent hand-written Mergeable instance is provided in a comment below.

Constructors

Status 

Fields

Instances

Instances details
Generic Status Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

from :: Status -> Rep Status x #

to :: Rep Status x -> Status #

Mergeable Status Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

symbolicMerge :: Bool -> SBool -> Status -> Status -> Status Source #

select :: (Ord b, SymVal b, Num b, Num (SBV b), OrdSymbolic (SBV b)) => [Status] -> Status -> SBV b -> Status Source #

Mergeable a => Mergeable (Move a) Source #

Mergeable instance for Move simply pushes the merging the data after run of each branch starting from the same state.

Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

Methods

symbolicMerge :: Bool -> SBool -> Move a -> Move a -> Move a Source #

select :: (Ord b, SymVal b, Num b, Num (SBV b), OrdSymbolic (SBV b)) => [Move a] -> Move a -> SBV b -> Move a Source #

type Rep Status Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.U2Bridge

start :: Status Source #

Start configuration, time elapsed is 0 and everybody is here

type Move a = State Status a Source #

A puzzle move is modeled as a state-transformer

peek :: (Status -> a) -> Move a Source #

Read the state via an accessor function

whereIs :: SU2Member -> Move SLocation Source #

Given an arbitrary member, return his location

xferFlash :: Move () Source #

Transferring the flash to the other side

xferPerson :: SU2Member -> Move () Source #

Transferring a person to the other side

bumpTime1 :: SU2Member -> Move () Source #

Increment the time, when only one person crosses

bumpTime2 :: SU2Member -> SU2Member -> Move () Source #

Increment the time, when two people cross together

whenS :: SBool -> Move () -> Move () Source #

Symbolic version of when

move1 :: SU2Member -> Move () Source #

Move one member, remembering to take the flash

move2 :: SU2Member -> SU2Member -> Move () Source #

Move two members, again with the flash

Actions

type Actions = [(SBool, SU2Member, SU2Member)] Source #

A move action is a sequence of triples. The first component is symbolically True if only one member crosses. (In this case the third element of the triple is irrelevant.) If the first component is (symbolically) False, then both members move together

run :: Actions -> Move [Status] Source #

Run a sequence of given actions.

Recognizing valid solutions

isValid :: Actions -> SBool Source #

Check if a given sequence of actions is valid, i.e., they must all cross the bridge according to the rules and in less than 17 seconds

Solving the puzzle

solveN :: Int -> IO Bool Source #

See if there is a solution that has precisely n steps

solveU2 :: IO () Source #

Solve the U2-bridge crossing puzzle, starting by testing solutions with increasing number of steps, until we find one. We have:

>>> solveU2
Checking for solutions with 1 move.
Checking for solutions with 2 moves.
Checking for solutions with 3 moves.
Checking for solutions with 4 moves.
Checking for solutions with 5 moves.
Solution #1:
 0 --> Edge, Bono
 2 <-- Bono
 3 --> Larry, Adam
13 <-- Edge
15 --> Edge, Bono
Total time: 17
Solution #2:
 0 --> Edge, Bono
 2 <-- Edge
 4 --> Larry, Adam
14 <-- Bono
15 --> Edge, Bono
Total time: 17
Found: 2 solutions with 5 moves.

Finding all possible solutions to the puzzle.