File size: 9,576 Bytes
a2ee19a | 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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | import OAI.Probability.SATComputability.PhysicalExpressions
import OAI.Probability.DilutedSpin.CavityBounds
namespace OAI
namespace FixedClauseThreshold.Computability.FiniteArithmetic
open Nat.Partrec DilutedSpinGlass RapidForcing.EffectiveArithmetic
open scoped BigOperators
local instance cavityExpressionsRatPrimcodable : Primcodable ℚ := PeriodicLattice.RecursiveArithmetic.ratPrimcodable
noncomputable def boltzmannAtom {p : ℕ} (θ : ℚ) (xs : Fin p → Code)
(s : Fin p → Bool) : Code :=
.pair (rationalExpression θ)
(sumExpressions (List.ofFn (fun i => logQExpression (xs i) (s i))))
@[fun_prop] theorem boltzmannAtom_computable (p : ℕ) :
Computable (fun a : ℚ × (Fin p → Code) × (Fin p → Bool) =>
boltzmannAtom a.1 a.2.1 a.2.2) := by
have hv : Computable (fun a : ℚ × (Fin p → Code) × (Fin p → Bool) =>
List.ofFn (fun i => logQExpression (a.2.1 i) (a.2.2 i))) := by
apply Computable.list_ofFn
intro i
fun_prop
unfold boltzmannAtom
fun_prop
theorem exp_boltzmannAtom {p : ℕ} (θ : ℚ) (xs : Fin p → Code) (s : Fin p → Bool) :
Real.exp (expressionValue (boltzmannAtom θ xs s)) =
Real.exp (θ : ℝ) * ∏ i, q (expressionValue (xs i)) (s i) := by
simp only [boltzmannAtom, expressionValue, rationalExpression_value,
sumExpressions_value, List.map_ofFn, List.sum_ofFn, Function.comp_def,
Real.exp_add, Real.exp_sum, exp_logQExpression]
def clausePenalty (β : ℚ) (J s : Fin 3 → Bool) : ℚ :=
if ∀ i, s i ≠ J i then -β else 0
@[fun_prop] theorem clausePenalty_computable :
Computable (fun p : ℚ × (Fin 3 → Bool) × (Fin 3 → Bool) =>
clausePenalty p.1 p.2.1 p.2.2) := by
have h : Computable (fun p : ℚ × (Fin 3 → Bool) × (Fin 3 → Bool) =>
if p.2.2 0 ≠ p.2.1 0 ∧ p.2.2 1 ≠ p.2.1 1 ∧ p.2.2 2 ≠ p.2.1 2
then -p.1 else 0) := by fun_prop
exact h.of_eq (fun p => by simp [clausePenalty, Fin.forall_fin_succ])
theorem clausePenalty_cast (β : ℚ) (J s : Fin 3 → Bool) :
(clausePenalty β J s : ℝ) = satInteraction (β : ℝ) J s := by
unfold clausePenalty satInteraction
split <;> simp
theorem sum_bool_vector_succ {p : ℕ} (f : (Fin (p+1) → Bool) → ℝ) :
(∑ s, f s) =
(∑ t : Fin p → Bool, f (Fin.cons false t)) +
∑ t : Fin p → Bool, f (Fin.cons true t) := by
rw [← (Fin.consEquiv (fun _ : Fin (p+1) => Bool)).sum_comp, Fintype.sum_prod_type]
simp only [Fintype.sum_bool]
exact add_comm _ _
noncomputable def edgeExpression (β : ℚ) (J : Fin 3 → Bool) (xs : Fin 3 → Code) : Code :=
binaryLogSumExpression
(binaryLogSumExpression
(binaryLogSumExpression (boltzmannAtom (clausePenalty β J ![false,false,false]) xs ![false,false,false])
(boltzmannAtom (clausePenalty β J ![false,false,true]) xs ![false,false,true]))
(binaryLogSumExpression (boltzmannAtom (clausePenalty β J ![false,true,false]) xs ![false,true,false])
(boltzmannAtom (clausePenalty β J ![false,true,true]) xs ![false,true,true])))
(binaryLogSumExpression
(binaryLogSumExpression (boltzmannAtom (clausePenalty β J ![true,false,false]) xs ![true,false,false])
(boltzmannAtom (clausePenalty β J ![true,false,true]) xs ![true,false,true]))
(binaryLogSumExpression (boltzmannAtom (clausePenalty β J ![true,true,false]) xs ![true,true,false])
(boltzmannAtom (clausePenalty β J ![true,true,true]) xs ![true,true,true])))
@[fun_prop] theorem edgeExpression_computable :
Computable (fun p : ℚ × (Fin 3 → Bool) × (Fin 3 → Code) =>
edgeExpression p.1 p.2.1 p.2.2) := by
unfold edgeExpression
fun_prop
theorem exp_edgeExpression (β : ℚ) (J : Fin 3 → Bool) (xs : Fin 3 → Code) :
Real.exp (expressionValue (edgeExpression β J xs)) =
edge (satInteraction (β : ℝ) J) (fun i => expressionValue (xs i)) := by
unfold edgeExpression edge
simp only [exp_binaryLogSumExpression, exp_boltzmannAtom, clausePenalty_cast]
rw [sum_bool_vector_succ]
simp_rw [sum_bool_vector_succ]
simp only [Fintype.sum_unique]
rfl
theorem edgeExpression_value (β : ℚ) (J : Fin 3 → Bool) (xs : Fin 3 → Code) :
expressionValue (edgeExpression β J xs) =
Real.log (edge (satInteraction (β : ℝ) J) (fun i => expressionValue (xs i))) := by
rw [← exp_edgeExpression, Real.log_exp]
@[fun_prop] theorem spinsThree_computable :
Computable (fun p : Bool × Bool × Bool => ![p.1,p.2.1,p.2.2]) := by
apply computable_fin_lambda
intro i
fin_cases i <;> simp only [Matrix.cons_val_zero', Matrix.cons_val_succ']
all_goals fun_prop
def extendSpins (a b ε : Bool) : Fin 3 → Bool := ![a,b,ε]
@[fun_prop] theorem extendSpins_computable :
Computable (fun p : Bool × Bool × Bool => extendSpins p.1 p.2.1 p.2.2) :=
spinsThree_computable
noncomputable def messageExpression (β : ℚ) (J : Fin 3 → Bool)
(xs : Fin 2 → Code) (ε : Bool) : Code :=
binaryLogSumExpression
(binaryLogSumExpression
(boltzmannAtom (clausePenalty β J (extendSpins false false ε)) xs ![false,false])
(boltzmannAtom (clausePenalty β J (extendSpins false true ε)) xs ![false,true]))
(binaryLogSumExpression
(boltzmannAtom (clausePenalty β J (extendSpins true false ε)) xs ![true,false])
(boltzmannAtom (clausePenalty β J (extendSpins true true ε)) xs ![true,true]))
@[fun_prop] theorem messageExpression_computable :
Computable (fun p : ℚ × (Fin 3 → Bool) × (Fin 2 → Code) × Bool =>
messageExpression p.1 p.2.1 p.2.2.1 p.2.2.2) := by
unfold messageExpression
fun_prop
theorem appendSpin_three (a b ε : Bool) :
appendSpin (p := 3) ![a,b] ε = ![a,b,ε] := by
funext i
fin_cases i <;> rfl
theorem messageExpression_value (β : ℚ) (J : Fin 3 → Bool)
(xs : Fin 2 → Code) (ε : Bool) :
expressionValue (messageExpression β J xs ε) =
message (satInteraction (β : ℝ) J) (fun i => expressionValue (xs i)) ε := by
rw [← Real.log_exp (expressionValue (messageExpression β J xs ε))]
unfold messageExpression message
congr 1
simp only [exp_binaryLogSumExpression, exp_boltzmannAtom, clausePenalty_cast]
simp_rw [sum_bool_vector_succ]
simp only [Fintype.sum_unique]
have ht (a b : Bool) (t : Fin 0 → Bool) : Fin.cons a (Fin.cons b t) = ![a,b] := by
funext i
fin_cases i <;> rfl
simp only [ht, appendSpin_three, extendSpins]
abbrev SiteExpressionDatum := (Fin 3 → Bool) × (Fin 2 → Code)
noncomputable def siteExpression (β : ℚ) (data : List SiteExpressionDatum) : Code :=
binaryLogMeanExpression
(sumExpressions (data.map (fun z => messageExpression β z.1 z.2 false)))
(sumExpressions (data.map (fun z => messageExpression β z.1 z.2 true)))
@[fun_prop] theorem siteExpression_computable :
Computable (fun p : ℚ × List SiteExpressionDatum => siteExpression p.1 p.2) := by
have hm (ε : Bool) : Computable (fun p : ℚ × List SiteExpressionDatum =>
p.2.map (fun z => messageExpression p.1 z.1 z.2 ε)) := by
apply computable_list_map Computable.snd
unfold Computable₂
fun_prop
unfold siteExpression
fun_prop
theorem siteExpression_value (β : ℚ) (data : List SiteExpressionDatum) :
expressionValue (siteExpression β data) =
siteLog (fun j : Fin data.length => satSample (β : ℝ) (data.get j).1) 0
(fun i => expressionValue ((data.get i.1).2 i.2)) := by
have hs (ε : Bool) : (data.map (fun z =>
message (satInteraction (β : ℝ) z.1) (fun i => expressionValue (z.2 i)) ε)).sum =
∑ j : Fin data.length, message (satInteraction (β : ℝ) (data.get j).1)
(fun i => expressionValue ((data.get j).2 i)) ε := by
rw [← List.sum_ofFn]
have h := congrArg (fun ds : List SiteExpressionDatum =>
(ds.map (fun z => message (satInteraction (β : ℝ) z.1)
(fun i => expressionValue (z.2 i)) ε)).sum) (List.ofFn_get data)
simpa only [List.map_ofFn, Function.comp_def] using h.symm
simp only [siteExpression, binaryLogMeanExpression_value, sumExpressions_value,
List.map_map, Function.comp_def, messageExpression_value, hs]
simp only [siteLog, zero_mul, zero_add, satSample, Fintype.sum_bool]
congr 2
exact add_comm _ _
attribute [local irreducible] edgeExpression siteExpression
theorem edgeExpression_comp {A : Type} [Primcodable A]
(β : A → ℚ) (J : A → Fin 3 → Bool) (xs : A → Fin 3 → Code)
(hβ : Computable β) (hJ : Computable J) (hx : Computable xs) :
Computable (fun a => edgeExpression (β a) (J a) (xs a)) := by
exact edgeExpression_computable.comp (hβ.pair (hJ.pair hx))
theorem siteExpression_comp {A : Type} [Primcodable A]
(β : A → ℚ) (data : A → List SiteExpressionDatum)
(hβ : Computable β) (hd : Computable data) :
Computable (fun a => siteExpression (β a) (data a)) := by
exact siteExpression_computable.comp (hβ.pair hd)
theorem siteExpression_ofFn_value {k : ℕ} (β : ℚ)
(J : Fin k → Fin 3 → Bool) (xs : Fin k → Fin 2 → Code) :
expressionValue (siteExpression β (List.ofFn (fun j => (J j,xs j)))) =
siteLog (fun j => satSample (β : ℝ) (J j)) 0
(fun i => expressionValue (xs i.1 i.2)) := by
simp only [siteExpression, binaryLogMeanExpression_value, sumExpressions_value,
List.map_ofFn, List.sum_ofFn, Function.comp_def, messageExpression_value]
simp only [siteLog, zero_mul, zero_add, satSample, Fintype.sum_bool]
congr 2
exact add_comm _ _
end FixedClauseThreshold.Computability.FiniteArithmetic
end OAI
|