Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 198161d

Browse files
committed
feat(data/prod/basic): prod.lex is trichotomous (#17931)
or irreflexive when the base relations are.
1 parent d97d4fa commit 198161d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/data/prod/basic.lean

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ lemma map_map {ε ζ : Type*}
6868
prod.map g g' (prod.map f f' x) = prod.map (g ∘ f) (g' ∘ f') x :=
6969
rfl
7070

71-
@[simp] theorem mk.inj_iff {a₁ a₂ : α} {b₁ b₂ : β} : (a₁, b₁) = (a₂, b₂) ↔ (a₁ = a₂ ∧ b₁ = b₂) :=
72-
⟨prod.mk.inj, by cc⟩
71+
variables {a a₁ a₂ : α} {b b₁ b₂ : β}
72+
73+
@[simp] lemma mk.inj_iff : (a₁, b₁) = (a₂, b₂) ↔ a₁ = a₂ ∧ b₁ = b₂ := ⟨prod.mk.inj, by cc⟩
7374

7475
lemma mk.inj_left {α β : Type*} (a : α) :
7576
function.injective (prod.mk a : β → α × β) :=
@@ -79,6 +80,9 @@ lemma mk.inj_right {α β : Type*} (b : β) :
7980
function.injective (λ a, prod.mk a b : α → α × β) :=
8081
by { intros b₁ b₂ h, by simpa only [and_true, eq_self_iff_true, mk.inj_iff] using h }
8182

83+
lemma mk_inj_left : (a, b₁) = (a, b₂) ↔ b₁ = b₂ := (mk.inj_left _).eq_iff
84+
lemma mk_inj_right : (a₁, b) = (a₂, b) ↔ a₁ = a₂ := (mk.inj_right _).eq_iff
85+
8286
lemma ext_iff {p q : α × β} : p = q ↔ p.1 = q.1 ∧ p.2 = q.2 :=
8387
by rw [← @mk.eta _ _ p, ← @mk.eta _ _ q, mk.inj_iff]
8488

@@ -148,6 +152,8 @@ lemma fst_eq_iff : ∀ {p : α × β} {x : α}, p.1 = x ↔ p = (x, p.2)
148152
lemma snd_eq_iff : ∀ {p : α × β} {x : β}, p.2 = x ↔ p = (p.1, x)
149153
| ⟨a, b⟩ x := by simp
150154

155+
variables {r : α → α → Prop} {s : β → β → Prop} {x y : α × β}
156+
151157
theorem lex_def (r : α → α → Prop) (s : β → β → Prop)
152158
{p q : α × β} : prod.lex r s p q ↔ r p.1 q.1 ∨ p.1 = q.1 ∧ s p.2 q.2 :=
153159
⟨λ h, by cases h; simp *,
@@ -157,6 +163,8 @@ theorem lex_def (r : α → α → Prop) (s : β → β → Prop)
157163
by change a = c at e; subst e; exact lex.right _ h
158164
end
159165

166+
lemma lex_iff : lex r s x y ↔ r x.1 y.1 ∨ x.1 = y.1 ∧ s x.2 y.2 := lex_def _ _
167+
160168
instance lex.decidable [decidable_eq α]
161169
(r : α → α → Prop) (s : β → β → Prop) [decidable_rel r] [decidable_rel s] :
162170
decidable_rel (prod.lex r s) :=
@@ -178,6 +186,9 @@ instance is_refl_right {r : α → α → Prop} {s : β → β → Prop} [is_ref
178186
is_refl (α × β) (lex r s) :=
179187
⟨lex.refl_right _ _⟩
180188

189+
instance is_irrefl [is_irrefl α r] [is_irrefl β s] : is_irrefl (α × β) (lex r s) :=
190+
by rintro ⟨i, a⟩ (⟨_, _, h⟩ | ⟨_, h⟩); exact irrefl _ h⟩
191+
181192
@[trans] lemma lex.trans {r : α → α → Prop} {s : β → β → Prop} [is_trans α r] [is_trans β s] :
182193
∀ {x y z : α × β}, prod.lex r s x y → prod.lex r s y z → prod.lex r s x z
183194
| (x₁, x₂) (y₁, y₂) (z₁, z₂) (lex.left _ _ hxy₁) (lex.left _ _ hyz₁) :=
@@ -212,6 +223,15 @@ instance is_total_right {r : α → α → Prop} {s : β → β → Prop} [is_tr
212223
{ exact or.inr (lex.left _ _ hji) }
213224
end
214225

226+
instance is_trichotomous [is_trichotomous α r] [is_trichotomous β s] :
227+
is_trichotomous (α × β) (lex r s) :=
228+
⟨λ ⟨i, a⟩ ⟨j, b⟩, begin
229+
obtain hij | rfl | hji := trichotomous_of r i j,
230+
{ exact or.inl (lex.left _ _ hij) },
231+
{ exact (trichotomous_of s a b).imp3 (lex.right _) (congr_arg _) (lex.right _) },
232+
{ exact or.inr (or.inr $ lex.left _ _ hji) }
233+
end
234+
215235
end prod
216236

217237
open prod

0 commit comments

Comments
 (0)