Srinivasa

From Esolang
Jump to navigation Jump to search

Srinivasa, named after the genius young mathmetician, who's great with infinite series, is an esolang with the only programmable things being two recursive functions and the input variables.

Semantics and Syntax

Srinivasa has two functions, called κ, and a function called ζ. These have nothing to do with anything outside of this language. κ and ζ are defined like this:

κ(x,y,z,...) <- expression here
ζ(x,y,z,...) <- other expression here

Both functions must have the same amount of inputs, though even still, ζ can be left empty/not in the program. Recursive functions are explicitly allowed, and are in fact the only way of looping. The commands within a function are :?+-*/&_()v#", which are described below:

+(x,y): add x to y.
-(x,y): subtract y from x.
*(x,y): multiply and return.
/(x,y): divide x by y, halt if division by zero.
?(x,y,z): if x is equal to zero return y, else z.
&(x,y): if one of them is 0, return 0, else return x.
_(x): if x is 0, return 1, else return 0.
(x): brackets.
v(x): round x down to the closest 10.
#(x): print x as a number.
"(x): print x as unicode.
:(x,y,z): find the leftmost, ignoring brackets, term in both y and z and replace it with x. 
Another operator will need to be applied on top, since this returns (y,z). Note that this is generalized for any number of expressions after x.
Also note that, say we have (x,y,z) and we apply -(x,y,z), then it will return the pair (-(x,y),z)
!(x,y): discard y.

Order of operations follow with left first: ()"#:?*/+-&v_!. The final line of the program, is κ, with all its inputs(restricted to signed decimals), on an indented line starting with an arrow and a space, like this:

	> κ(x,y,z,...)

All numbers written in base 16, in the 0xN format. There is a way of taking input. This is by referencing a variable iN. It gets a single number as input(or, if not a number, then a unicode character converted to a number), when first encountering the variable, and returns that input.

Examples

Truth-machine:

κ(x,y) <- ζ(x,x)
ζ(x,y) <- ζ(#(x),0x1/x)
	> κ(i0,0x0)

A+B problem:

κ(x,y) <- #(+(x,y))
 	> κ(i0,i1)

Variants

Srinivasa has two of simple variants, both proven turing complete:

Srinivasa Unbounded

Srinivasa has any number of functions defined in the program. Srinivasa Unbounded is obviously Turing complete, because it can be compiled from Blindfolded Arithmetic with the following process(note that here I use a, b, and c as examples):

  • a = b + c becomes Fn(o,a,b,c,d,e,i) <- Fn+1(?(i,"0xA,#i),+(b,c),b,c,d,e,i).
  • a = b - c becomes Fn(o,a,b,c,d,e,i) <- Fn+1(?(i,"0xA,#i),-(b,c),b,c,d,e,i).
  • a = b * c becomes Fn(o,a,b,c,d,e,i) <- Fn+1(?(i,"0xA,#i),*(b,c),b,c,d,e,i).
  • a = b / c becomes Fn(o,a,b,c,d,e,i) <- Fn+1(?(i,"0xA,#i),/(b,c),b,c,d,e,i).
  • All of which have Fn with the n as their line index, starting at 0.
  • And for the last function, we set the body to reference the function F0(...).
  • Then we initialize as:
 	> F0(0,0,0,0,0,0,i0)

(Note that output is, when not halting, always outputting a newline)

Inline Srinivasa

In Inline Srinivasa, inline functions can be created lambda style:

(\x,y,z.something)(inputs)

Inline Srinivasa is also turing complete, because Srinivasa Unbounded can be simulated. You do this, by simulating Blindfolded Arithmetic in almost the same way. The only difference is that for each separately lined function is made into a lambda. Then for the final cycle, we just do:

κ(o,a,b,c,d,e,i) <- ζ(program expression here)
ζ(o,a,b,c,d,e,i) <- κ(o,a,b,c,d,e,i)

Mock theta

This variant of Srinivasa is string based. Note that I wont describe it here, because its basically its own language.

Computational class

As you can see above, the two mentioned extensions of Srinivasa are turing complete. However is Srinivasa TC? It is, via compilation from FRACTRAN with the following process:

  • For every fraction pn/qn, where n is their index, add to κ the arguments (pn,qn), and finally let κ have the form: κ(n,p0,q0,p1,q1,...pn/qn) <- κ((pn),p0,q0,p1,q1,...pn/qn), where p in (pn) is the converted Fractran program.
  • Now for the converted p, reverse the fraction list of the program, and then for every fraction pn/qn followed by the program p, translate into: (?((-(:((p),*(* (v(0x0),/(pn,qn)),0xA),*(0x0,0xA),0,*(v(0x0),/(pn,qn)))))). Note that by this, the original κ input n will be the innermost p.
  • Then last, leave ζ never created, and initialize with:
 	> κ(i0,p0,q0,p1,q1,...pn/qn)

As such, Srinivasa is turing complete.