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.Birthday

Description

This is a formalization of the Cheryl's birthday problem, which went viral in April 2015.

Here's the puzzle:

Albert and Bernard just met Cheryl. "When’s your birthday?" Albert asked Cheryl.

Cheryl thought a second and said, "I’m not going to tell you, but I’ll give you some clues." She wrote down a list of 10 dates:

  May 15, May 16, May 19
  June 17, June 18
  July 14, July 16
  August 14, August 15, August 17

"My birthday is one of these," she said.

Then Cheryl whispered in Albert’s ear the month — and only the month — of her birthday. To Bernard, she whispered the day, and only the day.
“Can you figure it out now?” she asked Albert.

Albert: I don’t know when your birthday is, but I know Bernard doesn’t know, either.
Bernard: I didn’t know originally, but now I do.
Albert: Well, now I know, too!

When is Cheryl’s birthday?

NB. Thanks to Amit Goel for suggesting the formalization strategy used in here.

Synopsis

Types and values

data Month Source #

Months. We only put in the months involved in the puzzle for simplicity

Constructors

May 
Jun 
Jul 
Aug 

Instances

Instances details
Arbitrary Month Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.Birthday

Methods

arbitrary :: Gen Month #

shrink :: Month -> [Month] #

SymVal Month Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.Birthday

HasKind Month Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.Birthday

EnumSymbolic Month Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.Birthday

SatModel Month Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.Birthday

Methods

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

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

OrdSymbolic (SBV Month) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.Birthday

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

Defined in Documentation.SBV.Examples.Puzzles.Birthday

Methods

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

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

Defined in Documentation.SBV.Examples.Puzzles.Birthday

Methods

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

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

Defined in Documentation.SBV.Examples.Puzzles.Birthday

Methods

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

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

Defined in Documentation.SBV.Examples.Puzzles.Birthday

Methods

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

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

Defined in Documentation.SBV.Examples.Puzzles.Birthday

Methods

inductionSchema :: (Forall ta Month -> 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 Month -> 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.Birthday

Methods

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

data Day Source #

Days. Again, only the ones mentioned in the puzzle.

Constructors

D14 
D15 
D16 
D17 
D18 
D19 

Instances

Instances details
Arbitrary Day Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.Birthday

Methods

arbitrary :: Gen Day #

shrink :: Day -> [Day] #

SymVal Day Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.Birthday

HasKind Day Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.Birthday

EnumSymbolic Day Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.Birthday

SatModel Day Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.Birthday

Methods

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

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

OrdSymbolic (SBV Day) Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.Birthday

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

Defined in Documentation.SBV.Examples.Puzzles.Birthday

Methods

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

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

Defined in Documentation.SBV.Examples.Puzzles.Birthday

Methods

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

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

Defined in Documentation.SBV.Examples.Puzzles.Birthday

Methods

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

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

Defined in Documentation.SBV.Examples.Puzzles.Birthday

Methods

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

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

Defined in Documentation.SBV.Examples.Puzzles.Birthday

Methods

inductionSchema :: (Forall ta Day -> 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 Day -> 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.Birthday

Methods

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

cv2Month :: String -> [CV] -> Month Source #

Conversion from SMT values to Month values.

_undefiner_Month :: a Source #

Autogenerated definition to avoid unused-variable warnings from GHC.

type SMonth = SBV Month Source #

Symbolic version of the type Month.

sMay :: SBV Month Source #

Symbolic version of the constructor May.

sJun :: SBV Month Source #

Symbolic version of the constructor Jun.

sJul :: SBV Month Source #

Symbolic version of the constructor Jul.

sAug :: SBV Month Source #

Symbolic version of the constructor Aug.

isMay :: SBV Month -> SBool Source #

Field recognizer predicate.

isJun :: SBV Month -> SBool Source #

Field recognizer predicate.

isJul :: SBV Month -> SBool Source #

Field recognizer predicate.

isAug :: SBV Month -> SBool Source #

Field recognizer predicate.

sCaseMonth :: Mergeable result => SBV Month -> result -> result -> result -> result -> result Source #

Case analyzer for the type Month.

cv2Day :: String -> [CV] -> Day Source #

Conversion from SMT values to Day values.

_undefiner_Day :: a Source #

Autogenerated definition to avoid unused-variable warnings from GHC.

type SDay = SBV Day Source #

Symbolic version of the type Day.

sD14 :: SBV Day Source #

Symbolic version of the constructor D14.

sD15 :: SBV Day Source #

Symbolic version of the constructor D15.

sD16 :: SBV Day Source #

Symbolic version of the constructor D16.

sD17 :: SBV Day Source #

Symbolic version of the constructor D17.

sD18 :: SBV Day Source #

Symbolic version of the constructor D18.

sD19 :: SBV Day Source #

Symbolic version of the constructor D19.

isD14 :: SBV Day -> SBool Source #

Field recognizer predicate.

isD15 :: SBV Day -> SBool Source #

Field recognizer predicate.

isD16 :: SBV Day -> SBool Source #

Field recognizer predicate.

isD17 :: SBV Day -> SBool Source #

Field recognizer predicate.

isD18 :: SBV Day -> SBool Source #

Field recognizer predicate.

isD19 :: SBV Day -> SBool Source #

Field recognizer predicate.

sCaseDay :: Mergeable result => SBV Day -> result -> result -> result -> result -> result -> result -> result Source #

Case analyzer for the type Day.

data Birthday Source #

Represent the birthday as a record

Constructors

BD SMonth SDay 

mkBirthday :: Symbolic Birthday Source #

Make a valid symbolic birthday

valid :: Birthday -> SBool Source #

Is this a valid birthday? i.e., one that was declared by Cheryl to be a possibility.

The puzzle

puzzle :: ConstraintSet Source #

Encode the conversation as given in the puzzle.

NB. Lee Pike pointed out that not all the constraints are actually necessary! (Private communication.) The puzzle still has a unique solution if the statements a1 and b1 (i.e., Albert and Bernard saying they themselves do not know the answer) are removed. To experiment you can simply comment out those statements and observe that there still is a unique solution. Thanks to Lee for pointing this out! In fact, it is instructive to assert the conversation line-by-line, and see how the search-space gets reduced in each step.

cheryl :: IO () Source #

Find all solutions to the birthday problem. We have:

>>> cheryl
Solution #1:
  birthMonth = Jul :: Month
  birthDay   = D16 :: Day
This is the only solution.