简体   繁体   中英

How to complete this proof of commutativity with `replace`?

On this documentation, it is mentioned how replace could be used to complete the proof, but it ends up using rewrite , which seems to be a syntax sugar that writes replace for you. I'm interested in understanding how to use it explicitly.

If I understand correctly, it could be used to rewrite S k = S (plus k 0) as S (plus k 0) = S (plus k 0) , given a proof that k = plus k 0 , which would then be provable by reflexivity. But if we instance it as replace {P = \\x => S x = S (plus k 0)} {x = k} {y = plus k 0} rec , we'll now need a proof of S k = S (plus k 0) , which is what we wanted to prove to begin with. In short, I'm not sure what exactly P should be.

Ah, it is fairly obvious in retrospect. If we let:

P = \x => S x = S (plus k 0)

Then, we can prove it for x = (plus k 0) (by reflexivity). Now, if we let y = k , then, by using replace , we gain a proof of S k = S (plus k 0) , which is what we need. Or, in other words:

plusCommZ : (m : Nat) -> m = plus m 0
plusCommZ Z = Refl
plusCommZ (S k) = replace 
  {P = \x => S x = S (plus k 0)}
  {x = plus k 0}
  {y = k}
  (sym (plusCommZ k))
  Refl

Completes the proof. We could do it the other way around with P = \\x => S x = S k .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM