Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
752 changes: 752 additions & 0 deletions submissions/dft/ananasclassic-relays5585/Submission.lean

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import Submission.AdaptiveRate.HistogramMoment
import Submission.AdaptiveRate.RateToDFT

open OAI.PowerSaving OAI.PowerSaving.RAM OAI.PowerSaving.TensorMoment
open OAI.PowerSaving.TensorPower OAI.PowerSaving.TensorMoment.BaseRate
open Asymptotics Filter
open scoped Topology

namespace FourierSearch.AdaptiveTensor

/-- A single positive tensor order suffices for all three overhead terms.
Taking the limit avoids losing score by fixing the order in advance. -/
private theorem exists_order {a b c : ℝ} (a0 : 0 ≤ a) (a1 : a < 1)
(b0 : 0 ≤ b) (b1 : b < 1) (c0 : 0 ≤ c) (c1 : c < 1) :
∃ n : ℕ, a ^ (n+1) + 2 * b ^ (n+1) + 2 * c ^ (n+1) ≤ 1 := by
have ha := tendsto_pow_atTop_nhds_zero_of_lt_one a0 a1
have hb := tendsto_pow_atTop_nhds_zero_of_lt_one b0 b1
have hc := tendsto_pow_atTop_nhds_zero_of_lt_one c0 c1
have h : Tendsto (fun v : ℕ => a^v + 2*b^v + 2*c^v) atTop (𝓝 0) := by
simpa using (ha.add (hb.const_mul 2)).add (hc.const_mul 2)
obtain ⟨n, hn⟩ := eventually_atTop.1 (h.eventually_lt_const (by norm_num : (0:ℝ) < 1))
exact ⟨n, (hn (n+1) (by omega)).le⟩

private theorem strict_at_some_order {P T : Multiset ℕ} {u : ℝ}
(hu : 0 ≤ u) (hu1 : u < 1) (hraw : mom (1-u) P < mom (1-u) T)
(hpaid : mom 1 P < (12:ℝ)^u * mom (1-u) T)
(hpad : (T.card : ℝ) * 13 < (12:ℝ)^u * mom (1-u) T) :
∃ n : ℕ, mom (1-u) (strictP T P (n+1) (12^(n+1)) (13^(n+1))) ≤
mom (1-u) (strictT T (n+1) (13^(n+1))) := by
have ht := (mom_nonneg _ _).trans_lt hraw
have hden : 0 < (12:ℝ)^u * mom (1-u) T := mul_pos (by positivity) ht
obtain ⟨n, hn⟩ := exists_order (div_nonneg (mom_nonneg _ _) ht.le)
((div_lt_one ht).2 hraw) (div_nonneg (mom_nonneg _ _) hden.le)
((div_lt_one hden).2 hpaid) (div_nonneg (by positivity) hden.le)
((div_lt_one hden).2 hpad)
refine ⟨n, strictify (t := 1-u) (u := u) (by norm_num) (by norm_num)
(by linarith) hu (by linarith) ht ?_⟩
norm_num only [sub_add_cancel, sub_sub_cancel, Nat.cast_ofNat] at *
exact hn

/-- The public batch supplies its exact linear map, output frames and paid moves.
The engine proof is adapted from the supplier's Apache-2.0 TensorPower.lean.
Only the choice of tensor order and the rate inequalities are replaced. -/
theorem bound_of_raw {s u : ℝ} (hs : 0 ≤ s) (hsu : s < u) (hu1 : u < 1)
(hsmall : 0 < Histogram.histFn BaseUnit.targetHist 4)
(hraw : mom (1-u) (ofHist BaseUnit.blockHist) < mom (1-u) (ofHist BaseUnit.targetHist))
(hpaid : mom 1 (ofHist BaseUnit.blockHist) <
(12:ℝ)^u * mom (1-u) (ofHist BaseUnit.targetHist))
(hpad : ((ofHist BaseUnit.targetHist).card : ℝ) * 13 <
(12:ℝ)^u * mom (1-u) (ofHist BaseUnit.targetHist)) :
∃ order solve W, DFTProgram order solve W ∧
(fun n : ℕ => (W n : ℝ)) =O[atTop]
(fun n : ℕ => (n : ℝ) * (Real.log (n : ℝ)) ^ (1-s)) := by
obtain ⟨n, hm⟩ := strict_at_some_order (hs.trans hsu.le) hu1 hraw hpaid hpad
obtain ⟨α, ρ, σ, _, _, _, _, _, _, e, tr, tz, wd, G,
he, hind, hP, hw, hG, hα, htr, hcnt, hhist⟩ := Batch48.rawCert_exists_B48
let A : BundledUnit := ⟨α, ρ, σ, ⟨e, he, tr, tz, hind, wd, hw⟩⟩
have hPr := RawCert.ranks_eq_of_histG A _ G hhist
have hTg := RawCert.tgts_eq_of_cardG A _ G hcnt
have hR : A.BlockRanksOk := fun _ hr => RawCert.rk_bounds_of_proper hP hr
have hT : A.TargetsOk := by
intro l
refine ⟨(htr l).1, ?_⟩
change tr l ≤ Fintype.card α
rw [hα]
exact (htr l).2
have hσ : 0 < Fintype.card σ := by
have h := Finset.card_le_univ (Finset.univ.filter fun l : σ => tr l = 4)
rw [hcnt 4] at h
exact (Nat.mul_pos hG hsmall).trans_le h
have hm' : mom (1-u) (strictP A.targets A.blockRanks (n+1) (12^(n+1)) (13^(n+1))) ≤
mom (1-u) (strictT A.targets (n+1) (13^(n+1))) := by
rw [hPr, hTg, RawCert.strictP_nsmul, RawCert.strictT_nsmul, RawCert.mom_nsmul, RawCert.mom_nsmul]
exact mul_le_mul_of_nonneg_left hm (Nat.cast_nonneg _)
have hsize : Fintype.card (A.pow n).α = 137 ^ (n+1) := by rw [BundledUnit.card_pow, hα]
have hmem : 13^(n+1) ∈ strictT A.targets (n+1) (13^(n+1)) := by
rw [hTg, RawCert.strictT_nsmul, Multiset.mem_nsmul_of_ne_zero (pow_ne_zero _ (by omega))]
have h4 : 4 ∈ ofHist BaseUnit.targetHist :=
Multiset.count_pos.1 (by rwa [RawCert.count_ofHist])
exact mem_padT (pow_mem_tpow h4 (n+1)) (Nat.pow_le_pow_left (by norm_num) _)
let z := 1 - (s+u)/2
have hz : z ≤ 1 := by dsimp [z]; linarith
have engine : RippleEngine.{0} z := by
refine ⟨by dsimp [z]; linarith, fun cl m _ k v => A.ripple_program n _ _ ?_ (by positivity)
(Nat.pow_lt_pow_left (by norm_num) (Nat.succ_ne_zero n)) hR hT ?_ ?_ hmem hm'
(by linarith) (by dsimp [z]; linarith) hz m cl k v⟩
· rw [hsize]; exact Nat.pow_le_pow_left (by norm_num) _
· rw [RawCert.card_σ_pow]; exact pow_pos hσ _
· rw [hsize]; exact le_trans (by norm_num) (Nat.le_self_pow (Nat.succ_ne_zero n) 137)
exact bound_of_engine engine hz (by dsimp [z]; linarith)

end FourierSearch.AdaptiveTensor
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import Submission.Data.BaseUnit.Rate

open OAI.PowerSaving OAI.PowerSaving.TensorMoment
open OAI.PowerSaving.TensorMoment.BaseRate

namespace FourierSearch.Moment

abbrev Hist := List (ℕ × ℕ)

theorem card_ofHist (h : Hist) : (ofHist h).card = (h.map Prod.snd).sum := by
induction h with
| nil => simp [ofHist]
| cons e h ih => simp [ofHist] at ih ⊢; omega

/-- The multiplier for moment endpoints and the precision of intermediate
decimal roots are independent. Near a crossing, coarse endpoints can hide
a genuine strict inequality even if the underlying circuit is unchanged. -/
structure Precision where
scale : ℕ
rootScale : ℕ
positive : 0 < rootScale

namespace Precision

variable (prec : Precision)

set_option maxHeartbeats 1000000

/-- Round the negative power down on the paid side or up on the target side
using the upstream base-ten root certificate. Separate endpoints also cover
rank one, where the exact power is an integer. -/
def bounds (digits : List ℕ) (r : ℕ) : ℕ × ℕ :=
let s := qWalk prec.rootScale digits (qInit prec.rootScale r)
(prec.scale * prec.rootScale * r / s.e, (prec.scale * prec.rootScale * r + s.c - 1) / s.c)

def certified (digits : List ℕ) (r : ℕ) : Bool :=
let s := qWalk prec.rootScale digits (qInit prec.rootScale r)
let (a, b) := bounds prec digits r
1 ≤ r && qGood prec.rootScale digits (qInit prec.rootScale r) &&
a * s.e ≤ prec.scale * prec.rootScale * r && prec.scale * prec.rootScale * r ≤ b * s.c

theorem enclose (digits : List ℕ) (r : ℕ) (hc : certified prec digits r = true) :
((bounds prec digits r).1 : ℝ) ≤ prec.scale * (r : ℝ) ^ (1 - qExpo 1 0 digits) ∧
prec.scale * (r : ℝ) ^ (1 - qExpo 1 0 digits) ≤ ((bounds prec digits r).2 : ℝ) := by
simp only [certified, Bool.and_eq_true, decide_eq_true_eq] at hc
obtain ⟨⟨⟨hr, hwalk⟩, ha⟩, hb⟩ := hc
have hr' : (0 : ℝ) < r := Nat.cast_pos.mpr hr
have hk' : (0 : ℝ) < prec.rootScale := Nat.cast_pos.mpr prec.positive
obtain ⟨lo, hi⟩ := qWalk_sound hr' prec.positive digits (qInit prec.rootScale r) 1 0
(by simp [qInit]) (by simp [qInit]) (by simp [qInit]) (by simp [qInit]) hwalk
set s := qWalk prec.rootScale digits (qInit prec.rootScale r)
let a := (bounds prec digits r).1
let b := (bounds prec digits r).2
have ha' : (a : ℝ) * s.e ≤ (prec.scale : ℝ) * prec.rootScale * r := by exact_mod_cast ha
have hb' : (prec.scale : ℝ) * prec.rootScale * r ≤ (b : ℝ) * s.c := by exact_mod_cast hb
have positive := Real.rpow_pos_of_pos hr' (qExpo 1 0 digits)
rw [Real.rpow_sub hr', Real.rpow_one, mul_div_assoc']
constructor
· apply (le_div_iff₀ positive).mpr
apply le_of_mul_le_mul_left (a := (prec.rootScale : ℝ)) _ hk'
calc
(prec.rootScale : ℝ) * ((a : ℝ) * (r : ℝ) ^ qExpo 1 0 digits) =
a * ((prec.rootScale : ℝ) * (r : ℝ) ^ qExpo 1 0 digits) := by ring
_ ≤ a * (s.e : ℝ) := mul_le_mul_of_nonneg_left hi (Nat.cast_nonneg _)
_ ≤ _ := by linarith only [ha']
· apply (div_le_iff₀ positive).mpr
apply le_of_mul_le_mul_left (a := (prec.rootScale : ℝ)) _ hk'
calc
(prec.rootScale : ℝ) * ((prec.scale : ℝ) * r) ≤ (b : ℝ) * s.c := by linarith only [hb']
_ ≤ b * ((prec.rootScale : ℝ) * (r : ℝ) ^ qExpo 1 0 digits) :=
mul_le_mul_of_nonneg_left lo (Nat.cast_nonneg _)
_ = _ := by ring

end Precision

def total (weight : ℕ → ℕ) (h : Hist) : ℕ :=
(h.map fun entry => entry.2 * weight entry.1).sum

namespace Precision

variable (prec : Precision)

theorem enclose_hist (digits : List ℕ) (h : Hist)
(ok : ∀ e ∈ h, certified prec digits e.1 = true) :
((total (fun r => (bounds prec digits r).1) h : ℕ) : ℝ) ≤
prec.scale * mom (1 - qExpo 1 0 digits) (ofHist h) ∧
prec.scale * mom (1 - qExpo 1 0 digits) (ofHist h) ≤
((total (fun r => (bounds prec digits r).2) h : ℕ) : ℝ) := by
rw [mo]
induction h with
| nil => simp [total]
| cons e tail ih =>
obtain ⟨l, u⟩ := ih fun b hb => ok b (List.mem_cons_of_mem _ hb)
obtain ⟨a, b⟩ := enclose prec digits e.1 (ok e (by simp))
simp only [total, List.map_cons, List.sum_cons, Nat.cast_add, Nat.cast_mul] at *
constructor <;> nlinarith [mul_le_mul_of_nonneg_left a (Nat.cast_nonneg e.2),
mul_le_mul_of_nonneg_left b (Nat.cast_nonneg e.2)]

end Precision
end FourierSearch.Moment
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import Submission.AdaptiveRate.AdaptiveTensor

open OAI.PowerSaving OAI.PowerSaving.TensorMoment
open OAI.PowerSaving.TensorMoment.BaseRate Asymptotics Filter
open FourierSearch.Moment

namespace FourierSearch.RateCertificate

/-- Leave guard digits in both the final moment sum and the repeated
tenth roots. Every rounding inequality is
checked against the exact rank and the actual supplier histogram. -/
def prec : Precision := ⟨10^93, 10^107, by norm_num⟩

def lower (ds : List ℕ) (h : Hist) := total (fun r => (prec.bounds ds r).1) h
def upper (ds : List ℕ) (h : Hist) := total (fun r => (prec.bounds ds r).2) h

/-- All supplier-specific integer tests for a proposed witness. The Boolean
form lets the kernel evaluate the same checklist for every published word. -/
def passes (ds : List ℕ) : Bool :=
BaseUnit.blockHist.all (fun e => prec.certified ds e.1) &&
BaseUnit.targetHist.all (fun e => prec.certified ds e.1) &&
decide (upper ds BaseUnit.blockHist < lower ds BaseUnit.targetHist) &&
decide (737415 * prec.scale ≤ lower ds BaseUnit.targetHist) &&
decide (total id BaseUnit.blockHist ≤ 742704) &&
decide ((BaseUnit.targetHist.map Prod.snd).sum ≤ 52896) &&
decide (0 < Histogram.histFn BaseUnit.targetHist 4)

theorem moment_lt {ds : List ℕ} {u : ℝ} {a b : Hist} (hd : qExpo 1 0 ds = u)
(ha : ∀ e ∈ a, prec.certified ds e.1 = true)
(hb : ∀ e ∈ b, prec.certified ds e.1 = true) (hlt : upper ds a < lower ds b) :
mom (1-u) (ofHist a) < mom (1-u) (ofHist b) := by
have A := (prec.enclose_hist ds a ha).2
have B := (prec.enclose_hist ds b hb).1
rw [hd] at A B
exact lt_of_mul_lt_mul_left (A.trans_lt ((Nat.cast_lt.mpr hlt).trans_le B)) (Nat.cast_nonneg _)

theorem score {ds : List ℕ} {s u : ℝ} (hs : 0 ≤ s) (hsu : s < u) (hu : u < 1)
(hd : qExpo 1 0 ds = u) (hw : (10097:ℝ)/10000 ≤ 12^u)
(hc : passes ds = true) :
∃ order solve W, DFTProgram order solve W ∧
(fun n : ℕ => (W n : ℝ)) =O[atTop]
(fun n : ℕ => (n : ℝ) * (Real.log (n : ℝ)) ^ (1-s)) := by
simp only [passes, Bool.and_eq_true, decide_eq_true_eq, List.all_eq_true] at hc
obtain ⟨⟨⟨⟨⟨⟨hp, ht⟩, hlt⟩, hfloor⟩, hsum⟩, hsize⟩, hsmall⟩ := hc
have hmass : mom 1 (ofHist BaseUnit.blockHist) ≤ 742704 := by
rw [mo]
simpa [total, Function.comp_def] using
(show (total id BaseUnit.blockHist : ℝ) ≤ 742704 by exact_mod_cast hsum)
rw [← Moment.card_ofHist] at hsize
have B := (prec.enclose_hist ds BaseUnit.targetHist ht).1
rw [hd] at B
have hval : (737415:ℝ) * prec.scale ≤ (lower ds BaseUnit.targetHist : ℝ) := by
exact_mod_cast hfloor
have hB : (737415:ℝ) ≤ mom (1-u) (ofHist BaseUnit.targetHist) := by
apply le_of_mul_le_mul_left (a := (prec.scale:ℝ)) _ (by norm_num [prec])
rw [mul_comm (prec.scale : ℝ) 737415]
exact hval.trans B
have hden := mul_le_mul hw hB (by norm_num) (by positivity)
apply AdaptiveTensor.bound_of_raw hs hsu hu hsmall (moment_lt hd hp ht hlt)
· linarith
· have hcard : ((ofHist BaseUnit.targetHist).card : ℝ) ≤ 52896 := by exact_mod_cast hsize
linarith

end FourierSearch.RateCertificate
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Submission.Work.U7604.Chain.FourierTB.Main

open OAI.PowerSaving Asymptotics Filter Real

namespace FourierSearch

/-- The compiler charges an extra squared iterated logarithm. Any strictly
larger log exponent absorbs that factor in the public DFT cost model. -/
theorem bound_of_engine {z p : ℝ} (engine : RippleEngine.{0} z)
(hz : z ≤ 1) (hp : z < p) :
∃ order solve W, DFTProgram order solve W ∧
(fun n : ℕ => (W n : ℝ)) =O[atTop]
(fun n : ℕ => (n : ℝ) * (log (n : ℝ)) ^ p) := by
obtain ⟨order, solve, W, program, work, _⟩ := dft_program_of_engine engine hz
refine ⟨order, solve, W, program, work.trans (isBigO_iff.mpr ⟨1, ?_⟩)⟩
filter_upwards [targetTime_le_eventually hp (show (0 : ℝ) < 1 by norm_num)] with n hn
rwa [Real.norm_of_nonneg (targetTime_nonneg _ n),
Real.norm_of_nonneg (mul_nonneg (Nat.cast_nonneg n) (rpow_nonneg (log_natCast_nonneg n) p))]

end FourierSearch
Loading