```Soroban
-------
The  Japanese abacus (Soroban) consists of an upper and lower deck, each housing
a number of columns of beads.

... ───┬───┬───┬───┐
O   O   O   │ <- "upper deck"
│   │   │   │
... ───┼───┼───┼───┤ <- "beam".
│   │   │   │
O   O   O   │ <- "lower deck"
O   O   O   │
O   O   O <-│--- "columns of beads"
O   O   O   │
... ───┴───┴───┴───┘

Beads  in the lower deck represent 1 and those in the upper deck, 5. Numbers are
counted  by  moving  beads  _towards_ the central beam, so the picture above re-
presents ...000.

Here  are  some more numbers. Above each abacus is the decimal equivalent of its

1   2   3               4   5   6               7   8   9
... ───┬───┬───┬───┐    ... ───┬───┬───┬───┐    ... ───┬───┬───┬───┐
O   O   O   │           O   │   │   │           │   │   │   │
│   │   │   │           │   O   O   │           O   O   O   │
... ───┼───┼───┼───┤    ... ───┼───┼───┼───┤    ... ───┼───┼───┼───┤
O   O   O   │           O   │   O   │           O   O   O   │
│   O   O   │           O   O   │   │           O   O   O   │
O   │   O   │           O   O   O   │           │   O   O   │
O   O   │   │           O   O   O   │           O   │   O   │
O   O   O   │           │   O   O   │           O   O   │   │
... ───┴───┴───┴───┘    ... ───┴───┴───┴───┘    ... ───┴───┴───┴───┘
0/1.0/2.0/3             0/4.1/0.1/1             1/2.1/3.1/4

The  expression at the base of each soroban corresponds to the bead positions in
the  columns  above.  Characters  0-4 show the number of beads moved towards the
central  beam  '/'  and  adjacent columns are separated by '.'. We will use this
symbolic  representation from here on. Auxiliary functions ⍺ and ⍵ in the script
convert  between  these ⍺bacus and ⍵estern number representations. Whole decimal
numbers  are  represented with a '.' separator between each digit; this is not a
decimal point (see →Overview←).

⍺ 3.7.4             ⍝ ⍺bacus from ⍵estern number 374.
0/3.1/2.0/4

⍵ 0/3.1/2.0/4       ⍝ ⍵estern from ⍺bacus.
3.7.4

Addition is performed with reference to the following small table:

┌───┬───┬───┬───┐
+ │ 1 │ 2 │ 3 │ 4 │
┌───┼───┼───┼───┼───┤
│i/0│i/1│i/2│i/3│i/4│   Where: + = i+1
├───┼───┼───┼───┼───┤
│i/1│i/2│i/3│i/4│+/0│   Addends of 5 and above are recast:
├───┼───┼───┼───┼───┤
│i/2│i/3│i/4│+/0│+/1│       i/n + (5+j) => (i+1)/n + j
├───┼───┼───┼───┼───┤
│i/3│i/4│+/0│+/1│+/2│   If i=1, then  (i+1) carries to the next column:
├───┼───┼───┼───┼───┤
│i/4│+/0│+/1│+/2│+/3│       i/m . (1+1)/n =>  i/(m+1) . 0/n
└───┴───┴───┴───┴───┘

Similarly, subtraction is performed with reference to:

┌───┬───┬───┬───┐
- │ 1 │ 2 │ 3 │ 4 │
┌───┼───┼───┼───┼───┤
│i/0│-/4│-/3│-/2│-/1│   Where: - = i-1
├───┼───┼───┼───┼───┤
│i/1│i/0│-/4│-/3│-/2│   Subtrahends of 5 and above are recast:
├───┼───┼───┼───┼───┤
│i/2│i/1│i/0│-/4│-/3│       i/n - (5+j) => (i-1)/n - j
├───┼───┼───┼───┼───┤
│i/3│i/2│i/1│i/0│-/4│   If i=0, then  (i-1) carries to the next column:
├───┼───┼───┼───┼───┤
│i/4│i/3│i/2│i/1│i/0│       i/m . (0-1)/n =>  i/(m-1) . 1/n
└───┴───┴───┴───┴───┘

(
The  Chinese  abacus, or "Suan-Pan", has an extra bead in both the upper and
lower deck:

... ───┬───┬───┬───┐
O   O   O   │
O   O   O   │ <- 2 beads/column in upper deck,
│   │   │   │
... ───┼───┼───┼───┤
│   │   │   │
O   O   O   │
O   O   O   │
O   O   O   │ <- 5 beads/column in lower deck.
O   O   O   │
O   O   O   │
... ───┴───┴───┴───┘

For  decimal calculations, the outermost beads are not used, except to defer
an overflow-carry operation if desired. The prime purpose of the extra beads
is  to  provide a total of 3 × 6 = 18 combinations, allowing the possibility
of hexadecimal arithmetic in calculating weights (1 Jin = 16 Liang).

The Japanese Soroban evolved from the Chinese Suan Pan by losing a bead from
its upper deck in the middle of the 19th century and one from its lower deck
in the middle of the 20th.
)

(
As  the  Pre-Columbian  people of Central America used their toes as well as
their  fingers for counting, they wound up with a base 20 number system. The
digits  were written in columns, each expressed as a series of up to 5 marks
arranged in up to 4 rows (fingers/toes per hand/foot).

See: dfns.dws/notes.mayan for further details.

The  4×5  arrangement of marks suggests an abacus with 3 beads in the upper,
and  4  in  the lower deck, giving 4×5 combinations. The Mesoamerican abacus
appears  to  have been invented independently of the Chinese abacus (just as
their invention of the Zero appears to be independent of the Arab Zero).

... ───┬───┬───┬───┐
O   O   O   │
O   O   O   │ <- 3 beads/column in upper deck,
O   O   O   │
│   │   │   │
... ───┼───┼───┼───┤
│   │   │   │
O   O   O   │
O   O   O   │ <- 4 beads/column in lower deck.
O   O   O   │
O   O   O   │
... ───┴───┴───┴───┘

An example "Nepohualtzitzin" dates from 900-1000 AD. It was made from maize-
the  upper  and lower floating ones. Nepohualtzitzin was worn on the forearm
as a nifty fashion accessory. (It would be interesting to find how ownership
of  such  abaci  was spread within mesoamerican society; perhaps the average
market  trader  sported  one, or perhaps they were the exclusive preserve of
the  Astronomer-Priest. Given that the device itself looks relatively inexp-
ensive to manufacture, this would say more about the general grasp or avail-
ability  of  arithmetic within the community, than about the distribution of
wealth needed to own such a beautiful calculator - JMS).

Ref: Ifrah, G. "The Universal History of Numbers".
)

(
A common feature of all of these abaci is that they respect the limit of the
number  of objects or states that the human recognition system can grasp im-
mediately  without  explicitly  having to count them. This limit seems to be
around 4.

Just for fun and given this constraint, here is a proposal for an abacus for
a base 60 (sexagesimal) number system, as used by the Babylonians and Sumer-
ians.

... ───┬───┬───┬───┐
│   │   │   │
O   O   O   │ <- 2 beads/column in upper deck,
O   O   O   │
... ───┼───┼───┼───┤
│   │   │   │
O   O   O   │
O   O   O   │ <- 3 beads/column in middle deck,
O   O   O   │
... ───┼───┼───┼───┤
│   │   │   │
O   O   O   │
O   O   O   │ <- 4 beads/column in lower deck.
O   O   O   │
O   O   O   │
... ───┴───┴───┴───┘

We would see something like:

⍺ 12.34.56
0/2/2.1/2/4.2/3/1

Here is a function to translate a decimal number into "abacus format":

enco←{                      ⍝ Encode to ⍺-abacus.
⍺←2 5                   ⍝ default to soroban.
cols←⌈(×/⍺)⍟⍵           ⍝ number of columns to use.
base←cols/×/⍺           ⍝ encoding base.
digs←⍺⊤base⊤⍵           ⍝ digits in each column, in each deck.
nums←⍕¨¨↓⍉digs          ⍝ formatted digits per deck, per column.
join←{↑⍺{⍺,⍺⍺,⍵}/⍵}     ⍝ ⍺-join function.
'.'join'/'join¨nums     ⍝ collected abacus representation.
}

enco 23           ⍝ encode to soroban.
0/2.0/3

enco 87
1/3.1/2

For the base-60 "triple-decker" above, we bind a left argument of 3 4 5:

tridek←3 4 5∘enco

tridek 20
1/0/0

tridek 83
0/0/1.1/0/3

tridek 60⊥12 34 56
0/2/2.1/2/4.2/3/1
)

Examples:

soroban script until'→'

⍺ 1.2.3                         ⍝ abacus representation of decimal 123.
0/1.0/2.0/3

⍺ 4.5.6                         ⍝ ditto 456.
0/4.1/0.1/1

0/0 + 1.2.3                     ⍝ addition into cleared abacus.
0/1.0/2.0/3

⍵ 0/0 + 1.2.3                   ⍝ ... reinterpreted into (⍵estern) decimal.
1.2.3

⍵ 0/0 + 1.2.3 + 4.5.6           ⍝ sequence of additions.
5.7.9

⍵ (⍺ 3.5) - 7                   ⍝ succession of subtractions of 7 ...
2.8

⍵ (⍺ 3.5) - 7 - 7
2.1

⍵ (⍺ 3.5) - 7 - 7 - 7
1.4

→                               ⍝ etc.

soroban trace eval'⍵ 0/0 + 9.9.9 + 1'         ⍝ traced additions.
···0/0+9.9.9 [h/e+q.d → (0/0+q).(h/e+d)] (0/0+9.9).(0/0+9)
····0/0+9.9 [h/e+q.d → (0/0+q).(h/e+d)] (0/0+9).(0/0+9)
·····0/0+9 [h/e+d → (h+1)/e+⌊d] (0+1)/0+⌊9
······(0+1)/0 [(0+1)/e → 1/e] 1/0
······⌊9 [⌊9 → 4] 4
·····1/0+4 [h/0+e → h/e] 1/4
·····0/0+9 [h/e+d → (h+1)/e+⌊d] (0+1)/0+⌊9
······(0+1)/0 [(0+1)/e → 1/e] 1/0
······⌊9 [⌊9 → 4] 4
·····1/0+4 [h/0+e → h/e] 1/4
····0/0+9 [h/e+d → (h+1)/e+⌊d] (0+1)/0+⌊9
·····(0+1)/0 [(0+1)/e → 1/e] 1/0
·····⌊9 [⌊9 → 4] 4
····1/0+4 [h/0+e → h/e] 1/4
··1/4.1/4.1/4+1 [p.h/e+d → p.(h/e+d)] 1/4.1/4.(1/4+1)
···1/4+1 [h/4+1 → (h+1)/0] (1+1)/0
···(1+1)/0 [(1+1)/e → 0/1.0/e] 0/1.0/0
··1/4.1/4.(0/1.0/0) [p.(0/1.q) → (p+1).q] (1/4.1/4+1).0/0
···1/4.1/4+1 [p.h/e+d → p.(h/e+d)] 1/4.(1/4+1)
····1/4+1 [h/4+1 → (h+1)/0] (1+1)/0
····(1+1)/0 [(1+1)/e → 0/1.0/e] 0/1.0/0
···1/4.(0/1.0/0) [p.(0/1.q) → (p+1).q] (1/4+1).0/0
····1/4+1 [h/4+1 → (h+1)/0] (1+1)/0
····(1+1)/0 [(1+1)/e → 0/1.0/e] 0/1.0/0
·⍵0/1.0/0.0/0.0/0 [⍵p.q → (⍵p).⍵q] (⍵0/1.0/0.0/0).⍵0/0
··⍵0/1.0/0.0/0 [⍵p.q → (⍵p).⍵q] (⍵0/1.0/0).⍵0/0
···⍵0/1.0/0 [⍵p.q → (⍵p).⍵q] (⍵0/1).⍵0/0
····⍵0/1 [⍵0/e → e]  1
····⍵0/0 [⍵0/e → e]  0
···⍵0/0 [⍵0/e → e]  0
··⍵0/0 [⍵0/e → e]  0
1.0.0.0

References:

http://werwolf.ee.ryerson.ca:8080/~elf/abacus