File size: 5,299 Bytes
8769036 | 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 144 145 146 147 148 149 150 151 152 | import OAI.NumberTheory.TwoPoint.Circuits.CircuitRestriction
namespace OAI
/-! Partial assignments and the consistent terms used in the canonical
decision tree of a DNF. Each term contains at most one literal per variable. -/
namespace TwoPointCorrelations
open Finset
open scoped Classical
abbrev PartialAssignment (n : ℕ) := Fin n → Option Bool
namespace PartialAssignment
def apply {n : ℕ} (ρ : PartialAssignment n) (x : BooleanCube n) : BooleanCube n :=
fun i => (ρ i).getD (x i)
def Extends {n : ℕ} (ρ τ : PartialAssignment n) : Prop :=
∀ i b, ρ i = some b → τ i = some b
def assign {n : ℕ} (ρ : PartialAssignment n) (S : Finset (Fin n))
(x : BooleanCube n) : PartialAssignment n := fun i => if i ∈ S then some (x i) else ρ i
def free {n : ℕ} (ρ : PartialAssignment n) : Finset (Fin n) :=
univ.filter (fun i => ρ i = none)
@[simp] lemma assign_empty {n : ℕ} (ρ : PartialAssignment n) (x : BooleanCube n) :
ρ.assign ∅ x = ρ := by funext i; simp [assign]
lemma assign_insert {n : ℕ} (ρ : PartialAssignment n) (S : Finset (Fin n))
(x : BooleanCube n) (i : Fin n) :
ρ.assign (insert i S) x = assign (Function.update ρ i (some (x i))) S x := by
funext j
by_cases hji : j = i <;> by_cases hj : j ∈ S <;> simp [assign, hji, hj]
lemma apply_assign_free {n : ℕ} (ρ : PartialAssignment n) (S : Finset (Fin n))
(hS : S ⊆ ρ.free) (x : BooleanCube n) :
(ρ.assign S x).apply x = ρ.apply x := by
funext i
by_cases hi : i ∈ S
· have hρ : ρ i = none := (mem_filter.mp (hS hi)).2
simp [assign, apply, hi, hρ]
· simp [assign, apply, hi]
lemma assign_extends {n : ℕ} (ρ : PartialAssignment n) (S : Finset (Fin n))
(hS : S ⊆ ρ.free) (x : BooleanCube n) : ρ.Extends (ρ.assign S x) := by
intro i b hb
have hi : i ∉ S := by
intro hi
have hn := (mem_filter.mp (hS hi)).2
rw [hb] at hn
cases hn
simp [assign, hi, hb]
lemma extends_trans {n : ℕ} {ρ σ τ : PartialAssignment n}
(hρσ : ρ.Extends σ) (hστ : σ.Extends τ) : ρ.Extends τ :=
fun i b hb => hστ i b (hρσ i b hb)
end PartialAssignment
structure CubeTerm (n : ℕ) where
support : Finset (Fin n)
value : BooleanCube n
namespace CubeTerm
def eval {n : ℕ} (C : CubeTerm n) (x : BooleanCube n) : Bool :=
decide (∀ i ∈ C.support, x i = C.value i)
def Compatible {n : ℕ} (C : CubeTerm n) (ρ : PartialAssignment n) : Prop :=
∀ i ∈ C.support, ρ i = none ∨ ρ i = some (C.value i)
def Satisfied {n : ℕ} (C : CubeTerm n) (ρ : PartialAssignment n) : Prop :=
∀ i ∈ C.support, ρ i = some (C.value i)
def live {n : ℕ} (C : CubeTerm n) (ρ : PartialAssignment n) : Finset (Fin n) :=
C.support.filter (fun i => ρ i = none)
lemma live_subset_free {n : ℕ} (C : CubeTerm n) (ρ : PartialAssignment n) :
C.live ρ ⊆ ρ.free := by
intro i hi
exact mem_filter.mpr ⟨mem_univ _, (mem_filter.mp hi).2⟩
lemma incompatible_mono {n : ℕ} (C : CubeTerm n) {ρ τ : PartialAssignment n}
(hρ : ¬ C.Compatible ρ) (h : ρ.Extends τ) : ¬ C.Compatible τ := by
intro hτ
apply hρ
intro i hi
cases hri : ρ i with
| none => exact Or.inl rfl
| some b =>
have hti := h i b hri
rcases hτ i hi with hn | hv
· rw [hti] at hn
cases hn
· have hb : b = C.value i := Option.some.inj (hti.symm.trans hv)
exact Or.inr (congrArg some hb)
lemma eval_apply_of_incompatible {n : ℕ} (C : CubeTerm n)
(ρ : PartialAssignment n) (hρ : ¬ C.Compatible ρ) (x : BooleanCube n) :
C.eval (ρ.apply x) = false := by
apply Bool.eq_false_iff.mpr
intro he
apply hρ
have he : ∀ i ∈ C.support, ρ.apply x i = C.value i := of_decide_eq_true he
intro i hi
cases hr : ρ i with
| none => exact Or.inl rfl
| some b =>
right
have hb := he i hi
simpa [PartialAssignment.apply, hr] using hb
lemma satisfied_assign_live_iff {n : ℕ} (C : CubeTerm n)
(ρ : PartialAssignment n) (hρ : C.Compatible ρ) (x : BooleanCube n) :
C.Satisfied (ρ.assign (C.live ρ) x) ↔ C.eval (ρ.apply x) = true := by
simp only [Satisfied, eval, decide_eq_true_eq]
constructor
· intro hs i hi
by_cases hl : i ∈ C.live ρ
· have hn := (mem_filter.mp hl).2
have hb := hs i hi
simpa [PartialAssignment.assign, PartialAssignment.apply, hl, hn] using hb
· have hn : ρ i ≠ none := fun hn => hl (mem_filter.mpr ⟨hi, hn⟩)
have hv := (hρ i hi).resolve_left hn
simp [PartialAssignment.apply, hv]
· intro hx i hi
by_cases hn : ρ i = none
· have hl : i ∈ C.live ρ := mem_filter.mpr ⟨hi, hn⟩
have hv := hx i hi
simpa [PartialAssignment.assign, PartialAssignment.apply, hl, hn] using hv
· have hl : i ∉ C.live ρ := fun hl => hn (mem_filter.mp hl).2
simp [PartialAssignment.assign, hl, (hρ i hi).resolve_left hn]
lemma satisfied_assign_value {n : ℕ} (C : CubeTerm n)
(ρ : PartialAssignment n) (hρ : C.Compatible ρ) :
C.Satisfied (ρ.assign (C.live ρ) C.value) := by
rw [C.satisfied_assign_live_iff ρ hρ]
apply decide_eq_true
intro i hi
rcases hρ i hi with hn | hv
· simp [PartialAssignment.apply, hn]
· simp [PartialAssignment.apply, hv]
end CubeTerm
end TwoPointCorrelations
end OAI
|