File size: 4,964 Bytes
2f887db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.Computability.PerfectCompleteness.Machines.CanonicalKeyShapeMachineLemmas
import OAI.Computability.PerfectCompleteness.Reduction.ExactPreliminaryTarget

namespace OAI

section

namespace PerfectCompleteness.ExactTargetOnlineEncoding

open UniqueGamesTheorem.Foundations.Complexity
open scoped Classical

noncomputable section

private theorem encodeWords_flatMap {α : Type*} (xs : List α) (words : α → List Nat) :
    encodeWords (xs.flatMap words) = xs.flatMap (fun x => encodeWords (words x)) := by
  induction xs with
  | nil => rfl
  | cons x xs ih => simp only [List.flatMap_cons, encodeWords_append, ih]

variable {branch : Nat → Nat} {n t v m : Nat} [NeZero m]
    (clauses : Fin m → SourceClause.NormalizedClause v) (rows repeats : Nat → Nat)
    (hn : 0 < n) (hbranch : ∀ k < n, 0 < branch k)
    (hrows : ∀ k, 0 < rows (k + 1)) (δ : ℚ)

local notation "F" => FinitePreliminaryCompletion.blockFamily clauses branch n t rows repeats
local notation "C" => CompletedSignedLaw.Completed (t := t) clauses rows repeats hn hbranch hrows δ
local notation "order" => CompletedVisitOrder.completedOrder
  (t := t) clauses rows repeats hn hbranch hrows δ
local notation "target" => ExactPreliminaryTarget.construct
  (t := t) clauses rows repeats hn hbranch hrows δ
local notation "edge" => ExactPreliminaryTarget.entry
  (t := t) clauses rows repeats hn hbranch hrows δ

def leftKeys (occurrences : List C) := occurrences.map (fun e => CanonicalGame.leftKey F e.1)

def rightKeys (occurrences : List C) := occurrences.map (fun e => CanonicalGame.rightKey F e.1)

theorem left_online (earlier suffix : List C) (e : C) (split : order = earlier ++ e :: suffix) :
    CanonicalOnlineNames.onlineID (leftKeys (t := t) clauses rows repeats hn hbranch hrows δ earlier)
        (CanonicalGame.leftKey F e.1) = (edge e).left.val := by
  change _ = (BinaryNameSearch.payloads (CanonicalVertexNames.tokens
    (((order).map Sigma.fst).map (CanonicalGame.leftKey F)))).idxOf
      (CanonicalVertexNames.payload (CanonicalGame.leftKey F e.1))
  rw [List.map_map, split, List.map_append, List.map_cons]
  exact CanonicalOnlineNames.onlineID_eq_global _ _ _

theorem right_online (earlier suffix : List C) (e : C) (split : order = earlier ++ e :: suffix) :
    CanonicalOnlineNames.onlineID (rightKeys (t := t) clauses rows repeats hn hbranch hrows δ earlier)
        (CanonicalGame.rightKey F e.1) = (edge e).right.val := by
  change _ = (BinaryNameSearch.payloads (CanonicalVertexNames.tokens
    (((order).map Sigma.fst).map (CanonicalGame.rightKey F)))).idxOf
      (CanonicalVertexNames.payload (CanonicalGame.rightKey F e.1))
  rw [List.map_map, split, List.map_append, List.map_cons]
  exact CanonicalOnlineNames.onlineID_eq_global _ _ _

def onlineWords (earlier : List C) (e : C) : List Nat :=
  [CanonicalOnlineNames.onlineID
      (leftKeys (t := t) clauses rows repeats hn hbranch hrows δ earlier)
      (CanonicalGame.leftKey F e.1),
    CanonicalOnlineNames.onlineID
      (rightKeys (t := t) clauses rows repeats hn hbranch hrows δ earlier)
      (CanonicalGame.rightKey F e.1)] ++ Encoding.tableWords (edge e).projection

theorem onlineWords_eq (earlier suffix : List C) (e : C)
    (split : order = earlier ++ e :: suffix) :
    onlineWords (t := t) clauses rows repeats hn hbranch hrows δ earlier e =
      Encoding.edgeWords (edge e) := by
  unfold onlineWords Encoding.edgeWords
  rw [left_online (t := t) clauses rows repeats hn hbranch hrows δ earlier suffix e split,
    right_online (t := t) clauses rows repeats hn hbranch hrows δ earlier suffix e split]

theorem reverse_edge_fields {l r q : Nat} (e : Edge l r q) (tail : List Bool) :
    (encodeWords (Encoding.tableWords e.projection)).reverse ++
      ((encodeWord e.right.val).reverse ++ ((encodeWord e.left.val).reverse ++ tail)) =
      (encodeWords (Encoding.edgeWords e)).reverse ++ tail := by
  simp only [Encoding.edgeWords, encodeWords_append, encodeWords,
    List.append_nil, List.reverse_append, List.append_assoc]

theorem target_gameBits :
    Encoding.gameBits target =
      encodeWords [(order).length, (order).length,
        FinitePreliminaryCompletion.alphabet branch n t δ, (order).length] ++
      (order).flatMap (fun e => encodeWords (Encoding.edgeWords (edge e))) := by
  change encodeWords
    ([(CompletedVisitOrder.rawOrder (t := t) clauses rows repeats hn hbranch hrows δ).length,
      (CompletedVisitOrder.rawOrder (t := t) clauses rows repeats hn hbranch hrows δ).length,
      FinitePreliminaryCompletion.alphabet branch n t δ, ((order).map edge).length] ++
        ((order).map edge).flatMap Encoding.edgeWords) = _
  rw [encodeWords_append, encodeWords_flatMap]
  apply congrArg₂ List.append
  · apply congrArg encodeWords
    simp only [List.length_map]
    simp only [CompletedVisitOrder.rawOrder, List.length_map]
  · simp only [List.flatMap_map]

end
end PerfectCompleteness.ExactTargetOnlineEncoding

end

end OAI