Semiring.hs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. {-# LANGUAGE TemplateHaskell #-}
  2. module Internal.Termination.Semiring
  3. ( semiringInvariant
  4. , tests
  5. ) where
  6. import Agda.Termination.Semiring
  7. import Internal.Helpers
  8. ------------------------------------------------------------------------------
  9. -- Properties
  10. -- | Semiring invariant.
  11. -- I think it's OK to use the same x, y, z triple for all the
  12. -- properties below.
  13. semiringInvariant :: Eq a
  14. => Semiring a
  15. -> a -> a -> a -> Bool
  16. semiringInvariant (Semiring { add = (+), mul = (*)
  17. , zero = zero --, one = one
  18. }) = \x y z ->
  19. isAssociative (+) x y z &&
  20. isIdentity zero (+) x &&
  21. isCommutative (+) x y &&
  22. isAssociative (*) x y z &&
  23. -- isIdentity one (*) x &&
  24. isLeftDistributive (*) (+) x y z &&
  25. isRightDistributive (*) (+) x y z &&
  26. isZero zero (*) x
  27. prop_integerSemiring :: Integer -> Integer -> Integer -> Bool
  28. prop_integerSemiring = semiringInvariant integerSemiring
  29. prop_intSemiring :: Int -> Int -> Int -> Bool
  30. prop_intSemiring = semiringInvariant intSemiring
  31. prop_boolSemiring :: Bool -> Bool -> Bool -> Bool
  32. prop_boolSemiring = semiringInvariant boolSemiring
  33. ------------------------------------------------------------------------
  34. -- * All tests
  35. ------------------------------------------------------------------------
  36. -- Template Haskell hack to make the following $allProperties work
  37. -- under ghc-7.8.
  38. return [] -- KEEP!
  39. -- | All tests as collected by 'allProperties'.
  40. --
  41. -- Using 'allProperties' is convenient and superior to the manual
  42. -- enumeration of tests, since the name of the property is added
  43. -- automatically.
  44. tests :: TestTree
  45. tests = testProperties "Internal.Termination.Semiring" $allProperties