Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proof that (prev n) <= m starting from n <= m

Tags:

agda

I have the next definition:

data Nat : Set where
  zero : Nat
  succ : Nat -> Nat

prev : Nat -> Nat
prev zero = zero
prev (succ n) = n

data _<=_ : Nat -> Nat -> Set where
  z<=n : forall {n} -> zero <= n
  s<=s : forall {n m} -> (n<=m : n <= m) -> (succ n) <= (succ m)

It easy to proof the next lemma:

lem-prev : {x y : Nat} -> x <= y -> (prev x) <= (prev y)
lem-prev z<=n = z<=n
lem-prev (s<=s t) = t

But I can't find a way to proof the next lemma:

lem-prev' : {x y : Nat} -> x <= y -> (prev x) <= y

I can change definition of <= to the next:

data _<='_ : Nat -> Nat -> Set where
  z<=n' : forall {n} -> zero <=' n
  s<=s' : forall {n m} -> (n<=m : n <=' m) -> (succ n) <=' m

In that case I can proof lem-prev':

lem-prev' : {x y : Nat} -> x <=' y -> (prev x) <=' y
lem-prev' z<=n' = z<=n'
lem-prev' (s<=s' t) = t

But now I can't proof lem-prev.

Is there a way to proof both lemmas for <= and/or <='? If no, then how should I change the definition to make it possible?

ADD: The solution using hammar's helper lemma:

lem-prev : {x y : Nat} -> x <= y -> (prev x) <= y
lem-prev z<=n = z<=n
lem-prev (s<=s prev-n<=prev-m) = weaken (prev-n<=prev-m)
like image 217
Yuras Avatar asked Dec 27 '22 15:12

Yuras


1 Answers

you can find a proof of that lemma in the standard library http://www.cse.chalmers.se/~nad/listings/lib/Data.Nat.Properties.html#10457

like image 81
Saizan Avatar answered Dec 29 '22 03:12

Saizan