Documentation

Complexitylib.Circuits.BinaryComparison

Little-endian binary comparison #

This module exposes unsigned semantics for fixed-width little-endian words, a linear-size Boolean formula comparing two consecutive input words, and its verified compilation to a typed fan-in-two circuit.

theorem Complexity.BitString.unsignedLE_eq_decide {width : } (left right : BitString width) :

Recursive most-significant-bit comparison agrees with unsigned natural comparison.

@[simp]
theorem Complexity.BoolFormula.eval_ofBool (value : Bool) (assignment : Bool) :
eval assignment (ofBool value) = value

Constant formula leaves evaluate to their embedded Boolean values.

theorem Complexity.BoolFormula.eval_unsignedLEOf {width : } (left right : Fin widthBoolFormula) (assignment : Bool) :
eval assignment (unsignedLEOf left right) = BitString.unsignedLE (fun (i : Fin width) => eval assignment (left i)) fun (i : Fin width) => eval assignment (right i)

Comparing vectors of formulas compares their evaluated unsigned words.

theorem Complexity.BoolFormula.size_unsignedLEOf {width : } (left right : Fin widthBoolFormula) (hleft : ∀ (i : Fin width), (left i).size = 1) (hright : ∀ (i : Fin width), (right i).size = 1) :
(unsignedLEOf left right).size = 15 * width + 1

The generalized comparator retains the exact linear size when every operand bit is represented by one formula node.

@[simp]
theorem Complexity.BoolFormula.eval_unsignedLELeftConstant {width : } (left : BitString width) (rightBase : ) (assignment : Bool) :
eval assignment (unsignedLELeftConstant left rightBase) = decide (left.unsignedValue BitString.unsignedValue fun (i : Fin width) => assignment (rightBase + i))

Constant-left comparison has the expected unsigned semantics.

@[simp]
theorem Complexity.BoolFormula.eval_unsignedLERightConstant {width : } (leftBase : ) (right : BitString width) (assignment : Bool) :
eval assignment (unsignedLERightConstant leftBase right) = decide ((BitString.unsignedValue fun (i : Fin width) => assignment (leftBase + i)) right.unsignedValue)

Constant-right comparison has the expected unsigned semantics.

@[simp]
theorem Complexity.BoolFormula.size_unsignedLELeftConstant {width : } (left : BitString width) (rightBase : ) :
(unsignedLELeftConstant left rightBase).size = 15 * width + 1

A constant-left comparator has exactly fifteen nodes per bit, plus its base constant.

@[simp]
theorem Complexity.BoolFormula.size_unsignedLERightConstant {width : } (leftBase : ) (right : BitString width) :
(unsignedLERightConstant leftBase right).size = 15 * width + 1

A constant-right comparator has exactly fifteen nodes per bit, plus its base constant.

theorem Complexity.BoolFormula.vars_unsignedLELeftConstant_lt {width : } (left : BitString width) (rightBase available : ) (hright : rightBase + width available) (j : ) :
j (unsignedLELeftConstant left rightBase).varsj < available

Every variable in a constant-left comparator lies in its right operand block.

theorem Complexity.BoolFormula.vars_unsignedLERightConstant_lt {width : } (leftBase : ) (right : BitString width) (available : ) (hleft : leftBase + width available) (j : ) :
j (unsignedLERightConstant leftBase right).varsj < available

Every variable in a constant-right comparator lies in its left operand block.

@[simp]
theorem Complexity.BoolFormula.size_unsignedLE (width : ) :
(unsignedLE width).size = 15 * width + 1

The unsigned-comparison formula has exactly fifteen nodes per input bit, plus its base constant.

@[simp]
theorem Complexity.BoolFormula.eval_unsignedLE (width : ) (left right : BitString width) :

The formula compares two consecutive fixed-width little-endian input words as unsigned naturals.

@[simp]

Exact raw gate count for the unsigned-comparison construction.

The raw unsigned-comparison construction is a valid single-output circuit for every positive word width.

noncomputable def Complexity.Circuit.unsignedLE (width : ) [NeZero width] :

Typed fan-in-two circuit comparing two consecutive width-bit unsigned little-endian words.

Equations
Instances For
    @[simp]
    theorem Complexity.Circuit.size_unsignedLE (width : ) [NeZero width] :
    (unsignedLE width).size = 15 * width + 1

    Exact size of the typed unsigned-comparison circuit.

    @[simp]
    theorem Complexity.Circuit.eval_unsignedLE (width : ) [NeZero width] (left right : BitString width) :
    (unsignedLE width).eval (Fin.append left right) 0 = decide (left.unsignedValue right.unsignedValue)

    The typed circuit returns the unsigned comparison of its two input words.