Operation bases for word RAMs #
Word-RAM models differ in their arithmetic and logical instructions. Hagerup distinguishes the restricted RAM, without multiplication, from the multiplication RAM Hagerup, and the AC⁰ RAM allows only operations computed by polynomial-size constant-depth circuits, which excludes multiplication Andersson, Miltersen and Thorup. Linear-time and data-structure bounds can depend on this choice.
A basis (Cslib.WordRAM.Basis) fixes these operations, as a circuit basis does: a signature of
operation symbols with arities (Cslib.Circuits.Signature), and the value of every symbol on
natural numbers at each word size w, which may be undefined (none). The machine itself, its
registers, memory, control flow and faults are the same for every basis; an operation faults
when its value is undefined or does not fit a word. A basis also marks the operations that are
exempt from word-size monotonicity: every other operation keeps each value that fits a word at
every larger word size, so that a successful run of a program avoiding the marked operations
succeeds in the same way at every larger word size.
Bases are compared by meaning-preserving maps of their operations (Cslib.WordRAM.Basis.Hom),
built on Cslib.Circuits.Signature.Hom. A program over a basis runs instruction for instruction
over a larger one; Cslib.WordRAM.Basis.restrict gives the sub-bases of a basis.
Main definitions #
Cslib.WordRAM.Basis: operation symbols, their meaning at each word size, and the symbols exempt from word-size monotonicity.Cslib.WordRAM.BinOp,Cslib.WordRAM.StandardOp,Cslib.WordRAM.Basis.standard: the standard word-RAM operations: addition, subtraction, multiplication, bitwise operations and shifts as in Hagerup, together with division, remainder and the word size, with truncated subtraction and Lean's division by zero.Cslib.WordRAM.BinOp.evalExact,Cslib.WordRAM.Basis.exact: the same operations with their exact values: subtraction below zero and division and remainder by zero are undefined.Cslib.WordRAM.Basis.Hom: a map of bases that keeps the meaning of every operation.Cslib.WordRAM.Basis.restrict: the sub-basis of the operations satisfying a predicate.Cslib.WordRAM.Basis.additive,Cslib.WordRAM.Basis.arithmetic: addition and subtraction; and these with multiplication, division and remainder, the operation symbols of the bounded-word RAM of MIT–ULB CompGeom Group, on unsigned words with truncated subtraction.
Main results #
Cslib.WordRAM.Basis.Hom.interp_map: the image of an operation under a map of bases has the operation's value.Cslib.WordRAM.Basis.arithmeticHomStandard_comp_additiveHomArithmetic: the inclusions of the named bases commute.
References #
- A. Andersson, P. B. Miltersen and M. Thorup, Fusion trees can be implemented with AC⁰ instructions only
- M. L. Fredman and D. E. Willard, Surpassing the information theoretic bound with fusion trees
- T. Hagerup, Sorting and searching on the word RAM
- MIT–ULB CompGeom Group, Undecidability of tiling with a tromino
A basis of word operations: a signature of operation symbols, the value of each operation at
each word size, none where it is undefined, and the operations that may read the word size. An
operation that does not read the word size keeps each value that fits a word at every larger word
size. Whether a value fits a word is checked by the machine, not by the basis.
- decEq : DecidableEq self.Op
Operation symbols have decidable equality, so that programs do.
The operations exempt from word-size monotonicity (
interp_mono_of_not_readsWidth), such as one that returns the word size.- decReadsWidth : DecidablePred self.ReadsWidth
Whether an operation reads the word size is decidable.
The value of every operation at word size
w, ornoneif it is undefined.- interp_mono_of_not_readsWidth (f : self.Op) (hf : ¬self.ReadsWidth f) {w w' : ℕ} (hw : w ≤ w') {args : Fin (self.Arity f) → ℕ} {v : ℕ} (h : self.interp w f args = some v) (hv : v < 2 ^ w) : self.interp w' f args = some v
An operation that does not read the word size keeps each value that fits a word at every larger word size.
Instances For
The standard basis #
The binary operations of the word RAM.
- add : BinOp
Addition.
- sub : BinOp
Subtraction.
- mul : BinOp
Multiplication.
- div : BinOp
Division, rounding down.
- mod : BinOp
Remainder.
- and : BinOp
Bitwise and.
- or : BinOp
Bitwise or.
- xor : BinOp
Bitwise exclusive or.
- shiftLeft : BinOp
Shift left:
x <<< y = x * 2 ^ y. - shiftRight : BinOp
Shift right:
x >>> y = x / 2 ^ y.
Instances For
The value of a binary operation on natural numbers. Subtraction is truncated, and division
and remainder by zero follow Lean's conventions x / 0 = 0 and x % 0 = x. Whether the value
fits a word is checked by the instruction that writes it.
Instances For
The operations of the standard basis: the binary operations, and reading the word size.
- bin (f : BinOp) : StandardOp
A binary operation.
- width : StandardOp
The word size, an operation without arguments.
Instances For
Instances For
The number of arguments of a standard operation.
Instances For
The value of a standard operation at word size w.
Instances For
The standard word-RAM basis: addition, subtraction, multiplication, bitwise operations and shifts as in Hagerup, together with division and remainder, and the word size, which word-RAM algorithms may read Fredman and Willard. Only the word size reads the word size.
Instances For
The exact basis #
The exact value of a binary operation on natural numbers: subtraction below zero, and
division and remainder by zero, are undefined. Elsewhere it is BinOp.eval.
Instances For
The exact value of a standard operation at word size w.
Instances For
The exact word-RAM basis: the operations of Basis.standard, where every operation computes
its exact value, so that subtraction below zero and division and remainder by zero are undefined
and fault. Only the word size reads the word size. The bounded-word RAM of
MIT–ULB CompGeom Group does not reject a negative difference or a zero divisor as
such: it subtracts signed words, its division and remainder by zero follow Lean's integer
conventions x / 0 = 0 and x % 0 = x, and only its usual check that the result fits a signed
word applies.
Instances For
Maps of bases #
A map of bases: a map of signatures (Cslib.Circuits.Signature.Hom) such that at each word
size the image of every operation has the operation's value, and that sends an operation not
marked as reading the word size to one not so marked. Programs over B then run instruction for
instruction over B'.
- preserves (w : ℕ) (f : B.Op) (x : Fin (B.Arity f) → ℕ) : (B'.interp w (self.toHom f) fun (a : Fin (B'.Arity (self.toHom f))) => x (Fin.cast ⋯ a)) = B.interp w f x
At each word size, the image of each operation, applied to arguments reindexed along
Signature.Hom.arity_eq, has the operation's value. - readsWidth_of_map (f : B.Op) : B'.ReadsWidth (self.toHom f) → B.ReadsWidth f
An operation whose image reads the word size reads it itself.
Instances For
Sub-bases #
Addition, truncated subtraction, multiplication, division and remainder: the operation symbols of the bounded-word RAM of MIT–ULB CompGeom Group, without bitwise operations, shifts or the word size. Words here are unsigned and subtraction is truncated, whereas the source subtracts signed words; on the other operations and nonnegative arguments the two agree.
Instances For
The additive operations are arithmetic.
Instances For
The arithmetic operations are standard.
Instances For
The additive operations are standard.
Instances For
The two inclusions of the additive operations in the standard ones agree.