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

Commit 3ee1071

Browse files
ChrisHughes24digama0
authored andcommitted
feat(data/polynomial): lemmas relating unit and irreducible with degree (#514)
1 parent d4d05e3 commit 3ee1071

File tree

7 files changed

+189
-21
lines changed

7 files changed

+189
-21
lines changed

algebra/ordered_group.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ end
336336

337337
instance has_one [has_one α] : has_one (with_bot α) := ⟨(1 : α)⟩
338338

339+
@[simp] lemma coe_one [has_one α] : ((1 : α) : with_bot α) = 1 := rfl
340+
339341
end with_bot
340342

341343
section canonically_ordered_monoid

algebra/ordered_ring.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ begin
397397
end
398398

399399
private lemma one_mul' : ∀a : with_top α, 1 * a = a
400-
| none := show ((1:α) : with_top α) * ⊤ = ⊤, by simp
401-
| (some a) := show ((1:α) : with_top α) * a = a, by simp [coe_mul.symm]
400+
| none := show ((1:α) : with_top α) * ⊤ = ⊤, by simp [-with_bot.coe_one]
401+
| (some a) := show ((1:α) : with_top α) * a = a, by simp [coe_mul.symm, -with_bot.coe_one]
402402

403403
instance [canonically_ordered_comm_semiring α] [decidable_eq α] :
404404
canonically_ordered_comm_semiring (with_top α) :=

data/nat/basic.lean

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ theorem pos_iff_ne_zero : n > 0 ↔ n ≠ 0 :=
3939

4040
theorem pos_iff_ne_zero' : 0 < n ↔ n ≠ 0 := pos_iff_ne_zero
4141

42+
lemma one_lt_iff_ne_zero_and_ne_one : ∀ {n : ℕ}, 1 < n ↔ n ≠ 0 ∧ n ≠ 1
43+
| 0 := dec_trivial
44+
| 1 := dec_trivial
45+
| (n+2) := dec_trivial
46+
4247
theorem eq_of_lt_succ_of_not_lt {a b : ℕ} (h1 : a < b + 1) (h2 : ¬ a < b) : a = b :=
4348
have h3 : a ≤ b, from le_of_lt_succ h1,
4449
or.elim (eq_or_lt_of_not_lt h2) (λ h, h) (λ h, absurd h (not_lt_of_ge h3))
@@ -835,5 +840,23 @@ lemma exists_eq_add_of_lt : ∀ {m n : ℕ}, m < n → ∃ k : ℕ, n = m + k +
835840
| 0 (n+1) h := ⟨n, by simp⟩
836841
| (m+1) (n+1) h := let ⟨k, hk⟩ := exists_eq_add_of_le (nat.le_of_succ_le_succ h) in ⟨k, by simp [hk]⟩
837842

843+
lemma with_bot.add_eq_zero_iff : ∀ {n m : with_bot ℕ}, n + m = 0 ↔ n = 0 ∧ m = 0
844+
| none m := iff_of_false dec_trivial (λ h, absurd h.1 dec_trivial)
845+
| n none := iff_of_false (by cases n; exact dec_trivial)
846+
(λ h, absurd h.2 dec_trivial)
847+
| (some n) (some m) := show (n + m : with_bot ℕ) = (0 : ℕ) ↔ (n : with_bot ℕ) = (0 : ℕ) ∧
848+
(m : with_bot ℕ) = (0 : ℕ),
849+
by rw [← with_bot.coe_add, with_bot.coe_eq_coe, with_bot.coe_eq_coe,
850+
with_bot.coe_eq_coe, add_eq_zero_iff' (nat.zero_le _) (nat.zero_le _)]
851+
852+
lemma with_bot.add_eq_one_iff : ∀ {n m : with_bot ℕ}, n + m = 1 ↔ (n = 0 ∧ m = 1) ∨ (n = 1 ∧ m = 0)
853+
| none none := dec_trivial
854+
| none (some m) := dec_trivial
855+
| (some n) none := iff_of_false dec_trivial (λ h, h.elim (λ h, absurd h.2 dec_trivial)
856+
(λ h, absurd h.2 dec_trivial))
857+
| (some n) (some 0) := by erw [with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe,
858+
with_bot.coe_eq_coe]; simp
859+
| (some n) (some (m + 1)) := by erw [with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe,
860+
with_bot.coe_eq_coe, with_bot.coe_eq_coe]; simp [nat.add_succ, nat.succ_inj', nat.succ_ne_zero]
838861

839862
end nat

data/nat/prime.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ theorem prime.ge_two {p : ℕ} : prime p → p ≥ 2 := and.left
1919

2020
theorem prime.gt_one {p : ℕ} : prime p → p > 1 := prime.ge_two
2121

22+
lemma prime.ne_one {p : ℕ} (hp : p.prime) : p ≠ 1 :=
23+
ne.symm $ (ne_of_lt hp.gt_one)
24+
2225
theorem prime_def_lt {p : ℕ} : prime p ↔ p ≥ 2 ∧ ∀ m < p, m ∣ p → m = 1 :=
2326
and_congr_right $ λ p2, forall_congr $ λ m,
2427
⟨λ h l d, (h d).resolve_right (ne_of_lt l),

data/polynomial.lean

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Authors: Chris Hughes, Johannes Hölzl, Jens Wagemaker
55
66
Theory of univariate polynomials, represented as `ℕ →₀ α`, where α is a commutative semiring.
77
-/
8-
import data.finsupp algebra.euclidean_domain tactic.ring
8+
import data.finsupp algebra.euclidean_domain tactic.ring ring_theory.associated
99

1010
/-- `polynomial α` is the type of univariate polynomials over `α`.
1111
@@ -81,6 +81,7 @@ lemma single_eq_C_mul_X : ∀{n}, single n a = C a * X^n
8181
lemma sum_C_mul_X_eq (p : polynomial α) : p.sum (λn a, C a * X^n) = p :=
8282
eq.trans (sum_congr rfl $ assume n hn, single_eq_C_mul_X.symm) (finsupp.sum_single _)
8383

84+
8485
@[elab_as_eliminator] protected lemma induction_on {M : polynomial α → Prop} (p : polynomial α)
8586
(h_C : ∀a, M (C a))
8687
(h_add : ∀p q, M p → M q → M (p + q))
@@ -131,6 +132,8 @@ by simp [coeff, eq_comm, C, single]; congr
131132

132133
@[simp] lemma coeff_X_one : coeff (X : polynomial α) 1 = 1 := rfl
133134

135+
@[simp] lemma coeff_X_zero : coeff (X : polynomial α) 0 = 0 := rfl
136+
134137
@[simp] lemma coeff_C_mul_X (x : α) (k n : ℕ) :
135138
coeff (C x * X^k : polynomial α) n = if n = k then x else 0 :=
136139
by rw [← single_eq_C_mul_X]; simp [single, eq_comm, coeff]; congr
@@ -312,6 +315,12 @@ lemma root_mul_right_of_is_root {p : polynomial α} (q : polynomial α) :
312315
is_root p a → is_root (p * q) a :=
313316
λ H, by rw [is_root, eval_mul, is_root.def.1 H, zero_mul]
314317

318+
lemma coeff_zero_eq_eval_zero (p : polynomial α) :
319+
coeff p 0 = p.eval 0 :=
320+
calc coeff p 0 = coeff p 0 * 0 ^ 0 : by simp
321+
... = p.eval 0 : eq.symm $
322+
finset.sum_eq_single _ (λ b _ hb, by simp [zero_pow (nat.pos_of_ne_zero hb)]) (by simp)
323+
315324
end eval
316325

317326
section comp
@@ -424,6 +433,12 @@ let ⟨n, hn⟩ :=
424433
have hn : degree p = some n := not_not.1 hn,
425434
by rw [nat_degree, hn]; refl
426435

436+
lemma nat_degree_eq_of_degree_eq_some {p : polynomial α} {n : ℕ}
437+
(h : degree p = n) : nat_degree p = n :=
438+
have hp0 : p ≠ 0, from λ hp0, by rw hp0 at h; exact option.no_confusion h,
439+
option.some_inj.1 $ show (nat_degree p : with_bot ℕ) = n,
440+
by rwa [← degree_eq_nat_degree hp0]
441+
427442
@[simp] lemma degree_le_nat_degree : degree p ≤ nat_degree p :=
428443
begin
429444
by_cases hp : p = 0, { rw hp, exact bot_le },
@@ -579,6 +594,8 @@ leading_coeff_monomial a 0
579594
suffices leading_coeff (C (1:α) * X^1) = 1, by rwa [C_1, pow_one, one_mul] at this,
580595
leading_coeff_monomial 1 1
581596

597+
@[simp] lemma monic_X : monic (X : polynomial α) := leading_coeff_X
598+
582599
@[simp] lemma leading_coeff_one : leading_coeff (1 : polynomial α) = 1 :=
583600
suffices leading_coeff (C (1:α) * X^0) = 1, by rwa [C_1, pow_zero, mul_one] at this,
584601
leading_coeff_monomial 1 0
@@ -710,6 +727,13 @@ else with_bot.coe_le_coe.1 $
710727
(le_nat_degree_of_ne_zero (finsupp.mem_support_iff.1 hn))
711728
(nat.zero_le _))
712729

730+
lemma zero_le_degree_iff {p : polynomial α} : 0 ≤ degree p ↔ p ≠ 0 :=
731+
by rw [ne.def, ← degree_eq_bot];
732+
cases degree p; exact dec_trivial
733+
734+
@[simp] lemma coeff_mul_X_zero (p : polynomial α) : coeff (p * X) 0 = 0 :=
735+
by rw [coeff_mul_left, sum_range_succ]; simp
736+
713737
end comm_semiring
714738

715739
section comm_ring
@@ -992,6 +1016,12 @@ lemma dvd_iff_mod_by_monic_eq_zero (hq : monic q) : p %ₘ q = 0 ↔ q ∣ p :=
9921016
degree_eq_nat_degree (mt leading_coeff_eq_zero.2 hrpq0)] at this;
9931017
exact not_lt_of_ge (nat.le_add_right _ _) (with_bot.some_lt_some.1 this))⟩
9941018

1019+
@[simp] lemma mod_by_monic_one (p : polynomial α) : p %ₘ 1 = 0 :=
1020+
(dvd_iff_mod_by_monic_eq_zero monic_one).2 (one_dvd _)
1021+
1022+
@[simp] lemma div_by_monic_one (p : polynomial α) : p /ₘ 1 = p :=
1023+
by conv_rhs { rw [← mod_by_monic_add_div p monic_one] }; simp
1024+
9951025
lemma degree_pos_of_root (hp : p ≠ 0) (h : is_root p a) : 0 < degree p :=
9961026
lt_of_not_ge $ λ hlt, begin
9971027
have := eq_C_of_degree_le_zero hlt,
@@ -1024,6 +1054,9 @@ begin
10241054
refl
10251055
end
10261056

1057+
lemma X_ne_zero : (X : polynomial α) ≠ 0 :=
1058+
mt (congr_arg (λ p, coeff p 1)) (by simp)
1059+
10271060
@[simp] lemma degree_X_sub_C (a : α) : degree (X - C a) = 1 :=
10281061
begin
10291062
rw [sub_eq_add_neg, add_comm, ← @degree_X α],
@@ -1099,6 +1132,9 @@ lemma dvd_iff_is_root : (X - C a) ∣ p ↔ is_root p a :=
10991132
mod_by_monic_X_sub_C_eq_C_eval, ← C_0, C_inj] at h,
11001133
λ h, ⟨(p /ₘ (X - C a)), by rw mul_div_by_monic_eq_iff_is_root.2 h⟩⟩
11011134

1135+
lemma mod_by_monic_X (p : polynomial α) : p %ₘ X = C (p.eval 0) :=
1136+
by rw [← mod_by_monic_X_sub_C_eq_C_eval, C_0, sub_zero]
1137+
11021138
end nonzero_comm_ring
11031139

11041140
section integral_domain
@@ -1140,6 +1176,12 @@ instance : integral_domain (polynomial α) :=
11401176
end,
11411177
..polynomial.nonzero_comm_ring }
11421178

1179+
lemma nat_degree_mul_eq (hp : p ≠ 0) (hq : q ≠ 0) : nat_degree (p * q) =
1180+
nat_degree p + nat_degree q :=
1181+
by rw [← with_bot.coe_eq_coe, ← degree_eq_nat_degree (mul_ne_zero hp hq),
1182+
with_bot.coe_add, ← degree_eq_nat_degree hp,
1183+
← degree_eq_nat_degree hq, degree_mul_eq]
1184+
11431185
@[simp] lemma nat_degree_pow_eq (p : polynomial α) (n : ℕ) :
11441186
nat_degree (p ^ n) = n * nat_degree p :=
11451187
if hp0 : p = 0
@@ -1285,13 +1327,53 @@ lemma leading_coeff_comp (hq : nat_degree q ≠ 0): leading_coeff (p.comp q) =
12851327
leading_coeff p * leading_coeff q ^ nat_degree p :=
12861328
by rw [← coeff_comp_degree_mul_degree hq, ← nat_degree_comp]; refl
12871329

1330+
lemma degree_eq_zero_of_is_unit (h : is_unit p) : degree p = 0 :=
1331+
let ⟨q, hq⟩ := is_unit_iff_dvd_one.1 h in
1332+
have hp0 : p ≠ 0, from λ hp0, by simpa [hp0] using hq,
1333+
have hq0 : q ≠ 0, from λ hp0, by simpa [hp0] using hq,
1334+
have nat_degree (1 : polynomial α) = nat_degree (p * q),
1335+
from congr_arg _ hq,
1336+
by rw [nat_degree_one, nat_degree_mul_eq hp0 hq0, eq_comm,
1337+
add_eq_zero_iff, ← with_bot.coe_eq_coe,
1338+
← degree_eq_nat_degree hp0] at this;
1339+
exact this.1
1340+
12881341
end integral_domain
12891342

12901343
section field
12911344
variables [discrete_field α] {p q : polynomial α}
12921345
instance : vector_space α (polynomial α) :=
12931346
{ ..finsupp.to_module ℕ α }
12941347

1348+
lemma is_unit_iff_degree_eq_zero : is_unit p ↔ degree p = 0 :=
1349+
⟨degree_eq_zero_of_is_unit,
1350+
λ h, have degree p ≤ 0, by simp [*, le_refl],
1351+
have hc : coeff p 00, from λ hc,
1352+
by rw [eq_C_of_degree_le_zero this, hc] at h;
1353+
simpa using h,
1354+
is_unit_iff_dvd_one.2 ⟨C (coeff p 0)⁻¹, begin
1355+
conv in p { rw eq_C_of_degree_le_zero this },
1356+
rw [← C_mul, _root_.mul_inv_cancel hc, C_1]
1357+
end⟩⟩
1358+
1359+
lemma degree_pos_of_ne_zero_of_nonunit (hp0 : p ≠ 0) (hp : ¬is_unit p) :
1360+
0 < degree p :=
1361+
lt_of_not_ge (λ h, by rw [eq_C_of_degree_le_zero h] at hp0 hp;
1362+
exact hp ⟨units.map C (units.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0))), rfl⟩)
1363+
1364+
lemma irreducible_of_degree_eq_one (hp1 : degree p = 1) : irreducible p :=
1365+
⟨mt is_unit_iff_dvd_one.1 (λ ⟨q, hq⟩,
1366+
absurd (congr_arg degree hq) (λ h,
1367+
have degree q = 0, by rw [degree_one, degree_mul_eq, hp1, eq_comm,
1368+
nat.with_bot.add_eq_zero_iff] at h; exact h.2,
1369+
by simp [degree_mul_eq, this, degree_one, hp1] at h;
1370+
exact absurd h dec_trivial)),
1371+
λ q r hpqr, begin
1372+
have := congr_arg degree hpqr,
1373+
rw [hp1, degree_mul_eq, eq_comm, nat.with_bot.add_eq_one_iff] at this,
1374+
rw [is_unit_iff_degree_eq_zero, is_unit_iff_degree_eq_zero]; tautology
1375+
end
1376+
12951377
lemma monic_mul_leading_coeff_inv (h : p ≠ 0) :
12961378
monic (p * C (leading_coeff p)⁻¹) :=
12971379
by rw [monic, leading_coeff_mul, leading_coeff_C,

data/zmod/quadratic_reciprocity.lean

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ open function finset nat finite_field zmodp
99

1010
namespace zmodp
1111

12-
variables {p q : ℕ} (hp : prime p) (hq : prime q)
12+
variables {p q : ℕ} (hp : nat.prime p) (hq : nat.prime q)
1313

1414
@[simp] lemma card_units_zmodp : fintype.card (units (zmodp p hp)) = p - 1 :=
1515
by rw [card_units, card_zmodp]
1616

17-
theorem fermat_little {p : ℕ} (hp : prime p) {a : zmodp p hp} (ha : a ≠ 0) : a ^ (p - 1) = 1 :=
17+
theorem fermat_little {p : ℕ} (hp : nat.prime p) {a : zmodp p hp} (ha : a ≠ 0) : a ^ (p - 1) = 1 :=
1818
by rw [← units.mk0_val ha, ← @units.coe_one (zmodp p hp), ← units.coe_pow, ← units.ext_iff,
1919
← card_units_zmodp hp, pow_card_eq_one]
2020

@@ -47,7 +47,7 @@ hp.eq_two_or_odd.elim
4747
(λ hp1, by rw [← mul_self_eq_one_iff, ← _root_.pow_add, ← two_mul, two_mul_odd_div_two hp1];
4848
exact fermat_little hp ha)
4949

50-
@[simp] lemma wilsons_lemma {p : ℕ} (hp : prime p) : (fact (p - 1) : zmodp p hp) = -1 :=
50+
@[simp] lemma wilsons_lemma {p : ℕ} (hp : nat.prime p) : (fact (p - 1) : zmodp p hp) = -1 :=
5151
begin
5252
rw [← finset.prod_range_id_eq_fact, ← @units.coe_one (zmodp p hp), ← units.coe_neg,
5353
← @prod_univ_units_id_eq_neg_one (zmodp p hp),
@@ -66,7 +66,7 @@ begin
6666
by simp [val_cast_of_lt hp this.2]⟩))
6767
end
6868

69-
@[simp] lemma prod_range_prime_erase_zero {p : ℕ} (hp : prime p) :
69+
@[simp] lemma prod_range_prime_erase_zero {p : ℕ} (hp : nat.prime p) :
7070
((range p).erase 0).prod (λ x, (x : zmodp p hp)) = -1 :=
7171
by conv in (range p) { rw [← succ_sub_one p, succ_sub hp.pos] };
7272
rw [prod_hom (coe : ℕ → zmodp p hp) nat.cast_one nat.cast_mul,
@@ -76,7 +76,7 @@ end zmodp
7676

7777
namespace quadratic_reciprocity_aux
7878

79-
variables {p q : ℕ} (hp : prime p) (hq : prime q) (hp1 : p % 2 = 1) (hq1 : q % 2 = 1)
79+
variables {p q : ℕ} (hp : nat.prime p) (hq : nat.prime q) (hp1 : p % 2 = 1) (hq1 : q % 2 = 1)
8080
(hpq : p ≠ q)
8181

8282
include hp hq hp1 hq1 hpq
@@ -115,7 +115,7 @@ finset.ext.2 $ λ x,
115115
← nat.sub_add_comm (mul_pos hp.pos hq.pos), add_succ, succ_eq_add_one, nat.add_sub_cancel];
116116
exact le_trans (nat.sub_le_self _ _) (nat.le_add_right _ _),
117117
end,
118-
by rw [prime.coprime_iff_not_dvd hp, ← hk₂, ← nat.dvd_add_iff_left (dvd_mul_right _ _),
118+
by rw [nat.prime.coprime_iff_not_dvd hp, ← hk₂, ← nat.dvd_add_iff_left (dvd_mul_right _ _),
119119
dvd_iff_mod_eq_zero, mod_eq_of_lt]; clear _let_match _let_match; simp at hk₁; tauto⟩)
120120
(λ h, let ⟨m, hm₁, hm₂⟩ := mem_image.1 h in ⟨mem_range.2 $ hm₂ ▸ begin
121121
refine (mul_lt_mul_left (show 0 < 2, from dec_trivial)).1 _,
@@ -219,7 +219,7 @@ begin
219219
by rw nat.div_mul_cancel hb'.2⟩))
220220
end
221221

222-
lemma prod_range_p_mul_q_filter_coprime_mod_p (hq : prime q) (hp1 : p % 2 = 1) (hq1 : q % 2 = 1) (hpq : p ≠ q) :
222+
lemma prod_range_p_mul_q_filter_coprime_mod_p (hq : nat.prime q) (hp1 : p % 2 = 1) (hq1 : q % 2 = 1) (hpq : p ≠ q) :
223223
((((range ((p * q) / 2).succ).filter (coprime (p * q))).prod (λ x, x) : ℕ) : zmodp p hp) =
224224
(-1) ^ (q / 2) * q ^ (p / 2) :=
225225
have hq0 : (q : zmodp p hp) ≠ 0, by rwa [← nat.cast_zero, ne.def, zmodp.eq_iff_modeq_nat, nat.modeq.modeq_zero_iff,
@@ -294,7 +294,7 @@ have hinj : ∀ a₁ a₂ : ℕ,
294294
by simpa [lt_succ_iff, coprime_mul_iff_left] using hb,
295295
have hbpq' : b < ((⟨p * q, mul_pos hp.pos hq.pos⟩ : ℕ+) : ℕ) :=
296296
lt_of_le_of_lt hb'.1 (div_lt_self (mul_pos hp.pos hq.pos) dec_trivial),
297-
have val_inj : ∀ {p : ℕ} (hp : prime p) (x y : zmodp p hp), x.val = y.val ↔ x = y,
297+
have val_inj : ∀ {p : ℕ} (hp : nat.prime p) (x y : zmodp p hp), x.val = y.val ↔ x = y,
298298
from λ _ _ _ _, ⟨fin.eq_of_veq, fin.veq_of_eq⟩,
299299
have hbpq0 : (b : zmod (⟨p * q, mul_pos hp.pos hq.pos⟩)) ≠ 0,
300300
by rw [ne.def, zmod.eq_zero_iff_dvd_nat];
@@ -322,9 +322,9 @@ have hmem : ∀ a : ℕ,
322322
(if (a : zmodp q hq).1 ≤ q / 2 then ((a : zmodp p hp).1, (a : zmodp q hq).1)
323323
else ((-a : zmodp p hp).1, (-a : zmodp q hq).1)) ∈
324324
((range p).erase 0).product ((range (succ (q / 2))).erase 0),
325-
from λ x, have hxp : ∀ {p : ℕ} (hp : prime p), (x : zmodp p hp).val = 0 ↔ p ∣ x,
325+
from λ x, have hxp : ∀ {p : ℕ} (hp : nat.prime p), (x : zmodp p hp).val = 0 ↔ p ∣ x,
326326
from λ p hp, by rw [zmodp.val_cast_nat, nat.dvd_iff_mod_eq_zero],
327-
have hxpneg : ∀ {p : ℕ} (hp : prime p), (-x : zmodp p hp).val = 0 ↔ p ∣ x,
327+
have hxpneg : ∀ {p : ℕ} (hp : nat.prime p), (-x : zmodp p hp).val = 0 ↔ p ∣ x,
328328
from λ p hp, by rw [← int.cast_coe_nat x, ← int.cast_neg, ← int.coe_nat_inj',
329329
zmodp.coe_val_cast_int, int.coe_nat_zero, ← int.dvd_iff_mod_eq_zero, dvd_neg, int.coe_nat_dvd],
330330
have hxplt : (x : zmodp p hp).val < p := (x : zmodp p hp).2,
@@ -451,32 +451,32 @@ end quadratic_reciprocity_aux
451451

452452
open quadratic_reciprocity_aux
453453

454-
variables {p q : ℕ} (hp : prime p) (hq : prime q)
454+
variables {p q : ℕ} (hp : nat.prime p) (hq : nat.prime q)
455455

456456
namespace zmodp
457457

458-
def legendre_sym (a p : ℕ) (hp : prime p) : ℤ :=
458+
def legendre_sym (a p : ℕ) (hp : nat.prime p) : ℤ :=
459459
if (a : zmodp p hp) = 0 then 0 else if ∃ b : zmodp p hp, b ^ 2 = a then 1 else -1
460460

461-
lemma legendre_sym_eq_pow (a p : ℕ) (hp : prime p) : (legendre_sym a p hp : zmodp p hp) = (a ^ (p / 2)) :=
461+
lemma legendre_sym_eq_pow (a p : ℕ) (hp : nat.prime p) : (legendre_sym a p hp : zmodp p hp) = (a ^ (p / 2)) :=
462462
if ha : (a : zmodp p hp) = 0 then by simp [*, legendre_sym, _root_.zero_pow (nat.div_pos hp.ge_two (succ_pos 1))]
463463
else
464-
(prime.eq_two_or_odd hp).elim
464+
(nat.prime.eq_two_or_odd hp).elim
465465
(λ hp2, begin subst hp2,
466-
suffices : ∀ a : zmodp 2 prime_two,
467-
(((ite (a = 0) 0 (ite (∃ (b : zmodp 2 hp), b ^ 2 = a) 1 (-1))) : ℤ) : zmodp 2 prime_two) = a ^ (2 / 2),
466+
suffices : ∀ a : zmodp 2 nat.prime_two,
467+
(((ite (a = 0) 0 (ite (∃ (b : zmodp 2 hp), b ^ 2 = a) 1 (-1))) : ℤ) : zmodp 2 nat.prime_two) = a ^ (2 / 2),
468468
{ exact this a },
469469
exact dec_trivial,
470470
end)
471471
(λ hp1, have _ := euler_criterion hp ha,
472472
have (-1 : zmodp p hp) ≠ 1, from (ne_neg_self hp hp1 zero_ne_one.symm).symm,
473473
by cases zmodp.pow_div_two_eq_neg_one_or_one hp ha; simp [legendre_sym, *] at *)
474474

475-
lemma legendre_sym_eq_one_or_neg_one (a : ℕ) (hp : prime p) (ha : (a : zmodp p hp) ≠ 0) :
475+
lemma legendre_sym_eq_one_or_neg_one (a : ℕ) (hp : nat.prime p) (ha : (a : zmodp p hp) ≠ 0) :
476476
legendre_sym a p hp = -1 ∨ legendre_sym a p hp = 1 :=
477477
by unfold legendre_sym; split_ifs; simp * at *
478478

479-
theorem quadratic_reciprocity (hp : prime p) (hq : prime q) (hp1 : p % 2 = 1) (hq1 : q % 2 = 1) (hpq : p ≠ q) :
479+
theorem quadratic_reciprocity (hp : nat.prime p) (hq : nat.prime q) (hp1 : p % 2 = 1) (hq1 : q % 2 = 1) (hpq : p ≠ q) :
480480
legendre_sym p q hq * legendre_sym q p hp = (-1) ^ ((p / 2) * (q / 2)) :=
481481
have hneg_one_or_one : ((range (p * q / 2).succ).filter (coprime (p * q))).prod
482482
(λ (x : ℕ), if (x : zmodp q hq).val ≤ q / 2 then (1 : zmodp p hp × zmodp q hq) else -1) = 1

0 commit comments

Comments
 (0)