File size: 3,982 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
import OAI.Computability.PerfectCompleteness.Foundations.CanonicalEdgesLemmas

namespace OAI


namespace PerfectCompleteness.SourceQuestionReconstruction

open SourceClause SourceKeys

noncomputable section

variable {I E Q : Type*} {Leaf : I β†’ Type*}
  (designated : (i : I) β†’ Leaf i) (clean : I β†’ Prop) [DecidablePred clean]
  [βˆ€ i, DecidableEq (Leaf i)]

abbrev Visible := (i : I) β†’ {s : Leaf i // Β¬(clean i ∧ s = designated i)} β†’ E

def reveal (x : (i : I) β†’ Leaf i β†’ E) : Visible (E := E) designated clean :=
  fun i s => x i s.1

def reconstruct (endpoint : I β†’ E β†’ Q)
    (visible : Visible (E := E) designated clean) (own : {i : I // clean i} β†’ Q) :
    (i : I) β†’ Leaf i β†’ Q :=
  fun i s => if h : clean i ∧ s = designated i then own ⟨i, h.1⟩
    else endpoint i (visible i ⟨s, h⟩)

theorem reconstruct_eq (endpoint : I β†’ E β†’ Q) (x : (i : I) β†’ Leaf i β†’ E) :
    reconstruct designated clean endpoint (reveal designated clean x)
      (fun i => endpoint i.1 (x i.1 (designated i.1))) =
        fun i s => endpoint i (x i s) := by
  funext i s
  by_cases h : clean i ∧ s = designated i
  Β· simp [reconstruct, h]
  Β· simp [reconstruct, reveal, h]


variable {v m t : Nat}
  (clauses : Fin m β†’ NormalizedClause v)

abbrev SourceTuple (m t : Nat) := Fin t β†’ Occurrence m

def leftTuple (e : SourceTuple m t) : Fin t β†’ Endpoint v m :=
  fun k => .clause (e k).1

def rightTuple (projected : Bool) (e : SourceTuple m t) : Fin t β†’ Endpoint v m :=
  fun k => if projected then .variable (occurrenceVariable clauses (e k)) else .clause (e k).1

def reconstructLeft
    (visible : Visible (E := SourceTuple m t) designated clean)
    (own : {i : I // clean i} β†’ Fin t β†’ Fin m) :
    (i : I) β†’ Leaf i β†’ Fin t β†’ Endpoint v m :=
  reconstruct designated clean (fun _ => leftTuple) visible
    (fun i k => .clause (own i k))

def reconstructRight (projected : I β†’ Bool)
    (visible : Visible (E := SourceTuple m t) designated clean)
    (own : {i : I // clean i} β†’ Fin t β†’ Fin v) :
    (i : I) β†’ Leaf i β†’ Fin t β†’ Endpoint v m :=
  reconstruct designated clean (fun i => rightTuple clauses (projected i)) visible
    (fun i k => .variable (own i k))

theorem reconstructLeft_eq (x : (i : I) β†’ Leaf i β†’ SourceTuple m t) :
    reconstructLeft designated clean (reveal designated clean x)
      (fun i k => (x i.1 (designated i.1) k).1) =
        fun i s => leftTuple (v := v) (x i s) := by
  exact reconstruct_eq designated clean (fun _ => leftTuple) x

theorem reconstructRight_eq (projected : I β†’ Bool)
    (clean_projected : βˆ€ i, clean i β†’ projected i = true)
    (x : (i : I) β†’ Leaf i β†’ SourceTuple m t) :
    reconstructRight designated clean clauses projected (reveal designated clean x)
      (fun i k => occurrenceVariable clauses (x i.1 (designated i.1) k)) =
        fun i s => rightTuple clauses (projected i) (x i s) := by
  have hown : (fun (i : {i : I // clean i}) k =>
      Endpoint.variable (m := m) (occurrenceVariable clauses (x i.1 (designated i.1) k))) =
      (fun (i : {i : I // clean i}) =>
        rightTuple clauses (projected i.1) (x i.1 (designated i.1))) := by
    funext i k
    simp only [rightTuple, clean_projected i.1 i.2, ite_true]
  unfold reconstructRight
  rw [hown]
  exact reconstruct_eq designated clean (fun i => rightTuple clauses (projected i)) x

theorem reconstructRight_slots (projected : I β†’ Bool)
    (clean_projected : βˆ€ i, clean i β†’ projected i = true)
    (x : (i : I) β†’ Leaf i β†’ SourceTuple m t) :
    (fun i s k => slot clauses
      (reconstructRight designated clean clauses projected (reveal designated clean x)
        (fun i k => occurrenceVariable clauses (x i.1 (designated i.1) k)) i s k)) =
      (fun i s k => slot clauses (rightTuple clauses (projected i) (x i s) k)) := by
  rw [reconstructRight_eq designated clean clauses projected clean_projected x]

end
end PerfectCompleteness.SourceQuestionReconstruction

end OAI