Sūtras in Silicon

Shortcuts from Vedic Mathematics that turn up again inside computers, and where they stop.

Mathematics / Sūtras in Silicon

The methods in Bhāratī Kṛṣṇa Tīrtha’s book were designed for a person working in base 10. A computer works in base 2⁶⁴ and multiplies two 64-bit numbers in one instruction, so for ordinary-sized numbers no digit-by-digit trick can be faster. But for very large numbers, the hundreds of digits used in cryptography and exact arithmetic, several of the same ideas are standard techniques that were discovered independently and go by other names.

Method by method

Each Vedic name links to its animated lesson.

in use

Vertically and crosswise

Ūrdhva-Tiryagbhyām → Comba (product-scanning) multiplication
Computing the answer one column at a time, taking all the products that land in the same place and then the carry, is how big-number libraries multiply small and medium operands. P. G. Comba (1990) showed that column order needs far fewer memory writes than row-by-row multiplication.
in use

Duplex squaring

Dvandva-yoga → symmetric squaring
When both factors are the same, every crosswise product appears twice. Libraries such as GMP compute each one once and double it (the duplex), which makes squaring much cheaper than general multiplication.
in use

All from nine, the last from ten

Nikhilam division → pseudo-Mersenne reduction
Dividing by a number just below a power of the base reduces to multiplying by its small complement and adding. Cryptographers choose primes for exactly this reason. Curve25519 works modulo 2²⁵⁵ − 19, so every reduction is a Nikhilam step with complement 19, and it runs in every modern secure web connection.
in use

The vinculum

bar digits → Booth recoding · signed-digit arithmetic
Writing 576 as 6 2̄ 4̄ trades big digits for small negative ones. In binary the same idea, with digits −1, 0 and 1, cuts the number of additions in hardware multipliers (A. D. Booth, 1951) and in elliptic-curve arithmetic (the non-adjacent form). Redundant signed digits also let fast dividers add without waiting for carries (A. Avizienis, 1961).
in use

Osculation

Veṣṭana → Montgomery reduction
Each osculation step adds a multiple of the divisor that makes the last digit 0, then drops that digit. That is exactly one step of P. L. Montgomery’s reduction (1985), the workhorse of RSA and elliptic-curve arithmetic, done in base 2⁶⁴ instead of base 10.
in use

Recurring decimals by the ekādhika

Ekādhikena Pūrveṇa → multiply-with-carry random numbers
Generating 1/19 from the right, multiplying by 2 and keeping the carry, is G. Marsaglia’s multiply-with-carry generator. With multiplier a and base b it outputs the digits of a fraction with denominator ab − 1. With a = 2 and b = 10 that fraction is 1/19.
same method

Straight division

Dhvajāṅka → Knuth’s Algorithm D
Guessing each quotient digit from the leading digit or digits of the divisor, then correcting with the rest, is the standard long-division algorithm for big numbers (Knuth, The Art of Computer Programming, vol. 2). It is the same method, with no speed-up.
same method

Square and cube roots digit by digit

Vargamūla → digit-recurrence roots
Taking a root one digit at a time and subtracting duplexes is the digit-recurrence method used in some hardware square-root units. Software usually prefers Newton’s iteration, which doubles the number of correct digits at each step.
in use

Casting out nines

Guṇita-samuccaya → checksums and residue checks
Checking a calculation by its remainder modulo 9 is a residue check. Some processors check their arithmetic units with small residues, and the Internet checksum is arithmetic modulo 2¹⁶ − 1, which is casting out nines in base 2¹⁶.
no gain

Special-case tricks

These depend on base-10 patterns that vanish in binary, and on numbers small enough to fit in one machine word, where a single hardware multiply takes a few clock cycles. There is no gain.

The ceiling

Vertically-and-crosswise multiplication takes about n² digit products for n-digit numbers. A. A. Karatsuba (1962) needed only about n1.58, Toom–Cook and FFT-based methods need fewer still, and D. Harvey and J. van der Hoeven (2019) reached n log n. Libraries therefore use the column method only below a few dozen machine words and switch to these methods for anything larger. None of the sūtras beats them.

Where something may remain

Decimal arithmetic. Financial software, decimal floating point and big numbers stored in base 10⁹ really do work in powers of ten, so Nikhilam-style reduction by divisors near 10ᵏ and Ekādhika-style generation of recurring decimals apply directly. Explanation. The sūtras give short, memorable descriptions of algorithms that textbooks often show only as code, which is a useful way to teach why they work.

References: P. G. Comba, “Exponentiation cryptosystems on the IBM PC” (1990); P. L. Montgomery, “Modular multiplication without trial division” (1985); A. D. Booth (1951); A. Avizienis (1961); G. Marsaglia, multiply-with-carry generators (1990s); D. E. Knuth, The Art of Computer Programming vol. 2; D. J. Bernstein, Curve25519 (2006); A. A. Karatsuba (1962); D. Harvey & J. van der Hoeven (2019).