Split Computation on Rings

2026-09-30

Table of Contents

Idea

If two numbers mod 15 can be summed mod 15 and those two numbers can be summed mod 3 and mod 5, can the 'sum' computation be split?...

For example, if we want to compute $ 9 + 13 \pmod{15} $, we perform the computations modulo 3 and 5 then reconstruct the result:

$ 9 + 13 \equiv 0 + 1 \equiv 1 \pmod{3} $

$ 9 + 13 \equiv 4 + 3 \equiv 2 \pmod{5} $

$ 7 \equiv 1 \pmod{3} \text{ and } 7 \equiv 2 \pmod{5} $

$ \implies 9 + 13 \equiv 7 \pmod{15} $

Proof of Concept

Here's some code to demo the entire process, with an example of multiplying $ 123 * 456 \pmod{3 * 5 * 17 * 101} $.

import math

import numpy as np

DATATYPE = np.int64

def modular_inverse(n, m):
    if n == 0:
        return 0
    assert math.gcd(n, m) == 1, f"Inverse does not exist for {n} % {m}."
    assert m != 1
    
    m_original = m
    y = 0
    x = 1

    while n > 1:
        y, x = x - n // m * y, y
        m, n = n % m, m

    if x < 0:
        x += m_original

    return x

def demo(a=11, b=23, factors=[2, 3, 5]):
    # First, we need some prime numbers.
    # Theoretically, the factors can be non-primes but must be...
    # - coprime with other "factors"
    # - coprime with any intermediate numbers calculated
    factors = np.array(factors, dtype=DATATYPE)
    prod_factors = math.prod(factors)
    magic_nums = np.array([prod_factors // f * modular_inverse(prod_factors // f, f) for f in factors], dtype=DATATYPE)
    print(f"{factors=}  ({prod_factors=})")
    print(f"{magic_nums=}")
    print()

    print(f"{a} * {b} % {prod_factors} == {a * b % prod_factors}")
    print()

    print(f"{a} % {factors} == {a % factors}")
    print(f"{b} % {factors} == {b % factors}")
    print(f"{a % factors} * {b % factors} == {(a % factors) * (b % factors)}")
    print(f"{a % factors} * {b % factors} % {factors} == {(a % factors) * (b % factors) % factors}")
    print()

    ab_split = (a % factors) * (b % factors) % factors
    print(f"sum({ab_split} * {magic_nums}) % {prod_factors} = {sum(ab_split * magic_nums) % prod_factors}")
    print()

demo()
print("\n------------------------------\n")
demo(a=123, b=456, factors=[3, 5, 17, 101])
# Output:
"""
factors=array([2, 3, 5])  (prod_factors=30)
magic_nums=array([15, 10,  6])

11 * 23 % 30 == 13

11 % [2 3 5] == [1 2 1]
23 % [2 3 5] == [1 2 3]
[1 2 1] * [1 2 3] == [1 4 3]
[1 2 1] * [1 2 3] % [2 3 5] == [1 1 3]

sum([1 1 3] * [15 10  6]) % 30 = 13


------------------------------

factors=array([  3,   5,  17, 101])  (prod_factors=25755)
magic_nums=array([17170,  5151, 13635, 15555])

123 * 456 % 25755 == 4578

123 % [  3   5  17 101] == [ 0  3  4 22]
456 % [  3   5  17 101] == [ 0  1 14 52]
[ 0  3  4 22] * [ 0  1 14 52] == [   0    3   56 1144]
[ 0  3  4 22] * [ 0  1 14 52] % [  3   5  17 101] == [ 0  3  5 33]

sum([ 0  3  5 33] * [17170  5151 13635 15555]) % 25755 = 4578
"""

Limitations

As far as I know this can only work on computations that can be performed on a ring. In other words, you can only do addition, multiplication, subtraction, and modular division on integers modulo some number N that is a product of non-repeating primes.

For example, you cannot compute with fractions directly or with a modulus like $2^{64}$.

Advantages and Use-cases

Even the product of the first 100 primes, from 2 to 541 inclusive, is quite large: 220 digits (or 730 bits).

4711930799906184953162487834760260422020574773409675520188634839616415335845034221205289256705544681972439104097777157991804380284218315038719444943990492579030720635990538452312528339864352999310398481791730017201031090

Parallel Computation (Impractical)

If you can break up large numbers into smaller number, then you can distribute them, perform the computions on the smaller numbers, then recombine to get the final result.

Partially Secret Computation (Impractical)

If you have access to computation on multiple machines that do not cooridnate and that you cannot trust... you can send each machine a piece of the computation to perform and that machine will only know the inputs and outputs of that computation modulo some 'small' prime(s).

I would be so surprised if this were ever practical.

Computing with Light (Practical?)

This is something that may be practical though it probably isn't

Say that you have 2 lasers emitting light at independent phases. Each phase corresponds to a number. Where the lasers interfere, those numbers are added (modulo the range of possible phases). Due to inability to measure precisely or inability to control the phases precisely, it may not be possible to add numbers with much resolution. However, if the addition is split into much smaller additions where much less resolution is required, now the computation is possible.

For example, if the 2 lasers can have their phases set with 1% accuracy and any detectors can also only measure the phase with 1% accuracy, then it would be difficult to perform any computation based on phase with more than 1% accuracy (i.e. with whole number larger than 100). However... using factors which cover the primes from 2 to 97 inclusive gives you the ability to add numbers with up to 36 digits (120 bits).

COMMENTS

You can comment on this post by replying to infosec.exchange/@mikelmcdaniel/117630480265218666 on Mastodon.

Don't have a Mastodon account? JoinMastodon.org.