<div dir="ltr"><div><div>One solution is to use 'let' instead of 'where':<br><br><div style="margin-left:40px">lemma : ∀ n → n ≤ n + 1<br>lemma 0 = z≤n<br>lemma 1 = s≤s z≤n<br>lemma (suc (suc n)) =<br> let n'≤n'+1 = lemma (suc n)<br> in s≤s n'≤n'+1<br><br></div>I'm not sure why Agda accepts the let-version, but not the where-version, though.<br><br></div>cheers,<br></div>Jesper<br><div><div><div><div><br></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 2, 2016 at 11:47 AM, Sergei Meshveliani <span dir="ltr"><<a href="mailto:mechvel@botik.ru" target="_blank">mechvel@botik.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
Can people advise, please, on the following subject?<br>
The below program can be rewritten with removing a double `suc' pattern.<br>
But let it be a contrived example:<br>
<br>
------------------------------------------------------------------<br>
open import Relation.Binary.PropositionalEquality as PE using (_≡_)<br>
open import Data.Nat using (ℕ; suc; _+_; _≤_; pred)<br>
<br>
open _≤_<br>
<br>
lemma : ∀ n → n ≤ n + 1<br>
lemma 0 = z≤n<br>
lemma 1 = s≤s z≤n<br>
lemma (suc (suc n)) = s≤s n'≤n'+1 where<br>
n'≤n'+1 = lemma (suc n)<br>
------------------------------------------------------------------<br>
<br>
Agda does not see termination here.<br>
What is the nicest way to prove termination with preserving this suc-suc<br>
pattern?<br>
I write it this way:<br>
<br>
--------------------------------<br>
lemma n = aux n (pred n) PE.refl<br>
where<br>
aux : (n m : ℕ) → m ≡ pred n → n ≤ n + 1<br>
aux 0 _ _ = z≤n<br>
aux 1 _ _ = s≤s z≤n<br>
aux (suc (suc n)) 0 ()<br>
aux (suc (suc n)) (suc m) m'≡pred-n'' = s≤s n'≤n'+1<br>
where<br>
m≡pred-n' = PE.cong pred m'≡pred-n''<br>
n'≤n'+1 = aux (suc n) m m≡pred-n'<br>
---------------------------------<br>
<br>
And it looks awkward.<br>
<br>
Thanks,<br>
<br>
------<br>
Sergei<br>
<br>
<br>
_______________________________________________<br>
Agda mailing list<br>
<a href="mailto:Agda@lists.chalmers.se">Agda@lists.chalmers.se</a><br>
<a href="https://lists.chalmers.se/mailman/listinfo/agda" rel="noreferrer" target="_blank">https://lists.chalmers.se/mailman/listinfo/agda</a><br>
</blockquote></div><br></div>