/-
Copyright 2025 The Formal Conjectures Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
import FormalConjecturesUtilErdős Problem 1059
Reference: erdosproblems.com/1059
namespace Erdos1059def IsFactorial (d : ℕ) : Prop :=
d ∈ Set.range Nat.factorialdef factorialsLessThanN (n : ℕ) : Set ℕ :=
{ d | d < n ∧ IsFactorial d }def AllFactorialSubtractionsComposite (n : ℕ) : Prop :=
∀d ∈ factorialsLessThanN n, (n - d).CompositeAre there infinitely many primes $p$ such that $p - k!$ is composite for each $k$ such that $1 ≤ k! < p$?
@[category research open, AMS 11]
theorem erdos_1059 :
answer(sorry) ↔ Set.Infinite {p | p.Prime ∧ AllFactorialSubtractionsComposite p} := ⊢ True ↔ {p | Nat.Prime p ∧ AllFactorialSubtractionsComposite p}.Infinite
All goals completed! 🐙abbrev DecidableIsFactorial (d : ℕ) : Prop :=
((Finset.Icc 0 d).filter (λ k => Nat.factorial k = d)).Nonemptydef decidableFactorialsLessThanN (n : ℕ) : Finset ℕ :=
(Finset.range n).filter DecidableIsFactorialdef DecidableAllFactorialSubtractionsComposite (n : ℕ) : Prop :=
∀ d ∈ decidableFactorialsLessThanN n, (n - d).Compositeh d:ℕk:ℕhk:k ∈ Finset.Icc 0 d ∧ k.factorial = d⊢ k.factorial = d
exact hk.2 All goals completed! 🐙@[category test, AMS 11]
lemma factorialsLessThanN_equivalent (n : ℕ) :
factorialsLessThanN n = ↑(decidableFactorialsLessThanN n) := by n:ℕ⊢ factorialsLessThanN n = ↑(decidableFactorialsLessThanN n)
ext d n:ℕd:ℕ⊢ d ∈ factorialsLessThanN n ↔ d ∈ ↑(decidableFactorialsLessThanN n)
unfold factorialsLessThanN decidableFactorialsLessThanN n:ℕd:ℕ⊢ d ∈ {d | d < n ∧ IsFactorial d} ↔ d ∈ ↑(Finset.filter DecidableIsFactorial (Finset.range n))
simp n:ℕd:ℕ⊢ d < n → (IsFactorial d ↔ DecidableIsFactorial d)
exact λ _ => isFactorial_equivalent d All goals completed! 🐙
@[category test, AMS 11]
lemma allFactorialSubtractionsComposite_equivalent (d : ℕ) :
DecidableAllFactorialSubtractionsComposite d ↔ AllFactorialSubtractionsComposite d := by d:ℕ⊢ DecidableAllFactorialSubtractionsComposite d ↔ AllFactorialSubtractionsComposite d
unfold AllFactorialSubtractionsComposite DecidableAllFactorialSubtractionsComposite d:ℕ⊢ (∀ d_1 ∈ decidableFactorialsLessThanN d, (d - d_1).Composite) ↔ ∀ d_1 ∈ factorialsLessThanN d, (d - d_1).Composite
rw [factorialsLessThanN_equivalent d d:ℕ⊢ (∀ d_1 ∈ decidableFactorialsLessThanN d, (d - d_1).Composite) ↔
∀ d_1 ∈ ↑(decidableFactorialsLessThanN d), (d - d_1).Composite d:ℕ⊢ (∀ d_1 ∈ decidableFactorialsLessThanN d, (d - d_1).Composite) ↔
∀ d_1 ∈ ↑(decidableFactorialsLessThanN d), (d - d_1).Composite] d:ℕ⊢ (∀ d_1 ∈ decidableFactorialsLessThanN d, (d - d_1).Composite) ↔
∀ d_1 ∈ ↑(decidableFactorialsLessThanN d), (d - d_1).Composite
simp All goals completed! 🐙
@[category test, AMS 11]
theorem allFactorialSubtractionsComposite_101 : AllFactorialSubtractionsComposite 101 := by ⊢ AllFactorialSubtractionsComposite 101
have h : DecidableAllFactorialSubtractionsComposite 101 := by
norm_num [DecidableAllFactorialSubtractionsComposite, decidableFactorialsLessThanN] ⊢ ∀ d < 101, DecidableIsFactorial d → (101 - d).Composite h:DecidableAllFactorialSubtractionsComposite 101⊢ AllFactorialSubtractionsComposite 101
decide +kernel h:DecidableAllFactorialSubtractionsComposite 101⊢ AllFactorialSubtractionsComposite 101 h:DecidableAllFactorialSubtractionsComposite 101⊢ AllFactorialSubtractionsComposite 101
exact (allFactorialSubtractionsComposite_equivalent 101).mp h All goals completed! 🐙
@[category test, AMS 11]
theorem allFactorialSubtractionsComposite_211 : AllFactorialSubtractionsComposite 211 := by ⊢ AllFactorialSubtractionsComposite 211
have h : DecidableAllFactorialSubtractionsComposite 211 := by
norm_num [DecidableAllFactorialSubtractionsComposite, decidableFactorialsLessThanN] ⊢ ∀ d < 211, DecidableIsFactorial d → (211 - d).Composite h:DecidableAllFactorialSubtractionsComposite 211⊢ AllFactorialSubtractionsComposite 211
decide +kernel h:DecidableAllFactorialSubtractionsComposite 211⊢ AllFactorialSubtractionsComposite 211 h:DecidableAllFactorialSubtractionsComposite 211⊢ AllFactorialSubtractionsComposite 211
exact (allFactorialSubtractionsComposite_equivalent 211).mp h All goals completed! 🐙
@[category test, AMS 11]
theorem notAllFactorialSubtractionsComposite_89 : ¬(AllFactorialSubtractionsComposite 89) := by ⊢ ¬AllFactorialSubtractionsComposite 89
have h : ¬(DecidableAllFactorialSubtractionsComposite 89) := by
unfold DecidableAllFactorialSubtractionsComposite decidableFactorialsLessThanN ⊢ ¬∀ d ∈ Finset.filter DecidableIsFactorial (Finset.range 89), (89 - d).Composite h:¬DecidableAllFactorialSubtractionsComposite 89⊢ ¬AllFactorialSubtractionsComposite 89
intro h h:∀ d ∈ Finset.filter DecidableIsFactorial (Finset.range 89), (89 - d).Composite⊢ False h:¬DecidableAllFactorialSubtractionsComposite 89⊢ ¬AllFactorialSubtractionsComposite 89
specialize h 6 h:6 ∈ Finset.filter DecidableIsFactorial (Finset.range 89) → (89 - 6).Composite⊢ False h:¬DecidableAllFactorialSubtractionsComposite 89⊢ ¬AllFactorialSubtractionsComposite 89
have : Nat.Prime (89 - 6) := by ⊢ ¬AllFactorialSubtractionsComposite 89 h:6 ∈ Finset.filter DecidableIsFactorial (Finset.range 89) → (89 - 6).Compositethis:Nat.Prime (89 - 6)⊢ False h:¬DecidableAllFactorialSubtractionsComposite 89⊢ ¬AllFactorialSubtractionsComposite 89 norm_num h:6 ∈ Finset.filter DecidableIsFactorial (Finset.range 89) → (89 - 6).Compositethis:Nat.Prime (89 - 6)⊢ False h:¬DecidableAllFactorialSubtractionsComposite 89⊢ ¬AllFactorialSubtractionsComposite 89 h:6 ∈ Finset.filter DecidableIsFactorial (Finset.range 89) → (89 - 6).Compositethis:Nat.Prime (89 - 6)⊢ False h:¬DecidableAllFactorialSubtractionsComposite 89⊢ ¬AllFactorialSubtractionsComposite 89
contradiction h:¬DecidableAllFactorialSubtractionsComposite 89⊢ ¬AllFactorialSubtractionsComposite 89 h:¬DecidableAllFactorialSubtractionsComposite 89⊢ ¬AllFactorialSubtractionsComposite 89
simp [allFactorialSubtractionsComposite_equivalent] at h h:¬AllFactorialSubtractionsComposite 89⊢ ¬AllFactorialSubtractionsComposite 89
exact h All goals completed! 🐙
@[category test, AMS 11]
theorem testFactorialsLessThanN : factorialsLessThanN 100 = {1, 2, 6, 24} := by ⊢ factorialsLessThanN 100 = {1, 2, 6, 24}
have h : decidableFactorialsLessThanN 100 = {1, 2, 6, 24} := by
norm_num [decidableFactorialsLessThanN] ⊢ Finset.filter DecidableIsFactorial (Finset.range 100) = {1, 2, 6, 24} h:decidableFactorialsLessThanN 100 = {1, 2, 6, 24}⊢ factorialsLessThanN 100 = {1, 2, 6, 24}
decide +kernel h:decidableFactorialsLessThanN 100 = {1, 2, 6, 24}⊢ factorialsLessThanN 100 = {1, 2, 6, 24} h:decidableFactorialsLessThanN 100 = {1, 2, 6, 24}⊢ factorialsLessThanN 100 = {1, 2, 6, 24}
rw [factorialsLessThanN_equivalent h:decidableFactorialsLessThanN 100 = {1, 2, 6, 24}⊢ ↑(decidableFactorialsLessThanN 100) = {1, 2, 6, 24} h:decidableFactorialsLessThanN 100 = {1, 2, 6, 24}⊢ ↑(decidableFactorialsLessThanN 100) = {1, 2, 6, 24}] h:decidableFactorialsLessThanN 100 = {1, 2, 6, 24}⊢ ↑(decidableFactorialsLessThanN 100) = {1, 2, 6, 24}
simp [h] All goals completed! 🐙end Erdos1059