Skip to content

Commit 2ed3e35

Browse files
committed
feat(NumberTheory/SumTwoSquares): it is decidable whether a number is the sum of two squares
Try `#eval Finset.range 50 |>.filter (∃ x y, · = x ^ 2 + y ^ 2)`
1 parent 9bee9f3 commit 2ed3e35

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Mathlib/NumberTheory/SumTwoSquares.lean

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,10 @@ theorem Nat.eq_sq_add_sq_iff {n : ℕ} :
228228
exact odd_two_mul_add_one _
229229

230230
end Main
231+
232+
theorem Nat.eq_sq_add_sq_iff' {n : ℕ} :
233+
(∃ x y, n = x ^ 2 + y ^ 2) ↔ ∀ q ∈ n.primeFactors, q % 4 = 3 → Even (padicValNat q n) :=
234+
eq_sq_add_sq_iff.trans <| by grind [Nat.mem_primeFactors, padicValNat.eq_zero_iff]
235+
236+
instance {n : ℕ} : Decidable (∃ x y, n = x ^ 2 + y ^ 2) :=
237+
decidable_of_iff' _ Nat.eq_sq_add_sq_iff'

0 commit comments

Comments
 (0)