File size: 3,738 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
import OAI.MathematicalPhysics.AlternatingFlow.ProfileNames
import OAI.MathematicalPhysics.AlternatingFlow.DecoderBounds

namespace OAI

section DecoderNamesDevelopment

open scoped BigOperators Topology ContDiff
open Filter

namespace AlternatingNS.Effective
attribute [local instance] Arithmetic.rationalCoding

lemma decoderBound : Primrecβ‚‚ Quantitative.decoderBound :=
  Primrec.nat_add.comp (Primrec.const 1)
    (Primrec.nat_mul.comp
      (nat_pow.comp (Primrec.nat_mul.comp (Primrec.const 3)
        (Primrec.nat_sub.comp Primrec.fst (Primrec.const 1))) Primrec.snd)
      (transitionBound.comp Primrec.snd))

lemma rat_fract : Primrec (fun q : β„š => Int.fract q) :=
  Arithmetic.rat_sub.comp Primrec.id (Arithmetic.rat_intCast.comp Arithmetic.rat_floor)

lemma frac_cast (q : β„š) : ((Int.fract q : β„š) : ℝ) = Int.fract (q : ℝ) := by
  simp only [Int.fract, Rat.cast_sub, Rat.cast_intCast, Rat.floor_cast]

lemma periodizer_named : Named (fun z : (β„š Γ— β„š) Γ— β„š => Profiles.periodizer z.1.1 z.1.2 z.2) := by
  have hv : Computable (fun z : (β„š Γ— β„š) Γ— β„š => Int.fract z.2) := rat_fract.to_comp.comp Computable.snd
  have hA : Computable (fun z : (β„š Γ— β„š) Γ— β„š => (Int.fract z.2 - z.1.1)/(z.1.2-z.1.1)) :=
    Arithmetic.rat_div.to_comp.comp
      (Arithmetic.rat_sub.to_comp.comp hv (Computable.fst.comp Computable.fst))
      (Arithmetic.rat_sub.to_comp.comp (Computable.snd.comp Computable.fst)
        (Computable.fst.comp Computable.fst))
  exact ((Named.rational hv).sub (transition_named.comp hA)).congr (by
    intro z
    simp only [Function.comp_def, Profiles.periodizer, Rat.cast_div, Rat.cast_sub]
    rw [frac_cast])

lemma decoder_named : Named (fun z : β„• Γ— β„š => Profiles.decoder z.1 (z.2 : ℝ)) := by
  let m (b : β„•) : β„š := ((b : β„š)-2)/((b : β„š)-1)
  have hm : Computable m := Arithmetic.rat_div.to_comp.comp
    (Arithmetic.rat_sub.to_comp.comp Arithmetic.rat_natCast.to_comp (Computable.const 2))
    (Arithmetic.rat_sub.to_comp.comp Arithmetic.rat_natCast.to_comp (Computable.const 1))
  have ha : Computable (fun z : β„• Γ— β„š => (2*m z.1+1)/3) := Arithmetic.rat_div.to_comp.comp
    (Arithmetic.rat_add.to_comp.comp
      (Arithmetic.rat_mul.to_comp.comp (Computable.const 2) (hm.comp Computable.fst))
      (Computable.const 1)) (Computable.const 3)
  have hc : Computable (fun z : β„• Γ— β„š => (m z.1+2)/3) := Arithmetic.rat_div.to_comp.comp
    (Arithmetic.rat_add.to_comp.comp (hm.comp Computable.fst) (Computable.const 2)) (Computable.const 3)
  exact (periodizer_named.comp ((ha.pair hc).pair Computable.snd)).congr (by
    intro z; simp [Profiles.decoder, Encoding.tailMax, m])

lemma Named.decoder {A : Type*} [Primcodable A] (b : A β†’ β„•) (hb : Computable b)
    (hbase : βˆ€ x, 2 ≀ b x) {f : A β†’ ℝ} (hf : Named f) :
    Named (fun x => Profiles.decoder (b x) (f x)) := by
  let L (x : A) : β„š := Quantitative.decoderBound (b x) 1
  have hL : Computable L := Arithmetic.rat_natCast.to_comp.comp
    (decoderBound.to_comp.comp hb (Computable.const 1))
  have hg : Named (fun z : A Γ— β„š => Profiles.decoder (b z.1) (z.2 : ℝ)) :=
    Named.comp (g := fun z : A Γ— β„š => (b z.1, z.2)) decoder_named
      ((hb.comp Computable.fst).pair Computable.snd)
  have hlip (a : A) (x y : ℝ) : |Profiles.decoder (b a) x - Profiles.decoder (b a) y| ≀
      (L a : ℝ) * |x-y| := by
    simpa only [L, Rat.cast_natCast] using jet_one_lipschitz (Profiles.decoder_smooth _ (hbase a))
      (Quantitative.decoderBound (b a) 1) (Quantitative.decoder_jet_bound (b a) (hbase a) 1) x y
  exact Named.apply_lipschitz (fun x => Profiles.decoder (b x)) L hL
    (fun _ => Nat.cast_nonneg _) hlip hg hf

end AlternatingNS.Effective

end DecoderNamesDevelopment

end OAI