File size: 4,383 Bytes
92416a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import Mathlib
import OAI.Computability.VertexCover.Machines.GraphNumber
import OAI.Computability.VertexCover.Machines.BinaryOutput

namespace OAI

section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
                                
section

namespace VertexCover.Machine.GraphMachine
open LabelCover
noncomputable section
variable {a b d : ℕ}

def candidates (I : FixedLC a b) (d : ℕ) : List (ℕ × ℕ) :=
  (List.range (count I d * count I d)).map (fun i => (i/count I d,i%count I d))
def edgeValues (I : FixedLC a b) (d : ℕ) (t : ℝ) : List (ℕ × ℕ) :=
  (candidates I d).filter (fun p => test (d := d) t (I,p))

theorem candidates_eq (I : FixedLC a b) (d : ℕ) :
    candidates I d = (List.ofFn fun e : Fin (count I d * count I d) => finProdFinEquiv.symm e).map
      (fun p => (p.1.val,p.2.val)) := by
  apply List.ext_getElem
  · simp [candidates]
  · intro i hi hj
    simp only [candidates,List.getElem_map,List.getElem_range,List.getElem_ofFn]
    rfl

theorem edgeValues_eq (I : FixedLC a b) (d : ℕ) (t : ℝ) :
    edgeValues I d t=(explicitGraph I d t).edges.map (fun p => (p.1.val,p.2.val)) := by
  classical
  rw [edgeValues,candidates_eq,List.filter_map]
  change List.map _ (List.filter _ _) = List.map _ (List.filter _ _)
  congr 1
  apply List.filter_congr
  intro p hp
  apply Bool.eq_iff_iff.mpr
  exact (test_correct I t p.1 p.2).trans decide_eq_true_iff.symm

def candidatesPoly (ha : 0<a) (hb : 0<b) (d : ℕ) :
    Poly (FixedLC.code (a := a) (b := b)) (listBits (prodBits natBits natBits)) (fun I => candidates I d) := by
  let c := countPoly (a := a) hb d
  let n := (c.pair c).comp Poly.natMul
  let count := (Poly.fst (FixedLC.code (a := a) (b := b)) natBits).comp c
  let i := Poly.snd (FixedLC.code (a := a) (b := b)) natBits
  let pair := ((i.pair count).comp Poly.natDiv).pair ((i.pair count).comp Poly.natMod)
  exact Poly.tabulate FixedLC.code (prodBits natBits natBits) (FixedLC.one ha hb) (0,0) n pair

def edgeValuesPoly (ha : 0<a) (hb : 0<b) (d : ℕ) (t : ℝ) :
    Poly (FixedLC.code (a := a) (b := b)) (listBits (prodBits natBits natBits)) (fun I => edgeValues I d t) :=
  (((Poly.identity FixedLC.code).pair (candidatesPoly ha hb d)).comp
    (Poly.listFilterWith FixedLC.code (prodBits natBits natBits) (FixedLC.one ha hb) (0,0)
      (testPoly (d := d) ha hb t))).congr (fun _ => rfl)

def endpointPoly : Poly (prodBits natBits natBits) (listBits natBits) (fun p : ℕ × ℕ => [p.1,p.2]) :=
  (((Poly.fst natBits natBits).pair ((Poly.snd natBits natBits).comp (Poly.listSingleton natBits))).comp
    (Poly.listCons natBits)).congr (fun _ => rfl)
def names (I : FixedLC a b) (d : ℕ) (t : ℝ) : List ℕ :=
  [count I d] ++ List.range (count I d) ++ [(edgeValues I d t).length] ++
    (edgeValues I d t).flatMap (fun p => [p.1,p.2])
def namesPoly (ha : 0<a) (hb : 0<b) (d : ℕ) (t : ℝ) :
    Poly (FixedLC.code (a := a) (b := b)) (listBits natBits) (fun I => names I d t) := by
  let n := countPoly (a := a) hb d
  let head := n.comp (Poly.listSingleton natBits)
  let verts := n.comp Poly.range
  let es := edgeValuesPoly ha hb d t
  let ne := ((es.comp (Poly.listLength (prodBits natBits natBits) (0,0))).comp (Poly.listSingleton natBits))
  let ends := es.comp (Poly.listFlatMap (prodBits natBits natBits) natBits (0,0) 0 endpointPoly)
  let one := (head.pair verts).comp (Poly.listAppend natBits 0)
  let two := (one.pair ne).comp (Poly.listAppend natBits 0)
  exact ((two.pair ends).comp (Poly.listAppend natBits 0)).congr (fun _ => rfl)

theorem names_bits (I : FixedLC a b) (d : ℕ) (t : ℝ) :
    (names I d t).flatMap UniqueGames.BinaryEncoding.nameBits = (explicitGraph I d t).bits := by
  rw [names,edgeValues_eq]
  simp only [List.length_map,List.flatMap_map]
  rfl

def outputPoly (ha : 0<a) (hb : 0<b) (d : ℕ) (t : ℝ) :
    Poly (FixedLC.code (a := a) (b := b)) ExplicitGraph.bits (fun I => explicitGraph I d t) :=
  ((namesPoly ha hb d t).comp Poly.nameList).encodeCongr id (fun _ => rfl) (fun I => names_bits I d t)
end
end VertexCover.Machine.GraphMachine
end


end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end

end OAI