Binary subtraction and comparison #
The existing borrow algorithm runs through consuming input-word cursors, so every round costs only a linear amount and there are at most as many rounds as input digits. The plain machine certificate retains quadratic time and linear output-charged workspace, independently of the numeric operands.
Comparison is computed by one zip transducer (Turing.MultiTapeTM.ZipTransducer) that reads both
operands in lockstep, least significant digit first, and remembers whether the digits read so far
compare as less than (or as less than or equal); equality by one that remembers whether they agree.
Both run in linear time and in work space linear in the first operand.
Main results #
ComputableInO.natSub: truncated subtraction in quadratic time and linear charged space.Turing.MultiTapeTM.computableInTimeAndSpace_natLt: strict comparison within3 * (encPair encNat encNat p).length + 1steps and(encNat p.1).length + 2work-tape cells.Turing.MultiTapeTM.computableInTimeAndSpace_natLe,Turing.MultiTapeTM.computableInTimeAndSpace_natEq: non-strict comparison and equality within the same bounds.Turing.MultiTapeTM.ComputableInDegree.natLt,.natLe,.natEq: their linear forms.ComputableInO.natLt: strict comparison with the bounds ofComputableInO.natSub.
Binary comparison in linear time. One zip transducer decides a < b from
encPair encNat encNat (a, b) within 3 * (encPair encNat encNat p).length + 1 steps and
(encNat p.1).length + 2 work-tape cells.
Binary comparison in linear time and work space, from computableInTimeAndSpace_natLt.
Non-strict binary comparison in linear time. One zip transducer decides a ≤ b from
encPair encNat encNat (a, b) within 3 * (encPair encNat encNat p).length + 1 steps and
(encNat p.1).length + 2 work-tape cells.
Non-strict binary comparison in linear time and work space, from
computableInTimeAndSpace_natLe.
Binary equality in linear time. One zip transducer decides a = b from
encPair encNat encNat (a, b) within 3 * (encPair encNat encNat p).length + 1 steps and
(encNat p.1).length + 2 work-tape cells.
Binary equality in linear time and work space, from computableInTimeAndSpace_natEq.
Truncated subtraction in binary, b - a from (a, b).
The strict order in binary, from the linear zip-transducer certificate
Turing.MultiTapeTM.computableInTimeAndSpace_natLt.