简体   繁体   English

如何用`replace`完成可交换性的证明?

[英]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. 文档中,提到了如何使用replace来完成证明,但最终使用rewrite ,这似乎是为您编写replace的语法糖。 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. 如果我理解正确,它可以用来将S k = S (plus k 0)重写为S (plus k 0) = S (plus k 0) ,并证明k = plus k 0 ,那么这是可证明的通过反射。 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. 但是,如果我们将其replace {P = \\x => S x = S (plus k 0)} {x = k} {y = plus k 0} recreplace {P = \\x => S x = S (plus k 0)} {x = k} {y = plus k 0} rec ,我们现在需要S k = S (plus k 0)的证明S k = S (plus k 0) ,这就是我们想证明的开始。 In short, I'm not sure what exactly P should be. 简而言之,我不确定P应该是什么。

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). 然后,我们可以证明x = (plus k 0) (通过自反)。 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. 现在,如果让y = k ,那么通过使用replace ,我们得到了S k = S (plus k 0)的证明。 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 . 我们可以用P = \\x => S x = S k来进行另一种方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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