Documentation

Complexity.Computability.WordRAM.Signed.Comparison

Comparing encoded signed words #

The low bits distinguish opposite signs. Within one sign, the encoded unsigned comparison has the usual order for nonnegative integers and the reverse order for negative integers. No signed comparison is added to the target machine.

Main definitions #

Main results #

References #

The instruction block is an original implementation using the sign-and-magnitude encoding.

Compare two encoded signed integers, returning zero or one in result.

Instances For
    theorem Cslib.WordRAM.Signed.exec_less {r w : ℕ} (h2 : Fits w 2) (x : Data (r + 9)) {a b : ℤ} (hxa : x.regs left = encode a) (hxb : x.regs right = encode b) :
    ∃ (y : Data (r + 9)), ExecWithin w less x y 11 ∧ (y.regs result = if a < b then 1 else 0) ∧ Frame x y

    Signed comparison costs at most eleven unsigned instructions. The input encodings may be used at any physical width admitting the constant two; the frame preserves the operands.