Zulip Chat Archive

Stream: new members

Topic: rw of self


Damiano Testa (Jan 15 2021 at 13:31):

While playing around with the question of this thread, I came across the funny behaviour below. I expected that rw could be used to rewrite a hypothesis with itself, but I was not able to make it work. Below is also an awkward way of doing it, by "duplicating a hypothesis". I can see that this is borderline self-referential, but is there a way to make the proof below work without duplicating a hypothesis?

Thanks!

import data.polynomial.basic

open polynomial

example {R : Type*} [semiring R] (h : (X : polynomial R) = X ^ 2) : (X : polynomial R) = X ^4 :=
begin
-- I would like to do this, but it does nothing...
--  rw [h] at h {occs := occurrences.pos [2]},
  have h' : X = X ^ 2 := h,
  rw [h] at h' {occs := occurrences.pos [2]},
  rw  pow_mul at h',
  exact h',
end

Damiano Testa (Jan 15 2021 at 13:35):

Unsurprisingly, repeat { rw [h] at h {occs := occurrences.pos [2]} } times out.

Johan Commelin (Jan 15 2021 at 14:30):

hmm, I don't know if that's possible

Riccardo Brasca (Jan 15 2021 at 14:30):

Is occurrences.pos the same as nth_rewrite?

Johan Commelin (Jan 15 2021 at 14:31):

not exactly, but almost

Damiano Testa (Jan 15 2021 at 14:32):

Fair enough! The solution is not so bad, just feels clunky. I also suspect that these kind of rewrites would be more common when working with power series and finding better approximations, from earlier ones. Maybe also results like the contraction theorem... Btw, is the contraction theorem in mathlib?

Johan Commelin (Jan 15 2021 at 14:32):

you could do rw at pos [1] in the goal

Damiano Testa (Jan 15 2021 at 14:32):

maybe yes:

mathlib/src/topology/metric_space/contracting.lean:/-- Banach fixed-point theorem, contraction mapping theorem, emetric_space version.

Damiano Testa (Jan 15 2021 at 14:33):

Johan, I am not sure that I understand how to try what you suggested...

Damiano Testa (Jan 15 2021 at 14:39):

I got it! Thanks!

example {R : Type*} [semiring R] (h : (X : polynomial R) = X ^ 2) : (X : polynomial R) = X ^4 :=
begin
  rw [h] {occs := occurrences.pos [1]}, -- Johan's suggestion to work on the goal, instead
  rw [h] {occs := occurrences.pos [1]},

rw [h] at h {occs := occurrences.pos [2]},

  rw  pow_mul,
  refl,
end

I like this, although I view it as a different workaround. In any case, this question mostly arose as a curiosity, than an actual issue.

Johan Commelin (Jan 15 2021 at 14:41):

what is the 3rd line doing?

Damiano Testa (Jan 15 2021 at 14:42):

It was a left-over from before. As I learned, it does absolutely nothing! I could replicate it as much as I wanted and it would still be useless! :grinning:

Johan Commelin (Jan 15 2021 at 14:43):

example {R : Type*} [semiring R] (a : R) (h : a = a ^ 2) : a = a ^ 4 :=
by { rw [h, h] {occs := occurrences.pos [1]}, rw  pow_mul, refl }

Damiano Testa (Jan 15 2021 at 14:44):

Ah, I did not know that you could compress the rw with the optional parameters!


Last updated: Dec 20 2023 at 11:08 UTC