Last active
April 23, 2021 17:25
-
-
Save rosalogia/f504f21af914149a406101f1c7623297 to your computer and use it in GitHub Desktop.
A short Haskell program using QuickCheck to identify whether a defined relation R is an equivalence relation or partial ordering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Test.QuickCheck | |
-- unfortunately, function names cannot start with uppercase letters | |
r :: Positive Integer -> Positive Integer -> Bool | |
r a b = | |
let (x, y) = (getPositive a, getPositive b) in | |
y `mod` (x * x) == 0 | |
implies p q = not p || q | |
prop_reflexive :: Positive Integer -> Bool | |
prop_reflexive a = a `r` a | |
prop_symmetric :: Positive Integer -> Positive Integer -> Bool | |
prop_symmetric a b = a `r` b && b `r` a | |
prop_antisymmetric :: Positive Integer -> Positive Integer -> Bool | |
prop_antisymmetric a b = ((a `r` b) && (b `r` a)) `implies` (b == a) | |
prop_transitive :: Positive Integer -> Positive Integer -> Positive Integer -> Bool | |
prop_transitive x y z = ((x `r` y) && (y `r` z)) `implies` (x `r` z) | |
-- Output whether a property is satisfied, or otherwise which cases don't satisfy the property | |
main :: IO () | |
main = do | |
quickCheck prop_transitive | |
quickCheck prop_antisymmetric | |
quickCheck prop_symmetric | |
quickCheck prop_reflexive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment