Frackit

From Esolang
Jump to navigation Jump to search

Frackit is an esolang created by islptng. It operates on fractions. It has a stack.

Commands

Command Meaning
#n push(n) (n is a positive integer)
/ push(1/pop())
! pop()
< insert(0,pop())
> push(pop(0))
^ push(pop().denominator)
* push(pop()*pop())
: duplicate top of stack
% swap top 2 items
[code] execute code infinitely
(code1|code2) pop, if equal to 1, execute code1, else execute code2
+ continue
- break
, input a number(can be fraction or integer), push it
. pop a value and print it(as fraction or integer)
'c print c as a character

If the program begins with a number, the I/O will be modified to the number-base.
For example, if the program begins with 2, inputting 16 will cause 65536 to be pushed(2^16=65536); outputting 65536 will cause 16 to be printed.

Computational class

Two of the easiest models to implement in Frackit are tag and counter machines. An example for a tag system is given below. The procedure for tag is to wrap everything in a top level infinite loop. A starting word can be pushed before the loop. At the start of each loop iteration are m > instructions, corresponding to the m-tag system. all but the first > are paired with a ! to throw away the symbol. After the start of the word is properly handled, the top of stack is now what was the start of the word. A nested check can be done to produce the correct rule. Each check is in the form : #symbol / * ( production | next rule ). This scheme duplicates the top of stack, then divides it by the symbol number, running the production if the result was 1 (they were the same) or the next rule check if it was not. This scheme means that symbols should be 1 indexed, with the first being 1, second being 2, and so on. The production itself has the form ! #sym #sym... with the first ! popping the top of stack, which was the start of the word. There should also be a rule, explicitly corresponding to a symbol or corresponding to any invalid symbol, which halts. The production body of the halting rule is simply -.

Counter machines can also be implemented in a fairly straightforward manner. We can identify the 0 state of a counter using the conditional structure. Counters start at 1 and can be incremented by multiplying with a constant. Decrementation can be done with division by the same constant. Since the stack can access at least two elements, and there are both loops and if/else conditionals, PMMN can be translated into Frackit.

These together prove that Frackit is Turing complete for either unbounded states or unbounded stack, of course also showing that Frackit with both is complete as well.

Examples

Hello World

'H'e'l'l'o',' 'w'o'r'l'd'!'

Truth Machine

,(['1]|'0)

Cat

There's no current Cat Programs, since this language only allows you to input an any fraction, so the below one is actually a fraction cat.

[,.]

XKCD Random Number

#4.

Alternative:

'4

A+B problem

2,,*.

It supports any positive integers.

Wikipedia's example 2-tag system

Note the space at the start.

 #2 #1 #1
[
  > > !
  : #1 / * (
    ! #3 #3 #2 #1 #4
    |
    : #2 / * (
      ! #3 #3 #1
      |
      : #3 / * (
        ! #3 #3
        |
          -
      )
    )
  )
]

Interpreter