import OAI.Computability.FourierTransform.ChineseRemainder namespace OAI /- Prime supply and bounded parameters -/ namespace PowerSaving.Selection open Finset Real noncomputable section def stackN (n : ℕ) := Nat.log 2 (2*n)+1 lemma stack_pos (n : ℕ) : 0< stackN n := Nat.succ_pos _ lemma stack_above (n : ℕ) : 2*n < 2^stackN n := Nat.lt_pow_succ_log_self Nat.one_lt_two _ lemma stack_pow (n : ℕ) (hn : 02 instance (i) : Decidable (Bar i) := inferInstanceAs (Decidable (_ ∧ _)) def bars (p : ℕ) : ℕ := ∑ i ∈ range p, if Bar i then 1 else 0 lemma bars_step (i : ℕ) : bars (i+1)=bars i+(if Bar i then 1 else 0) := sum_range_succ .. lemma bars_zero : bars 0=0 := by simp [bars] lemma bars_count (p : ℕ) (hp : 2 ≤ p) : bars (p+1)+1 = Nat.primeCounting p := by let Q := range (p+1) have h (i : ℕ) : (if Bar i then 1 else 0)+(if i=2 then 1 else 0)= (if i.Prime then 1 else 0) := by by_cases g : i.Prime · have ht := g.two_le; simp only [Bar,g,true_and,ite_true]; split_ifs <;> omega · have hh : i≠2 := by intro H; rw [H] at g; exact g Nat.prime_two simp [g,hh,Bar] have hh1 : ∑ i ∈ Q, (if i=2 then 1 else 0)=1 := by have hg : 2 rhs; rw [← hh1] rw [bars] dsimp only [Q] rw [← sum_add_distrib] simp_rw [h] rw [← Nat.primesLE_card_eq_primeCounting] -- filter rw [← sum_filter] simp [Nat.primesLE,Nat.primesBelow] lemma bar_bounds (k : ℕ) : k < bars (silo k+1) := by have H := bars_count _ (silo_big k).le have G := harvest k omega end end PowerSaving.Selection end OAI