Skip to content

Commit 63af23d

Browse files
committed
chore: golf using contrapose for (leanprover-community#32193)
This PR golfs some proofs to use the new `↔` support in the `contrapose`/`contrapose!` tactic.
1 parent 6f1ec98 commit 63af23d

File tree

42 files changed

+75
-86
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+75
-86
lines changed

Mathlib/Algebra/CharP/MixedCharZero.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,7 @@ A ring of characteristic zero is not a `ℚ`-algebra iff it has mixed characteri
284284
-/
285285
theorem isEmpty_algebraRat_iff_mixedCharZero [CharZero R] :
286286
IsEmpty (Algebra ℚ R) ↔ ∃ p > 0, MixedCharZero R p := by
287-
rw [← not_iff_not]
288-
push_neg
287+
contrapose!
289288
rw [← EqualCharZero.iff_not_mixedCharZero]
290289
apply EqualCharZero.nonempty_algebraRat_iff
291290

Mathlib/Algebra/GroupWithZero/NonZeroDivisors.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ section CommMonoidWithZero
391391
variable {M₀ : Type*} [CommMonoidWithZero M₀] {a : M₀}
392392

393393
theorem mk_mem_nonZeroDivisors_associates : Associates.mk a ∈ (Associates M₀)⁰ ↔ a ∈ M₀⁰ := by
394-
rw [mem_nonZeroDivisors_iff_right, mem_nonZeroDivisors_iff_right, ← not_iff_not]
395-
push_neg
394+
rw [mem_nonZeroDivisors_iff_right, mem_nonZeroDivisors_iff_right]
395+
contrapose!
396396
constructor
397397
· rintro ⟨⟨x⟩, hx₁, hx₂⟩
398398
refine ⟨x, ?_, ?_⟩

Mathlib/Algebra/Order/Floor/Semiring.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ theorem floor_sub_ofNat [Sub R] [OrderedSub R] [ExistsAddOfLE R] (a : R) (n :
336336

337337
theorem ceil_add_natCast (ha : 0 ≤ a) (n : ℕ) : ⌈a + n⌉₊ = ⌈a⌉₊ + n :=
338338
eq_of_forall_ge_iff fun b => by
339-
rw [← not_lt, ← not_lt, not_iff_not, lt_ceil]
339+
contrapose!
340+
rw [lt_ceil]
340341
obtain hb | hb := le_or_gt n b
341342
· obtain ⟨d, rfl⟩ := exists_add_of_le hb
342343
rw [Nat.cast_add, add_comm n, add_comm (n : R), add_lt_add_iff_right, add_lt_add_iff_right,

Mathlib/Algebra/Order/Group/Defs.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ theorem inv_le_self_iff : a⁻¹ ≤ a ↔ 1 ≤ a := by simp [inv_le_iff_one_le
116116
theorem inv_lt_self_iff : a⁻¹ < a ↔ 1 < a := by simp [inv_lt_iff_one_lt_mul]
117117

118118
@[to_additive (attr := simp)]
119-
theorem le_inv_self_iff : a ≤ a⁻¹ ↔ a ≤ 1 := by simp [← not_iff_not]
119+
theorem le_inv_self_iff : a ≤ a⁻¹ ↔ a ≤ 1 := by contrapose!; exact inv_lt_self_iff
120120

121121
@[to_additive (attr := simp)]
122-
theorem lt_inv_self_iff : a < a⁻¹ ↔ a < 1 := by simp [← not_iff_not]
122+
theorem lt_inv_self_iff : a < a⁻¹ ↔ a < 1 := by contrapose!; exact inv_le_self_iff
123123

124124
end LinearOrderedCommGroup
125125

Mathlib/Algebra/Order/Monoid/Defs.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ theorem one_lt_mul_self_iff : 1 < a * a ↔ 1 < a :=
117117
⟨(fun h ↦ by push_neg at h ⊢; exact mul_le_one' h h).mtr, fun h ↦ one_lt_mul'' h h⟩
118118

119119
@[to_additive (attr := simp)]
120-
theorem mul_self_le_one_iff : a * a ≤ 1 ↔ a ≤ 1 := by simp [← not_iff_not]
120+
theorem mul_self_le_one_iff : a * a ≤ 1 ↔ a ≤ 1 := by contrapose!; exact one_lt_mul_self_iff
121121

122122
@[to_additive (attr := simp)]
123-
theorem mul_self_lt_one_iff : a * a < 1 ↔ a < 1 := by simp [← not_iff_not]
123+
theorem mul_self_lt_one_iff : a * a < 1 ↔ a < 1 := by contrapose!; exact one_le_mul_self_iff

Mathlib/Analysis/Complex/Basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,8 @@ open Metric in
639639
the `slitPlane` if it does not contain `-r`. -/
640640
lemma subset_slitPlane_iff_of_subset_sphere {r : ℝ} {s : Set ℂ} (hs : s ⊆ sphere 0 r) :
641641
s ⊆ slitPlane ↔ (-r : ℂ) ∉ s := by
642-
simp_rw +singlePass [← not_iff_not, Set.subset_def, mem_slitPlane_iff_not_le_zero]
643-
push ¬ _
642+
simp_rw [Set.subset_def, mem_slitPlane_iff_not_le_zero]
643+
contrapose!
644644
refine ⟨?_, fun hr ↦ ⟨_, hr, by simpa using hs hr⟩⟩
645645
rintro ⟨z, hzs, hz⟩
646646
have : ‖z‖ = r := by simpa using hs hzs

Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,10 +649,11 @@ theorem cos_pos_iff_abs_toReal_lt_pi_div_two {θ : Angle} : 0 < cos θ ↔ |θ.t
649649
rw [lt_iff_le_and_ne, lt_iff_le_and_ne, cos_nonneg_iff_abs_toReal_le_pi_div_two, ←
650650
and_congr_right]
651651
rintro -
652-
rw [Ne, Ne, not_iff_not, @eq_comm ℝ 0, abs_toReal_eq_pi_div_two_iff, cos_eq_zero_iff]
652+
contrapose
653+
rw [@eq_comm ℝ 0, abs_toReal_eq_pi_div_two_iff, cos_eq_zero_iff]
653654

654655
theorem cos_neg_iff_pi_div_two_lt_abs_toReal {θ : Angle} : cos θ < 0 ↔ π / 2 < |θ.toReal| := by
655-
rw [← not_le, ← not_le, not_iff_not, cos_nonneg_iff_abs_toReal_le_pi_div_two]
656+
contrapose!; exact cos_nonneg_iff_abs_toReal_le_pi_div_two
656657

657658
theorem abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi {θ ψ : Angle}
658659
(h : (2 : ℕ) • θ + (2 : ℕ) • ψ = π) : |cos θ| = |sin ψ| := by

Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ theorem sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π =
517517
fun ⟨_, hn⟩ => hn ▸ sin_int_mul_pi _⟩
518518

519519
theorem sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x := by
520-
rw [← not_exists, not_iff_not, sin_eq_zero_iff]
520+
contrapose!; exact sin_eq_zero_iff
521521

522522
theorem sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by
523523
rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, right_eq_add, mul_eq_zero, or_self]

Mathlib/Analysis/SpecialFunctions/Trigonometric/Complex.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ theorem cos_eq_zero_iff {θ : ℂ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1
4141
ring
4242

4343
theorem cos_ne_zero_iff {θ : ℂ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 := by
44-
rw [← not_exists, not_iff_not, cos_eq_zero_iff]
44+
contrapose!; exact cos_eq_zero_iff
4545

4646
theorem sin_eq_zero_iff {θ : ℂ} : sin θ = 0 ↔ ∃ k : ℤ, θ = k * π := by
4747
rw [← Complex.cos_sub_pi_div_two, cos_eq_zero_iff]
@@ -56,7 +56,7 @@ theorem sin_eq_zero_iff {θ : ℂ} : sin θ = 0 ↔ ∃ k : ℤ, θ = k * π :=
5656
ring
5757

5858
theorem sin_ne_zero_iff {θ : ℂ} : sin θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ k * π := by
59-
rw [← not_exists, not_iff_not, sin_eq_zero_iff]
59+
contrapose!; exact sin_eq_zero_iff
6060

6161
/-- The tangent of a complex number is equal to zero
6262
iff this number is equal to `k * π / 2` for an integer `k`.
@@ -69,7 +69,7 @@ theorem tan_eq_zero_iff {θ : ℂ} : tan θ = 0 ↔ ∃ k : ℤ, k * π / 2 = θ
6969
simp [field, mul_comm, eq_comm]
7070

7171
theorem tan_ne_zero_iff {θ : ℂ} : tan θ ≠ 0 ↔ ∀ k : ℤ, (k * π / 2 : ℂ) ≠ θ := by
72-
rw [← not_exists, not_iff_not, tan_eq_zero_iff]
72+
contrapose!; exact tan_eq_zero_iff
7373

7474
theorem tan_int_mul_pi_div_two (n : ℤ) : tan (n * π / 2) = 0 :=
7575
tan_eq_zero_iff.mpr (by use n)

Mathlib/CategoryTheory/Abelian/Injective/Dimension.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ lemma injectiveDimension_le_iff (X : C) (n : ℕ) :
268268

269269
lemma injectiveDimension_ge_iff (X : C) (n : ℕ) :
270270
n ≤ injectiveDimension X ↔ ¬ HasInjectiveDimensionLT X n := by
271-
rw [← not_iff_not, not_le, not_not, injectiveDimension_lt_iff]
271+
contrapose!; exact injectiveDimension_lt_iff
272272

273273
lemma injectiveDimension_eq_bot_iff (X : C) :
274274
injectiveDimension X = ⊥ ↔ Limits.IsZero X := by

0 commit comments

Comments
 (0)