{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wall -Werror #-}
module Documentation.SBV.Examples.Lists.CountOutAndTransfer where
import Prelude hiding (length, take, drop, reverse, (++))
import Data.SBV
import Data.SBV.List
coat :: SymVal a => SInteger -> SList a -> SList a
coat :: SInteger -> SList a -> SList a
coat SInteger
k SList a
cards = SInteger -> SList a -> SList a
forall a. SymVal a => SInteger -> SList a -> SList a
drop SInteger
k SList a
cards SList a -> SList a -> SList a
forall a. SymVal a => SList a -> SList a -> SList a
++ SList a -> SList a
forall a. SymVal a => SList a -> SList a
reverse (SInteger -> SList a -> SList a
forall a. SymVal a => SInteger -> SList a -> SList a
take SInteger
k SList a
cards)
fourCoat :: SymVal a => SInteger -> SList a -> SList a
fourCoat :: SInteger -> SList a -> SList a
fourCoat SInteger
k = SInteger -> SList a -> SList a
forall a. SymVal a => SInteger -> SList a -> SList a
coat SInteger
k (SList a -> SList a) -> (SList a -> SList a) -> SList a -> SList a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SInteger -> SList a -> SList a
forall a. SymVal a => SInteger -> SList a -> SList a
coat SInteger
k (SList a -> SList a) -> (SList a -> SList a) -> SList a -> SList a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SInteger -> SList a -> SList a
forall a. SymVal a => SInteger -> SList a -> SList a
coat SInteger
k (SList a -> SList a) -> (SList a -> SList a) -> SList a -> SList a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SInteger -> SList a -> SList a
forall a. SymVal a => SInteger -> SList a -> SList a
coat SInteger
k
type Deck = SList Integer
coatCheck :: Integer -> IO ThmResult
coatCheck :: Integer -> IO ThmResult
coatCheck Integer
n = SymbolicT IO SBool -> IO ThmResult
forall a. Provable a => a -> IO ThmResult
prove (SymbolicT IO SBool -> IO ThmResult)
-> SymbolicT IO SBool -> IO ThmResult
forall a b. (a -> b) -> a -> b
$ do
Deck
deck :: Deck <- String -> Symbolic Deck
forall a. SymVal a => String -> Symbolic (SBV a)
free String
"deck"
SInteger
k <- String -> Symbolic SInteger
forall a. SymVal a => String -> Symbolic (SBV a)
free String
"k"
SBool -> SymbolicT IO ()
forall (m :: * -> *). SolverContext m => SBool -> m ()
constrain (SBool -> SymbolicT IO ()) -> SBool -> SymbolicT IO ()
forall a b. (a -> b) -> a -> b
$ Deck -> SInteger
forall a. SymVal a => SList a -> SInteger
length Deck
deck SInteger -> SInteger -> SBool
forall a. EqSymbolic a => a -> a -> SBool
.== Integer -> SInteger
forall a. SymVal a => a -> SBV a
literal Integer
n
SBool -> SymbolicT IO ()
forall (m :: * -> *). SolverContext m => SBool -> m ()
constrain (SBool -> SymbolicT IO ()) -> SBool -> SymbolicT IO ()
forall a b. (a -> b) -> a -> b
$ SInteger
2SInteger -> SInteger -> SInteger
forall a. Num a => a -> a -> a
*SInteger
k SInteger -> SInteger -> SBool
forall a. OrdSymbolic a => a -> a -> SBool
.>= Integer -> SInteger
forall a. SymVal a => a -> SBV a
literal Integer
n
SBool -> SymbolicT IO SBool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SBool -> SymbolicT IO SBool) -> SBool -> SymbolicT IO SBool
forall a b. (a -> b) -> a -> b
$ Deck
deck Deck -> Deck -> SBool
forall a. EqSymbolic a => a -> a -> SBool
.== SInteger -> Deck -> Deck
forall a. SymVal a => SInteger -> SList a -> SList a
fourCoat SInteger
k Deck
deck