Documentation

Complexity.Computability.Machines.Turing.MultiTape.Encodings.Nat.Subtraction

The existing binary subtraction word algorithm #

The public borrow, digit-pair and subtraction definitions and laws are moved unchanged from the higher arithmetic facade. No machine or computability predicate is needed for these identities. The consuming-cursor realization has the same borrow rounds without repeated indexed lookup.

Main definitions #

Main results #

The borrow out of a digit position: the minuend digit x minus the subtrahend digit y and the incoming borrow c is negative.

Instances For

    One round of schoolbook subtraction, least significant digit first: append the difference digit and pass on the borrow.

    Instances For

      The digit pairs of two binary naturals at their first size a + size b positions.

      Instances For

        Truncated subtraction through the borrow of schoolbook subtraction: when the final borrow is set the difference is negative, and otherwise the digits read off the difference.

        Realize one existing borrow round by consuming the two remaining input words. The clock symbol is ignored; its word supplies the number of digit positions to visit.

        Instances For
          theorem Turing.MultiTapeTM.BinarySub.foldl_cursorStep (clock left right : List Bool) (acc : Bool × List Bool) :
          List.foldl cursorStep ((left, right), acc) clock = ((List.drop clock.length left, List.drop clock.length right), List.foldl subStep acc (List.map (fun (i : ℕ) => (left.getD i false, right.getD i false)) (List.range clock.length)))

          The consuming-word realization executes exactly the original indexed borrow fold.

          theorem Turing.MultiTapeTM.BinarySub.cursorStep_lengths (clock left right : List Bool) (acc : Bool × List Bool) :
          (List.foldl cursorStep ((left, right), acc) clock).1.1.length ≤ left.length ∧ (List.foldl cursorStep ((left, right), acc) clock).1.2.length ≤ right.length ∧ (List.foldl cursorStep ((left, right), acc) clock).2.2.length = acc.2.length + clock.length

          No cursor grows, and the existing subtraction accumulator appends one digit per round.