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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With