2020-08-19 00:26:56 +03:00
|
|
|
||| Implementation of ordering relations for `Nat`ural numbers
|
|
|
|
module Data.Nat.Order
|
|
|
|
|
2021-07-09 11:06:27 +03:00
|
|
|
import Control.Relation
|
2020-08-19 00:26:56 +03:00
|
|
|
import Data.Nat
|
|
|
|
import Data.Fun
|
|
|
|
import Data.Rel
|
|
|
|
import Decidable.Decidable
|
|
|
|
import Decidable.Equality
|
|
|
|
|
2021-06-09 01:05:10 +03:00
|
|
|
%default total
|
|
|
|
|
2020-08-19 00:26:56 +03:00
|
|
|
public export
|
2021-07-13 17:32:01 +03:00
|
|
|
zeroNeverGreater : Not (LTE (S n) Z)
|
2021-02-16 14:56:43 +03:00
|
|
|
zeroNeverGreater LTEZero impossible
|
|
|
|
zeroNeverGreater (LTESucc _) impossible
|
2020-08-19 00:26:56 +03:00
|
|
|
|
|
|
|
public export
|
2021-07-09 11:06:27 +03:00
|
|
|
zeroAlwaysSmaller : {n : Nat} -> LTE Z n
|
2020-08-19 00:26:56 +03:00
|
|
|
zeroAlwaysSmaller = LTEZero
|
|
|
|
|
|
|
|
public export
|
2021-07-09 11:06:27 +03:00
|
|
|
ltesuccinjective : {0 n, m : Nat} -> Not (LTE n m) -> Not (LTE (S n) (S m))
|
2021-02-16 14:56:43 +03:00
|
|
|
ltesuccinjective disprf (LTESucc nLTEm) = void (disprf nLTEm)
|
|
|
|
ltesuccinjective disprf LTEZero impossible
|
2020-08-19 00:26:56 +03:00
|
|
|
|
|
|
|
public export
|
2021-07-09 11:06:27 +03:00
|
|
|
decideLTE : (n : Nat) -> (m : Nat) -> Dec (LTE n m)
|
2020-08-19 00:26:56 +03:00
|
|
|
decideLTE Z y = Yes LTEZero
|
|
|
|
decideLTE (S x) Z = No zeroNeverGreater
|
|
|
|
decideLTE (S x) (S y) with (decEq (S x) (S y))
|
2021-07-09 11:06:27 +03:00
|
|
|
decideLTE (S x) (S y) | Yes eq = rewrite eq in Yes (reflexive {rel = LTE})
|
2020-08-19 00:26:56 +03:00
|
|
|
decideLTE (S x) (S y) | No _ with (decideLTE x y)
|
2021-02-22 21:46:35 +03:00
|
|
|
decideLTE (S x) (S y) | No _ | Yes nLTEm = Yes (LTESucc nLTEm)
|
|
|
|
decideLTE (S x) (S y) | No _ | No nGTm = No (ltesuccinjective nGTm)
|
2020-08-19 00:26:56 +03:00
|
|
|
|
|
|
|
public export
|
2021-07-09 11:06:27 +03:00
|
|
|
Decidable 2 [Nat,Nat] LTE where
|
2020-08-19 00:26:56 +03:00
|
|
|
decide = decideLTE
|
|
|
|
|
|
|
|
public export
|
|
|
|
lte : (m : Nat) -> (n : Nat) -> Dec (LTE m n)
|
|
|
|
lte m n = decide {ts = [Nat,Nat]} {p = LTE} m n
|
|
|
|
|
|
|
|
public export
|
|
|
|
shift : (m : Nat) -> (n : Nat) -> LTE m n -> LTE (S m) (S n)
|
|
|
|
shift m n mLTEn = LTESucc mLTEn
|