Skip to content

Commit 9e92f67

Browse files
committed
1 parent 645da3e commit 9e92f67

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

Mathlib/Algebra/Parity.lean

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,44 @@ theorem isSquare_mul_self (m : α) : IsSquare (m * m) :=
5858
#align even_add_self even_add_self
5959

6060
@[to_additive]
61-
theorem isSquare_op_iff (a : α) : IsSquare (op a) ↔ IsSquare a :=
62-
fun ⟨c, hc⟩ => ⟨unop c, by rw [← unop_mul, ← hc, unop_op]⟩, fun ⟨c, hc⟩ => by simp [hc]
61+
theorem isSquare_op_iff {a : α} : IsSquare (op a) ↔ IsSquare a :=
62+
fun ⟨c, hc⟩ => ⟨unop c, congr_arg unop hc⟩, fun ⟨c, hc⟩ => ⟨op c, congr_arg op hc⟩
6363
#align is_square_op_iff isSquare_op_iff
6464
#align even_op_iff even_op_iff
6565

66+
@[to_additive]
67+
theorem isSquare_unop_iff {a : αᵐᵒᵖ} : IsSquare (unop a) ↔ IsSquare a := isSquare_op_iff.symm
68+
69+
@[to_additive]
70+
instance [DecidablePred (IsSquare : α → Prop)] : DecidablePred (IsSquare : αᵐᵒᵖ → Prop) :=
71+
fun _ => decidable_of_iff _ isSquare_unop_iff
72+
73+
@[simp]
74+
theorem even_ofMul_iff {a : α} : Even (Additive.ofMul a) ↔ IsSquare a := Iff.rfl
75+
76+
@[simp]
77+
theorem isSquare_toMul_iff {a : Additive α} : IsSquare (Additive.toMul a) ↔ Even a := Iff.rfl
78+
79+
instance [DecidablePred (IsSquare : α → Prop)] : DecidablePred (Even : Additive α → Prop) :=
80+
fun _ => decidable_of_iff _ isSquare_toMul_iff
81+
6682
end Mul
6783

84+
section Add
85+
variable [Add α]
86+
87+
@[simp]
88+
theorem isSquare_ofAdd_iff {a : α} : IsSquare (Multiplicative.ofAdd a) ↔ Even a := Iff.rfl
89+
90+
@[simp]
91+
theorem even_toAdd_iff {a : Multiplicative α} :
92+
Even (Multiplicative.toAdd a) ↔ IsSquare a := Iff.rfl
93+
94+
instance [DecidablePred (Even : α → Prop)] : DecidablePred (IsSquare : Multiplicative α → Prop) :=
95+
fun _ => decidable_of_iff _ even_toAdd_iff
96+
97+
end Add
98+
6899
@[to_additive (attr := simp)]
69100
theorem isSquare_one [MulOneClass α] : IsSquare (1 : α) :=
70101
1, (mul_one _).symm⟩
@@ -165,7 +196,7 @@ theorem isSquare_inv : IsSquare a⁻¹ ↔ IsSquare a := by
165196
refine' ⟨fun h => _, fun h => _⟩
166197
· rw [← isSquare_op_iff, ← inv_inv a]
167198
exact h.map (MulEquiv.inv' α)
168-
· exact ((isSquare_op_iff a).mpr h).map (MulEquiv.inv' α).symm
199+
· exact (isSquare_op_iff.mpr h).map (MulEquiv.inv' α).symm
169200
#align is_square_inv isSquare_inv
170201
#align even_neg even_neg
171202

Mathlib/Data/Int/Sqrt.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ theorem sqrt_nonneg (n : ℤ) : 0 ≤ sqrt n :=
3737
coe_nat_nonneg _
3838
#align int.sqrt_nonneg Int.sqrt_nonneg
3939

40+
/-- `IsSquare` can be decided on `ℤ` by checking against the square root. -/
41+
instance : DecidablePred (IsSquare : ℤ → Prop) :=
42+
fun m => decidable_of_iff' (sqrt m * sqrt m = m) <| by
43+
simp_rw [←exists_mul_self m, IsSquare, eq_comm]
44+
4045
end Int

Mathlib/Data/Nat/Sqrt.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Copyright (c) 2015 Microsoft Corporation. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Leonardo de Moura, Johannes Hölzl, Mario Carneiro
55
-/
6+
import Mathlib.Algebra.Parity
67
import Mathlib.Data.Int.Order.Basic
78
import Mathlib.Data.Nat.Size
89
import Mathlib.Data.Nat.ForSqrt
@@ -176,6 +177,11 @@ theorem exists_mul_self' (x : ℕ) : (∃ n, n ^ 2 = x) ↔ sqrt x ^ 2 = x := by
176177
simpa only [pow_two] using exists_mul_self x
177178
#align nat.exists_mul_self' Nat.exists_mul_self'
178179

180+
/-- `IsSquare` can be decided on `ℕ` by checking against the square root. -/
181+
instance : DecidablePred (IsSquare : ℕ → Prop) :=
182+
fun m => decidable_of_iff' (Nat.sqrt m * Nat.sqrt m = m) <| by
183+
simp_rw [←Nat.exists_mul_self m, IsSquare, eq_comm]
184+
179185
theorem sqrt_mul_sqrt_lt_succ (n : ℕ) : sqrt n * sqrt n < n + 1 :=
180186
lt_succ_iff.mpr (sqrt_le _)
181187
#align nat.sqrt_mul_sqrt_lt_succ Nat.sqrt_mul_sqrt_lt_succ

Mathlib/Data/Rat/Sqrt.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@ theorem sqrt_nonneg (q : ℚ) : 0 ≤ Rat.sqrt q :=
4242
Int.coe_nat_nonneg _
4343
#align rat.sqrt_nonneg Rat.sqrt_nonneg
4444

45+
/-- `IsSquare` can be decided on `ℚ` by checking against the square root. -/
46+
instance : DecidablePred (IsSquare : ℚ → Prop) :=
47+
fun m => decidable_of_iff' (sqrt m * sqrt m = m) <| by
48+
simp_rw [←exists_mul_self m, IsSquare, eq_comm]
49+
4550
end Rat

0 commit comments

Comments
 (0)