{-# OPTIONS_GHC -Wall -Werror #-}
module Documentation.SBV.Examples.Misc.Polynomials where
import Data.SBV
import Data.SBV.Tools.Polynomial
type GF28 = SWord8
gfMult :: GF28 -> GF28 -> GF28
GF28
a gfMult :: GF28 -> GF28 -> GF28
`gfMult` GF28
b = forall a. Polynomial a => (a, a, [Int]) -> a
pMult (GF28
a, GF28
b, [Int
8, Int
4, Int
3, Int
1, Int
0])
multUnit :: GF28 -> SBool
multUnit :: GF28 -> SBool
multUnit GF28
x = (GF28
x GF28 -> GF28 -> GF28
`gfMult` GF28
unit) forall a. EqSymbolic a => a -> a -> SBool
.== GF28
x
where unit :: GF28
unit = forall a. Polynomial a => [Int] -> a
polynomial [Int
0]
multComm :: GF28 -> GF28 -> SBool
multComm :: GF28 -> GF28 -> SBool
multComm GF28
x GF28
y = (GF28
x GF28 -> GF28 -> GF28
`gfMult` GF28
y) forall a. EqSymbolic a => a -> a -> SBool
.== (GF28
y GF28 -> GF28 -> GF28
`gfMult` GF28
x)
multAssoc :: GF28 -> GF28 -> GF28 -> SBool
multAssoc :: GF28 -> GF28 -> GF28 -> SBool
multAssoc GF28
x GF28
y GF28
z = ((GF28
x GF28 -> GF28 -> GF28
`gfMult` GF28
y) GF28 -> GF28 -> GF28
`gfMult` GF28
z) forall a. EqSymbolic a => a -> a -> SBool
.== (GF28
x GF28 -> GF28 -> GF28
`gfMult` (GF28
y GF28 -> GF28 -> GF28
`gfMult` GF28
z))
polyDivMod :: GF28 -> GF28 -> SBool
polyDivMod :: GF28 -> GF28 -> SBool
polyDivMod GF28
x GF28
y = forall a. Mergeable a => SBool -> a -> a -> a
ite (GF28
y forall a. EqSymbolic a => a -> a -> SBool
.== GF28
0) ((GF28
0, GF28
x) forall a. EqSymbolic a => a -> a -> SBool
.== (GF28
a, GF28
b)) (GF28
x forall a. EqSymbolic a => a -> a -> SBool
.== (GF28
y GF28 -> GF28 -> GF28
`gfMult` GF28
a) forall a. Bits a => a -> a -> a
`xor` GF28
b)
where (GF28
a, GF28
b) = GF28
x forall a. Polynomial a => a -> a -> (a, a)
`pDivMod` GF28
y
testGF28 :: IO ()
testGF28 :: IO ()
testGF28 = do
forall a. Show a => a -> IO ()
print forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall a. Provable a => a -> IO ThmResult
prove GF28 -> SBool
multUnit
forall a. Show a => a -> IO ()
print forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall a. Provable a => a -> IO ThmResult
prove GF28 -> GF28 -> SBool
multComm
forall a. Show a => a -> IO ()
print forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall a. Provable a => a -> IO ThmResult
prove GF28 -> GF28 -> SBool
polyDivMod