Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit e738e90

Browse files
feat(algebra/group_power/identities): named ring identities (#4390)
This PR adds a new file containing some "named" ring identities provable by `ring`.
1 parent f2044a5 commit e738e90

File tree

2 files changed

+77
-6
lines changed

2 files changed

+77
-6
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/-
2+
Copyright (c) 2020 Bryan Gin-ge Chen. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Bryan Gin-ge Chen, Kevin Lacker
5+
-/
6+
import tactic.ring
7+
/-!
8+
# Identities
9+
10+
This file contains some "named" commutative ring identities.
11+
-/
12+
13+
variables {R : Type*} [comm_ring R]
14+
{a b x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈ y₁ y₂ y₃ y₄ y₅ y₆ y₇ y₈ n : R}
15+
16+
/--
17+
Brahmagupta-Fibonacci identity or Diophantus identity, see
18+
<https://en.wikipedia.org/wiki/Brahmagupta%E2%80%93Fibonacci_identity>.
19+
20+
This sign choice here corresponds to the signs obtained by multiplying two complex numbers.
21+
-/
22+
theorem pow_two_add_pow_two_mul_pow_two_add_pow_two :
23+
(x₁^2 + x₂^2) * (y₁^2 + y₂^2) = (x₁*y₁ - x₂*y₂)^2 + (x₁*y₂ + x₂*y₁)^2 :=
24+
by ring
25+
26+
/--
27+
Brahmagupta's identity, see <https://en.wikipedia.org/wiki/Brahmagupta%27s_identity>
28+
-/
29+
theorem pow_two_add_mul_pow_two_mul_pow_two_add_mul_pow_two :
30+
(x₁^2 + n*x₂^2) * (y₁^2 + n*y₂^2) = (x₁*y₁ - n*x₂*y₂)^2 + n*(x₁*y₂ + x₂*y₁)^2 :=
31+
by ring
32+
33+
/--
34+
Sophie Germain's identity, see <https://www.cut-the-knot.org/blue/SophieGermainIdentity.shtml>.
35+
-/
36+
theorem pow_four_add_four_mul_pow_four : a^4 + 4*b^4 = ((a - b)^2 + b^2) * ((a + b)^2 + b^2) :=
37+
by ring
38+
39+
/--
40+
Sophie Germain's identity, see <https://www.cut-the-knot.org/blue/SophieGermainIdentity.shtml>.
41+
-/
42+
theorem pow_four_add_four_mul_pow_four' :
43+
a^4 + 4*b^4 = (a^2 - 2*a*b + 2*b^2) * (a^2 + 2*a*b + 2*b^2) :=
44+
by ring
45+
46+
/--
47+
Euler's four-square identity, see <https://en.wikipedia.org/wiki/Euler%27s_four-square_identity>.
48+
49+
This sign choice here corresponds to the signs obtained by multiplying two quaternions.
50+
-/
51+
theorem sum_four_sq_mul_sum_four_sq : (x₁^2 + x₂^2 + x₃^2 + x₄^2) * (y₁^2 + y₂^2 + y₃^2 + y₄^2) =
52+
(x₁*y₁ - x₂*y₂ - x₃*y₃ - x₄*y₄)^2 + (x₁*y₂ + x₂*y₁ + x₃*y₄ - x₄*y₃)^2 +
53+
(x₁*y₃ - x₂*y₄ + x₃*y₁ + x₄*y₂)^2 + (x₁*y₄ + x₂*y₃ - x₃*y₂ + x₄*y₁)^2 :=
54+
by ring
55+
56+
/--
57+
Degen's eight squares identity, see <https://en.wikipedia.org/wiki/Degen%27s_eight-square_identity>.
58+
59+
This sign choice here corresponds to the signs obtained by multiplying two octonions.
60+
-/
61+
theorem sum_eight_sq_mul_sum_eight_sq : (x₁^2 + x₂^2 + x₃^2 + x₄^2 + x₅^2 + x₆^2 + x₇^2 + x₈^2) *
62+
(y₁^2 + y₂^2 + y₃^2 + y₄^2 + y₅^2 + y₆^2 + y₇^2 + y₈^2) =
63+
(x₁*y₁ - x₂*y₂ - x₃*y₃ - x₄*y₄ - x₅*y₅ - x₆*y₆ - x₇*y₇ - x₈*y₈)^2 +
64+
(x₁*y₂ + x₂*y₁ + x₃*y₄ - x₄*y₃ + x₅*y₆ - x₆*y₅ - x₇*y₈ + x₈*y₇)^2 +
65+
(x₁*y₃ - x₂*y₄ + x₃*y₁ + x₄*y₂ + x₅*y₇ + x₆*y₈ - x₇*y₅ - x₈*y₆)^2 +
66+
(x₁*y₄ + x₂*y₃ - x₃*y₂ + x₄*y₁ + x₅*y₈ - x₆*y₇ + x₇*y₆ - x₈*y₅)^2 +
67+
(x₁*y₅ - x₂*y₆ - x₃*y₇ - x₄*y₈ + x₅*y₁ + x₆*y₂ + x₇*y₃ + x₈*y₄)^2 +
68+
(x₁*y₆ + x₂*y₅ - x₃*y₈ + x₄*y₇ - x₅*y₂ + x₆*y₁ - x₇*y₄ + x₈*y₃)^2 +
69+
(x₁*y₇ + x₂*y₈ + x₃*y₅ - x₄*y₆ - x₅*y₃ + x₆*y₄ + x₇*y₁ - x₈*y₂)^2 +
70+
(x₁*y₈ - x₂*y₇ + x₃*y₆ + x₄*y₅ - x₅*y₄ - x₆*y₃ + x₇*y₂ + x₈*y₁)^2 :=
71+
by ring

src/number_theory/sum_four_squares.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ a proof that every natural number is the sum of four square numbers.
1212
1313
The proof used is close to Lagrange's original proof.
1414
-/
15+
import algebra.group_power.identities
1516
import data.zmod.basic
1617
import field_theory.finite.basic
1718
import data.int.parity
@@ -201,14 +202,13 @@ have n / min_fac n < n := factors_lemma,
201202
let ⟨a, b, c, d, h₁⟩ := show ∃ a b c d : ℤ, a^2 + b^2 + c^2 + d^2 = min_fac n,
202203
by exactI prime_sum_four_squares (min_fac (k+2)) in
203204
let ⟨w, x, y, z, h₂⟩ := sum_four_squares (n / min_fac n) in
204-
⟨(a * x - b * w - c * z + d * y).nat_abs,
205-
(a * y + b * z - c * w - d * x).nat_abs,
206-
(a * z - b * y + c * x - d * w).nat_abs,
207-
(a * w + b * x + c * y + d * z).nat_abs,
205+
⟨(a * w - b * x - c * y - d * z).nat_abs,
206+
(a * x + b * w + c * z - d * y).nat_abs,
207+
(a * y - b * z + c * w + d * x).nat_abs,
208+
(a * z + b * y - c * x + d * w).nat_abs,
208209
begin
209210
rw [← int.coe_nat_inj', ← nat.mul_div_cancel' (min_fac_dvd (k+2)), int.coe_nat_mul, ← h₁, ← h₂],
210-
simp,
211-
ring
211+
simp [sum_four_sq_mul_sum_four_sq],
212212
end
213213

214214
end nat

0 commit comments

Comments
 (0)