{-# 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 :: forall a. SymVal a => SInteger -> SList a -> SList a
coat SInteger
k SList a
cards = forall a. SymVal a => SInteger -> SList a -> SList a
drop SInteger
k SList a
cards forall a. SymVal a => SList a -> SList a -> SList a
++ forall a. SymVal a => SList a -> SList a
reverse (forall a. SymVal a => SInteger -> SList a -> SList a
take SInteger
k SList a
cards)
fourCoat :: SymVal a => SInteger -> SList a -> SList a
fourCoat :: forall a. SymVal a => SInteger -> SList a -> SList a
fourCoat SInteger
k = forall a. SymVal a => SInteger -> SList a -> SList a
coat SInteger
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SymVal a => SInteger -> SList a -> SList a
coat SInteger
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SymVal a => SInteger -> SList a -> SList a
coat SInteger
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall a. Provable a => a -> IO ThmResult
prove forall a b. (a -> b) -> a -> b
$ do
Deck
deck :: Deck <- forall a. SymVal a => String -> Symbolic (SBV a)
free String
"deck"
SInteger
k <- forall a. SymVal a => String -> Symbolic (SBV a)
free String
"k"
forall (m :: * -> *). SolverContext m => SBool -> m ()
constrain forall a b. (a -> b) -> a -> b
$ forall a. SymVal a => SList a -> SInteger
length Deck
deck forall a. EqSymbolic a => a -> a -> SBool
.== forall a. SymVal a => a -> SBV a
literal Integer
n
forall (m :: * -> *). SolverContext m => SBool -> m ()
constrain forall a b. (a -> b) -> a -> b
$ SInteger
2forall a. Num a => a -> a -> a
*SInteger
k forall a. OrdSymbolic a => a -> a -> SBool
.>= forall a. SymVal a => a -> SBV a
literal Integer
n
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Deck
deck forall a. EqSymbolic a => a -> a -> SBool
.== forall a. SymVal a => SInteger -> SList a -> SList a
fourCoat SInteger
k Deck
deck