File size: 4,789 Bytes
9dbc64e | 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 | import OAI.Computability.DepthThree.Circuit
import OAI.Computability.DepthThree.RestrictionNormalization
namespace OAI
universe uDepth1
namespace DepthThreeLowerBound
variable {V : Type uDepth1}
namespace RawClause
def literalPart : GateInput V → Option (Literal V)
| .inl l => some l
| .inr _ => none
noncomputable def literals (C : RawClause V) : Clause V := by
classical
exact (C.filterMap literalPart).toFinset
@[simp] theorem mem_literals (C : RawClause V) (l : Literal V) :
l ∈ C.literals ↔ Sum.inl l ∈ C := by
classical
simp only [literals, List.mem_toFinset, List.mem_filterMap]
constructor
· rintro ⟨a, ha, he⟩
cases a with
| inl k =>
have hk : k = l := Option.some.inj he
simpa [hk] using ha
| inr b => simp [literalPart] at he
· intro h
exact ⟨.inl l, h, rfl⟩
theorem eval_true_iff (C : RawClause V) (x : Cube V) :
C.eval x = true ↔ Sum.inr true ∈ C ∨ C.literals.eval x = true := by
rw [eval_eq_true, Clause.eval_eq_true]
constructor
· rintro ⟨a, ha, hx⟩
cases a with
| inl l => exact Or.inr ⟨l, (mem_literals C l).mpr ha, (Literal.eval_eq_true l x).mp hx⟩
| inr b =>
change b = true at hx
exact Or.inl (hx ▸ ha)
· rintro (h | ⟨l, hl, hx⟩)
· exact ⟨.inr true, h, rfl⟩
· exact ⟨.inl l, (mem_literals C l).mp hl, (Literal.eval_eq_true l x).mpr hx⟩
noncomputable def normalize (C : RawClause V) : Option (Clause V) := by
classical
exact if Sum.inr true ∈ C ∨ ¬ C.literals.Normalized then none else some C.literals
theorem normalized_of_normalize_eq_some {C : RawClause V} {D : Clause V}
(h : C.normalize = some D) : D.Normalized := by
classical
unfold normalize at h
split at h
· contradiction
· rename_i hn
have hCD : C.literals = D := Option.some.inj h
rw [← hCD]
exact Classical.not_not.mp (fun hbad => hn (Or.inr hbad))
theorem normalize_eval (C : RawClause V) (x : Cube V) :
((C.normalize).map (fun D => D.eval x)).getD true = C.eval x := by
classical
unfold normalize
split
· rename_i h
have ht : C.eval x = true := by
apply (eval_true_iff C x).mpr
rcases h with h | h
· exact Or.inl h
· exact Or.inr (Clause.eval_true_of_not_normalized h x)
simp [ht]
· rename_i h
have hc : Sum.inr true ∉ C := fun hc => h (Or.inl hc)
change C.literals.eval x = C.eval x
apply Bool.eq_iff_iff.mpr
rw [eval_true_iff]
simp [hc]
end RawClause
namespace Circuit3
noncomputable def middleCNF (C : Circuit3 V) (j : Fin C.middleCount) : CNF V :=
(C.middle j).toList.filterMap fun i => (C.bottom i).normalize
theorem mem_middleCNF (C : Circuit3 V) (j : Fin C.middleCount) (D : Clause V) :
D ∈ C.middleCNF j ↔ ∃ i ∈ C.middle j, (C.bottom i).normalize = some D := by
simp [middleCNF, List.mem_filterMap]
theorem middleCNF_normalized (C : Circuit3 V) (j : Fin C.middleCount) :
(C.middleCNF j).Normalized := by
intro D hD
obtain ⟨i, _, hi⟩ := (mem_middleCNF C j D).mp hD
exact RawClause.normalized_of_normalize_eq_some hi
theorem middleCNF_length_le_bottomCount (C : Circuit3 V) (j : Fin C.middleCount) :
(C.middleCNF j).length ≤ C.bottomCount := by
calc
(C.middleCNF j).length ≤ (C.middle j).toList.length := List.length_filterMap_le _ _
_ = (C.middle j).card := Finset.length_toList _
_ ≤ C.bottomCount := by simpa using Finset.card_le_univ (C.middle j)
theorem middleCNF_length_le_gateCount (C : Circuit3 V) (j : Fin C.middleCount) :
(C.middleCNF j).length ≤ C.gateCount :=
(C.middleCNF_length_le_bottomCount j).trans C.bottomCount_le_gateCount
@[simp] theorem eval_middleCNF (C : Circuit3 V) (j : Fin C.middleCount) (x : Cube V) :
(C.middleCNF j).eval x = C.middleEval j x := by
classical
apply Bool.eq_iff_iff.mpr
rw [CNF.eval_eq_true, middleEval_eq_true]
constructor
· intro hx i hi
have he := (C.bottom i).normalize_eval x
cases hn : (C.bottom i).normalize with
| none => simpa [hn] using he.symm
| some D =>
have hD := hx D ((mem_middleCNF C j D).mpr ⟨i, hi, hn⟩)
simpa [hn, hD] using he.symm
· intro hx D hD
obtain ⟨i, hi, hn⟩ := (mem_middleCNF C j D).mp hD
have he := (C.bottom i).normalize_eval x
simpa [hn, hx i hi] using he
theorem eval_eq_true_iff_middleCNF (C : Circuit3 V) (x : Cube V) :
C.eval x = true ↔ ∃ j ∈ C.top, (C.middleCNF j).eval x = true := by
simp only [eval_middleCNF, eval_eq_true]
theorem middleCNF_implies_output (C : Circuit3 V) {j : Fin C.middleCount}
(hj : j ∈ C.top) {x : Cube V} (hx : (C.middleCNF j).eval x = true) :
C.eval x = true := (eval_eq_true_iff_middleCNF C x).mpr ⟨j, hj, hx⟩
end Circuit3
end DepthThreeLowerBound
end OAI
|