Piece of cake

From Esolang
Jump to navigation Jump to search
Piece of cake
Designed by User:Hakerh400
Appeared in 2026
Computational class Turing complete
Major implementations Implemented
Influenced by Fractran
File extension(s) .txt

Piece of cake is an esolang invented by User:Hakerh400 in 2026.

Overview

Piece of cake is conceptually similar to Fractran. It is designed to overcome several of the Fractran's inconveniences:

  • In Fractran, replacing x with y is represented as fraction y/x, which frequently leads to typos, because most people perceive time flowing from left to right, and replacing x with y should be written in a way such that x appears first. In Piece of cake we write x -> y
  • Original Fractran does not support uncancelled fractions such as (x*z)/(x*y). Even though it is possible to rewrite any program to avoid using uncancelled fractions, it may be invonvenient and unnecessarily obfuscates the program. Piece of cake supports x y -> x z
  • Prime numbers in Fractran are a distraction. The exact value of prime numbers has no meaning, all we care about is that they are distinct and we store data in exponents. So, primes are just labels for registers. In Piece of cake we use identifiers instead of prime numbers. For example, Fractran fraction (2^3*5^7)/(3^2) can be written in Piece of cake as a:2 -> b:3 c:7

The author invented this esolang while playing game "Fractran" by Thomas Kern.[1]

Syntax

Source code consists of lines. Each line consists of two terms separated by -> token. Each term consists of a number of variables and their cardinalities. For example:

A x:2 y:7 -> B x:1 z:3

This means: whenewer we have a term that contains variable A at least once, variable x at least 2 times and variable y at least 7 times, remove those matched variables and add B once, x once (colon is redundant for cardinality 1, but added here as an example) and z 3 times. For example, it will replace A x:2 y:8 with B x y z:3. The order of variables does not matter. Cardinality 0 (such as x:0) is the same as not writing a variable at all. If the same variable appears multiple times, their cardinalities are added (x:5 y:3 x:7 is the same as x:12 y:3).

Input is a term. Before the program starts, insert identifier INP (with cardinality 1) in the input term. In a loop, find the first line that can be matched, perform replacement and continue search. When no lines can be matched, terminate the loop, remove OUT from the final term and output the final term.

Examples

Multiplication

Multiply a and b, store the product in c.

INP -> A
A b -> B
A -> D
B a -> B c d
B -> C
C d -> C a
C -> A
D a -> D
D -> OUT

Division

Divide n by d, store the quotient in q and the remainder in r.

INP -> A
A n -> B n
B d -> B c e
B -> C
C e -> C d
C -> D
D n c -> D
D c -> E c
D -> A q
A -> F
F d -> F
F -> G
E c -> E x
E -> G
G d x -> G
G d -> G r
G -> OUT

Conversion to Fractran

The official interpreter supports direct conversion to Fractran. For example, the division example translates to:

13^16 / 11
23 / 13^16
13^15*19 / 23*2
29*2 / 13^15*19
13^14*19^2 / 29*3
29*53*59 / 13^14*19^2
13^13*19^3 / 29
31 / 13^13*19^3
13^12*19^4 / 31*59
31*3 / 13^12*19^4
13^11*19^5 / 31
37 / 13^11*19^5
13^10*19^6 / 37*2*53
37 / 13^10*19^6
13^9*19^7 / 37*53
41*53 / 13^9*19^7
13^8*19^8 / 37
23*5 / 13^8*19^8
13^7*19^9 / 23
43 / 13^7*19^9
13^6*19^10 / 43*3
43 / 13^6*19^10
13^5*19^11 / 43
47 / 13^5*19^11
13^4*19^12 / 41*53
41*61 / 13^4*19^12
13^3*19^13 / 41
47 / 13^3*19^13
13^2*19^14 / 47*3*61
47 / 13^2*19^14
13*19^15 / 47*3
47*7 / 13*19^15
19^16 / 47
17 / 19^16

(Here we assume that / has lower precedence than *, to avoid parentheses)

External resources

References