Zulip Chat Archive

Stream: new members

Topic: On repeated rewrites


Lauri Oksanen (Apr 18 2025 at 17:51):

Is there a way to repeat an implication in the same way as the equivalence is repeated in

example {x : } (h1 : (x - 1) * (x - 2) * (x - 3) = 0) :
  (x - 1 = 0  x - 2 = 0)  x - 3 = 0
:= by
  repeat rw [mul_eq_zero] at h1
  assumption

Clearly this example can be proven using mul_eq_zero.mp only. The first step is

example {x : } (h1 : (x - 1) * (x - 2) * (x - 3) = 0) :
  (x - 1) * (x - 2) = 0  x - 3 = 0
:= mul_eq_zero.mp h1

Can I repeat this somehow?

Bjørn Kjos-Hanssen (Apr 18 2025 at 18:53):

Well, yes...

import Mathlib

example {x : } (h1 : (x - 1) * (x - 2) * (x - 3) = 0) :
  (x - 1 = 0  x - 2 = 0)  x - 3 = 0 :=
    (mul_eq_zero.mp h1).elim (.inl  mul_eq_zero.mp) .inr

Aaron Liu (Apr 18 2025 at 18:55):

A bit shorter:

import Mathlib

example {x : } (h1 : (x - 1) * (x - 2) * (x - 3) = 0) :
  (x - 1 = 0  x - 2 = 0)  x - 3 = 0 :=
    (mul_eq_zero.mp h1).imp_left mul_eq_zero.mp

Jz Pan (Apr 19 2025 at 15:34):

simp_rw? Or just simpa only [mul_eq_zero] using h1

Lauri Oksanen (Apr 22 2025 at 16:15):

Thanks a lot for the fast replies, and sorry for the delay from my part. The repeat/simp based solutions generalize easily. For example,

example {x : } (h1 : (x - 1) * (x - 2) * (x - 3) * (x - 4) = 0) :
  ((x - 1 = 0  x - 2 = 0)  x - 3 = 0)  x - 4 = 0
:= by
  simp only [mul_eq_zero] at h1
  assumption

But is it possible to make these work with only the implication mul_eq_zero.mp instead of the equivalence mul_eq_zero? On the other hand, it seems to me that the solutions that use mul_eq_zero.mp more directly don't generalize so easily for longer products.

Robin Arnez (Apr 23 2025 at 10:22):

Generalization using Aaron's method:

example {x : } (h : (x - 1) * (x - 2) * (x - 3) * (x - 4) * (x - 5) * (x - 6) = 0) :
    ((((x - 1 = 0  x - 2 = 0)  x - 3 = 0)  x - 4 = 0)  x - 5 = 0)  x - 6 = 0 :=
  (mul_eq_zero.mp h).imp_left fun h =>
  (mul_eq_zero.mp h).imp_left fun h =>
  (mul_eq_zero.mp h).imp_left fun h =>
  (mul_eq_zero.mp h).imp_left mul_eq_zero.mp

Lauri Oksanen (Apr 25 2025 at 11:26):

Thanks a lot! Is there a way to say repeat (mul_eq_zero.mp h).imp_left fun h => four times?

Robin Arnez (Apr 25 2025 at 21:36):

if you mean as a tactic:

import Mathlib.Analysis.Normed.Field.Basic

example {x : } (h : (x - 1) * (x - 2) * (x - 3) * (x - 4) * (x - 5) * (x - 6) = 0) :
    ((((x - 1 = 0  x - 2 = 0)  x - 3 = 0)  x - 4 = 0)  x - 5 = 0)  x - 6 = 0 := by
  repeat refine (mul_eq_zero.mp h).imp_left fun h => ?_
  assumption

Lauri Oksanen (Apr 26 2025 at 05:17):

This is exactly what I was wondering about. Thanks a lot! Here is the same thing, written in a slightly different way.

example {x : } (h : (x - 1) * (x - 2) * (x - 3) * (x - 4) * (x - 5) * (x - 6) = 0) :
    ((((x - 1 = 0  x - 2 = 0)  x - 3 = 0)  x - 4 = 0)  x - 5 = 0)  x - 6 = 0 := by
  repeat (
    refine (mul_eq_zero.mp h).imp_left ?_
    intro h
  )
  assumption

Last updated: May 02 2025 at 03:31 UTC