/- 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 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).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 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).Composited: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! 🐙d:(∀ d_1 decidableFactorialsLessThanN d, (d - d_1).Composite) d_1 (decidableFactorialsLessThanN d), (d - d_1).Composite All goals completed! 🐙h:DecidableAllFactorialSubtractionsComposite 101AllFactorialSubtractionsComposite 101 All goals completed! 🐙h:DecidableAllFactorialSubtractionsComposite 211AllFactorialSubtractionsComposite 211 All goals completed! 🐙h:¬DecidableAllFactorialSubtractionsComposite 89¬AllFactorialSubtractionsComposite 89 h:¬AllFactorialSubtractionsComposite 89¬AllFactorialSubtractionsComposite 89 All goals completed! 🐙h:decidableFactorialsLessThanN 100 = {1, 2, 6, 24}(decidableFactorialsLessThanN 100) = {1, 2, 6, 24} All goals completed! 🐙end Erdos1059