sbv-8.1: SMT Based Verification: Symbolic Haskell theorem prover using SMT solving.

Documentation.SBV.Examples.Puzzles.Garden

Description

The origin of this puzzle is Raymond Smullyan's "The Flower Garden" riddle:

In a certain flower garden, each flower was either red, yellow, or blue, and all three colors were represented. A statistician once visited the garden and made the observation that whatever three flowers you picked, at least one of them was bound to be red. A second statistician visited the garden and made the observation that whatever three flowers you picked, at least one was bound to be yellow.

Two logic students heard about this and got into an argument. The first student said: “It therefore follows that whatever three flowers you pick, at least one is bound to be blue, doesn’t it?” The second student said: “Of course not!”

Which student was right, and why?

We slightly modify the puzzle. Assuming the first student is right, we use SBV to show that the garden must contain exactly 3 flowers. In any other case, the second student would be right.

Synopsis

# Documentation

data Color Source #

Colors of the flowers

Constructors

 Red Yellow Blue
Instances
 Source # Instance details Methods(==) :: Color -> Color -> Bool #(/=) :: Color -> Color -> Bool # Source # Instance details Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Color -> c Color #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Color #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Color) #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Color) #gmapT :: (forall b. Data b => b -> b) -> Color -> Color #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Color -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Color -> r #gmapQ :: (forall d. Data d => d -> u) -> Color -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> Color -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Color -> m Color #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Color -> m Color #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Color -> m Color # Source # Instance details Methods(<) :: Color -> Color -> Bool #(<=) :: Color -> Color -> Bool #(>) :: Color -> Color -> Bool #(>=) :: Color -> Color -> Bool #max :: Color -> Color -> Color #min :: Color -> Color -> Color # Source # Instance details Methods Source # Instance details MethodsshowsPrec :: Int -> Color -> ShowS #show :: Color -> String #showList :: [Color] -> ShowS # Source # Instance details Methods Source # Instance details MethodsisConcretely :: SBV Color -> (Color -> Bool) -> Bool Source #forall :: MonadSymbolic m => String -> m (SBV Color) Source #forall_ :: MonadSymbolic m => m (SBV Color) Source #mkForallVars :: MonadSymbolic m => Int -> m [SBV Color] Source #exists :: MonadSymbolic m => String -> m (SBV Color) Source #exists_ :: MonadSymbolic m => m (SBV Color) Source #mkExistVars :: MonadSymbolic m => Int -> m [SBV Color] Source #free :: MonadSymbolic m => String -> m (SBV Color) Source #free_ :: MonadSymbolic m => m (SBV Color) Source #mkFreeVars :: MonadSymbolic m => Int -> m [SBV Color] Source #symbolic :: MonadSymbolic m => String -> m (SBV Color) Source #symbolics :: MonadSymbolic m => [String] -> m [SBV Color] Source # Source # Make Color a symbolic value. Instance details MethodsparseCVs :: [CV] -> Maybe (Color, [CV]) Source #cvtModel :: (Color -> Maybe b) -> Maybe (Color, [CV]) -> Maybe (b, [CV]) Source # Source # Instance details MethodssexprToVal :: SExpr -> Maybe Color Source #

Represent flowers by symbolic integers

The uninterpreted function col assigns a color to each flower.

Describe a valid pick of three flowers i, j, k, assuming we have n flowers to start with. Essentially the numbers should be within bounds and distinct.

count :: Color -> [Flower] -> SInteger Source #

Count the number of flowers that occur in a given set of flowers.

Smullyan's puzzle.

Solve the puzzle. We have:

>>> flowerCount
Solution #1:
N = 3 :: Integer
This is the only solution. (Unique up to prefix existentials.)


So, a garden with 3 flowers is the only solution. (Note that we simply skip over the prefix existentials and the assignments to uninterpreted function col for model purposes here, as they don't represent a different solution.)