RiptideRiptide
Download Riptide SDKInstall Riptorch
Menu
Raya · Research

Exact number types built from msets, in Raya

Multiply polynomials exactly as arrays of counts, compose matrices exactly, and keep small rationals in two registers. Msets, polynumbers, multinumbers, maxels, vexels, boxes and Rat64 as Raya types, with their definitions and laws, measured against C, GMP and Raya's BigInt on Arm and x86. Wins and losses.

Date
30 November 2026
Author
Samario Torres, Riptide
Software
Raya 0.4.0 (AOT); C, gcc -O3 -march=native; GMP 6.3
Hardware
AWS Graviton3 (Arm), Intel Xeon (x86)

Research note, 30 November 2026. Samario Torres, Riptide. A prototype, not a shipped Raya library.

These types follow N J Wildberger's construction of arithmetic from msets in his Math Foundations series (Insights into Mathematics); the lectures used are listed under Sources.

An mset is an unordered list with repetition. Store an mset as its counts and three familiar objects become arrays of small integers: a polynomial is an mset of naturals, a matrix is an mset of pixels, a natural number is an mset of one mark. This note builds those types in Raya, with exact arithmetic on the counts, and measures what they buy.

Short answer. It pays off where the counts are small numbers that fit in a byte, so the CPU's SIMD units can work on many of them at once.

  • Polynumbers (msets of naturals). Exact polynomial products on Graviton3 run faster than C's scalar loop and than GMP for degrees from about 256 to 1,024, and about 5,000 times faster than a one-object-per-element version.
  • Maxels and bipolynumbers. 760 to 2,300 times faster than the object versions, all exact.
  • Where it does not pay. Natural numbers written out as msets of ones or zeros (tallies) are exponentially large. The box of zeros only becomes usable once it is compressed to a count, and that count is an ordinary int (or a BigInt).

111 property tests pass on Arm and x86. Every timed result was first checked against a second implementation.

What you can do with these types

  • Multiply polynomials exactly, as counts, at SIMD speed (PolyMset): degree 1,024 in 87 µs on Graviton3, against 97 µs for GMP and 252 µs for C.
  • Build matrices that compose exactly (DenseMaxel): 0/1 maxels of 512 × 512 multiply in 10.3 ms, with counts that widen instead of overflowing.
  • Convolve 2-D arrays exactly (BipolyMset): 32 × 32 in 0.47 ms.
  • Do algebra in many variables (Multinumber): products of 2,048 × 2,048 terms in 0.61 s.
  • Count divisors and invert the divisibility order with the caret and the Möbius maxel.
  • Keep small rationals in two registers (Rat64): a + b in 100 ns, 8 times faster than a BigInt rational.

Every operation is exact or raises ExactOverflow; nothing wraps. Counts widen from int (64-bit) to BigInt automatically, the way int and BigInt relate.

Msets: sum, union and intersection

What it does. CountMset stores an mset over an alphabet as one count per letter. Pooling two msets is one pass of additions: over an alphabet of 65,536 letters it takes 116 µs, against 205 µs for Raya's scalar loop and 3.1 ms for a Map<int, int>.

Example. With A = [a a b] and B = [a c]:

  • A + B = [a a a b c] (pool both),
  • A ∪ B = [a a b c] (the larger count of each letter),
  • A ∩ B = [a] (the smaller count).

The mathematics. An mset over a set is a function that is zero outside a finite set; is the multiplicity of , and order does not matter, so [a a b] = [a b a]. The three operations act on multiplicities:

All three are commutative and associative. Sum distributes over union and over intersection, and ; union and intersection absorb each other, ; and sum cancels, .

Measured. The win above is against Raya's own loop and maps. C's auto-vectorised int32 add is 4 to 11 times faster than our count layout, and at alphabet 16 our vector path is slower than a plain loop.

Natural numbers and integers as msets

What it shows. A natural number is the simplest mset, and writing it out is the clearest way to see why int exists.

The mathematics. The natural is the mset of copies of one mark (or, in the box form, empty boxes, with ). Sum pools the two msets; product takes every pair, one element from each, with mark × mark = mark, so . Both are commutative and associative, and product distributes over sum.

Integers add anti-elements: an anti-mark cancels a mark, and anti × anti = mark is a definition chosen so the laws survive. Stored as a signed count per element, every law above still holds. In a variant with an anti-zero, distributivity fails at level zero, but ; that variant is kept only in the one-object-per-element reference.

Example. 3 + 2 = [| | |] + [| |] = [| | | | |] = 5, and 3 × 2 has 3 · 2 = 6 pairs.

Measured. The tally costs bytes, and a -bit number needs bytes: 10⁷ + 10⁷ takes 6.1 ms against about 1 ns for int. Compressed to its count, the mset is int (and BigInt beyond 64 bits).

The natural 6 as a tally, as a count and as a base-2 vexel
Figure 1. The natural 6 as a tally (6 bytes), as one count (an int), and as a base-2 vexel (binary 110).

Polynumbers: multiply polynomials exactly as counts

What it does. PolyMset holds a polynomial with natural coefficients as its list of counts and multiplies it exactly. With counts 0 … 255 at degree 256 the product takes 12.3 µs on Graviton3, against 16.0 µs for C's int64 loop, 18.9 µs for GMP and 63.8 ms for the object version (5,200×). Counts widen to int64 and then to BigInt when they grow.

Example. [2 3] × [1 1 0] = [3 3 2 4 4 3]. Read as polynomials, [2 3] = and [1 1 0] = , and the product [2 3 3 3 4 4] is . Likewise [0 0 1 1 1 2 3 3 3 3] = .

The mathematics. A polynumber is an mset of naturals. Its multiplicity list , with the number of copies of , is a coefficient list, and the polynumber is . Sum pools the msets, so coefficients add. Product adds every pair:

which is exactly polynomial multiplication. Sum and product are commutative and associative, and product distributes over sum.

Measured. At degree 1,024: ours 87 µs, GMP 97 µs, C 252 µs. Below degree about 128 C's scalar loop is faster (degree 64: C 1.1 µs, ours 2.9 µs). Past degree about 2,000 GMP's subquadratic multiplication wins (degree 4,096: GMP 0.54 ms, ours 0.96 ms), and with 40-bit counts we are 15 to 30 times behind GMP because Raya's BigInt is the bottleneck.

PolyMset: a polynumber as counts
Figure 2. PolyMset: a polynumber as its multiplicity list, int64 counts or a packed byte layout for small counts.

The caret: exponentiation of msets

What it does. The caret multiplies elements where the product adds them. On polynumbers of degree 256 it takes 0.66 ms, against 5.6 ms with Raya's BigInt.

Example. [1 2 … n] ^ [1 2 … n] contains every product , so the multiplicity of each is the number of divisors of . The caret product of the polynumbers [1, p, p², …] over the primes , cut at , is [1, 2, …, n]: that is unique factorisation (Euler's product).

The mathematics.

The caret is commutative and associative and distributes over sum, . The polynumber [1] is its identity, and (with ) counts : it is copies of 0, the natural .

PackedPoly: a small polynumber in one 64-bit word
Figure 3. PackedPoly: a small polynumber in one 64-bit word, the monomial of a multinumber.

Multinumbers: polynomials in many variables

What it does. Multinumber multiplies polynomials in many variables with integer coefficients: 15 terms in 20.6 µs against 253 µs for the object version (12×), the caret in 6.0 µs against 54 µs (9×), and 2,048 × 2,048 terms (4.2 M term pairs, 676 k result terms) in 0.61 s. The one-object-per-element version did not finish in 30 minutes; it takes 41 minutes at 512 terms and grows as n^4.0 (about 6 days at 2,048, extrapolated). For comparison, FLINT's fmpz_mpoly does the same product in about 9 ms, so for large sparse products FLINT remains the faster tool.

The mathematics. A multinumber is an mset of polynumbers. The variables are , the mset holding the single polynumber [n], and sum, product and caret are defined exactly as before, one level up. The result is ordinary algebra in the variables .

Example. . The tests also check the nested caret [[1 2] 4] ^ [0 [0 3]].

Maxels: matrices that compose exactly

What it does. DenseMaxel stores a matrix as counts and multiplies it exactly. With 0/1 counts at 512 × 512 the product takes 10.3 ms, against 22 ms for C's int64 loop (C's byte loop, 4.6 ms, is faster); at 64 × 64 the object version takes 32.7 ms against our 43 µs (760×).

Example. [1, 2] · [2, 3] = [1, 3], and [1, 2] · [3, 1] = 0, because the inner indices 2 and 3 differ.

The mathematics. A pixel is a pair and a maxel is an mset of pixels. Pixels multiply by

and the product extends to any two maxels by taking every pair, so the count at is : an integer matrix product over the shared middle index. The product is associative and reverses under transpose, with . For a set , the partial identity keeps the rows (on the left) or columns (on the right) in .

The Möbius maxel. The divisibility maxel on 1 … n has the inverse , so inverting gives the Möbius function. For that takes 82 µs, against 748 µs for the object version.

Maxels and bipolynumbers share one count array
Figure 4. Maxels and bipolynumbers share the array and differ only in the product.

Bipolynumbers: exact 2-D convolution

What it does. BipolyMset multiplies polynomials in two variables, which is a 2-D convolution: 32 × 32 in 0.47 ms, against 1.10 s for the object version (2,300×).

The mathematics. A bipolynumber is a finite 2-D array of numbers , the polynomial . The product is

Example. : a 2 × 1 array of ones times a 1 × 2 array of ones is the 2 × 2 array of ones.

Vexels: where BigInt is already the answer

What it shows. A vexel is the mset picture of positional notation. The measurement says the existing BigInt is that picture, already normalised.

The mathematics. A vexel is an mset of singletons , with , so vexels multiply like polynumbers. A base-2 vexel adds the exchange rule , and two vexels are equal when one can be reached from the other by exchanges. The normalised base-2 vexel, with every count 0 or 1, is the binary expansion.

Example. 6 = [1] + [2] = binary 110, and [1] + [1] + [2] = [2] + [2] = [3] = 8.

Measured. Deferring carries (base , = 8 or 16) does not pay: the product is 8 to 48 times slower than Raya's BigInt (4,096 bits: 43 µs against 5.4 µs; GMP 2.1 µs), and summing many 1,024-bit numbers costs 65 ns per term against 37 ns.

Boxes: nested boxes at real sizes

What it does. BoxPool makes nested-box arithmetic usable at real sizes by storing every distinct box once. The natural 10⁹ is one (child, multiplicity) pair, and the product of boxes of naturals up to takes 42 µs, flat in , against 4.2 ms and growing for the object version (100×).

The mathematics. In box arithmetic every number is a box, an mset of boxes: , the natural is a box of zeros, and a polynumber is a box of naturals, so the same sum, product and caret apply at every level of nesting.

Measured. On small random boxes (depth 3, tiny naturals) the pool is 2 to 8 times slower than the object version; it wins only when elements repeat or naturals are large.

BoxPool: every distinct box stored once
Figure 5. BoxPool: every distinct box is stored once; the natural 10⁹ is one pair.

Rationals: Rat64

What it does. Rat64 keeps a rational as two int64 in lowest terms and adds two rationals with 8-bit parts in 100 ns, against 835 ns for Raya's BigInt rational (8×). It falls back to the BigInt rational when a result does not fit.

The mathematics. A rational is a pair of integers with , and when . Then

and the field laws hold. In lowest terms with each rational has one representation, so Raya's generated value-class equality is rational equality.

Example. .

Measured. Rat64 is 1.3 to 3.5 times behind GMP's mpq (8-bit parts: 100 ns against 78 ns; 30-bit parts: 365 ns against 103 ns).

Rat64: an exact rational in two registers
Figure 6. Rat64: an exact rational in two registers.

The Raya types and how each one sits in memory

Table 1. The prototype's types: each one is a layout of counts, measured against a one-object-per-element version of the same type.
Raya typeWhat it storesMathematical typeRelation to int and BigInt
ByteMsetone byte per element: the natural n is n zero bytes (a tally)natural number as an mset of zerosthe uncompressed box; a b-bit number needs 2ᵇ bytes
CountMsetone int32 count per letter, in a packed layout for the CPU's SIMD unitsmset over an alphabetunion and intersection are max and min of counts
PolyMsetone count per natural: int64 counts, BigInt counts when a count outgrows int64; byte counts for small countspolynumber (an mset of naturals)a box of zeros compressed to its count is int
PackedPolya small polynumber in one 64-bit word, one byte per natural 0 … 7 (a value class)a monomial of a multinumberthe standard packed-monomial layout of computer algebra
Multinumbersorted (word, int64 count) pairs, 16 bytes per distinct monomialmultinumberpolynomials in many variables with integer coefficients
DenseMaxelrows × columns of countsmaxelthe product is an integer matrix product over the shared middle index
BipolyMsetthe same array as a maxelbipolynumberthe product is a 2-D convolution
VexelNatone count per position, base 2ᵏ (k = 8 or 16), carries deferredvexelthe normalised vexel is BigInt's binary digits
BoxPoolhash-consed boxes: every distinct box stored once, as (child id, multiplicity) pairsnested boxesthe natural 10⁹ is one pair; equality is id equality
Rat64two int64 in lowest terms, denominator > 0 (a value class, kept in registers)rational numberfalls back to a BigInt rational
CountMset: one int32 count per letter
Figure 7. CountMset: one int32 count per letter, packed for the CPU's SIMD units.

Laws and how they are tested

raya test runs 111 tests, and all pass on Arm (Graviton3) and x86 (Xeon) with Raya 0.4.0.

  • Every law above is a seeded property test: 40 to 300 random cases each, for sum, union, intersection, product and caret on every type (commutativity, associativity, distributivity, identities, absorption, cancellation, (A+B)^C = A^C + B^C, 1 ^ A = the count of A, transpose of a product).
  • Every type is cross-checked against a straightforward one-object-per-element implementation (boxes, msets as sorted lists, polynumbers and bipolynumbers over the rationals, maxels as maps of pixels) or against BigInt and the BigInt rational.
  • The worked examples are tests: [2 3] × [1 1 0] = [3 3 2 4 4 3]; [0 3] × [1 4] × [2 7]; (4, 1)·(3, 7); [0 0 1 1 1 2 3 3 3 3] = 2 + 3α + α² + 4α³; a maxel product of pixels; the caret [[1 2] 4] ^ [0 [0 3]]; the multinumber caret (1 + α₀ + α₁) ^ (1 + α₀²); Euler's product ∏^[1, p, p², …] = [1, 2, …, n]; [1 … n] ^ [1 … n] = the divisor counts; and the Möbius function from the divisibility maxel.
  • Every product implementation of a type is tested equal to the others on random inputs.
  • Every benchmark row is checked against a second implementation before it is timed.

Testing found three bugs in the prototype's own tests, all fixed before the measurements: a comparison that relied on an unnormalised compareTo, a 40-bit Rat64 test that expected results which legitimately overflow, and a multinumber benchmark that asked for 15 distinct polynumbers from a space of 8.

Results

Measured on AWS Graviton3 (Arm) and Intel Xeon (x86), one thread, against C (gcc -O3) and GMP; times are per operation on Arm unless stated. Full setup under Method details at the end.

Where the mset layouts win

Table 2. Wins, arm64 single thread. "Object version" is the one-object-per-element implementation of the same type.
WhatOursOthers
Polynumber product, counts 0 … 255, degree 25612.3 µsC int64 16.0 µs, GMP 18.9 µs, object version 63.8 ms (5,200×)
Polynumber product, degree 1,02487 µsGMP 97 µs, C 252 µs
Caret A ^ B, degree 2560.66 msRaya BigInt 5.6 ms
Maxel product, 0/1 counts, 512 × 51210.3 msC int64 22 ms (C byte loop 4.6 ms is faster); object version at 64 × 64: 32.7 ms against our 43 µs (760×)
Möbius maxel, n = 6482 µsobject version 748 µs
Bipolynumber product, 32 × 320.47 msobject version 1.10 s (2,300×)
Multinumber product, 15 terms20.6 µsobject version 253 µs (12×); caret 6.0 µs against 54 µs (9×)
Multinumber product, 2,048 × 2,048 terms0.61 s (4.2 M term pairs, 676 k result terms)object version did not finish in 30 min (41 min at 512 terms); FLINT fmpz_mpoly ≈ 9 ms
Boxes of naturals up to n = 1,000: product42 µs, flat in nobject version 4.2 ms, growing with n (100×)
Rationals with 8-bit parts: a + b100 nsRaya BigInt rational 835 ns (8×); GMP mpq 78 ns
Mset sum, alphabet 65,536116 µsRaya scalar loop 205 µs, Map<int, int> 3.1 ms

Where they lose

  • Tallies (unary naturals). The tally costs n bytes: 10⁷ + 10⁷ takes 6.1 ms against about 1 ns for int; 1,000 × 1,000 writes a million bytes in 341 µs. A b-bit number needs 2ᵇ bytes. The box of zeros is only usable compressed, and the compression is int (BigInt beyond 64 bits).
  • Vexels as a bignum. Deferring carries does not pay: the product is 8 to 48 times slower than Raya's BigInt (4,096 bits: 43 µs against 5.4 µs; GMP 2.1 µs), and summing many 1,024-bit numbers costs 65 ns per term against 37 ns. BigInt already is the normalised vexel.
  • GMP at large sizes. Past degree about 2,000, GMP's subquadratic multiplication beats our quadratic products (degree 4,096: GMP 0.54 ms, ours 0.96 ms). Polynumbers with 40-bit counts are 15 to 30 times behind GMP; Raya's BigInt is the bottleneck there.
  • Small polynumbers. Below degree about 128, C's scalar int64 loop is faster (degree 64: C 1.1 µs, ours 2.9 µs).
  • x86. Raya has no SIMD intrinsics on x86-64 yet, so the byte layouts run scalar code there (polynumber degree 4,096: 55 ms against 27 ms for int64 counts) and C is 3 to 6 times faster. The Xeons do have the matching SIMD instructions, so this is a compiler gap, not a hardware one.
  • Small random boxes. The hash-consed pool is 2 to 8 times slower than the object version on depth-3 boxes of tiny naturals; it wins only when elements repeat or naturals are large.
  • Rationals against GMP. Rat64 is 1.3 to 3.5 times behind GMP's mpq (8-bit parts: 100 ns against 78 ns; 30-bit parts: 365 ns against 103 ns).
  • Mset counts against C. C's auto-vectorised int32 add is 4 to 11 times faster than our count layout; at alphabet 16 our vector path is slower than a plain loop.

Charts

Each chart shows arm64 on the left and x64 on the right, log scales, nanoseconds per operation.

Polynumber product against C, GMP, Raya BigInt and the object versions
Figure 8. Polynumber product: our byte counts against C, GMP, Raya BigInt and the object versions.
Maxel product
Figure 9. Maxel product, 0/1 counts.
Caret
Figure 10. Caret A ^ B.
Bipolynumber product
Figure 11. Bipolynumber product.
Multinumber product
Figure 12. Multinumber product.
Boxes of naturals: hash-consed pool against the object version
Figure 13. Boxes of naturals: the hash-consed pool against the object version.
Small random boxes: the pool loses
Figure 14. Small random boxes: the pool loses.
Natural numbers: tally against int, BigInt and GMP
Figure 15. Natural numbers, n + n: the tally against int, BigInt and GMP.
Natural numbers: product
Figure 16. Natural numbers, n × n.
Vexels against BigInt and GMP: vexels lose
Figure 17. Naturals as vexels against BigInt and GMP: vexels lose.
Summing many naturals
Figure 18. Summing many 1,024-bit naturals.
Rationals: a + b
Figure 19. Rationals: a + b.
Rationals: a × b
Figure 20. Rationals: a × b.
Mset sum
Figure 21. Mset sum (pooling) over an alphabet.
Polynumbers with 40-bit counts
Figure 22. Polynumbers with 40-bit counts: GMP wins.
Möbius maxel of divisibility
Figure 23. The Möbius maxel of divisibility on 1 … n.

Memory

Table 3. Payload bytes per value. For the object versions, measured RSS growth per value.
ValueOursObject version
natural 1008 B as an int; one 16 B pool pair; 100 B as a tally1,370 B
polynumber, degree 64520 B (int64 counts), 65 B (byte counts)7,100 B (polynumber over the rationals)
maxel 32 × 32, half full8,192 B (int64), 1,024 B (bytes)20,700 B (map of pixels)
rational16 B in registers (31 B when boxed in a list)two BigInts
polynumber inside a multinumber8 B word + 8 B counta box of boxes

Every measurement

Show all 286 rows (ns per operation; blank = not run on that architecture, — = memory-only row)
caseoperationsizeimplementationarm64 nsx64 nsbytes
bipolymul8ours: byte counts, SIMD1.845e+043.109e+04512
bipolymul8reference: Bipolynumber over Q4.49e+065.525e+06
bipolymul32ours: byte counts, SIMD4.703e+053.619e+068192
bipolymul32reference: Bipolynumber over Q1.095e+091.378e+09
bipolymul128ours: byte counts, SIMD5.644e+078.683e+08131072
caretcaret16Raya BigInt1.417e+041.801e+04
caretcaret16ours: int64 kernel13592144136
caretcaret16reference: sorted element list (Mset)7.744e+089.639e+08
caretcaret64Raya BigInt2.131e+052.491e+05
caretcaret64ours: int64 kernel2.075e+043.116e+04520
caretcaret256Raya BigInt5.6e+067.597e+06
caretcaret256ours: int64 kernel6.606e+059.912e+052056
caretcaret1024Raya BigInt2.056e+082.636e+08
caretcaret1024ours: int64 kernel1.106e+071.508e+078200
caretcaret4096ours: int64 kernel2.252e+084.809e+0832776
hboxcaret2ours: hash-consed boxes68367856
hboxcaret2reference: one object per element (Box)14681720
hboxcaret3ours: hash-consed boxes97681.114e+04
hboxcaret3reference: one object per element (Box)41785008
hboxcaret4ours: hash-consed boxes1.968e+042.124e+04
hboxcaret4reference: one object per element (Box)1.686e+041.876e+04
hboxmul2ours: hash-consed boxes61847045
hboxmul2reference: one object per element (Box)784.8896.9
hboxmul3ours: hash-consed boxes82869296
hboxmul3reference: one object per element (Box)18942264
hboxmul4ours: hash-consed boxes1.496e+041.628e+04
hboxmul4reference: one object per element (Box)28273138
hboxnatcaret10ours: hash-consed boxes1.797e+042.091e+04
hboxnatcaret10reference: one object per element (Box)2.707e+053.133e+05
hboxnatcaret1000ours: hash-consed boxes5.62e+04 (Graviton2)4.861e+04
hboxnatcaret100000ours: hash-consed boxes4.054e+044.732e+04
hboxnatmul10ours: hash-consed boxes1.334e+041.554e+04
hboxnatmul10reference: one object per element (Box)5.552e+047.057e+04
hboxnatmul1000ours: hash-consed boxes4.226e+04 (Graviton2)3.641e+04
hboxnatmul1000reference: one object per element (Box)4.174e+06 (Graviton2)3.568e+06
hboxnatmul100000ours: hash-consed boxes3.042e+043.55e+04
maxelmobius16ours: int64 kernel20083928
maxelmobius16reference: Maxel as a map of pixels3.86e+044.935e+04
maxelmobius64ours: int64 kernel8.19e+041.761e+05
maxelmobius64reference: Maxel as a map of pixels7.483e+059.256e+05
maxelmobius256ours: int64 kernel5.464e+061.002e+07
maxelmul16C int64, gcc -O3 -march=native666.8966.82048
maxelmul16C u8 dot, gcc -O3 -march=native501.91168256
maxelmul16ours: int64 kernel374850892048
maxelmul16ours: int64 kernel, counts ±1000613970552048
maxelmul16reference: Maxel as a map of pixels2.717e+053.019e+05
maxelmul16ours: byte counts, SIMD23961.783e+042048
maxelmul64C int64, gcc -O3 -march=native3.22e+046.663e+0432768
maxelmul64C u8 dot, gcc -O3 -march=native1.127e+043.62e+044096
maxelmul64ours: int64 kernel1.87e+052.061e+0532768
maxelmul64ours: int64 kernel, counts ±10003.61e+053.496e+0532768
maxelmul64reference: Maxel as a map of pixels3.275e+073.666e+07
maxelmul64ours: byte counts, SIMD4.318e+049.751e+0532768
maxelmul256C int64, gcc -O3 -march=native2.688e+063.289e+06524288
maxelmul256C u8 dot, gcc -O3 -march=native5.355e+052.101e+0665536
maxelmul256ours: int64 kernel1.138e+071.12e+07524288
maxelmul256ours: int64 kernel, counts ±10002.244e+072.1e+07524288
maxelmul256ours: byte counts, SIMD1.39e+065.948e+07524288
maxelmul512C int64, gcc -O3 -march=native2.241e+072.816e+072097152
maxelmul512C u8 dot, gcc -O3 -march=native4.603e+061.657e+07262144
maxelmul512ours: int64 kernel8.402e+078.451e+072097152
maxelmul512ours: int64 kernel, counts ±10001.581e+081.613e+082097152
maxelmul512ours: byte counts, SIMD1.032e+074.717e+082097152
msetadd16C int32 add, auto-vectorised4.15611.5764
msetadd16ours: int32 counts, SIMD59.8289.5964
msetadd16Raya Int32List loop27.6445.764
msetadd16Raya Map<int, int>513.8640.5
msetadd16reference: sorted element list (Mset)45105183144
msetadd256C int32 add, auto-vectorised28.6127.641024
msetadd256ours: int32 counts, SIMD191.6245.51024
msetadd256Raya Int32List loop393.3508.31024
msetadd256Raya Map<int, int>83701.005e+04
msetadd256reference: sorted element list (Mset)1.615e+051.784e+053168
msetadd4096C int32 add, auto-vectorised457.2745.316384
msetadd4096ours: int32 counts, SIMD1787259316384
msetadd4096Raya Int32List loop5670748016384
msetadd4096Raya Map<int, int>1.288e+051.587e+05
msetadd4096reference: sorted element list (Mset)3.081e+063.43e+0649016
msetadd65536C int32 add, auto-vectorised1.026e+041.173e+04262144
msetadd65536ours: int32 counts, SIMD1.163e+052.481e+05262144
msetadd65536Raya Int32List loop2.048e+053.557e+05262144
msetadd65536Raya Map<int, int>3.071e+065.286e+06
msetunion16ours: int32 counts, SIMD59.54118.764
msetunion256ours: int32 counts, SIMD192.8934.61024
msetunion4096ours: int32 counts, SIMD18421.375e+0416384
msetunion65536ours: int32 counts, SIMD1.274e+056.392e+05262144
multicaret8ours: packed 64-bit words64838631112
multicaret8reference: one object per element (Box)4.689e+045.393e+04
multicaret15ours: packed 64-bit words59777921112
multicaret15reference: one object per element (Box)5.435e+046.185e+04
multimul8ours: packed 64-bit words77639344128
multimul8reference: one object per element (Box)4.678e+045.606e+04
multimul15ours: packed 64-bit words2.078e+042.445e+04240
multimul15reference: one object per element (Box)2.527e+053.067e+05
multimul256ours: packed words, many terms3.129e+073.962e+074096
multimul2048ours: packed words, many terms6.098e+088.803e+0832768
natadd10Raya BigInt23.0532.8824
natadd10C int64, gcc -O3 -march=native0.36140.1768
natadd10ours: int64 counts31.545.968
natadd10GMP mpz5.3917.82916
natadd10Raya int (native int64)1.0231.2968
natadd10reference: one object per element (Box)10241344
natadd10tally: mset of zeros, 1 byte each16.6941.0810
natadd1000Raya BigInt23.4532.8424
natadd1000C int64, gcc -O3 -march=native0.36070.17518
natadd1000ours: int64 counts32.0745.928
natadd1000GMP mpz5.3917.8216
natadd1000Raya int (native int64)1.0271.2958
natadd1000reference: one object per element (Box)7.485e+049.76e+04
natadd1000tally: mset of zeros, 1 byte each201.4197.61000
natadd100000Raya BigInt23.6532.8724
natadd100000C int64, gcc -O3 -march=native0.36230.1768
natadd100000ours: int64 counts32.3945.898
natadd100000GMP mpz5.427.83816
natadd100000Raya int (native int64)1.0271.2958
natadd100000reference: one object per element (Box)1.278e+071.986e+07
natadd100000tally: mset of zeros, 1 byte each1.881e+042.295e+04100000
natadd10000000Raya BigInt23.6432.7324
natadd10000000C int64, gcc -O3 -march=native0.36120.17548
natadd10000000ours: int64 counts31.9845.838
natadd10000000GMP mpz5.3967.80216
natadd10000000Raya int (native int64)1.0141.2958
natadd10000000tally: mset of zeros, 1 byte each6.135e+061.242e+0710000000
natmul10Raya BigInt23.133.3124
natmul10C int64, gcc -O3 -march=native0.30170.27968
natmul10ours: int64 counts57.677.238
natmul10GMP mpz6.3138.75216
natmul10Raya int (native int64)1.1721.6198
natmul10reference: one object per element (Box)1.609e+041.848e+04
natmul10tally: mset of zeros, 1 byte each120.9247.410
natmul1000Raya BigInt23.5833.4524
natmul1000C int64, gcc -O3 -march=native0.30440.2798
natmul1000ours: int64 counts57.5276.178
natmul1000GMP mpz6.3098.73116
natmul1000Raya int (native int64)1.1461.6198
natmul1000tally: mset of zeros, 1 byte each3.406e+056.818e+051000
natmul100000Raya BigInt22.931.3224
natmul100000C int64, gcc -O3 -march=native0.30430.27918
natmul100000ours: int64 counts57.9276.288
natmul100000GMP mpz6.3358.74616
natmul100000Raya int (native int64)1.1691.6198
natmul10000000Raya BigInt23.2631.3324
natmul10000000C int64, gcc -O3 -march=native0.30440.27888
natmul10000000ours: int64 counts57.2676.378
natmul10000000GMP mpz6.3128.7516
natmul10000000Raya int (native int64)1.1591.628
polyadd16ours: int64 counts227.8311.6136
polyadd64ours: int64 counts807.51001520
polyadd256ours: int64 counts305840202056
polyadd1024ours: int64 counts1.226e+041.522e+048200
polyadd4096ours: int64 counts4.822e+046.213e+0432776
polymul16ours: automatic choice515750.8136
polymul16C int64, gcc -O3 -march=native141148.1136
polymul16GMP Kronecker (bit packing)795.51267136
polymul16GMP Kronecker (mpz_import)779.41015136
polymul16ours: int64 kernel499.4743.8136
polymul16Raya BigInt, Kronecker4.609e+044.577e+04136
polymul16reference: sorted element list (Mset)7.109e+089.06e+0820920
polymul16reference: Polynumber over Q2.59e+053.444e+05
polymul16Raya BigInt, schoolbook1.56e+041.972e+04136
polymul16ours: byte counts, SIMD11544563136
polymul64ours: automatic choice29307568520
polymul64C int64, gcc -O3 -march=native10711157520
polymul64GMP Kronecker (bit packing)49008402520
polymul64GMP Kronecker (mpz_import)32013915520
polymul64ours: int64 kernel58907558520
polymul64Raya BigInt, Kronecker1.677e+051.604e+05520
polymul64reference: Polynumber over Q3.977e+064.901e+06
polymul64Raya BigInt, schoolbook2.114e+052.541e+05520
polymul64ours: byte counts, SIMD28562.487e+04520
polymul256ours: automatic choice1.223e+041.127e+052056
polymul256C int64, gcc -O3 -march=native1.605e+041.955e+042056
polymul256GMP Kronecker (bit packing)4.919e+041.132e+052056
polymul256GMP Kronecker (mpz_import)1.894e+042.333e+042056
polymul256ours: int64 kernel9.854e+041.126e+052056
polymul256Raya BigInt, Kronecker7.326e+057.429e+052056
polymul256reference: Polynumber over Q6.382e+078.029e+07
polymul256Raya BigInt, schoolbook3.539e+064.147e+062056
polymul256ours: byte counts, SIMD1.225e+042.716e+052056
polymul1024ours: automatic choice8.427e+041.72e+068200
polymul1024C int64, gcc -O3 -march=native2.518e+053.197e+058200
polymul1024GMP Kronecker (bit packing)6.99e+051.686e+068200
polymul1024GMP Kronecker (mpz_import)9.708e+041.161e+058200
polymul1024ours: int64 kernel1.413e+061.72e+068200
polymul1024Raya BigInt, Kronecker2.998e+062.99e+068200
polymul1024Raya BigInt, schoolbook5.018e+075.968e+078200
polymul1024ours: byte counts, SIMD8.726e+043.879e+068200
polymul4096ours: automatic choice9.537e+052.716e+0732776
polymul4096C int64, gcc -O3 -march=native4.271e+066.137e+0632776
polymul4096GMP Kronecker (bit packing)1.054e+072.706e+0732776
polymul4096GMP Kronecker (mpz_import)5.419e+056.091e+0532776
polymul4096ours: int64 kernel2.209e+072.713e+0732776
polymul4096Raya BigInt, Kronecker1.663e+071.935e+0732776
polymul4096ours: byte counts, SIMD9.566e+055.549e+0732776
polybigadd16ours: int64 counts228.9310136
polybigadd64ours: int64 counts8021035520
polybigadd256ours: int64 counts303839632056
polybigadd1024ours: int64 counts1.216e+041.578e+048200
polybigmul16ours: automatic choice1.541e+041.97e+04136
polybigmul16GMP Kronecker (bit packing)14872456136
polybigmul16GMP Kronecker (mpz_import)20802712136
polybigmul16Raya BigInt, Kronecker1.115e+051.159e+05136
polybigmul16reference: Polynumber over Q2.503e+053.33e+05
polybigmul16Raya BigInt, schoolbook1.498e+041.971e+04136
polybigmul64ours: automatic choice2.199e+052.726e+05520
polybigmul64GMP Kronecker (bit packing)1.338e+042.603e+04520
polybigmul64GMP Kronecker (mpz_import)1.017e+041.224e+04520
polybigmul64Raya BigInt, Kronecker4.236e+054.473e+05520
polybigmul64reference: Polynumber over Q3.705e+064.807e+06
polybigmul64Raya BigInt, schoolbook2.146e+052.732e+05520
polybigmul256ours: automatic choice1.785e+061.914e+062056
polybigmul256GMP Kronecker (bit packing)1.579e+053.656e+052056
polybigmul256GMP Kronecker (mpz_import)5.956e+047.063e+042056
polybigmul256Raya BigInt, Kronecker1.804e+061.914e+062056
polybigmul256reference: Polynumber over Q5.497e+077.574e+07
polybigmul256Raya BigInt, schoolbook3.511e+064.374e+062056
polybigmul1024ours: automatic choice9.059e+061.061e+078200
polybigmul1024GMP Kronecker (bit packing)2.184e+065.389e+068200
polybigmul1024GMP Kronecker (mpz_import)3.347e+053.747e+058200
polybigmul1024Raya BigInt, Kronecker9.169e+061.065e+078200
polybigmul1024Raya BigInt, schoolbook5.3e+076.494e+078200
ratadd8double (inexact)1.9251.6218
ratadd8GMP mpq77.72103.532
ratadd8ours: Rat64 value class99.74133.516
ratadd8Raya Rational over BigInt834.81061
ratadd16double (inexact)1.9251.6198
ratadd16GMP mpq85.56119.232
ratadd16ours: Rat64 value class203.5246.516
ratadd16Raya Rational over BigInt14761889
ratadd30double (inexact)1.9251.6228
ratadd30GMP mpq102.6146.432
ratadd30ours: Rat64 value class365.4445.216
ratadd30Raya Rational over BigInt28123591
ratadd40double (inexact)1.9251.6228
ratadd40GMP mpq114.4168.932
ratadd40Raya Rational over BigInt39315106
ratmul8double (inexact)1.9251.9458
ratmul8GMP mpq96.48125.632
ratmul8ours: Rat64 value class111156.216
ratmul8Raya Rational over BigInt14942037
ratmul16double (inexact)1.9251.9438
ratmul16GMP mpq113.8158.832
ratmul16ours: Rat64 value class226.8283.716
ratmul16Raya Rational over BigInt21902944
ratmul30double (inexact)1.9261.9438
ratmul30GMP mpq145.9217.432
ratmul30ours: Rat64 value class392.8480.916
ratmul30Raya Rational over BigInt33124338
ratmul40double (inexact)1.9251.9478
ratmul40GMP mpq168.425832
ratmul40Raya Rational over BigInt44585876
ratoverflow40ours: Rat64 value class——
vexmulmul256Raya BigInt52.5662.6732
vexmulmul256Raya BigInt fastMultiply60.8771.5232
vexmulmul256GMP mpz25.9724.0732
vexmulmul256ours: vexel base 2¹⁶956.11294128
vexmulmul256ours: vexel base 2⁸, SIMD25373367256
vexmulmul1024Raya BigInt413.2418.2128
vexmulmul1024Raya BigInt fastMultiply424.7429.1128
vexmulmul1024GMP mpz208.8200.5128
vexmulmul1024ours: vexel base 2¹⁶82769934512
vexmulmul1024ours: vexel base 2⁸, SIMD90873.401e+041024
vexmulmul4096Raya BigInt54325166512
vexmulmul4096Raya BigInt fastMultiply54565179512
vexmulmul4096GMP mpz21122007512
vexmulmul4096ours: vexel base 2¹⁶9.395e+041.21e+052048
vexmulmul4096ours: vexel base 2⁸, SIMD4.283e+044.528e+054096
vexmulmul16384Raya BigInt8.368e+048.122e+042048
vexmulmul16384Raya BigInt fastMultiply6.339e+047.202e+042048
vexmulmul16384GMP mpz1.79e+041.792e+042048
vexmulmul16384ours: vexel base 2¹⁶1.428e+061.77e+068192
vexmulmul16384ours: vexel base 2⁸, SIMD3.211e+056.912e+0616384
vexmulmul65536Raya BigInt1.334e+061.182e+068192
vexmulmul65536Raya BigInt fastMultiply6.001e+055.655e+058192
vexmulmul65536GMP mpz1.256e+051.242e+058192
vexmulmul65536ours: vexel base 2¹⁶2.235e+072.574e+0732768
vexmulmul65536ours: vexel base 2⁸, SIMD3.999e+061.025e+0865536
vexsumsum16Raya BigInt35.0545.37
vexsumsum16GMP mpz12.3814.21128
vexsumsum16ours: vexel base 2¹⁶, one carry132.8190.4
vexsumsum256Raya BigInt38.2346.75
vexsumsum256GMP mpz15.1416.59128
vexsumsum256ours: vexel base 2¹⁶, one carry68.8595.51
vexsumsum4096Raya BigInt36.6548.74
vexsumsum4096GMP mpz15.3817.31128
vexsumsum4096ours: vexel base 2¹⁶, one carry65.1992.05

What is worth making first-class in Raya

  1. **Polynumber counts (PolyMset).** The clearest win: exact polynomial arithmetic that beats C's scalar loop and GMP between degree about 256 and 1,024 on Graviton (C is faster below about 128, GMP above about 2,000), with automatic widening from int64 to BigInt. Bipolynumbers and vexel products reuse it. Next step: a subquadratic multiplication layer on top, to stay ahead of GMP past degree 2,000.
  2. **Small exact rationals (Rat64).** 8 times faster than the BigInt rational, and the generated value-class equality is rational equality. Making it first-class needs compiler support for a small/large split (a value class cannot hold a BigInt today, the way int and BigInt are split), plus one more integer intrinsic.
  3. **Checked count arrays for msets and maxels (CountMset, DenseMaxel).** Counts that widen instead of overflowing, with SIMD products for small counts. The measured gap to C says two compiler items would pay off more than the types themselves: an integer auto-vectoriser (today it vectorises float loops only), and SIMD lowering on x86.
  4. **Packed monomial words (PackedPoly, Multinumber).** The standard fast layout for polynomials in many variables; it belongs in a computer-algebra library.
  5. **Hash-consed boxes (BoxPool)** stay a library: they make nested boxes usable at real sizes, but they are slower for tiny boxes.

Not worth it: tallies (unary naturals) and base-2ᵏ vexels as number types. In both cases int and BigInt are already the compressed, faster form.

Sources

  • N J Wildberger, Math Foundations lectures 1 to 238 and Algebraic Calculus One, YouTube. The 44 lectures used, in date order:
  1. 29 January 2009 · What is a number? · Math Foundations 1
  2. 30 January 2009 · Arithmetic with numbers · Math Foundations 2
  3. 3 February 2009 · Laws of Arithmetic · Math Foundations 3
  4. 16 February 2009 · Fractions · Math Foundations 9
  5. 16 February 2009 · Arithmetic with fractions · Math Foundations 10
  6. 10 March 2009 · Introducing the integers · Math Foundations 12
  7. 10 March 2009 · Rational numbers · Math Foundations 13
  8. 18 March 2009 · Extremely big numbers · Math Foundations 17
  9. 3 May 2010 · Polynomials and polynumbers · Math Foundations 57
  10. 6 May 2010 · Arithmetic with positive polynumbers · Math Foundations 58
  11. 17 May 2010 · What exactly is a polynomial? · Math Foundations 60
  12. 16 November 2010 · Arithmetic with integral polynumbers · Math Foundations 62
  13. 29 December 2011 · Row and column polynumbers · Math Foundations 65
  14. 1 January 2012 · Laurent polynumbers (the New Years Day lecture) · Math Foundations 68
  15. 9 August 2015 · Fun with lists, ordered sets, multisets I · Math Foundations 152
  16. 16 August 2015 · Fun with lists, multisets + sets II · Math Foundations 153
  17. 23 August 2015 · Fun with lists, multisets and sets III · Math Foundations 154
  18. 7 September 2015 · The realm of natural number multisets · Math Foundations 156
  19. 13 September 2015 · The algebra of natural number multisets · Math Foundations 157
  20. 29 December 2015 · Fun with lists, multisets and sets IV · Math Foundations 161
  21. 7 February 2016 · Maxel theory: new thinking about matrices I · Math Foundations 166
  22. 21 February 2016 · Maxel algebra! I · Math Foundations 169
  23. 5 March 2016 · Singletons, vexels, and the rank of a maxel I · Math Foundations 171
  24. 19 March 2016 · A disruptive view of big number arithmetic · Math Foundations 173
  25. 18 June 2016 · Multisets and a new framework for arithmetic · Math Foundations 187
  26. 9 July 2016 · Numbers, polynumbers and arithmetic with vexels I · Math Foundations 190
  27. 16 July 2016 · Numbers, polynumbers, and arithmetic with vexels II · Math Foundations 191
  28. 24 July 2016 · Arithmetic with base 2 vexels · Math Foundations 192
  29. 22 October 2016 · Negative numbers, msets, and modern physics · Math Foundations 205
  30. 29 October 2016 · A new trichotomy to set up integers · Math Foundations 206
  31. 5 November 2016 · Integral vectors and matrices via vexels and maxels I · Math Foundations 207
  32. 26 November 2016 · A broad canvas: algebra with maxels from integers · Math Foundations 209
  33. 18 December 2016 · The anti operation in mathematics · Math Foundations 212
  34. 9 December 2017 · Vexels and Polynumbers via Multisets · Algebraic Calculus One
  35. 17 February 2018 · Bi Polynumbers and Tangents to Algebraic Curves · Algebraic Calculus One
  36. 17 December 2022 · A multiset approach to arithmetic · Math Foundations 227
  37. 25 December 2022 · The big step from polynumbers to multinumbers!! · Math Foundations 228
  38. 31 December 2022 · The operation of caret / exponentiation (new!) via multisets · Math Foundations 229
  39. 8 January 2023 · Multiset arithmetic via trees · Math Foundations 230
  40. 30 January 2023 · Negatives numbers from anti msets · Math Foundations 231
  41. 14 March 2023 · More arithmetic with negative msets · Math Foundations 232
  42. 13 August 2023 · Towards a New Arithmetic !!! with msets / boxes · Math Foundations 226
  43. 3 September 2023 · Introducing (finally!) Box Arithmetic · Math Foundations 237
  44. 15 October 2023 · Box Arithmetic with Polynumbers · Math Foundations 238
  • Measurements: 30 November 2026, Raya 0.4.0, C (gcc -O3 -march=native) and GMP 6.3 on Ubuntu 24.04.

Working with Riptide

Riptide works with a small number of teams. Each engagement starts with 4 weeks inside your systems, learning how your models, data and infrastructure work. Only then does Riptide apply its software to them. Contact samario@riptidecompute.com or riptidecompute.com/evaluate.

Method details
  • Hardware. Arm: AWS Graviton3 (Neoverse-V1); one point (boxes of naturals, n = 1,000) ran on a Graviton2. x86: Intel Xeon Platinum 8259CL and 8175M. Linux.
  • Software. Raya 0.4.0, compiled ahead of time (raya compile exe). Baselines: C compiled with gcc -O3 -march=native, and GMP 6.3, on Ubuntu 24.04.
  • Timing. Single thread. Each time is the best of 5 blocks of at least 60 ms, reported per operation. Every row is checked against a second implementation before it is timed.
  • Runs. Each type and size ran in its own fresh 2-vCPU container on both architectures, plus reruns; 593 rows in all.