##
#
To *B* or not...

Explains the essence of number expressions
`a,b`

from scratch.
People start to pay attention here!

### # Structures by RepExp

The highest principle for creating algorithms is
**frugality** –
to maximize the effect (function speed, Bigger numbers)
with minimal means.

- Minimize the length of the expression string.
- Use less character types (e.g. evaluations in Btrix don't insert brackets).
- Restrict the rules to their bare necessities.

Let Btrix count down variables fully.
Except for the initial entry `a`

at the left,
we allow a void (number `0`

)
in all positions.
This rules out multiple mixed separators,
keeping our algorithm simple.

The governing system of Btrix
interprets all kinds of general recursive structures numerically.
But she has a character rewriter
(our Abacus machine) under the hood.
Our matrix function, superficially dealing just with numbers,
is living in a programmer's world.

Ideally we should always point out the way a new jump to a higher structure
is represented by primitive rewrite steps inside a word (string).

From traditional Regular Expressions (RegExp)
we may use the quantifiers `?`

or `{0,1}`

for none or one occurrence, in context
`{k>0}`

or
`{1,}`

for one or more,
and `{k≥0}`

or `{0,}`

for any number. In general `{k}`

for exactly `k`

copies,
and `{m,n}`

for at least `m`

and at most `n`

copies of a preceding word: a single sign `x`

or

bracketed string.**(**X**)**

Our new **RepExp**
meta-notation to select and repeat parts of an expression in rules,
is quite practical and concise.
It applies a mathematical dot notation

to word repetition,
and usually regular expressions to repeat
*:k:*`{k}`

single characters.
Words can run from either side
or from single dots `.`

placed at the beginning of the *:left*
or *right:* repeated words.

Show a few examples of RepExp.

`x`*..* *:3* = x*..* *x:3* = x*{3}* = xxx
**F(***..***m***..*) *:3:* = F(**F(****F(****m**)))
A*.*n1,*..*Z *:2* = A**(**n1,**)**{2}Z = An1,n1,Z
aaaa*..*b*..*b*.*c_{i}*..* *aa:0 2: :4* = aabbbc_{0}c_{1}c_{2}c_{3}
**A***.*L_{i}*..*,{5}*..*R_{j}*.*Z *:3:* = **AL**_{0}L_{1}L_{2},,,,,R_{2}R_{1}R_{0}Z

The word to Rep(eat) from left to right
in the Exp(ression)
runs up to the double dot marks `..`

and we can connect this to a right word repeated inwards
(to the left) by a second pair/trio of dots.
The quantifier in this tandem repetition

counts how many word copies are placed on each side.*:k:*

### # Conventions

Our variables are **greedy** for number units,
naturally for the sign `1`

.
So when a variable `n`

sits next to a wildcard `X`

,
the proper substitute of `X`

won't have a number expressed on that end.

n = 1..:n= 1≥0{0,}(RegExp unlimited) Xn ≠ Y1n (greedy variablen)_n_≠_n1Y (underscore wildcard for passive parts)

We use the `=`

sign when two expressions are equal,
and when the right (decoded - output) expression follows from the left
(encoded - input) in the evaluation train to natural number.
Expressions are not equal `≠`

when one side cannot be reduced to the other.

We use the `≡`

sign
for the **equivalence** of expressions
in different formats,
or to justify a substitution (exchange)
of substrings within an expression.

Our Btrix matrix system applies two conventions: one at the beginning and one at the end of time (of the evaluation of an expression to Big number).

- 0.0 Btrix(
**X**)**≡ X**(simplify) - 0.1 Btrix(
**a**)**≡ a**= a (identify)

The **initial convention**
is to write the matrix in a simple format –
without function title and brackets –
which is sufficient because the evaluation rules of Btrix
won't nest an expression in place of a variable
(so common in other systems).

The **final convention**
is the identity function that reads the number result out.
It's a string of `1..`

(from here on your dedicated Abacus could translate it
to the preferred format ;-)

Because of our initial convention we feel fine
that `Btrix(`

is defined now.
But because our first rule, the **a**)*rule of choice*,
chooses to discard `a`

we might as well have left it undefined.

### # Choice rules

Our system starts with the simplest of rules.
Addition happens of itself when placing two variables
`ab`

holding number units `1..`

next to each other.
There's no use adding a rule to arrange for that,
as this could only mess things up.

It is when you want to keep *here*
what you are putting *there*
(and try to repeat that), that complexity arises.
A life lesson.

Anyway, more fundamental than any arithmetical operation
is *selection*, the operation of
choice.
This rule performs the last act of Btrix
to evaluate an expression to a (natural) number.

First the initial case where `b`

reduces to *=*0`0`

and then the standard rule of choice.
This rule is extended for when trailing commas have been kept,
and must now be discarded.

- 1.0 Btrix(
**a,**)**≡ a, =**(`a`

void) - 1.1
**a,b = b**(choice`b`

) - 1.2
**a,b,{k} = b**(choice, ignore trailing commas)

To drop or keep trailing structures is a convention,
with no significant impact on the resulting Big numbers.
This was a discovery by Jonathan Bowers,
an insight he had in array structures.

Bowers wanted to count off the pilot iterator
and just leave the residual `,1`

be,
even if it is never uploaded again.
Rule `1.2`

can be extended for this purpose, ignoring
the tail separator structures until the very last evaluation,
when no iterator entry remains in `$`

on the right.

In contrast Bird uses a comparison system
to determine whether left separators
`,`

are smaller than right,
and therefore are trailing and consequently dropped off.**[L]**1,**[R]**

- 2.1 a,Y, = a,Y (drop comma tail)

Rule `2.`

is optional.
If you work it out there's no need to remove trailing separators.
You can either let them be until the very end,
reuse some of them,
or optionally clean up during evaluation.

### # Adding by abacus

To add two numbers `ab`

is pretty straightforward.
But how do you copy a number to add it,
when you can only distribute a few characters at once?
Inside `4+2`

for example?

1111,11,1 =,1,,1111,11, =,11,,111,11, ==,1111,,1,11, (count down) =,1111,1,11, (prefix`,`

and insert`1,`

to split base) =,111,11,111, ==,1,1111,11111, (doubling) = 1111,111111, (carry`1`

over and drop prefix)

Prefix null ` ,`

parameters
for special machine modes!

All `colours`

are there to help your human eyes.

Next example `3+0`

of adding to zero,
coded (with `,`

for `0`

) in binary.

111,,1 =,1,,111,, =,11,,11,, =,111,,1,, =,111,1,, =,11,11,1, =,1,111,11, = 111,111,

Scheme for adding by doubling in Abacus,
with wildcards `W`

,
where *≥*∅`a`

is natural.*>*0

**a,b,1X**=**,1,,**a,b,X (down to addition)**,j,,**11X =**,j1,,**1X (move value) ==**,a,,**1,b,X**,a,,**1,X =**,a,**1,X (doubling mode) =**,a,**1,b,X (lower anchor)**,m1,**1n,Y =**,m,**1n1,1Y (double up) ==**,1,**a,ab-,X**,1,**a,Z =**a,1Z**(hail the anchor)**= a,ab,X**

Word repetition is our main tool in the definition of rules.
Here we add numbers on a primitive level –
doubling by copy `1`

and substitute `1,1`

or `,1`

in second place.

Check the initial case.

1,,1 =,1,,1,, (decrement1*1+0to addition mode) =,1,1,, (put1+0in doubling mode) = 1,1, (finish= 1in matrix mode) = 1,1 (drop trailing separator) = 1 (choice)

Only a pre-mathematical machine writes *null mode*
`,`

prefixes.
We have to do without the natural void ` `

(try unit `0'`

instead)
in the first entry.
At the anchor position
`a`

is mandatory.*≠*0

The Abacus machine abides,
with plenty of shekels to spend in the red.
It can resort to lengthy prefixes

where in **,{u}W _{i}..,{u1}**a,Z

*:v*

`W`

all `,`*{t**<*u}

to boil our rewrite rules down to the simplest of commands.
[it is so vicious :!]