Documentation

Complexitylib.Models.TuringMachine.Subroutines.BinaryRippleSub.Internal.Pure

Linear-time canonical binary subtraction -- pure proofs #

The raw scan is verified through the standard full-subtractor invariant. Its final borrow decides underflow, while trimming is proved to recover the canonical Nat.bits representation of the raw fixed-width value.

Interpret a Boolean bit as a natural number.

Equations
Instances For
    theorem Complexity.BinaryRippleSub.scan_bits_length_internal (borrow : Bool) (lhs rhs : List Bool) :
    (scan borrow lhs rhs).bits.length = max lhs.length rhs.length

    The raw borrow scan writes exactly the larger input width.

    theorem Complexity.BinaryRippleSub.scan_value_internal (borrow : Bool) (lhs rhs : List Bool) :
    (Nat.fromBitsLE lhs + if (scan borrow lhs rhs).borrow = true then 2 ^ max lhs.length rhs.length else 0) = Nat.fromBitsLE rhs + boolValue borrow + Nat.fromBitsLE (scan borrow lhs rhs).bits

    Arithmetic invariant for the fixed-width borrow scan. The final borrow is the coefficient of the width-sized wraparound term.

    Appending a redundant high zero does not change canonical trimming.

    A high one makes the entire lower prefix significant.

    Trimming arbitrary little-endian bits produces the canonical bits of their decoded natural value.

    The canonical pure subtraction result agrees with natural-number monus.

    Canonical subtraction has exactly the width of natural-number monus.

    The scan bound on canonical operands is the larger natural-number width.

    The cleanup bound equals the scan bound on canonical operands.

    The core bound is twice the larger width plus its two turning steps.

    The complete subtractor is linear in the sum of the operand widths.