2020-08-19 00:26:56 +03:00
|
|
|
||| Implementation of ordering relations for `Fin`ite numbers
|
|
|
|
module Data.Fin.Order
|
|
|
|
|
|
|
|
import Data.Fin
|
|
|
|
import Data.Fun
|
|
|
|
import Data.Rel
|
|
|
|
import Data.Nat
|
|
|
|
import Data.Nat.Order
|
|
|
|
import Decidable.Decidable
|
|
|
|
import Decidable.Order
|
|
|
|
|
2021-06-09 01:05:10 +03:00
|
|
|
%default total
|
|
|
|
|
2020-08-19 00:26:56 +03:00
|
|
|
using (k : Nat)
|
2021-01-16 10:03:45 +03:00
|
|
|
|
2021-01-05 16:56:04 +03:00
|
|
|
public export
|
2020-08-19 00:26:56 +03:00
|
|
|
data FinLTE : Fin k -> Fin k -> Type where
|
2020-12-11 14:58:26 +03:00
|
|
|
FromNatPrf : {m, n : Fin k} -> LTE (finToNat m) (finToNat n) -> FinLTE m n
|
2020-08-19 00:26:56 +03:00
|
|
|
|
2021-01-05 16:56:04 +03:00
|
|
|
public export
|
2020-08-19 00:26:56 +03:00
|
|
|
implementation Preorder (Fin k) FinLTE where
|
|
|
|
transitive m n o (FromNatPrf p1) (FromNatPrf p2) =
|
|
|
|
FromNatPrf (LTEIsTransitive (finToNat m) (finToNat n) (finToNat o) p1 p2)
|
|
|
|
reflexive n = FromNatPrf (LTEIsReflexive (finToNat n))
|
|
|
|
|
2021-01-05 16:56:04 +03:00
|
|
|
public export
|
2020-08-19 00:26:56 +03:00
|
|
|
implementation Poset (Fin k) FinLTE where
|
|
|
|
antisymmetric m n (FromNatPrf p1) (FromNatPrf p2) =
|
|
|
|
finToNatInjective m n (LTEIsAntisymmetric (finToNat m) (finToNat n) p1 p2)
|
|
|
|
|
2021-01-05 16:56:04 +03:00
|
|
|
public export
|
2020-12-11 14:58:26 +03:00
|
|
|
implementation Decidable 2 [Fin k, Fin k] FinLTE where
|
2020-08-19 00:26:56 +03:00
|
|
|
decide m n with (decideLTE (finToNat m) (finToNat n))
|
|
|
|
decide m n | Yes prf = Yes (FromNatPrf prf)
|
|
|
|
decide m n | No disprf = No (\ (FromNatPrf prf) => disprf prf)
|
|
|
|
|
2021-01-05 16:56:04 +03:00
|
|
|
public export
|
2020-08-19 00:26:56 +03:00
|
|
|
implementation Ordered (Fin k) FinLTE where
|
|
|
|
order m n =
|
|
|
|
either (Left . FromNatPrf)
|
|
|
|
(Right . FromNatPrf)
|
|
|
|
(order (finToNat m) (finToNat n))
|