Documentation

CslibFrontier.Logics.RealArithmetic.FormulaBooleanEvaluation

Backward Boolean evaluation of formula words #

This adapts the wire scan and its correctness proof from LeanCanny.Computation.BooleanCircuitSpace and LeanCanny.ETR.FormulaBooleanCircuitCorrect at lean-canny revision 970f28a5ecefc1327402ade16c068aa4b1b2c183. Every operand follows its parent in the prefix token stream, so visiting tokens from right to left gives each gate access to its previously computed operands. The scan accepts answers indexed by gate, as in LeanCanny.ETR.FormulaBooleanCircuitSource.value_signature at that same revision. Supplying the comparisons of term-word signs recovers the term-sign evaluator. Correct signs for the comparison terms in the word suffice for the root value to characterize membership in the real solution set. The backward scan stays in polynomial space when comparison answers are computed in polynomial space, keeping just one bit per processed gate.

Evaluate a formula with each comparison interpreted by its term's supplied sign.

def Cslib.Logic.RealArithmetic.formulaGateSuffixValue (suffix : List Bool) (gateIndex childIndex : ℕ) :

Read an absolute child index from the computed suffix, whose first bit is at gateIndex + 1. Indices at or before the gate or past the suffix read false.

Reading a child from the raw suffix bits is polynomial time in the input, with both positions in binary. The underlying lookup caps the offset at the suffix length.

def Cslib.Logic.RealArithmetic.formulaWordGateUpdate (word : List Bool) (index : ℕ) (answer : Bool) (suffix : List Bool) :

Prepend the value of an indexed gate to its computed suffix, given the answer to its comparison request. The answer is ignored at gates without a comparison request.

The Boolean gate update is polynomial time in the raw word, binary position, comparison-answer bit, and raw suffix.

theorem Cslib.Logic.RealArithmetic.formulaWordGateUpdate_eq_cons (word : List Bool) (index : ℕ) (termSign : List Bool → SignType) (suffix : List Bool) :
formulaWordGateUpdate word index (Option.any (fun (request : FormulaComparisonRequest) => decide (termSign request.termWord = request.requestedSign)) (formulaWordComparisonRequest word index)) suffix = formulaWordGateValue word index termSign (formulaGateSuffixValue suffix index) :: suffix

Supplying the comparison answer from the term signs gives the scan's next suffix.

Evaluate the total formula view from right to left, using the supplied answer at each comparison gate's index. The result lists gate values in prefix order.

Evaluate all gates of the total formula view from right to left, returning their Boolean values in prefix order. A child is read from the already evaluated suffix.

The scan stores one Boolean value per token.

theorem Cslib.Logic.RealArithmetic.formulaWordGateValuesWithAnswers_eq_of_comparisonAnswers (word : List Bool) (answer : ℕ → Bool) (termSign : List Bool → SignType) (h : ∀ index < (formulaWordTokens word).length, ∀ (request : FormulaComparisonRequest), formulaWordComparisonRequest word index = some request → answer index = decide (termSign request.termWord = request.requestedSign)) :

Gate-indexed answers recover the term-sign scan when they give the requested comparison at each comparison gate.

A polynomial-space comparison-answer computation suffices for the whole backward gate scan. Each query receives the original encoded input and a binary gate index, and the scan stores a raw suffix bit for each gate it has processed.

The term-sign scan uses polynomial space if each indexed comparison with the supplied term signs is computable in polynomial space.

theorem Cslib.Logic.RealArithmetic.formulaWordGateValues_getD_step (word : List Bool) (termSign : List Bool → SignType) (index : ℕ) (hi : index < (formulaWordTokens word).length) :
(formulaWordGateValues word termSign).getD index false = formulaWordGateValue word index termSign fun (child : ℕ) => if index < child then (formulaWordGateValues word termSign).getD child false else false

A gate reads the values already computed strictly to its right in the prefix stream.

Reading the value of an encoded subformula from the gate scan agrees with interpreting its comparisons using the signs of their encoded terms.

The first gate is the value of the total formula view, under signs assigned to term words.

Evaluate the total formula view using a finite sign signature indexed by gate. A comparison beyond the signature receives false.

The finite-signature scan uses polynomial space when the word and the list of signs in gate order are available in polynomial time. The signs use the framed encList encSign encoding, and each comparison looks up its sign at a binary gate index.

theorem Cslib.Logic.RealArithmetic.formulaWordGateValuesWithSignature_getD_zero {n : ℕ} (word : List Bool) (signature : Fin n → SignType) (termSign : List Bool → SignType) (hn : (formulaWordTokens word).length ≤ n) (hsign : ∀ (index : ℕ) (hi : index < (formulaWordTokens word).length) (request : FormulaComparisonRequest), formulaWordComparisonRequest word index = some request → signature ⟨index, ⋯⟩ = termSign request.termWord) :

A finite gate signature covering the formula word's tokens gives the term-sign value of the total formula view if its sign at every comparison agrees with the requested term's sign. This adapts LeanCanny.ETR.FormulaBooleanCircuitSource.value_signature to the frontier token view, which only requests signs at comparison gates.

The root gate holds at a real point if and only if the total formula view holds there, provided the sign reader gives the true sign for each comparison term in the word.

theorem Cslib.Logic.RealArithmetic.formulaWordGateValuesWithSignature_getD_zero_eq_true_iff {n : ℕ} (word : List Bool) (signature : Fin n → SignType) (x : Fin word.length → ℝ) (hn : (formulaWordTokens word).length ≤ n) (hsign : ∀ (index : ℕ) (hi : index < (formulaWordTokens word).length) (request : FormulaComparisonRequest) (t : Term word.length), formulaWordComparisonRequest word index = some request → request.termWord = (encTerm word.length) t → signature ⟨index, ⋯⟩ = SignType.sign (Term.eval x t)) :

A gate signature matching the real sign of every requested term gives the truth of the total formula view at that point. This is the token-view version of LeanCanny.ETR.FormulaBooleanCircuitSource.signature_holds at the revision cited above.