1. Introduction
Ternary computing, particularly balanced ternary systems (using digits $\{-1, 0, 1\}$), offers theoretical advantages in storage efficiency and logical complexity. However, its practical adoption, exemplified by the Setun computer, faced fundamental interoperability challenges:
- Human Interface (I/O): The need to convert data to and from the decimal (base 10) system, which dominates human interaction.
- Machine Interoperability: The need to exchange data with the ubiquitous binary (base 2) architecture.
Direct conversions (e.g., $10 \leftrightarrow 3$ or $3 \leftrightarrow 2$) are complex and slow arithmetic operations. This paper demonstrates how an algorithm for conversion between adjacent bases ($p$ and $p \pm 1$) [1] provides an elegant solution to both bottlenecks.
2. The $p \to p \pm 1$ Translation Algorithm
The core algorithm [1] allows the conversion of a number in base $p$ to base $p-1$ or $p+1$ through an iterative process similar to synthetic division. Given a number $(a_n \dots a_0)_p$, the algorithm computes a quotient $(b_n \dots b_0)_p$ and a remainder $c_0$ from the division by $(p \pm 1)$, processing digit by digit.
The recurrence formulas (with sign adjustments based on standard implementations) are:
Where $c_{n+1}=0$, $\{x\}_y$ denotes the remainder, and $[x]_y$ the integer quotient.
2.1. Mathematical Derivation
The correctness of these formulas derives from the substitution $p = (p \pm 1) \mp 1$ into the standard polynomial representation of the number. In any step $i$ of the division, the current partial value is $c_{i+1} \cdot p + a_i$.
By substituting $p$: $$ c_{i+1} \cdot ((p \pm 1) \mp 1) + a_i $$ $$ = c_{i+1} \cdot (p \pm 1) \mp c_{i+1} + a_i $$
Taking this value modulo $(p \pm 1)$, the first term vanishes, leaving the remainder $c_i = \{a_i \mp c_{i+1}\}_{p \pm 1}$. This simple linear recurrence avoids full multi-digit multiplication, explaining the algorithm's efficiency.
3. Methodology: The Nonary (Base 9) Bridge for Decimal I/O
The solution for the $10 \leftrightarrow 3$ conversion bottleneck lies in the observation that $9 = 3^2$. This power relationship allows for a trivial (mapping-based) conversion between bases 9 and 3, analogous to the established relationship between hexadecimal (base 16) and binary (base 2) systems.
The $p \to p \pm 1$ algorithm is therefore best applied to translate between bases 10 and 9, rather than directly to base 3.
3.1. Input Process: Decimal (10) $\to$ Ternary (3)
-
Decimal $\to$ Nonary Conversion ($p \to p-1$): The input number (base $p=10$) is converted to base 9 (base $p-1$) using the successive division algorithm by 9.
Example [1]: $1234_{10} \to 1621_9$ -
Nonary $\to$ Standard Ternary Conversion ($9 \to 3$): Each nonary digit is mapped directly to a pair of ternary digits (trits) $\{0, 1, 2\}$, since $9=3^2$.
Result: $1621_9 \to (01)(20)(02)(01)_3 = 1200201_3$ (standard representation) - Conversion to Balanced Ternary (Setun): The standard ternary number $\{0, 1, 2\}$ is finally converted to the balanced system $\{-1, 0, 1\}$ via a fast internal CPU algorithm.
3.2. Output Process: Ternary (3) $\to$ Decimal (10)
- Balanced $\to$ Standard Ternary Conversion: The Setun's internal balanced number is converted to its standard ternary representation $\{0, 1, 2\}$.
-
Standard Ternary $\to$ Nonary Conversion ($3 \to 9$): The trits are grouped in pairs (from right to left) and mapped directly to nonary digits.
Example: $1200201_3 \to (01)(20)(02)(01)_3 \to 1621_9$ -
Nonary $\to$ Decimal Conversion ($p \to p+1$): The base 9 number (base $p=9$) is converted to base 10 (base $p+1$) using the successive division algorithm by 10.
Example [1]: $1621_9 \to 1234_{10}$
4. Discussion and Application to Binary Interoperability
The "nonary bridge" methodology (Section 3) efficiently solves the decimal I/O problem. However, the $p \to p \pm 1$ algorithm has a second, equally crucial application: interoperability with standard binary systems.
For a ternary computer (base $p=3$) to communicate with a binary computer (base $p-1=2$), a $3 \to 2$ conversion is required. The $p \to p-1$ algorithm, with $p=3$, provides the most direct and computationally efficient method for performing this Ternary $\to$ Binary translation. A number in base 3 can be repeatedly divided by base 2 (represented in ternary arithmetic as standard digits) using the same linear, digit-by-digit method described in Section 2.
5. Conclusion
The $p \to p \pm 1$ translation algorithm is not merely a mathematical curiosity but a historically significant software and hardware engineering tool with a dual application for ternary systems:
- I/O Efficiency: It elegantly solves the decimal conversion bottleneck ($10 \leftrightarrow 3$) by strategically using base 9 as an intermediary.
- Interoperability: It provides a native, direct method for ternary-to-binary conversion ($3 \to 2$), essential for communication with standard architectures.
This approach demonstrates how the selection of adjacent base conversion algorithms is fundamental to the practical viability of non-binary computing architectures.
6. References
- Alvarez H., R. (1970). Simple algorithms for p→p-1 and p→p+1 translations. In: Computer Science and Cybernetics, issue 7. Moscow State University Press.