Zulip Chat Archive
Stream: Is there code for X?
Topic: Can this be golfed?
Antoine Chambert-Loir (Apr 13 2025 at 13:47):
I wrote this for #23993 and I wonder whether it can be made shorter.
import Mathlib.Algebra.Order.Monoid.Unbundled.Basic
@[to_additive]
theorem trichotomy_of_mul_eq_mul {α : Type*} [LinearOrder α] [Mul α]
[MulLeftMono α] [MulLeftStrictMono α] [MulRightMono α] [MulRightStrictMono α]
{a b c d : α} (h : a * b = c * d) :
(a = c ∧ b = d) ∨ (a < c ∨ b < d) := by
by_cases hac : a < c
· right; left; exact hac
· by_cases hbd : b < d
· right; right; exact hbd
· left
simp only [not_lt] at hac hbd
by_contra h'
apply ne_of_lt _ h.symm
rw [not_and_or] at h'
rcases h' with h' | h'
· exact mul_lt_mul_of_lt_of_le (lt_of_le_of_ne hac (Ne.symm h')) hbd
· exact mul_lt_mul_of_le_of_lt hac (lt_of_le_of_ne hbd (Ne.symm h'))
Kevin Buzzard (Apr 13 2025 at 13:53):
This doesn't compile for me, even after adding import Mathlib
and (a b c d : α)
.
Antoine Chambert-Loir (Apr 13 2025 at 13:58):
bad copy paste, I'm sorry.
Kevin Buzzard (Apr 13 2025 at 13:59):
Under your assumptions on alpha, are a * b = a * d -> b = d
and a * b = c * d -> c < a -> b < d
true and missing?
Antoine Chambert-Loir (Apr 13 2025 at 14:00):
I just tried that in the sandbox. (and the PR compiles).
Kevin Buzzard (Apr 13 2025 at 14:01):
Usually I would go for obtain hac | rfl | hca := lt_trichotomy a c
rather than by_cases
on an <
(which gives you \not <
in the other case, which is almost always not what you want). Even if you want to split into a < b or b <= a you can do obtain h1 | h2 := lt_or_le a b
Kevin Buzzard (Apr 13 2025 at 14:02):
But then you run into these two missing lemmas which I flagged above.
Edison Xie (Apr 13 2025 at 14:13):
Antoine Chambert-Loir said:
· right; left; exact hac
this is just tauto
Antoine Chambert-Loir (Apr 13 2025 at 14:14):
I hadn't thought about tauto
, but it doesn't yet exist in these early files.
Edison Xie (Apr 13 2025 at 14:15):
Ah okay but it's a easy hack for · right; right; exact hbd
as well :joy:
Edison Xie (Apr 13 2025 at 14:27):
combining @Kevin Buzzard 's suggestion gives:
import Mathlib
@[to_additive]
theorem trichotomy_of_mul_eq_mul {α : Type*} [LinearOrder α] [Mul α]
[MulLeftMono α] [MulLeftStrictMono α] [MulRightMono α] [MulRightStrictMono α]
{a b c d : α} (h : a * b = c * d) :
(a = c ∧ b = d) ∨ (a < c ∨ b < d) := by
obtain hac | rfl | hca := lt_trichotomy a c
· tauto
· left; simpa using mul_right_inj_of_comparable (LinearOrder.le_total d b)|>.1 h
· right; right; by_contra! h'; exact (ne_of_lt (mul_lt_mul_of_lt_of_le hca h')) h.symm
Last updated: May 02 2025 at 03:31 UTC