# Mark D. Niemiec's Numbers and Games Calculator

## Calculator

I have written a simple desk calculator program that allows one to explore a little bit about Numbers and Games. It is implemented as a Windows-32 console application, but it has no system dependencies in it, so it can be easily ported to the platform of one's choice.

The program has the following features:

• Enter numeric expressions involving numbers and games, and to display their values.
• May store results of expressions in user-defined variables.
• May store some results as user-defined constants, that behave like variables, but are treated as fundamental values for display purposes.
• May assign most operators to user-defined names.

The program has some limitations:

• No facility for saving a workspace. If values need to be preserved, they must be defined in a script that is loaded each time.
• Extremely primitive memory management (i.e. it keeps allocating memory as needed, until it can't get any more, and then garbage collects.)
• It does not support infinite sets (i.e. this precludes numbers like ω, ε, 1/3, π, etc.)
• It supports the 3 basic loopy games (on, off, dud), but no other loopy games. (The result of this is that the operation x:y is not closed, since it can sometimes produce such games, if one of x or y is itself loopy.)
• It is constrained by the ASCII character set, so many of Conway's colorful notations must use more prosaic forms.

## Syntax

The calculator accepts successive lines of input, that it interprets as numeric expressions. It evaluates the expressions, then displays the results. Each expression may be a number, or a set of multiple numbers.

The calculator accepts expressions with the following syntax:

expr = name | '(' [expr] ')' | '{' [expr] '}' | unary expr | expr binary expr

Names consist of one or more letters, digits, or any non-blank punctuation characters except !&()+,-:;<=>?[]{|}~. Due to conflicts with defined operators, the two names . and .. are reserved.

Parentheses force order of evaluation. Braces form sets. Since the calculator treats all expressions as sets, the two can be used interchangeably. However, the characters themselves are not treated as equivalent; e.g. {0} ⇔ (0) ⇔ 0, but {0) is a syntax error. Empty sets can be entered via empty parentheses or braces, but there is really little need to do so, since the game composition operator | allows either of its left or right parameters to be omitted.

Unary operations bind most closely. Binary operations are always evaluated left-to-right (except assignments, that are evaluated right-to-left), but different operations have different binding precedences, with those with higher precedences binding more closely than those with lower ones.

An expression may also have a value that is an operator, rather than a number or game. Such an expression is created by specifying any operator alone (or between parentheses or braces). The composition operator | may not be used this way, because because an expression consisting of | is already interpreted as a number formed from two empty sets (i.e. 0). Such expressions may be used in three different ways:

• An operator expression may be assigned; e.g. minus=-.
• An operator expression is treated as the operator itself; e.g. 4(minus=-)34(-)34-3.
• An operator variable is treated as the operator itself; e.g. 4 minus 34-3 and minus 3-3.

## Unary Operations

These are the supported unary operations, showing Conway's notation (if any), the calculator's notation, the operation name, and a brief description:

Conway Calculator Name Description
+x +x Self The game itself.
xL <x Left Set Given x, return x's left set.
xR >x Right Set Given x, return x's right set.
D(x) &x Day Number Given x, return the day it was created.
(none) >>x Absolute Positive absolute value.
(none) <<x - Absolute Negative absolute value.
(none) ::x Relative Position This shows a number's position relative to all other defined numbers. It prints its result and does not actually return any result.
(none) ?? Summary This shows all defined names. It prints its result and does not actually return any result.

## Binary Operations

These are the supported binary operations, showing the operation binding precedence group increasing from top to bottom, Conway's notation (if any), the calculator's notation, the operation name, and a brief description:

Prec. Conway Calculator Name Description
= x=y x=y Assign Variable Set a user-defined name x to value y. (5)
x=y x=:y Assign Constant Set a user-defined name x to value y, and use it as a constant for subsequent display. (5)
< x<y x<y Less Than Returns 1 if x is less than y. (1)
x>y x>y Greater Than Returns 1 if x is greater than y. (1)
xy x!<y Not Less Than Returns 1 if x is not less than y. (1)
xy x!>y Not Greater Than Returns 1 if x is not greater than y. (1)
xy x<=y Less or Equal Returns 1 if x is less than or equal to y. (1)
xy x>=y Greater or Equal Returns 1 if x is greater than or equal to y. (1)
xy xy x<?y Less or Fuzzy Returns 1 if x is less than or fuzzy to y. (1)
xy xy x>?y Greater or Fuzzy Returns 1 if x is greater than or fuzzy to y. (1)
xy x<>x More or Less Returns 1 if x is greater or less than y. (1)
xy x!<>x Not more or Less Returns 1 if x is not greater or less than y. (1)
x=y x==y Equals Returns 1 if x is equal to y. (1)
xy x!=y Not Equal Returns 1 if x is not equal to y. (1)
xy x?y Fuzzy Returns 1 if x is fuzzy to y. (1)
xy x!?y Not Fuzzy Returns 1 if x is not fuzzy to y. (1)
(none) x::x Compare Compare x and y. Return _1 if less than, 0 if equal, 1 if greater than, or * if fuzzy. (1)
| || ||| x|y x||y x|y x||y Bar Separate left and right sets. (2)
, x,y x,y Append Join two sets to form a larger set. (3)
! xy x!y Tardy Union (Or) Move in some components. (4)
xy x!!y Urgent Union (Ur) Move in some components; stop if any component stops. (4)
& xy x&y Fast Join (and) Move in all components; stop if any component stops. (4)
xy x&&y Slow Join (also) Move in all remaining components. (4)
>> (none) x>>y Maximum Whichever game is best for Left.
(none) x<<y Minimum Whichever game is best for Right.
+ x+y x+y Plus Move in one component.
x-y x-y Minus Plus negative.
x:y x:y Ordinal Sum Move in x, then in y when x is exhausted. (4)
. x·y x×y x.y Times Multiply numbers (and some games).
x·y x×y x..y Norton Multiply Multiply games.
Unary (See previous section.)
Space x,y x y Append Join two sets to form a larger set. (3)

Note 1: Comparison predicates return 1 if the entirety of set x compares appropriately against the entirety of set y, 0 otherwise.

Note 2: Any number of vertical bars may be used together, and the result is the same; the only difference is that higher number of bars bind at a lower precedence; i.e. a||b|ca|(b|c). Furthermore, it is permissible for one or both parameters to be empty.

Note 3: If no operation is given between two expressions, e.g. x y, a comma is assumed between them; this binds much tighter than comma itself does, or indeed any other operators, including unaries (e.g. -3,4 ⇔ _3 4 but -3 4 ⇔ _3 _4).

Note 4: This operation depends on the form of a game, not just its value. Unfortunately, the calculator performs most calculations on games assuming that equal games (i.e. ones with the same value) are interchangeable, so expressions involving this operation may not produce the desired results if any of the parameters are games in non-standard forms.

Note 5: This assigns a value to a user-defined name. The value must be a single number, and cannot be an empty set, or a set of two or more numbers. It can also be an operator (excluding |). If the name already has a value, the previous value is replaced. If the value is omitted, the variable is erased, and the previous value is returned.

## Vocabulary

Other than seven basic constants (0, 1, _1, *, on, off, dud), the calculator has no pre-defined values. Rather, all values are explicitly defined in an externally-supplied script file. For values that occur in ranges, most such ranges define all related values for n varying from 0 to 10.

These are the characters used in script-defined constants, showing Conway's notation (if any), the calculator's notation, and the description:

Conway Calculator Name
n n Positive integers (0-10)
-;n _n Negative integers (0-10)
1/2…7/8 1/2…7/8 Positive binary fractions below 1
-1/2…7/8 _1/2…7/8 Negative binary fractions below 1
* *n * *n Nimbers (0-10)
↑ ⇑ ⤊ ⟰ ^ ^^ etc. Multiples of Up (1-10)
↓ ⇓ ⤋ ⟱ v vv etc. Multiples of Down (1-10)
↑* ⇑* etc. ^* ^^* etc. Multiples of Up (1-10) plus Star
↓* ⇓* etc. v* vv* etc. Multiples of Down (1-10) plus Star
x Tx Tiny (0-10,on;)
⧿x _Tx Miny (0-10,on)
*/2 */2 *n/2 Semi-stars (1-10)
-*/2 _*/2 *n/2 Negative Semi-stars (1-10)
↑/2 3/2↑ etc. ^/2 ^3/2 etc. Semi-up, Sesqui-up, etc. (1-11)
↓/2 3/2↓ etc. v/2 v3/2 etc. Semi-down, Sesqui-down, etc. (1-11)
±x \x Hot game { x | -x } (0-10)