roseking's picture
Add lean source and binary files (part 64)
92416a2 verified
Raw History Blame Contribute Delete
22.2 kB
46
structure Encoding (α : Type) where
body · 2 lines
  size : ℕ
  code : α ≃ Fin size
52
def fin (n : ℕ) : Encoding (Fin n) := ⟨n, Equiv.refl _⟩
53
def bool : Encoding Bool := ⟨2, finTwoEquiv.symm⟩
54
def unit : Encoding Unit := ⟨1, finOneEquiv.symm⟩
56
def prod {α β : Type} (a : Encoding α) (b : Encoding β) : Encoding (α × β) :=
body · 1 line
  ⟨a.size * b.size, (Equiv.prodCongr a.code b.code).trans finProdFinEquiv⟩
59
def sum {α β : Type} (a : Encoding α) (b : Encoding β) : Encoding (α ⊕ β) :=
body · 1 line
  ⟨a.size + b.size, (Equiv.sumCongr a.code b.code).trans finSumFinEquiv⟩
62
def function {α β : Type} (a : Encoding α) (b : Encoding β) : Encoding (α → β) where
body · 6 lines
  size := b.size ^ a.size
  code := (show (α → β) ≃ (Fin a.size → Fin b.size) from
    { toFun := fun f i => b.code (f (a.code.symm i))
      invFun := fun f x => b.code.symm (f (a.code x))
      left_inv := by intro f; funext x; simp
      right_inv := by intro f; funext i; simp }).trans finFunctionFinEquiv
70
def enumerate {α : Type} (a : Encoding α) : List α := List.ofFn a.code.symm
72
@[simp] theorem length_enumerate {α : Type} (a : Encoding α) :
    a.enumerate.length = a.size := by simp [enumerate]
75
theorem mem_enumerate {α : Type} (a : Encoding α) (x : α) : x ∈ a.enumerate := by
proof · 2 lines
  rw [enumerate, List.mem_ofFn']
  exact ⟨a.code x, a.code.symm_apply_apply x⟩
79
theorem nodup_enumerate {α : Type} (a : Encoding α) : a.enumerate.Nodup :=
proof · 1 line
  List.nodup_ofFn_ofInjective a.code.symm.injective
82
theorem card_eq_size {α : Type} [Fintype α] (a : Encoding α) :
    Fintype.card α = a.size := by
proof · 1 line
  simpa only [Fintype.card_fin] using Fintype.card_congr a.code
88
abbrev GlobalKey (V C I J : Type) := (V × Cube I) ⊕ ((C × Cube J) ⊕ Unit)
90
def globalEncoding {V C I J : Type}
    (v : Encoding V) («c» : Encoding C) (i : Encoding I) (j : Encoding J) :
    Encoding (GlobalKey V C I J) :=
body · 2 lines
  (v.prod (i.function Encoding.bool)).sum
    ((«c».prod (j.function Encoding.bool)).sum Encoding.unit)
96
@[simp] theorem globalEncoding_size {V C I J : Type}
    (v : Encoding V) («c» : Encoding C) (i : Encoding I) (j : Encoding J) :
    (globalEncoding v «c» i j).size =
      v.size * 2 ^ i.size + («c».size * 2 ^ j.size + 1) := rfl
101
def extendRestricted {J : Type} (valid : J → Bool)
    (f : Cube {j : J // valid j = true}) : Cube J :=
body · 1 line
  fun j => if h : valid j = true then f ⟨j, h⟩ else false
105
@[simp] theorem extendRestricted_valid {J : Type} (valid : J → Bool)
    (f : Cube {j : J // valid j = true}) (j : {j : J // valid j = true}) :
    extendRestricted valid f j.val = f j := by simp [extendRestricted, j.property]
109
theorem extendRestricted_injective {J : Type} (valid : J → Bool) :
    Function.Injective (extendRestricted valid) := by
proof · 4 lines
  intro f g h
  funext j
  have := congrFun h j.val
  simpa only [extendRestricted_valid] using this
116
@[simp] theorem restrictQuery_extendRestricted {J : Type} (valid : J → Bool)
    (f : Cube {j : J // valid j = true}) :
    restrictQuery valid (extendRestricted valid f) = f := by
proof · 2 lines
  funext j
  exact extendRestricted_valid valid f j
122
@[simp] theorem canonicalInput_half {I : Type} [Fintype I] [DecidableEq I]
    (i₀ : I) (f : HalfCube i₀) :
    canonicalInput i₀ f.val = f := by
proof · 2 lines
  apply Subtype.ext
  simp [canonicalInput, representative, f.property]
128
def assignmentOfKey {V C I J : Type}
    (v : Encoding V) («c» : Encoding C) (i : Encoding I) (j : Encoding J)
    (bits : GlobalKey V C I J → Bool) : Fin (globalEncoding v «c» i j).size → Bool :=
body · 1 line
  fun q => bits ((globalEncoding v «c» i j).code.symm q)
133
@[simp] theorem assignmentOfKey_code {V C I J : Type}
    (v : Encoding V) («c» : Encoding C) (i : Encoding I) (j : Encoding J)
    (bits : GlobalKey V C I J → Bool) (key : GlobalKey V C I J) :
    assignmentOfKey v «c» i j bits ((globalEncoding v «c» i j).code key) = bits key := by
proof · 1 line
  exact congrArg bits ((globalEncoding v «c» i j).code.symm_apply_apply key)
139
theorem assignmentOfKey_surjective {V C I J : Type}
    (v : Encoding V) («c» : Encoding C) (i : Encoding I) (j : Encoding J) :
    Function.Surjective (assignmentOfKey v «c» i j) := by
proof · 4 lines
  intro bits
  refine ⟨fun key => bits ((globalEncoding v «c» i j).code key), ?_⟩
  funext q
  exact congrArg bits ((globalEncoding v «c» i j).code.apply_symm_apply q)
151
def localAddress (vE : Encoding V) (cE : Encoding C) (iE : Encoding I) (jE : Encoding J)
    (v : V) («c» : C) (valid : J → Bool) (i₀ : I) (j₀ : {j : J // valid j = true}) :
    FoldedEquation.Address i₀ j₀ → Fin (globalEncoding vE cE iE jE).size
body · 2 lines
  | .inl f => (globalEncoding vE cE iE jE).code (.inl (v, f.val))
  | .inr g => (globalEncoding vE cE iE jE).code (.inr (.inl («c», extendRestricted valid g.val)))
158
theorem localAddress_injective
    (vE : Encoding V) (cE : Encoding C) (iE : Encoding I) (jE : Encoding J)
    (v : V) («c» : C) (valid : J → Bool) (i₀ : I) (j₀ : {j : J // valid j = true}) :
    Function.Injective (localAddress vE cE iE jE v «c» valid i₀ j₀) := by
proof · 20 lines
  intro a b h
  cases a with
  | inl a =>
    cases b with
    | inl b =>
      have h' := (globalEncoding vE cE iE jE).code.injective h
      have hval : a.val = b.val := congrArg Prod.snd (Sum.inl.inj h')
      exact congrArg Sum.inl (Subtype.ext hval)
    | inr b =>
      have h' := (globalEncoding vE cE iE jE).code.injective h
      cases h'
  | inr a =>
    cases b with
    | inl b =>
      have h' := (globalEncoding vE cE iE jE).code.injective h
      cases h'
    | inr b =>
      have h' := (globalEncoding vE cE iE jE).code.injective h
      have hext := congrArg Prod.snd (Sum.inl.inj (Sum.inr.inj h'))
      exact congrArg Sum.inr (Subtype.ext (extendRestricted_injective valid hext))
183
def conditionedOccurrence
    (vE : Encoding V) (cE : Encoding C) (iE : Encoding I) (jE : Encoding J)
    (v : V) («c» : C) (valid : J → Bool) (π : J → I)
    (i₀ : I) (j₀ : {j : J // valid j = true}) (f : Cube I) (g μ : Cube J) :
    Equation (Fin (globalEncoding vE cE iE jE).size) :=
body · 2 lines
  mapEquation (localAddress vE cE iE jE v «c» valid i₀ j₀)
    (FoldedEquation.conditionedEquation valid π i₀ j₀ f g μ)
192
theorem conditionedOccurrence_satisfied
    (vE : Encoding V) (cE : Encoding C) (iE : Encoding I) (jE : Encoding J)
    (v : V) («c» : C) (valid : J → Bool) (π : J → I)
    (i₀ : I) (j₀ : {j : J // valid j = true})
    (bits : Fin (globalEncoding vE cE iE jE).size → Bool)
    (f : Cube I) (g μ : Cube J) :
    satisfied (conditionedOccurrence vE cE iE jE v «c» valid π i₀ j₀ f g μ) bits =
      !(foldedAnswer i₀ (fun h => bits ((globalEncoding vE cE iE jE).code (.inl (v, h.val)))) f ^^
        conditionedFoldedAnswer valid j₀
          (fun h => bits ((globalEncoding vE cE iE jE).code
            (.inr (.inl («c», extendRestricted valid h.val))))) g ^^
        conditionedFoldedAnswer valid j₀
          (fun h => bits ((globalEncoding vE cE iE jE).code
            (.inr (.inl («c», extendRestricted valid h.val))))) (thirdQuery π f g μ)) := by
proof · 12 lines
  rw [conditionedOccurrence, satisfied_mapEquation]
  let tableA : HalfCube i₀ → Bool :=
    fun h => bits ((globalEncoding vE cE iE jE).code (.inl (v, h.val)))
  let tableB : HalfCube j₀ → Bool :=
    fun h => bits ((globalEncoding vE cE iE jE).code
      (.inr (.inl («c», extendRestricted valid h.val))))
  have hbits : bits ∘ localAddress vE cE iE jE v «c» valid i₀ j₀ =
      FoldedEquation.storedAssignment tableA tableB := by
    funext a
    cases a <;> rfl
  rw [hbits]
  exact FoldedEquation.conditionedEquation_satisfied valid π i₀ j₀ tableA tableB f g μ
221
def findValid {J : Type} (valid : J → Bool) : List J → Option {j : J // valid j = true}
body · 2 lines
  | [] => none
  | j :: rest => if h : valid j = true then some ⟨j, h⟩ else findValid valid rest
225
theorem findValid_none_iff {J : Type} (valid : J → Bool) (xs : List J) :
    findValid valid xs = none ↔ ∀ j ∈ xs, valid j = false := by
proof · 6 lines
  induction xs with
  | nil => simp [findValid]
  | cons j xs ih =>
    by_cases hj : valid j = true
    · simp [findValid, hj]
    · simp [findValid, hj, ih]
234
def firstValid {J : Type} (e : Encoding J) (valid : J → Bool) :
    Option {j : J // valid j = true} := findValid valid e.enumerate
237
theorem firstValid_none_iff {J : Type} (e : Encoding J) (valid : J → Bool) :
    firstValid e valid = none ↔ ∀ j, valid j = false := by
proof · 2 lines
  rw [firstValid, findValid_none_iff]
  exact ⟨fun h j => h j (e.mem_enumerate j), fun h j _ => h j⟩
242
def occurrenceList {Tape Name : Type} (tape : Encoding Tape)
    (emit : Tape → Equation Name) : List (Equation Name) := tape.enumerate.map emit
245
@[simp] theorem occurrenceList_length {Tape Name : Type} (tape : Encoding Tape)
    (emit : Tape → Equation Name) : (occurrenceList tape emit).length = tape.size := by
proof · 1 line
  simp [occurrenceList]
249
private theorem countP_cast_eq_sum {α : Type} (xs : List α) (p : α → Bool) :
    (xs.countP p : ℝ) = (xs.map (fun x => if p x then (1 : ℝ) else 0)).sum := by
proof · 3 lines
  induction xs with
  | nil => simp
  | cons x xs ih => cases hp : p x <;> simp [hp, ih, add_comm]
255
theorem countP_enumerate {Tape : Type} [Fintype Tape]
    (tape : Encoding Tape) (p : Tape → Bool) :
    (tape.enumerate.countP p : ℝ) = ∑ x, if p x then (1 : ℝ) else 0 := by
proof · 3 lines
  rw [countP_cast_eq_sum]
  simp only [Encoding.enumerate, List.map_ofFn, List.sum_ofFn]
  exact Fintype.sum_equiv tape.code.symm _ _ (fun _ => rfl)
262
theorem occurrenceList_acceptance {Tape Name : Type} [Fintype Tape]
    (tape : Encoding Tape) (emit : Tape → Equation Name) (bits : Name → Bool) :
    ((occurrenceList tape emit).countP (fun e => satisfied e bits) : ℝ) /
        (occurrenceList tape emit).length =
      𝔼 x, if satisfied (emit x) bits then (1 : ℝ) else 0 := by
proof · 4 lines
  rw [occurrenceList_length, Fintype.expect_eq_sum_div_card, tape.card_eq_size]
  congr 1
  simpa only [occurrenceList, List.countP_map, Function.comp_def] using
    countP_enumerate tape (fun x => satisfied (emit x) bits)
277
def clauseAnswerEncoding : Encoding PCP.ClauseAnswer := ⟨8, clauseAnswerFinEquiv⟩
279
def slotEncoding : Encoding PCP.Slot where
body · 6 lines
  size := 3
  code :=
    { toFun := fun s => match s with | .first => 0 | .second => 1 | .third => 2
      invFun := fun i => if i.val = 0 then .first else if i.val = 1 then .second else .third
      left_inv := by intro s; cases s <;> rfl
      right_inv := by decide }
287
def iEncoding (u : ℕ) : Encoding (I u) := (Encoding.fin u).function Encoding.bool
288
def jEncoding (u : ℕ) : Encoding (J u) := (Encoding.fin u).function clauseAnswerEncoding
289
def variableEncoding (F : Target.Formula) (u : ℕ) : Encoding (VariableContext F u) :=
body · 1 line
  (Encoding.fin u).function (Encoding.fin F.«variables»)
291
def clauseEncoding (F : Target.Formula) (u : ℕ) : Encoding (ClauseContext F u) :=
body · 1 line
  (Encoding.fin u).function (Encoding.fin F.clauses.length)
293
def slotContextEncoding (u : ℕ) : Encoding (SlotContext u) :=
body · 1 line
  (Encoding.fin u).function slotEncoding
296
def proofEncoding (F : Target.Formula) (u : ℕ) :
    Encoding (GlobalKey (VariableContext F u) (ClauseContext F u) (I u) (J u)) :=
body · 1 line
  globalEncoding (variableEncoding F u) (clauseEncoding F u) (iEncoding u) (jEncoding u)
300
def nBits (F : Target.Formula) (u : ℕ) : ℕ := (proofEncoding F u).size
302
@[simp] theorem nBits_eq (F : Target.Formula) (u : ℕ) :
    nBits F u = F.«variables» ^ u * 2 ^ (2 ^ u) +
      (F.clauses.length ^ u * 2 ^ (8 ^ u) + 1) := rfl
306
def dummyIndex (F : Target.Formula) (u : ℕ) : Fin (nBits F u) :=
body · 1 line
  (proofEncoding F u).code (.inr (.inr ()))
309
def leftAnchor (u : ℕ) : I u := fun _ => false
311
def rightAnchor (F : Target.Formula) {u : ℕ} («c» : ClauseContext F u) :
    Option {j : J u // validJ F «c» j = true} := firstValid (jEncoding u) (validJ F «c»)
314
theorem rightAnchor_none_iff (F : Target.Formula) {u : ℕ} («c» : ClauseContext F u) :
    rightAnchor F «c» = none ↔ ∀ j : J u, validJ F «c» j = false :=
proof · 1 line
  firstValid_none_iff _ _
318
def halfTableKeyAssignment (F : Target.Formula) (u : ℕ)
    (a : VariableContext F u → HalfCube (leftAnchor u) → Bool)
    (b : ∀ «c» : ClauseContext F u, ∀ j₀ : {j : J u // validJ F «c» j = true},
      HalfCube j₀ → Bool) :
    GlobalKey (VariableContext F u) (ClauseContext F u) (I u) (J u) → Bool
body · 6 lines
  | .inl (v, f) => a v (canonicalInput (leftAnchor u) f)
  | .inr (.inl («c», g)) =>
    match rightAnchor F «c» with
    | none => false
    | some j₀ => b «c» j₀ (canonicalInput j₀ (restrictQuery (validJ F «c») g))
  | .inr (.inr _) => false
330
def extendHalfTables (F : Target.Formula) (u : ℕ)
    (a : VariableContext F u → HalfCube (leftAnchor u) → Bool)
    (b : ∀ «c» : ClauseContext F u, ∀ j₀ : {j : J u // validJ F «c» j = true},
      HalfCube j₀ → Bool) : Fin (nBits F u) → Bool :=
body · 2 lines
  assignmentOfKey (variableEncoding F u) (clauseEncoding F u) (iEncoding u) (jEncoding u)
    (halfTableKeyAssignment F u a b)
337
@[simp] theorem extendHalfTables_left (F : Target.Formula) (u : ℕ)
    (a : VariableContext F u → HalfCube (leftAnchor u) → Bool)
    (b : ∀ «c» : ClauseContext F u, ∀ j₀ : {j : J u // validJ F «c» j = true},
      HalfCube j₀ → Bool) (v : VariableContext F u) (h : HalfCube (leftAnchor u)) :
    extendHalfTables F u a b ((proofEncoding F u).code (.inl (v, h.val))) = a v h := by
proof · 5 lines
  calc
    _ = halfTableKeyAssignment F u a b (.inl (v, h.val)) :=
      assignmentOfKey_code (variableEncoding F u) (clauseEncoding F u) (iEncoding u)
        (jEncoding u) (halfTableKeyAssignment F u a b) (.inl (v, h.val))
    _ = a v h := congrArg (a v) (canonicalInput_half (leftAnchor u) h)
348
theorem extendHalfTables_right (F : Target.Formula) (u : ℕ)
    (a : VariableContext F u → HalfCube (leftAnchor u) → Bool)
    (b : ∀ «c» : ClauseContext F u, ∀ j₀ : {j : J u // validJ F «c» j = true},
      HalfCube j₀ → Bool) («c» : ClauseContext F u)
    (j₀ : {j : J u // validJ F «c» j = true}) (hanchor : rightAnchor F «c» = some j₀)
    (h : HalfCube j₀) :
    extendHalfTables F u a b ((proofEncoding F u).code
      (.inr (.inl («c», extendRestricted (validJ F «c») h.val)))) = b «c» j₀ h := by
proof · 8 lines
  calc
    _ = halfTableKeyAssignment F u a b
        (.inr (.inl («c», extendRestricted (validJ F «c») h.val))) :=
      assignmentOfKey_code (variableEncoding F u) (clauseEncoding F u) (iEncoding u)
        (jEncoding u) (halfTableKeyAssignment F u a b) _
    _ = b «c» j₀ h := by
      simp only [halfTableKeyAssignment, hanchor]
      rw [restrictQuery_extendRestricted, canonicalInput_half]
365
def emptyAddress (F : Target.Formula) (u : ℕ) (v : VariableContext F u) :
    EmptyContext.Address (leftAnchor u) → Fin (nBits F u)
body · 2 lines
  | .inl h => (proofEncoding F u).code (.inl (v, h.val))
  | .inr _ => dummyIndex F u
370
def contextEquation (F : Target.Formula) (u D : ℕ)
    («c» : ClauseContext F u) (v : VariableContext F u)
    (t : SourceTape.TestTape (I u) (J u) D) : Equation (Fin (nBits F u)) :=
body · 5 lines
  match rightAnchor F «c» with
  | none => mapEquation (emptyAddress F u v) (EmptyContext.equation (leftAnchor u) t.1)
  | some j₀ => conditionedOccurrence (variableEncoding F u) (clauseEncoding F u)
      (iEncoding u) (jEncoding u) v «c» (validJ F «c») (pi F «c» v) (leftAnchor u) j₀
      t.1 t.2.2 (realizedNoise t.2.1)
379
def leftResponse (F : Target.Formula) (u : ℕ) (bits : Fin (nBits F u) → Bool)
    (v : VariableContext F u) : Cube (I u) → Bool :=
body · 1 line
  foldedAnswer (leftAnchor u) (fun h => bits ((proofEncoding F u).code (.inl (v, h.val))))
383
def rightResponse (F : Target.Formula) (u : ℕ) (bits : Fin (nBits F u) → Bool)
    («c» : ClauseContext F u) : Cube (J u) → Bool :=
body · 4 lines
  match rightAnchor F «c» with
  | none => fun _ => false
  | some j₀ => conditionedFoldedAnswer (validJ F «c») j₀
      (fun h => bits ((proofEncoding F u).code (.inr (.inl («c», extendRestricted (validJ F «c») h.val)))))
390
theorem contextEquation_satisfied (F : Target.Formula) (u D : ℕ)
    («c» : ClauseContext F u) (v : VariableContext F u)
    (t : SourceTape.TestTape (I u) (J u) D) (bits : Fin (nBits F u) → Bool) :
    satisfied (contextEquation F u D «c» v t) bits =
      !(leftResponse F u bits v t.1 ^^ rightResponse F u bits «c» t.2.2 ^^
        rightResponse F u bits «c» (thirdQuery (pi F «c» v) t.1 t.2.2 (realizedNoise t.2.1))) := by
proof · 10 lines
  cases ha : rightAnchor F «c» with
  | none =>
    simp only [contextEquation, ha, satisfied_mapEquation, EmptyContext.equation_satisfied,
      rightResponse, Bool.xor_false]
    rfl
  | some j₀ =>
    simp only [contextEquation, ha, rightResponse]
    exact conditionedOccurrence_satisfied (variableEncoding F u) (clauseEncoding F u)
      (iEncoding u) (jEncoding u) v «c» (validJ F «c») (pi F «c» v) (leftAnchor u) j₀
      bits t.1 t.2.2 (realizedNoise t.2.1)
407
def testTapeEncoding (u D : ℕ) : Encoding (SourceTape.TestTape (I u) (J u) D) :=
body · 2 lines
  ((iEncoding u).function Encoding.bool).prod
    (((jEncoding u).function (Encoding.fin D)).prod ((jEncoding u).function Encoding.bool))
411
abbrev SourceIndex (F : Target.Formula) (u D : ℕ) :=
body · 1 line
  (ClauseContext F u × SlotContext u) × SourceTape.TestTape (I u) (J u) D
414
def sourceIndexEncoding (F : Target.Formula) (u D : ℕ) : Encoding (SourceIndex F u D) :=
body · 1 line
  ((clauseEncoding F u).prod (slotContextEncoding u)).prod (testTapeEncoding u D)
417
def sourceEquation (F : Target.Formula) (u D : ℕ) (p : SourceIndex F u D) :
    Equation (Fin (nBits F u)) :=
body · 1 line
  contextEquation F u D p.1.1 (sampledVariables F p.1.1 p.1.2) p.2
421
def rawSourceList (F : Target.Formula) (u D : ℕ) : List (Equation (Fin (nBits F u))) :=
body · 1 line
  occurrenceList (sourceIndexEncoding F u D) (sourceEquation F u D)
424
@[simp] theorem rawSourceList_length (F : Target.Formula) (u D : ℕ) :
    (rawSourceList F u D).length =
      (F.clauses.length ^ u * 3 ^ u) *
        (2 ^ (2 ^ u) * (D ^ (8 ^ u) * 2 ^ (8 ^ u))) := by
proof · 2 lines
  rw [rawSourceList, occurrenceList_length]
  rfl
431
theorem rawSourceList_acceptance (F : Target.Formula) (u D : ℕ)
    (hD : 0 < D) (bits : Fin (nBits F u) → Bool) :
    ((rawSourceList F u D).countP (fun e => satisfied e bits) : ℝ) /
        (rawSourceList F u D).length =
      𝔼 «c» : ClauseContext F u, 𝔼 s : SlotContext u,
        testAcceptance ((D : ℝ)⁻¹) (pi F «c» (sampledVariables F «c» s))
          (leftResponse F u bits (sampledVariables F «c» s)) (rightResponse F u bits «c») := by
proof · 15 lines
  rw [rawSourceList, occurrenceList_acceptance, SourceTape.expect_prod]
  rw [SourceTape.expect_prod]
  apply Finset.expect_congr rfl
  intro «c» _
  apply Finset.expect_congr rfl
  intro s _
  rw [← SourceTape.tapeAcceptance_eq_testAcceptance hD]
  unfold SourceTape.tapeAcceptance
  apply Finset.expect_congr rfl
  intro t _
  rw [sourceEquation, contextEquation_satisfied]
  cases h : leftResponse F u bits (sampledVariables F «c» s) t.1 ^^
    rightResponse F u bits «c» t.2.2 ^^
      rightResponse F u bits «c»
        (thirdQuery (pi F «c» (sampledVariables F «c» s)) t.1 t.2.2 (realizedNoise t.2.1)) <;> rfl
454
def emptyFormulaEquation (F : Target.Formula) (u : ℕ) : Equation (Fin (nBits F u)) :=
body · 1 line
  ⟨dummyIndex F u, dummyIndex F u, dummyIndex F u, false⟩
457
def sourceList (F : Target.Formula) (u D : ℕ) : List (Equation (Fin (nBits F u))) :=
body · 1 line
  if F.clauses.isEmpty then [emptyFormulaEquation F u] else rawSourceList F u D
460
theorem sourceList_empty (F : Target.Formula) (u D : ℕ) (h : F.clauses = []) :
    sourceList F u D = [emptyFormulaEquation F u] := by simp [sourceList, h]
463
theorem sourceList_nonempty (F : Target.Formula) (u D : ℕ) (h : F.clauses ≠ []) :
    sourceList F u D = rawSourceList F u D := by
proof · 3 lines
  unfold sourceList
  rw [List.isEmpty_eq_false_iff.mpr h]
  rfl
469
theorem sourceList_length_le_raw_add_one (F : Target.Formula) (u D : ℕ) :
    (sourceList F u D).length ≤ (rawSourceList F u D).length + 1 := by
proof · 6 lines
  by_cases h : F.clauses = []
  · rw [sourceList_empty F u D h]
    rw [List.length_singleton]
    omega
  · rw [sourceList_nonempty F u D h]
    omega
478
theorem sourceList_ne_nil (F : Target.Formula) (u D : ℕ) (hD : 0 < D) :
    sourceList F u D ≠ [] := by
proof · 8 lines
  by_cases h : F.clauses = []
  · rw [sourceList_empty F u D h]
    simp
  · rw [sourceList_nonempty F u D h]
    apply List.length_pos_iff.mp
    rw [rawSourceList_length]
    have hc : 0 < F.clauses.length := List.length_pos_iff.mpr h
    positivity
489
def sourceInput (F : Target.Formula) (u D : ℕ) (hD : 0 < D) :
    UniqueGames.Reduction.SourceEncoding.Input :=
body · 1 line
  ⟨nBits F u, sourceList F u D, sourceList_ne_nil F u D hD⟩
493
theorem emptyFormulaEquation_satisfied (F : Target.Formula) (u : ℕ)
    (bits : Fin (nBits F u) → Bool) :
    satisfied (emptyFormulaEquation F u) bits = !(bits (dummyIndex F u)) := by
proof · 1 line
  cases h : bits (dummyIndex F u) <;> simp [emptyFormulaEquation, satisfied, h]