add min/max functions and theorems

This commit is contained in:
rnhmjoj 2016-11-16 22:05:43 +01:00
parent 2c4ab33bc4
commit c631d24d38
No known key found for this signature in database
GPG Key ID: 362BB82B7E496B7C

View File

@ -19,7 +19,7 @@ import Data.Bool
import Data.Integer (Integer) import Data.Integer (Integer)
import Data.Function (id, const, ()) import Data.Function (id, const, ())
import Data.TypeClass (Eq, Show, Num, Enum, Bounded) import Data.TypeClass (Eq, Show, Num, Enum, Bounded)
import Data.Singletons.TH hiding ((:<), (:>), (%:<), Refl) import Data.Singletons.TH hiding ((:<), (:>), (%:<), Refl, Min, sMin, Max, sMax)
import qualified Data.TypeClass as T import qualified Data.TypeClass as T
@ -66,6 +66,15 @@ singletons [d|
(>) 𝔹 (>) 𝔹
n > m = (¬) (n < m) n > m = (¬) (n < m)
min
min Z _ = Z
min _ Z = Z
min (S n) (S m) = S (min n m)
max
max Z n = n
max n Z = n
max (S n) (S m) = S (max n m)
|] |]
@ -160,3 +169,14 @@ plus_commut ∷ S n → S m → (n :+ m) :≡ (m :+ n)
plus_commut n SZ = plus_right_id n plus_commut n SZ = plus_right_id n
plus_commut n (SS m) = plus_commut n (SS m) =
sym (succ_right n m) cong SS (plus_commut n m) succ_left m n sym (succ_right n m) cong SS (plus_commut n m) succ_left m n
-- | Minimum of itself
min_self S n Min n n : n
min_self SZ = Refl
min_self (SS n) = cong SS (min_self n)
-- | Maximum of itself
max_self S n Max n n : n
max_self SZ = Refl
max_self (SS n) = cong SS (max_self n)