/- 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 FormalConjecturesUtil

Erdős Problem 1059

Reference: erdosproblems.com/1059

namespace Erdos1059 def IsFactorial (d : ) : Prop := d Set.range Nat.factorial def factorialsLessThanN (n : ) : Set := { d | d < n IsFactorial d } def AllFactorialSubtractionsComposite (n : ) : Prop := d factorialsLessThanN n, (n - d).Composite

Are 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 declaration uses 'sorry'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)).Nonempty def decidableFactorialsLessThanN (n : ) : Finset := (Finset.range n).filter DecidableIsFactorial def DecidableAllFactorialSubtractionsComposite (n : ) : Prop := d decidableFactorialsLessThanN n, (n - d).Composite @[category test, AMS 11] lemma isFactorial_equivalent (d : ) : IsFactorial d DecidableIsFactorial d := d:IsFactorial d DecidableIsFactorial d d:d Set.range Nat.factorial {k Finset.Icc 0 d | k.factorial = d}.Nonempty d:(∃ y, y.factorial = d) {k Finset.Icc 0 d | k.factorial = d}.Nonempty d:(∃ y, y.factorial = d) {k Finset.Icc 0 d | k.factorial = d}.Nonemptyd:{k Finset.Icc 0 d | k.factorial = d}.Nonempty y, y.factorial = d d:(∃ y, y.factorial = d) {k Finset.Icc 0 d | k.factorial = d}.Nonempty d:k:hk:k.factorial = d{k Finset.Icc 0 d | k.factorial = d}.Nonempty d:k:hk:k.factorial = dk {k Finset.Icc 0 d | k.factorial = d} d:k:hk:k.factorial = dk Finset.Icc 0 d k.factorial = d d:k:hk:k.factorial = dk Finset.Icc 0 dd:k:hk:k.factorial = dk.factorial = d d:k:hk:k.factorial = dk Finset.Icc 0 d have hk : k <= d := d:IsFactorial d DecidableIsFactorial d d:k:hk:k.factorial = dk k.factorial All goals completed! 🐙 d:k:hk✝:k.factorial = dhk:k d := Eq.mpr (id (congrArg (fun _a => k _a) (Eq.symm hk✝))) (Nat.self_le_factorial k)0 k k d All goals completed! 🐙 d:k:hk:k.factorial = dk.factorial = d All goals completed! 🐙 d:{k Finset.Icc 0 d | k.factorial = d}.Nonempty y, y.factorial = d d:k:hk:k {k Finset.Icc 0 d | k.factorial = d} y, y.factorial = d d:k:hk:k {k Finset.Icc 0 d | k.factorial = d}k.factorial = d d:k:hk:k Finset.Icc 0 d k.factorial = dk.factorial = d All goals completed! 🐙 @[category test, AMS 11] lemma factorialsLessThanN_equivalent (n : ) : factorialsLessThanN n = (decidableFactorialsLessThanN n) := n:factorialsLessThanN n = (decidableFactorialsLessThanN n) n:d:d factorialsLessThanN n d (decidableFactorialsLessThanN n) n:d:d {d | d < n IsFactorial d} d (Finset.filter DecidableIsFactorial (Finset.range n)) n:d:d < n (IsFactorial d DecidableIsFactorial d) All goals completed! 🐙 @[category test, AMS 11] lemma allFactorialSubtractionsComposite_equivalent (d : ) : DecidableAllFactorialSubtractionsComposite d AllFactorialSubtractionsComposite d := d:DecidableAllFactorialSubtractionsComposite d AllFactorialSubtractionsComposite d d:(∀ d_1 decidableFactorialsLessThanN d, (d - d_1).Composite) d_1 factorialsLessThanN d, (d - d_1).Composite d:(∀ d_1 decidableFactorialsLessThanN d, (d - d_1).Composite) d_1 (decidableFactorialsLessThanN d), (d - d_1).Composite All goals completed! 🐙 @[category test, AMS 11] theorem allFactorialSubtractionsComposite_101 : AllFactorialSubtractionsComposite 101 := AllFactorialSubtractionsComposite 101 have h : DecidableAllFactorialSubtractionsComposite 101 := AllFactorialSubtractionsComposite 101 d < 101, DecidableIsFactorial d (101 - d).Composite All goals completed! 🐙 All goals completed! 🐙 @[category test, AMS 11] theorem allFactorialSubtractionsComposite_211 : AllFactorialSubtractionsComposite 211 := AllFactorialSubtractionsComposite 211 have h : DecidableAllFactorialSubtractionsComposite 211 := AllFactorialSubtractionsComposite 211 d < 211, DecidableIsFactorial d (211 - d).Composite All goals completed! 🐙 All goals completed! 🐙 @[category test, AMS 11] theorem notAllFactorialSubtractionsComposite_89 : ¬(AllFactorialSubtractionsComposite 89) := ¬AllFactorialSubtractionsComposite 89 have h : ¬(DecidableAllFactorialSubtractionsComposite 89) := ¬AllFactorialSubtractionsComposite 89 ¬ d Finset.filter DecidableIsFactorial (Finset.range 89), (89 - d).Composite h: d Finset.filter DecidableIsFactorial (Finset.range 89), (89 - d).CompositeFalse h:6 Finset.filter DecidableIsFactorial (Finset.range 89) (89 - 6).CompositeFalse have : Nat.Prime (89 - 6) := ¬AllFactorialSubtractionsComposite 89 All goals completed! 🐙 All goals completed! 🐙 h:¬AllFactorialSubtractionsComposite 89¬AllFactorialSubtractionsComposite 89 All goals completed! 🐙 @[category test, AMS 11] theorem testFactorialsLessThanN : factorialsLessThanN 100 = {1, 2, 6, 24} := factorialsLessThanN 100 = {1, 2, 6, 24} have h : decidableFactorialsLessThanN 100 = {1, 2, 6, 24} := factorialsLessThanN 100 = {1, 2, 6, 24} Finset.filter DecidableIsFactorial (Finset.range 100) = {1, 2, 6, 24} All goals completed! 🐙 h:decidableFactorialsLessThanN 100 = {1, 2, 6, 24} := id testFactorialsLessThanN._proof_1(decidableFactorialsLessThanN 100) = {1, 2, 6, 24} All goals completed! 🐙 end Erdos1059