Copyright | (c) Levent Erkok |
---|---|
License | BSD3 |
Maintainer | erkokl@gmail.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Documentation.SBV.Examples.Puzzles.KnightsAndKnaves
Description
From Raymond Smullyan: On a fictional island, all inhabitants are either knights, who always tell the truth, or knaves, who always lie. John and Bill are residents of the island of knights and knaves. John and Bill make several utterances. Determine which one is a knave or a knight, depending on their answers.
Synopsis
- data Inhabitant
- type SInhabitant = SBV Inhabitant
- data Identity
- type SIdentity = SBV Identity
- sKnave :: SBV Identity
- sKnight :: SBV Identity
- data Statement
- type SStatement = SBV Statement
- sTruth :: SBV Statement
- sFalsity :: SBV Statement
- john :: SInhabitant
- bill :: SInhabitant
- is :: SInhabitant -> SIdentity -> SStatement
- says :: SInhabitant -> SStatement -> SBool
- holds :: SStatement -> SBool
- and :: SStatement -> SStatement -> SStatement
- not :: SStatement -> SStatement
- iff :: SStatement -> SStatement -> SStatement
- puzzle :: IO ()
Documentation
data Inhabitant Source #
Inhabitants of the island, as an uninterpreted sort
Instances
type SInhabitant = SBV Inhabitant Source #
Symbolic version of the type Inhabitant
.
Each inhabitant is either a knave or a knight
Instances
Statements are utterances which are either true or false
Instances
john :: SInhabitant Source #
John is an inhabitant of the island.
bill :: SInhabitant Source #
Bill is an inhabitant of the island.
is :: SInhabitant -> SIdentity -> SStatement Source #
The connective is
makes a statement about an inhabitant regarding his/her identity.
says :: SInhabitant -> SStatement -> SBool Source #
The connective says
makes a predicate from what an inhabitant states
and :: SStatement -> SStatement -> SStatement Source #
The connective and
creates the conjunction of two statements
not :: SStatement -> SStatement Source #
The connective not
negates a statement
iff :: SStatement -> SStatement -> SStatement Source #
The connective iff
creates a statement that equates the truth values of its argument statements
Encode Smullyan's puzzle. We have:
>>>
puzzle
Question 1. John says, We are both knaves Then, John is: Knave And, Bill is: Knight Question 2. John says If (and only if) Bill is a knave, then I am a knave. Bill says We are of different kinds. Then, John is: Knave And, Bill is: Knight