File size: 4,869 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
116
import Mathlib
import OAI.Computability.MinUncut.PCP.Occurrences
import OAI.Computability.MinUncut.Search.FiniteQueryFamily

namespace OAI

section
namespace MinUncut.Outer
open MinUncut.Inner MinUncut.FiniteProof
open MinUncutGames.Foundations.Hastad.SourceOccurrences

def equationPair (N : β„•) : Equation (Fin N) ≃ ((Fin 3 β†’ Fin N) Γ— Fβ‚‚) where
  toFun E := (E.names,E.rhs)
  invFun p := ⟨p.1,p.2⟩
  left_inv _ := rfl
  right_inv _ := rfl

def fieldEncoding : Encoding Fβ‚‚ := ⟨2,Equiv.refl _⟩

def equationEncoding (N : β„•) : Encoding (Equation (Fin N)) :=
  let a := ((Encoding.fin 3).function (Encoding.fin N)).prod fieldEncoding
  ⟨a.size,(equationPair N).trans a.code⟩

def secondQuestionEncoding (N : β„•) : Encoding (SecondQuestion (Fin N)) :=
  (Encoding.fin N).sum (equationEncoding N)

def questionEncoding (N t : β„•) : Encoding (FamilyQuestion (Fin N) (Fin t)) :=
  ((Encoding.fin t).function (equationEncoding N)).sum
    ((Encoding.fin t).function (secondQuestionEncoding N))

def ambientEncoding (t : β„•) : Encoding (Fin t β†’ Triple) :=
  (Encoding.fin t).function ((Encoding.fin 3).function fieldEncoding)

instance validDecidable {N : β„•} (E : Equation (Fin N)) (a : Triple) : Decidable (Valid E a) :=
  inferInstanceAs (Decidable (parity a=E.rhs ∧ βˆ€p p', E.names p=E.names p' β†’ a p=a p'))

def encodeFirst {N t : β„•} (U : Fin t β†’ Equation (Fin N)) (a : FirstAlphabet U) : Fin t β†’ Triple :=
  fun j => (a j).val

def decodeFirst {N t : β„•} (U : Fin t β†’ Equation (Fin N)) (x : Fin t β†’ Triple) :
    Option (FirstAlphabet U) :=
  if h : βˆ€j, Valid (U j) (x j) then some (fun j => ⟨x j,h j⟩) else none

lemma decodeFirst_encodeFirst {N t : β„•} (U : Fin t β†’ Equation (Fin N)) (a : FirstAlphabet U) :
    decodeFirst U (encodeFirst U a)=some a := by
  have ha : βˆ€j, Valid (U j) (encodeFirst U a j) := fun j => (a j).property
  simp only [decodeFirst,dite_eq_left ha]
  rfl

lemma secondSlotCount_le {N : β„•} (q : SecondQuestion (Fin N)) : secondSlotCount q≀3 := by
  cases q <;> norm_num [secondSlotCount]

def encodeSecond {N t : β„•} (Q : Fin t β†’ SecondQuestion (Fin N)) (a : SecondAlphabet Q) : Fin t β†’ Triple :=
  fun j k => if h : k.val<secondSlotCount (Q j) then a j ⟨k.val,h⟩ else 0

def decodeSecond {N t : β„•} (Q : Fin t β†’ SecondQuestion (Fin N)) (x : Fin t β†’ Triple) : SecondAlphabet Q :=
  fun j k => x j ⟨k.val,k.isLt.trans_le (secondSlotCount_le (Q j))⟩

lemma decodeSecond_encodeSecond {N t : β„•} (Q : Fin t β†’ SecondQuestion (Fin N)) (a : SecondAlphabet Q) :
    decodeSecond Q (encodeSecond Q a)=a := by
  funext j k
  exact dite_eq_left k.isLt

def encodeAlphabet {N t : β„•} : (q : FamilyQuestion (Fin N) (Fin t)) β†’ FamilyAlphabet q β†’ (Fin t β†’ Triple)
  | .inl U => encodeFirst U
  | .inr Q => encodeSecond Q

def decodeAlphabet {N t : β„•} : (q : FamilyQuestion (Fin N) (Fin t)) β†’ (Fin t β†’ Triple) β†’ Option (FamilyAlphabet q)
  | .inl U => decodeFirst U
  | .inr Q => fun x => some (decodeSecond Q x)

lemma decodeAlphabet_encodeAlphabet {N t : β„•} (q : FamilyQuestion (Fin N) (Fin t)) (a : FamilyAlphabet q) :
    decodeAlphabet q (encodeAlphabet q a)=some a := by
  cases q with
  | inl U => exact decodeFirst_encodeFirst U a
  | inr Q => exact congrArg some (decodeSecond_encodeSecond Q a)

def extendTable {N t : β„•} (q : FamilyQuestion (Fin N) (Fin t)) (R : FamilyAlphabet q β†’ Bool) :
    (Fin t β†’ Triple) β†’ Bool := fun x => ((decodeAlphabet q x).map R).getD false

lemma extendTable_eval {N t : β„•} (q : FamilyQuestion (Fin N) (Fin t)) (R : FamilyAlphabet q β†’ Bool)
    (a : FamilyAlphabet q) : extendTable q R (encodeAlphabet q a)=R a := by
  simp only [extendTable,decodeAlphabet_encodeAlphabet,Option.map_some,Option.getD_some]

lemma extendTable_injective {N t : β„•} (q : FamilyQuestion (Fin N) (Fin t)) :
    Function.Injective (extendTable q) := by
  intro R S h
  funext a
  simpa only [extendTable_eval] using congrFun h (encodeAlphabet q a)

def paddedVariableEncoding (N t : β„•) :
    Encoding (FamilyQuestion (Fin N) (Fin t) Γ— ((Fin t β†’ Triple) β†’ Bool)) :=
  (questionEncoding N t).prod ((ambientEncoding t).function Encoding.bool)

def variableCode {N t : β„•} (v : FamilyVariable (Fin N) (Fin t)) : Fin (paddedVariableEncoding N t).size :=
  (paddedVariableEncoding N t).code (v.1,extendTable v.1 v.2.val)

lemma variableCode_injective {N t : β„•} : Function.Injective (variableCode (N := N) (t := t)) := by
  rintro ⟨q,R⟩ ⟨s,S⟩ h
  have hp := (paddedVariableEncoding N t).code.injective h
  have hq : q=s := congrArg Prod.fst hp
  subst s
  have hR : R=S := Subtype.ext (extendTable_injective q (congrArg Prod.snd hp))
  subst S
  rfl

lemma paddedVariableEncoding_size (N t : β„•) :
    (paddedVariableEncoding N t).size=
      ((N^3*2)^t+(N+N^3*2)^t)*2^((2^3)^t) := rfl

end MinUncut.Outer

end

end OAI