File size: 5,887 Bytes
4a56cd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import OAI.NumberTheory.Ostmann.Arithmetic.FrequencyTreeSum
import OAI.NumberTheory.Ostmann.Characters.SignedFrequencySum

namespace OAI

/-! # The full arithmetic frequency-tree budget -/

namespace Ostmann

open scoped BigOperators Classical

noncomputable def pairedFrequencyKernel (S : Finset β„€) (D : ℝ)
    (root left right : S Γ— S) : ℝ :=
  2 * D ^ 2 *
    (((reducedFrequency ((left.1 : β„€).natAbs.gcd (right.1 : β„€).natAbs) (root.1 : β„€).natAbs).lcm
       (reducedFrequency ((left.2 : β„€).natAbs.gcd (right.2 : β„€).natAbs) (root.2 : β„€).natAbs) : β„•) : ℝ)⁻¹

theorem pairedFrequencyKernel_sum_le (S : Finset β„€) (N : β„•) (D : ℝ) (hD : 0 ≀ D)
    (hS : βˆ€ s ∈ S, s β‰  0 ∧ s.natAbs ≀ N)
    (hdiv : βˆ€ v ∈ S, βˆ€ w ∈ S, ((v.natAbs.gcd w.natAbs).divisors.card : ℝ) ≀ D)
    (left right : S Γ— S) :
    (βˆ‘ root : S Γ— S, pairedFrequencyKernel S D root left right) ≀
      8 * D ^ 4 * (1 + Real.log N) ^ 3 := by
  let g := (left.1 : β„€).natAbs.gcd (right.1 : β„€).natAbs
  let h := (left.2 : β„€).natAbs.gcd (right.2 : β„€).natAbs
  have hg : g β‰  0 := Nat.ne_of_gt (Nat.gcd_pos_of_pos_left _
    (Int.natAbs_pos.mpr (hS _ left.1.property).1))
  have hh : h β‰  0 := Nat.ne_of_gt (Nat.gcd_pos_of_pos_left _
    (Int.natAbs_pos.mpr (hS _ left.2.property).1))
  have hgd : (g.divisors.card : ℝ) ≀ D := hdiv _ left.1.property _ right.1.property
  have hhd : (h.divisors.card : ℝ) ≀ D := hdiv _ left.2.property _ right.2.property
  have hpair :
      (βˆ‘ s : S, βˆ‘ t : S,
        (((reducedFrequency g (s : β„€).natAbs).lcm (reducedFrequency h (t : β„€).natAbs) : β„•) : ℝ)⁻¹) =
      βˆ‘ s ∈ S, βˆ‘ t ∈ S,
        (((reducedFrequency g s.natAbs).lcm (reducedFrequency h t.natAbs) : β„•) : ℝ)⁻¹ := by
    rw [Finset.sum_coe_sort S (fun s : β„€ => βˆ‘ t : S,
      (((reducedFrequency g s.natAbs).lcm (reducedFrequency h (t : β„€).natAbs) : β„•) : ℝ)⁻¹)]
    exact Finset.sum_congr rfl fun s _ => Finset.sum_coe_sort S (fun t : β„€ =>
      (((reducedFrequency g s.natAbs).lcm (reducedFrequency h t.natAbs) : β„•) : ℝ)⁻¹)
  calc
    _ = 2 * D ^ 2 * (βˆ‘ s : S, βˆ‘ t : S,
        (((reducedFrequency g (s : β„€).natAbs).lcm (reducedFrequency h (t : β„€).natAbs) : β„•) : ℝ)⁻¹) := by
      simp only [pairedFrequencyKernel, Fintype.sum_prod_type, ← Finset.mul_sum, g, h]
    _ ≀ 2 * D ^ 2 * (4 * (g.divisors.card : ℝ) * h.divisors.card * (1 + Real.log N) ^ 3) := by
      rw [hpair]
      exact mul_le_mul_of_nonneg_left (signed_reducedFrequency_lcm_sum_le S S N g h hS hS hg hh)
        (by positivity)
    _ ≀ 2 * D ^ 2 * (4 * D * D * (1 + Real.log N) ^ 3) := by
      apply mul_le_mul_of_nonneg_left _ (by positivity)
      have hlog : 0 ≀ (1 + Real.log N) ^ 3 := by
        have hbase := Real.log_natCast_nonneg N
        positivity
      exact mul_le_mul_of_nonneg_right
        (mul_le_mul (mul_le_mul_of_nonneg_left hgd (by norm_num)) hhd
          (Nat.cast_nonneg _) (by positivity)) hlog
    _ = _ := by ring

noncomputable def pairedFrequencyLeaf (S : Finset β„€) (V : β„•) (x : S Γ— S) : ℝ :=
  if (x.1 : β„€).natAbs ≀ V ∧ (x.2 : β„€).natAbs ≀ V then 1 else 0

theorem pairedFrequencyLeaf_sum_le (S : Finset β„€) (V : β„•)
    (hS : βˆ€ s ∈ S, s β‰  0) :
    (βˆ‘ x : S Γ— S, pairedFrequencyLeaf S V x) ≀ (2 * (V : ℝ)) ^ 2 := by
  let T := S.filter fun s => s.natAbs ≀ V
  have hT : βˆ€ s ∈ T, s β‰  0 ∧ s.natAbs ≀ V := by
    intro s hs
    exact ⟨hS s (Finset.mem_filter.mp hs).1, (Finset.mem_filter.mp hs).2⟩
  have hcard : (T.card : ℝ) ≀ 2 * V := by
    have hbound := sum_signed_magnitudes_le T V hT (fun _ => (1 : ℝ)) (by intros; norm_num)
    simpa using hbound
  have hsingle : (βˆ‘ s : S, if (s : β„€).natAbs ≀ V then (1 : ℝ) else 0) = T.card := by
    rw [Finset.sum_coe_sort S (fun s : β„€ => if s.natAbs ≀ V then (1 : ℝ) else 0)]
    simp only [← Finset.sum_filter, Finset.sum_const, nsmul_eq_mul, mul_one, T]
  have hterm (x y : S) : pairedFrequencyLeaf S V (x, y) =
      (if (x : β„€).natAbs ≀ V then (1 : ℝ) else 0) *
        (if (y : β„€).natAbs ≀ V then (1 : ℝ) else 0) := by
    unfold pairedFrequencyLeaf
    split_ifs <;> simp_all
  calc
    _ = (T.card : ℝ) ^ 2 := by
      rw [Fintype.sum_prod_type, pow_two, ← hsingle, Finset.sum_mul_sum]
      simp only [hterm]
    _ ≀ _ := pow_le_pow_leftβ‚€ (Nat.cast_nonneg _) hcard 2

/-- Root-first elimination leaves only the two histories' leaf frequencies.
The exponent `2^n-1` is the exact number of internal nodes. -/
theorem arithmetic_frequency_tree_sum_le (S : Finset β„€) (N V : β„•) (D : ℝ)
    (hD : 0 ≀ D) (hS : βˆ€ s ∈ S, s β‰  0 ∧ s.natAbs ≀ N)
    (hdiv : βˆ€ v ∈ S, βˆ€ w ∈ S, ((v.natAbs.gcd w.natAbs).divisors.card : ℝ) ≀ D)
    (n : β„•) :
    (βˆ‘ x : FrequencyTree (S Γ— S) n,
      frequencyTreeWeight (pairedFrequencyKernel S D) (pairedFrequencyLeaf S V) n x) ≀
      (8 * D ^ 4 * (1 + Real.log N) ^ 3) ^ (2 ^ n - 1) * (2 * (V : ℝ)) ^ (2 * 2 ^ n) := by
  have hC : 0 ≀ 8 * D ^ 4 * (1 + Real.log N) ^ 3 := by
    have hlog := Real.log_natCast_nonneg N
    positivity
  have hmain := frequencyTree_sum_le (pairedFrequencyKernel S D) (pairedFrequencyLeaf S V)
    (8 * D ^ 4 * (1 + Real.log N) ^ 3) (by intros; unfold pairedFrequencyKernel; positivity)
    (by intros; unfold pairedFrequencyLeaf; split_ifs <;> norm_num) hC
    (pairedFrequencyKernel_sum_le S N D hD hS hdiv) n
  apply hmain.trans
  have hleaf := pairedFrequencyLeaf_sum_le S V (fun s hs => (hS s hs).1)
  calc
    _ ≀ (8 * D ^ 4 * (1 + Real.log N) ^ 3) ^ (2 ^ n - 1) *
        ((2 * (V : ℝ)) ^ 2) ^ (2 ^ n) :=
      mul_le_mul_of_nonneg_left (pow_le_pow_leftβ‚€
        (Finset.sum_nonneg fun x _ => by unfold pairedFrequencyLeaf; split_ifs <;> norm_num)
        hleaf _) (pow_nonneg hC _)
    _ = _ := by rw [← pow_mul]

end Ostmann

end OAI