Skip to content

Commit

Permalink
style(SetTheory): remove useless parentheses (#8279)
Browse files Browse the repository at this point in the history
These were caused by a bad notation precedence in mathlib3, where the local version of `^` was given precedence 0. We're not using the local notation at all in Mathlib4 (partly because it was broken, which this PR fixes).
  • Loading branch information
eric-wieser committed Nov 9, 2023
1 parent 6032e3a commit a084bd5
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 94 deletions.
71 changes: 36 additions & 35 deletions Mathlib/SetTheory/Cardinal/Basic.lean
Expand Up @@ -65,7 +65,7 @@ We define cardinal numbers as a quotient of types under the equivalence relation
* There is an instance `Pow Cardinal`, but this will only fire if Lean already knows that both
the base and the exponent live in the same universe. As a workaround, you can add
```
local infixr:0 "^'" => @Pow.pow Cardinal Cardinal Cardinal.instPowCardinal
local infixr:80 " ^' " => @HPow.hPow Cardinal Cardinal Cardinal _
```
to a file. This notation will work even if Lean doesn't know yet that the base and the exponent
live in the same universe (but no exponents in other types can be used).
Expand Down Expand Up @@ -489,7 +489,7 @@ instance instPowCardinal : Pow Cardinal.{u} Cardinal.{u} :=
-- with `HPow`, but somebody should figure out
-- if this is still relevant in Lean4.
-- mathport name: cardinal.pow
local infixr:0 "^'" => @HPow.hPow Cardinal Cardinal Cardinal.instPowCardinal
local infixr:80 " ^' " => @HPow.hPow Cardinal Cardinal Cardinal _
-- -- mathport name: cardinal.pow.nat
local infixr:80 " ^ℕ " => @HPow.hPow Cardinal ℕ Cardinal instHPow

Expand All @@ -502,22 +502,22 @@ theorem mk_arrow (α : Type u) (β : Type v) : #(α → β) = (lift.{u} #β^lift
#align cardinal.mk_arrow Cardinal.mk_arrow

@[simp]
theorem lift_power (a b : Cardinal.{u}) : lift.{v} (a ^ b) = ((lift.{v} a) ^ (lift.{v} b)) :=
theorem lift_power (a b : Cardinal.{u}) : lift.{v} (a ^ b) = lift.{v} a ^ lift.{v} b :=
inductionOn₂ a b fun _ _ =>
mk_congr <| Equiv.ulift.trans (Equiv.ulift.arrowCongr Equiv.ulift).symm
#align cardinal.lift_power Cardinal.lift_power

@[simp]
theorem power_zero {a : Cardinal} : (a ^ 0) = 1 :=
theorem power_zero {a : Cardinal} : a ^ 0 = 1 :=
inductionOn a fun _ => mk_eq_one _
#align cardinal.power_zero Cardinal.power_zero

@[simp]
theorem power_one {a : Cardinal.{u}} : (a ^ 1) = a :=
theorem power_one {a : Cardinal.{u}} : a ^ 1 = a :=
inductionOn a fun α => mk_congr (Equiv.funUnique (ULift.{u} (Fin 1)) α)
#align cardinal.power_one Cardinal.power_one

theorem power_add {a b c : Cardinal} : (a ^ (b + c)) = (a ^ b) * (a ^ c) :=
theorem power_add {a b c : Cardinal} : a ^ (b + c) = a ^ b * a ^ c :=
inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumArrowEquivProdArrow β γ α
#align cardinal.power_add Cardinal.power_add

Expand All @@ -538,9 +538,9 @@ instance commSemiring : CommSemiring Cardinal.{u} where
mul_comm := mul_comm'
left_distrib a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.prodSumDistrib α β γ
right_distrib a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumProdDistrib α β γ
npow n c := c^n
npow n c := c ^ n
npow_zero := @power_zero
npow_succ n c := show (c ^ (n + 1 : ℕ)) = c * (c ^ n)
npow_succ n c := show c ^ (n + 1 : ℕ) = c * (c ^ n)
by rw [Cardinal.cast_succ, power_add, power_one, mul_comm']
natCast := (fun n => lift.{u} #(Fin n) : ℕ → Cardinal.{u})
natCast_zero := rfl
Expand All @@ -551,19 +551,19 @@ section deprecated
set_option linter.deprecated false

@[deprecated]
theorem power_bit0 (a b : Cardinal) : (a ^ bit0 b) = (a ^ b) * (a ^ b) :=
theorem power_bit0 (a b : Cardinal) : a ^ bit0 b = a ^ b * a ^ b :=
power_add
#align cardinal.power_bit0 Cardinal.power_bit0

@[deprecated]
theorem power_bit1 (a b : Cardinal) : (a ^ bit1 b) = (a ^ b) * (a ^ b) * a := by
theorem power_bit1 (a b : Cardinal) : a ^ bit1 b = a ^ b * a ^ b * a := by
rw [bit1, ← power_bit0, power_add, power_one]
#align cardinal.power_bit1 Cardinal.power_bit1

end deprecated

@[simp]
theorem one_power {a : Cardinal} : (1 ^ a) = 1 :=
theorem one_power {a : Cardinal} : 1 ^ a = 1 :=
inductionOn a fun _ => mk_eq_one _
#align cardinal.one_power Cardinal.one_power

Expand All @@ -578,31 +578,31 @@ theorem mk_Prop : #Prop = 2 := by simp
#align cardinal.mk_Prop Cardinal.mk_Prop

@[simp]
theorem zero_power {a : Cardinal} : a ≠ 0(0 ^ a) = 0 :=
theorem zero_power {a : Cardinal} : a ≠ 00 ^ a = 0 :=
inductionOn a fun _ heq =>
mk_eq_zero_iff.2 <|
isEmpty_pi.2 <|
let ⟨a⟩ := mk_ne_zero_iff.1 heq
⟨a, inferInstance⟩
#align cardinal.zero_power Cardinal.zero_power

theorem power_ne_zero {a : Cardinal} (b) : a ≠ 0(a ^ b)0 :=
theorem power_ne_zero {a : Cardinal} (b : Cardinal) : a ≠ 0 → a ^ b ≠ 0 :=
inductionOn₂ a b fun _ _ h =>
let ⟨a⟩ := mk_ne_zero_iff.1 h
mk_ne_zero_iff.2fun _ => a⟩
#align cardinal.power_ne_zero Cardinal.power_ne_zero

theorem mul_power {a b c : Cardinal} : ((a * b) ^ c) = (a ^ c) * (b ^ c) :=
theorem mul_power {a b c : Cardinal} : (a * b) ^ c = a ^ c * b ^ c :=
inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.arrowProdEquivProdArrow α β γ
#align cardinal.mul_power Cardinal.mul_power

theorem power_mul {a b c : Cardinal} : (a ^ (b * c)) = ((a ^ b) ^ c) := by
theorem power_mul {a b c : Cardinal} : a ^ (b * c) = (a ^ b) ^ c := by
rw [mul_comm b c]
exact inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.curry γ β α
#align cardinal.power_mul Cardinal.power_mul

@[simp]
theorem pow_cast_right (a : Cardinal.{u}) (n : ℕ) : (a^(↑n : Cardinal.{u})) = a ^ℕ n :=
theorem pow_cast_right (a : Cardinal.{u}) (n : ℕ) : a ^ (↑n : Cardinal.{u}) = a ^ℕ n :=
rfl
#align cardinal.pow_cast_right Cardinal.pow_cast_right

Expand Down Expand Up @@ -642,16 +642,17 @@ theorem lift_two : lift.{u, v} 2 = 2 := by simp [←one_add_one_eq_two]
#align cardinal.lift_two Cardinal.lift_two

@[simp]
theorem mk_set {α : Type u} : #(Set α) = (2 ^ #α) := by simp [←one_add_one_eq_two, Set, mk_arrow]
theorem mk_set {α : Type u} : #(Set α) = 2 ^ #α := by simp [←one_add_one_eq_two, Set, mk_arrow]
#align cardinal.mk_set Cardinal.mk_set

/-- A variant of `Cardinal.mk_set` expressed in terms of a `Set` instead of a `Type`. -/
@[simp]
theorem mk_powerset {α : Type u} (s : Set α) : #(↥(𝒫 s)) = (2 ^ #(↥s)) :=
theorem mk_powerset {α : Type u} (s : Set α) : #(↥(𝒫 s)) = 2 ^ #(↥s) :=
(mk_congr (Equiv.Set.powerset s)).trans mk_set
#align cardinal.mk_powerset Cardinal.mk_powerset

theorem lift_two_power (a) : lift.{v} (2 ^ a) = (2 ^ lift.{v} a) := by simp [←one_add_one_eq_two]
theorem lift_two_power (a : Cardinal) : lift.{v} (2 ^ a) = 2 ^ lift.{v} a := by
simp [←one_add_one_eq_two]
#align cardinal.lift_two_power Cardinal.lift_two_power

section OrderProperties
Expand Down Expand Up @@ -714,28 +715,28 @@ instance : CommMonoidWithZero Cardinal.{u} :=
instance : CommMonoid Cardinal.{u} :=
{ Cardinal.canonicallyOrderedCommSemiring with }

theorem zero_power_le (c : Cardinal.{u}) : ((0 : Cardinal.{u})^c)1 := by
theorem zero_power_le (c : Cardinal.{u}) : (0 : Cardinal.{u}) ^ c1 := by
by_cases h : c = 0
· rw [h, power_zero]
· rw [zero_power h]
apply zero_le
#align cardinal.zero_power_le Cardinal.zero_power_le

theorem power_le_power_left : ∀ {a b c : Cardinal}, a ≠ 0 → b ≤ c → (a^b)(a^c) := by
theorem power_le_power_left : ∀ {a b c : Cardinal}, a ≠ 0 → b ≤ c → a ^ ba ^ c := by
rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ hα ⟨e⟩
let ⟨a⟩ := mk_ne_zero_iff.1
exact ⟨@Function.Embedding.arrowCongrLeft _ _ _ ⟨a⟩ e⟩
#align cardinal.power_le_power_left Cardinal.power_le_power_left

theorem self_le_power (a : Cardinal) {b : Cardinal} (hb : 1 ≤ b) : a ≤ (a^b) := by
theorem self_le_power (a : Cardinal) {b : Cardinal} (hb : 1 ≤ b) : a ≤ a ^ b := by
rcases eq_or_ne a 0 with (rfl | ha)
· exact zero_le _
· convert power_le_power_left ha hb
exact power_one.symm
#align cardinal.self_le_power Cardinal.self_le_power

/-- **Cantor's theorem** -/
theorem cantor (a : Cardinal.{u}) : a < (2^a) := by
theorem cantor (a : Cardinal.{u}) : a < 2 ^ a := by
induction' a using Cardinal.inductionOn with α
rw [← mk_set]
refine' ⟨⟨⟨singleton, fun a b => singleton_eq_singleton_iff.1⟩⟩, _⟩
Expand All @@ -752,17 +753,17 @@ theorem one_lt_iff_nontrivial {α : Type u} : 1 < #α ↔ Nontrivial α := by
rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, Classical.not_not]
#align cardinal.one_lt_iff_nontrivial Cardinal.one_lt_iff_nontrivial

theorem power_le_max_power_one {a b c : Cardinal} (h : b ≤ c) : (a^b) ≤ max (a^c) 1 := by
theorem power_le_max_power_one {a b c : Cardinal} (h : b ≤ c) : a ^ b ≤ max (a ^ c) 1 := by
by_cases ha : a = 0
· simp [ha, zero_power_le]
· exact (power_le_power_left ha h).trans (le_max_left _ _)
#align cardinal.power_le_max_power_one Cardinal.power_le_max_power_one

theorem power_le_power_right {a b c : Cardinal} : a ≤ b → (a^c)(b^c) :=
theorem power_le_power_right {a b c : Cardinal} : a ≤ b → a ^ cb ^ c :=
inductionOn₃ a b c fun _ _ _ ⟨e⟩ => ⟨Embedding.arrowCongrRight e⟩
#align cardinal.power_le_power_right Cardinal.power_le_power_right

theorem power_pos {a : Cardinal} (b) (ha : 0 < a) : 0 < (a^b) :=
theorem power_pos {a : Cardinal} (b : Cardinal) (ha : 0 < a) : 0 < a ^ b :=
(power_ne_zero _ ha.ne').bot_lt
#align cardinal.power_pos Cardinal.power_pos

Expand Down Expand Up @@ -1051,12 +1052,12 @@ theorem mk_pi {ι : Type u} (α : ι → Type v) : #(∀ i, α i) = prod fun i =

@[simp]
theorem prod_const (ι : Type u) (a : Cardinal.{v}) :
(prod fun _ : ι => a) = (lift.{u} a^lift.{v} #ι) :=
(prod fun _ : ι => a) = lift.{u} a ^ lift.{v} #ι :=
inductionOn a fun _ =>
mk_congr <| Equiv.piCongr Equiv.ulift.symm fun _ => outMkEquiv.trans Equiv.ulift.symm
#align cardinal.prod_const Cardinal.prod_const

theorem prod_const' (ι : Type u) (a : Cardinal.{u}) : (prod fun _ : ι => a) = (a^#ι) :=
theorem prod_const' (ι : Type u) (a : Cardinal.{u}) : (prod fun _ : ι => a) = a ^ #ι :=
inductionOn a fun _ => (mk_pi _).symm
#align cardinal.prod_const' Cardinal.prod_const'

Expand Down Expand Up @@ -1346,7 +1347,7 @@ theorem card_le_of_finset {α} (s : Finset α) : (s.card : Cardinal) ≤ #α :=
-- Porting note: was `simp`. LHS is not normal form.
-- @[simp, norm_cast]
@[norm_cast]
theorem natCast_pow {m n : ℕ} : (↑(m ^ n) : Cardinal) = (m^n) := by
theorem natCast_pow {m n : ℕ} : (↑(m ^ n) : Cardinal) = m ^ n := by
induction n <;> simp [pow_succ', power_add, *, Pow.pow]
#align cardinal.nat_cast_pow Cardinal.natCast_pow

Expand Down Expand Up @@ -1398,7 +1399,7 @@ theorem card_le_of {α : Type u} {n : ℕ} (H : ∀ s : Finset α, s.card ≤ n)
exact n.lt_succ_self
#align cardinal.card_le_of Cardinal.card_le_of

theorem cantor' (a) {b : Cardinal} (hb : 1 < b) : a < (b^a) := by
theorem cantor' (a) {b : Cardinal} (hb : 1 < b) : a < b ^ a := by
rw [← succ_le_iff, (by norm_cast : succ (1 : Cardinal) = 2)] at hb
exact (cantor a).trans_le (power_le_power_right hb)
#align cardinal.cantor' Cardinal.cantor'
Expand Down Expand Up @@ -1598,7 +1599,7 @@ theorem mul_lt_aleph0_iff_of_ne_zero {a b : Cardinal} (ha : a ≠ 0) (hb : b ≠
a * b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := by simp [mul_lt_aleph0_iff, ha, hb]
#align cardinal.mul_lt_aleph_0_iff_of_ne_zero Cardinal.mul_lt_aleph0_iff_of_ne_zero

theorem power_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : (a^b) < ℵ₀ :=
theorem power_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a ^ b < ℵ₀ :=
match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← natCast_pow]; apply nat_lt_aleph0
#align cardinal.power_lt_aleph_0 Cardinal.power_lt_aleph0
Expand Down Expand Up @@ -2413,13 +2414,13 @@ def powerlt (a b : Cardinal.{u}) : Cardinal.{u} :=
@[inherit_doc]
infixl:80 " ^< " => powerlt

theorem le_powerlt {b c : Cardinal.{u}} (a) (h : c < b) : (a^c) ≤ a ^< b := by
refine le_ciSup (f := fun y : Iio b => a^y) ?_ ⟨c, h⟩
theorem le_powerlt {b c : Cardinal.{u}} (a) (h : c < b) : a ^ c ≤ a ^< b := by
refine le_ciSup (f := fun y : Iio b => a ^ y) ?_ ⟨c, h⟩
rw [← image_eq_range]
exact bddAbove_image.{u, u} _ bddAbove_Iio
#align cardinal.le_powerlt Cardinal.le_powerlt

theorem powerlt_le {a b c : Cardinal.{u}} : a ^< b ≤ c ↔ ∀ x < b, (a^x) ≤ c := by
theorem powerlt_le {a b c : Cardinal.{u}} : a ^< b ≤ c ↔ ∀ x < b, a ^ x ≤ c := by
rw [powerlt, ciSup_le_iff']
· simp
· rw [← image_eq_range]
Expand All @@ -2433,7 +2434,7 @@ theorem powerlt_le_powerlt_left {a b c : Cardinal} (h : b ≤ c) : a ^< b ≤ a
theorem powerlt_mono_left (a) : Monotone fun c => a ^< c := fun _ _ => powerlt_le_powerlt_left
#align cardinal.powerlt_mono_left Cardinal.powerlt_mono_left

theorem powerlt_succ {a b : Cardinal} (h : a ≠ 0) : a ^< succ b = (a^b) :=
theorem powerlt_succ {a b : Cardinal} (h : a ≠ 0) : a ^< succ b = a ^ b :=
(powerlt_le.2 fun _ h' => power_le_power_left h <| le_of_lt_succ h').antisymm <|
le_powerlt a (lt_succ b)
#align cardinal.powerlt_succ Cardinal.powerlt_succ
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/SetTheory/Cardinal/Ordinal.lean
Expand Up @@ -899,7 +899,7 @@ theorem add_one_le_add_one_iff_of_lt_aleph_0 {α β : Cardinal} : α + 1 ≤ β
/-! ### Properties about power -/

--Porting note: Annoying workaround because `c ^ n` when `n` is a `ℕ` coerces `c` for some reason.
local infixr:0 "^'" => @HPow.hPow Cardinal Cardinal Cardinal.instPowCardinal
local infixr:80 " ^' " => @HPow.hPow Cardinal Cardinal Cardinal _
-- -- mathport name: cardinal.pow.nat
local infixr:80 " ^ℕ " => @HPow.hPow Cardinal ℕ Cardinal instHPow

Expand Down

0 comments on commit a084bd5

Please sign in to comment.