Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add not LTE implies GT, and LTE implies maximum. #4428

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions libs/prelude/Prelude/Nat.idr
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ fromLteSucc (LTESucc x) = x
isLTE : (m, n : Nat) -> Dec (m `LTE` n)
isLTE Z n = Yes LTEZero
isLTE (S k) Z = No succNotLTEzero
isLTE (S k) (S j) with (isLTE k j)
isLTE (S k) (S j) | (Yes prf) = Yes (LTESucc prf)
isLTE (S k) (S j) | (No contra) = No (contra . fromLteSucc)
isLTE (S k) (S j) = case isLTE k j of

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason for the change here? 😄

Yes prf => Yes (LTESucc prf)
No contra => No (contra . fromLteSucc)

||| `LTE` is reflexive.
lteRefl : LTE n n
Expand Down Expand Up @@ -182,6 +182,12 @@ notLTImpliesGTE {b = Z} _ = LTEZero
notLTImpliesGTE {a = Z} {b = S k} notLt = absurd (notLt (LTESucc LTEZero))
notLTImpliesGTE {a = S k} {b = S j} notLt = LTESucc (notLTImpliesGTE (notLt . LTESucc))

||| If a number is not less than or equal to another, it is greater than it
notLTEImpliesGT : Not (i `LTE` j) -> i `GT` j
notLTEImpliesGT {i = Z} notLt = absurd $ notLt LTEZero
notLTEImpliesGT {i = S k} {j = Z} _ = LTESucc LTEZero
notLTEImpliesGT {i = S j} {j = S k} notLt = LTESucc (notLTEImpliesGT (notLt . LTESucc))

||| Boolean test than one Nat is less than or equal to another
total lte : Nat -> Nat -> Bool
lte Z right = True
Expand Down Expand Up @@ -840,3 +846,9 @@ sucMinL (S l) = cong (sucMinL l)
total sucMinR : (l : Nat) -> minimum l (S l) = l
sucMinR Z = Refl
sucMinR (S l) = cong (sucMinR l)

||| If one number is biggre than another, you know what the maximum is.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a small typo biggre -> bigger

total lteImpliesMax : i `LTE` j -> maximum i j = j

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be added to contrib instead of prelude?

lteImpliesMax {i = Z} _ = Refl
lteImpliesMax {i = S k} {j = Z} _ impossible
lteImpliesMax {i = S k} {j = S j} (LTESucc x) = cong {f = S} $ lteImpliesMax x