sbv-13.6: 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.SquareBirthday

Description

As of January 2026, to access the careers link at http://math.inc, you need to solve the following puzzle:

Suppose that today is June 1, 2025. We call a date "square" if all of its components (day, month, and year) are
perfect squares. I was born in the last millennium, and my next birthday (relative to that date) will be the last
square date in my life. If you sum the square roots of the components of that upcoming square birthday
(day, month, year), you obtain my age on June 1, 2025. My mother would have been born on a square date if the month
were a square number; in reality it is not a square date, but both the month and day are perfect cubes. When was
I born, and when was my mother born?

So, let's solve it using SBV.

Synopsis

Documentation

data Month Source #

Months in a year.

Constructors

Jan 
Feb 
Mar 
Apr 
May 
Jun 
Jul 
Aug 
Sep 
Oct 
Nov 
Dec 

Instances

Instances details
Arbitrary Month Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

Methods

arbitrary :: Gen Month #

shrink :: Month -> [Month] #

Show Month Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

Methods

showsPrec :: Int -> Month -> ShowS #

show :: Month -> String #

showList :: [Month] -> ShowS #

SymVal Month Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

HasKind Month Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

EnumSymbolic Month Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

SatModel Month Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

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

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

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

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

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

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

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

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

Methods

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

data Date Source #

A date. We use unbounded integers for day and year, which simplifies coding, though one can also enumerate the possible values from the problem itself.

Constructors

MkDate 

Fields

Instances

Instances details
Arbitrary Date Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

Methods

arbitrary :: Gen Date #

shrink :: Date -> [Date] #

Show Date Source #

Show instance for date, for pretty-printing.

Instance details

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

Methods

showsPrec :: Int -> Date -> ShowS #

show :: Date -> String #

showList :: [Date] -> ShowS #

SymVal Date Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

HasKind Date Source # 
Instance details

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

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

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

Methods

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

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

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

Methods

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

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

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

Methods

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

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

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

Methods

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

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

Defined in Documentation.SBV.Examples.Puzzles.SquareBirthday

Methods

inductionSchema :: (Forall ta Date -> 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 Date -> 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.SquareBirthday

Methods

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

cv2Date :: String -> [CV] -> Date Source #

Conversion from SMT values to Date values.

_undefiner_Date :: a Source #

Autogenerated definition to avoid unused-variable warnings from GHC.

type SDate = SBV Date Source #

Symbolic version of the type Date.

type SMonth = SBV Month Source #

Symbolic version of the type Month.

sJan :: SBV Month Source #

Symbolic version of the constructor Jan.

sFeb :: SBV Month Source #

Symbolic version of the constructor Feb.

sMar :: SBV Month Source #

Symbolic version of the constructor Mar.

sApr :: SBV Month Source #

Symbolic version of the constructor Apr.

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.

sSep :: SBV Month Source #

Symbolic version of the constructor Sep.

sOct :: SBV Month Source #

Symbolic version of the constructor Oct.

sNov :: SBV Month Source #

Symbolic version of the constructor Nov.

sDec :: SBV Month Source #

Symbolic version of the constructor Dec.

isJan :: SBV Month -> SBool Source #

Field recognizer predicate.

isFeb :: SBV Month -> SBool Source #

Field recognizer predicate.

isMar :: SBV Month -> SBool Source #

Field recognizer predicate.

isApr :: SBV Month -> SBool Source #

Field recognizer predicate.

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.

isSep :: SBV Month -> SBool Source #

Field recognizer predicate.

isOct :: SBV Month -> SBool Source #

Field recognizer predicate.

isNov :: SBV Month -> SBool Source #

Field recognizer predicate.

isDec :: SBV Month -> SBool Source #

Field recognizer predicate.

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

Case analyzer for the type Month.

sMkDate :: SBV Integer -> SBV Month -> SBV Integer -> SBV Date Source #

Symbolic version of the constructor MkDate.

isMkDate :: SBV Date -> SBool Source #

Field recognizer predicate.

getMkDate_1 :: SBV Date -> SBV Integer Source #

Field accessor function.

sday :: SBV Date -> SBV Integer Source #

Field accessor function.

getMkDate_2 :: SBV Date -> SBV Month Source #

Field accessor function.

smonth :: SBV Date -> SBV Month Source #

Field accessor function.

getMkDate_3 :: SBV Date -> SBV Integer Source #

Field accessor function.

syear :: SBV Date -> SBV Integer Source #

Field accessor function.

sCaseDate :: Mergeable result => SBV Date -> (SBV Integer -> SBV Month -> SBV Integer -> result) -> result Source #

Case analyzer for the type Date.

symDate :: String -> Symbolic SDate Source #

Get a symbolic date with the given name. Since we used integers for the day and year fields, we constrain them appropriately. Note that one can further constrain days based on the year and month; but that level detail isn't necessary for the current problem.

today :: SDate Source #

Encode today as a symbolic value. The puzzle says today is June 1st, 2025.

onOrAfter :: SDate -> SDate -> SBool Source #

A date is on or after another, if the month-day combo is lexicographically later. Note that we ignore the year for this comparison, as we're interested if the anniversary of a date is after or not.

after :: SDate -> SDate -> SBool Source #

Similar to onOrAfter, except we require strictly later.

age :: SDate -> SInteger Source #

The age based on a given date is the difference between years less than one. We have to adjust by 1 if today happens to be after the given date.

squareYears :: [(Integer, Integer)] Source #

We can let years to range over arbitrary integers. But that complicates the job of the solver. So, based on what we know from the problem, we restrict our attention to years betweek 1900 and 2100. Note that there are only two years that satisfy this in that range: 1936 and 2025. (Any other square year makes no sense for the setting of the problem.) To simplify the square-root computation, we also store the square root in this list as the second component:

>>> squareYears
[(1936,44),(2025,45)]

squareDate :: SDate -> SBool Source #

A date is square if all its components are.

sqrSum :: SDate -> SInteger Source #

Summing the square-roots of the components of a date.

puzzle :: IO () Source #

Formalizing the puzzle. We literally write down the description in SBV notation. As with any formalization, this step is subjective; there could be many different ways to express the same problem. The description below is quite faithful to the problem description given. We have:

>>> puzzle
Me : Sep 25, 1971
Mom: Aug  1, 1936