# Forex

“Forex” is a model of computation devised by Mason Green in 2022. It can be proven Turing-complete as it is a generalization of Bag and Fractran.

Forex, as the name indicates, uses a trader who exchanges currencies as an analogy for computation. The trader carries a *wallet* which can hold varying, non-negative amounts of each currency. The minimum amount of each currency is zero, while there may or may not be upper limits on how much the wallet can hold. If there are upper limits, they can apply to a single currency or jointly to multiple currencies. For instance if there are black and white currencies, limits could be specified as (black <= 30), (black + 2*white <= 45), etc.

There is also an ordered list of possible *exchanges* the trader can make. On each step, he will always attempt to make the first trade in the list. If he either does not have enough currency to cover the trade, or would end up with an over-stuffed wallet afterwards, then he will attempt the next trade on the list instead, and so on. Unlike real trades, these can occasionally involve simply giving away or receiving currencies for nothing in return.

One convention is to name the currencies as colors, which makes it possible to imagine bills or coins of that color being physically traded.

## An example

One list of possible trades is:

-(1 red) -> (1 blue)

-(2 blue + 1 yellow) -> (2 red + 1 green)

-(2 blue) -> (1 grey)

-(1 blue + 1 orange) -> (1 red + 1 grey)

-(1 blue + 1 grey) -> (2 red + 2 yellow)

-(1 grey + 1 green) -> (1 orange + 1 yellow)

-(1 grey) -> (2 blue)

-(1 green) -> (1 blue)

-(1 yellow) -> (nothing)

-(nothing) -> (1 grey + 1 blue)

Assuming the wallet has unlimited capacity for each currency, then this is equivalent to Devin Kilminster‘s Fractran program for generating prime numbers, as described in the Fractran article. The currencies correspond to prime factors: yellow (2), red (3), orange (5), blue (7), green (11) and grey (13).

We start with (1 orange + 1 yellow), which corresponds to n=10. From then on, whenever the wallet holds the same amount of orange and yellow currency (all other currencies being zero), the number of units of each type will be prime, and the program visits all primes in increasing order. This corresponds to the original program visiting only those powers of 10 in which the exponent is prime.

## Additional features

Compared to Bag and Fractran, Forex has two additional features that give it more potential. First, it allows an upper as well as a lower limit on the amount of some currencies in the wallet. This, in Fractran terms, would be analogous to placing upper limits on the exponents of certain prime factors of the number n.

Second, the quantity of currencies in each trade doesn’t have to be an integer, and in fact can be any real number, including irrational numbers. This makes it possible to simulate aperiodic sequences like the Fibonacci word and Sturmian words extremely easily, as well as opening the door to chaotic behavior (in which having 0.000001 more or less of a particular currency could have major effects on what the trader does in the future).