@@ -3,7 +3,7 @@ Copyright (c) 2016 Jeremy Avigad. All rights reserved.
33Released under Apache 2.0 license as described in the file LICENSE.
44Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro
55! This file was ported from Lean 3 source module algebra.order.ring.with_top
6- ! leanprover-community/mathlib commit e7e2ba8aa216a5833b5ed85a93317263711a36b5
6+ ! leanprover-community/mathlib commit afdb4fa3b32d41106a4a09b371ce549ad7958abd
77! Please do not edit these lines, except to modify the commit id
88! if you have ported upstream changes.
99-/
@@ -48,14 +48,36 @@ theorem mul_def {a b : WithTop α} :
4848theorem top_mul_top : (⊤ * ⊤ : WithTop α) = ⊤ := by simp [mul_def]; rfl
4949#align with_top.top_mul_top WithTop.top_mul_top
5050
51- @[simp]
52- theorem mul_top {a : WithTop α} (h : a ≠ 0 ) : a * ⊤ = ⊤ := by cases a <;> simp [mul_def, h] <;> rfl
51+ theorem mul_top' (a : WithTop α) : a * ⊤ = if a = 0 then 0 else ⊤ := by
52+ induction a using recTopCoe <;> simp [mul_def] <;> rfl
53+ #align with_top.mul_top' WithTop.mul_top'
54+
55+ @[simp] theorem mul_top {a : WithTop α} (h : a ≠ 0 ) : a * ⊤ = ⊤ := by rw [mul_top', if_neg h]
5356#align with_top.mul_top WithTop.mul_top
5457
55- @[simp]
56- theorem top_mul {a : WithTop α} (h : a ≠ 0 ) : ⊤ * a = ⊤ := by cases a <;> simp [mul_def, h] <;> rfl
58+ theorem top_mul' (a : WithTop α) : ⊤ * a = if a = 0 then 0 else ⊤ := by
59+ induction a using recTopCoe <;> simp [mul_def] <;> rfl
60+ #align with_top.top_mul' WithTop.top_mul'
61+
62+ @[simp] theorem top_mul {a : WithTop α} (h : a ≠ 0 ) : ⊤ * a = ⊤ := by rw [top_mul', if_neg h]
5763#align with_top.top_mul WithTop.top_mul
5864
65+ theorem mul_eq_top_iff {a b : WithTop α} : a * b = ⊤ ↔ a ≠ 0 ∧ b = ⊤ ∨ a = ⊤ ∧ b ≠ 0 := by
66+ rw [mul_def, ite_eq_iff, ← none_eq_top, Option.map₂_eq_none_iff]
67+ have ha : a = 0 → a ≠ none := fun h => h.symm ▸ zero_ne_top
68+ have hb : b = 0 → b ≠ none := fun h => h.symm ▸ zero_ne_top
69+ tauto
70+ #align with_top.mul_eq_top_iff WithTop.mul_eq_top_iff
71+
72+ theorem mul_lt_top' [LT α] {a b : WithTop α} (ha : a < ⊤) (hb : b < ⊤) : a * b < ⊤ := by
73+ rw [WithTop.lt_top_iff_ne_top] at *
74+ simp only [Ne.def, mul_eq_top_iff, *, and_false, false_and, false_or]
75+ #align with_top.mul_lt_top' WithTop.mul_lt_top'
76+
77+ theorem mul_lt_top [LT α] {a b : WithTop α} (ha : a ≠ ⊤) (hb : b ≠ ⊤) : a * b < ⊤ :=
78+ mul_lt_top' (WithTop.lt_top_iff_ne_top.2 ha) (WithTop.lt_top_iff_ne_top.2 hb)
79+ #align with_top.mul_lt_top WithTop.mul_lt_top
80+
5981instance noZeroDivisors [NoZeroDivisors α] : NoZeroDivisors (WithTop α) := by
6082 refine ⟨fun h₁ => Decidable.by_contradiction <| fun h₂ => ?_⟩
6183 rw [mul_def, if_neg h₂] at h₁
@@ -68,7 +90,7 @@ section MulZeroClass
6890
6991variable [MulZeroClass α]
7092
71- @[norm_cast]
93+ @ [simp, norm_cast]
7294theorem coe_mul {a b : α} : (↑(a * b) : WithTop α) = a * b := by
7395 by_cases ha : a = 0
7496 · simp [ha]
@@ -87,23 +109,6 @@ theorem mul_coe {b : α} (hb : b ≠ 0) : ∀ {a : WithTop α},
87109 rfl
88110#align with_top.mul_coe WithTop.mul_coe
89111
90- @[simp]
91- theorem mul_eq_top_iff {a b : WithTop α} : a * b = ⊤ ↔ a ≠ 0 ∧ b = ⊤ ∨ a = ⊤ ∧ b ≠ 0 := by
92- match a with
93- | none => match b with
94- | none => simp [none_eq_top]
95- | Option.some b => by_cases hb : b = 0 <;> simp [none_eq_top, some_eq_coe, hb]
96- | Option.some a => match b with
97- | none => by_cases ha : a = 0 <;> simp [none_eq_top, some_eq_coe, ha]
98- | Option.some b => simp [some_eq_coe, ← coe_mul]
99- #align with_top.mul_eq_top_iff WithTop.mul_eq_top_iff
100-
101- theorem mul_lt_top [Preorder α] {a b : WithTop α} (ha : a ≠ ⊤) (hb : b ≠ ⊤) : a * b < ⊤ := by
102- lift a to α using ha
103- lift b to α using hb
104- simp only [← coe_mul, coe_lt_top]
105- #align with_top.mul_lt_top WithTop.mul_lt_top
106-
107112@[simp]
108113theorem untop'_zero_mul (a b : WithTop α) : (a * b).untop' 0 = a.untop' 0 * b.untop' 0 := by
109114 by_cases ha : a = 0 ; · rw [ha, zero_mul, ← coe_zero, untop'_coe, zero_mul]
@@ -148,7 +153,7 @@ protected def MonoidWithZeroHom.withTopMap {R S : Type _} [MulZeroOneClass R] [D
148153 induction' y using WithTop.recTopCoe with y
149154 · have : (f x : WithTop S) ≠ 0 := by simpa [hf.eq_iff' (map_zero f)] using hx
150155 simp [mul_top hx, mul_top this]
151- · simp [ ← coe_mul, map_coe ] }
156+ · simp only [map_coe, ← coe_mul, map_mul ] } -- porting note: todo: `simp [← coe_mul]` fails
152157#align monoid_with_zero_hom.with_top_map WithTop.MonoidWithZeroHom.withTopMap
153158
154159instance [SemigroupWithZero α] [NoZeroDivisors α] : SemigroupWithZero (WithTop α) :=
@@ -250,13 +255,25 @@ theorem bot_mul_bot : (⊥ * ⊥ : WithBot α) = ⊥ :=
250255 WithTop.top_mul_top
251256#align with_bot.bot_mul_bot WithBot.bot_mul_bot
252257
258+ theorem mul_eq_bot_iff {a b : WithBot α} : a * b = ⊥ ↔ a ≠ 0 ∧ b = ⊥ ∨ a = ⊥ ∧ b ≠ 0 :=
259+ WithTop.mul_eq_top_iff
260+ #align with_bot.mul_eq_bot_iff WithBot.mul_eq_bot_iff
261+
262+ theorem bot_lt_mul' [LT α] {a b : WithBot α} (ha : ⊥ < a) (hb : ⊥ < b) : ⊥ < a * b :=
263+ WithTop.mul_lt_top' (α := αᵒᵈ) ha hb
264+ #align with_bot.bot_lt_mul' WithBot.bot_lt_mul'
265+
266+ theorem bot_lt_mul [LT α] {a b : WithBot α} (ha : a ≠ ⊥) (hb : b ≠ ⊥) : ⊥ < a * b :=
267+ WithTop.mul_lt_top (α := αᵒᵈ) ha hb
268+ #align with_bot.bot_lt_mul WithBot.bot_lt_mul
269+
253270end Mul
254271
255272section MulZeroClass
256273
257274variable [MulZeroClass α]
258275
259- @[norm_cast]
276+ @ [simp, norm_cast] -- porting note: added `simp`
260277theorem coe_mul {a b : α} : (↑(a * b) : WithBot α) = a * b :=
261278 WithTop.coe_mul
262279#align with_bot.coe_mul WithBot.coe_mul
@@ -266,17 +283,6 @@ theorem mul_coe {b : α} (hb : b ≠ 0) {a : WithBot α} :
266283 WithTop.mul_coe hb
267284#align with_bot.mul_coe WithBot.mul_coe
268285
269- @[simp]
270- theorem mul_eq_bot_iff {a b : WithBot α} : a * b = ⊥ ↔ a ≠ 0 ∧ b = ⊥ ∨ a = ⊥ ∧ b ≠ 0 :=
271- WithTop.mul_eq_top_iff
272- #align with_bot.mul_eq_bot_iff WithBot.mul_eq_bot_iff
273-
274- theorem bot_lt_mul [Preorder α] {a b : WithBot α} (ha : ⊥ < a) (hb : ⊥ < b) : ⊥ < a * b := by
275- lift a to α using ne_bot_of_gt ha
276- lift b to α using ne_bot_of_gt hb
277- simp only [← coe_mul, bot_lt_coe]
278- #align with_bot.bot_lt_mul WithBot.bot_lt_mul
279-
280286end MulZeroClass
281287
282288/-- `Nontrivial α` is needed here as otherwise we have `1 * ⊥ = ⊥` but also `= 0 * ⊥ = 0`. -/
0 commit comments