0

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.

MaiaVictor
  • 51,090
  • 44
  • 144
  • 286

1 Answers1

0

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.

MaiaVictor
  • 51,090
  • 44
  • 144
  • 286