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