Skip to content

Commit

Permalink
chore(data/nat/prime): fact (2.prime) (#10441)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric <ericrboidi@gmail.com>
  • Loading branch information
ericrbg and ericrbg committed Nov 28, 2021
1 parent a2e6bf8 commit f684721
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/data/nat/prime.lean
Expand Up @@ -1030,6 +1030,12 @@ namespace nat

theorem prime_three : prime 3 := by norm_num

/-- See note [fact non-instances].-/
lemma fact_prime_two : fact (prime 2) := ⟨prime_two⟩

/-- See note [fact non-instances].-/
lemma fact_prime_three : fact (prime 3) := ⟨prime_three⟩

end nat


Expand Down
7 changes: 7 additions & 0 deletions src/logic/basic.lean
Expand Up @@ -190,6 +190,13 @@ In particular, this class is not intended for turning the type class system
into an automated theorem prover for first order logic. -/
class fact (p : Prop) : Prop := (out [] : p)

/--
In most cases, we should not have global instances of `fact`; typeclass search only reads the head
symbol and then tries any instances, which means that adding any such instance will cause slowdowns
everywhere. We instead make them as lemmata and make them local instances as required.
-/
library_note "fact non-instances"

lemma fact.elim {p : Prop} (h : fact p) : p := h.1
lemma fact_iff {p : Prop} : fact p ↔ p := ⟨λ h, h.1, λ h, ⟨h⟩⟩

Expand Down
4 changes: 1 addition & 3 deletions src/number_theory/quadratic_reciprocity.lean
Expand Up @@ -429,9 +429,7 @@ have hqp0 : (q : zmod p) ≠ 0, from prime_ne_zero p q hpq,
by rw [eisenstein_lemma q hp1.1 hpq0, eisenstein_lemma p hq1.1 hqp0,
← pow_add, sum_mul_div_add_sum_mul_div_eq_mul q p hpq0, mul_comm]

-- move this
local attribute [instance]
lemma fact_prime_two : fact (nat.prime 2) := ⟨nat.prime_two⟩
local attribute [instance] nat.fact_prime_two

lemma legendre_sym_two [hp1 : fact (p % 2 = 1)] : legendre_sym 2 p = (-1) ^ (p / 4 + p / 2) :=
have hp2 : p ≠ 2, from mt (congr_arg (% 2)) (by simpa using hp1.1),
Expand Down

0 comments on commit f684721

Please sign in to comment.