Neg

From Esolang
Jump to: navigation, search

Neg is a esoteric programming language made by User:HereToAnnoy that requires the programmer to go against mathematics in order for it to be turing complete.

Neg uses prefix notation and a variety of "well-crafted" built in functions, carefully made to force one to break mathematics to do anything useful (hopefully). Whitespace can be used to separate things for clarity.
Values in Neg are (usually) integers.

Built in functions and variables

Function/Variable Description
. Constant value of -1
% Constant value of undefined
^ab Function that returns a^b
Lab Function that returns log(abs(a))(b) (the first argument is the base)
{key:val,key2:val2,...} Standard JSON object notation. Note: When accessing a property of the object, omit the []. Also note: There are no strings in Neg, so you cannot use a string as a key. Also also note: Properties can be added to a JSON object, just like in JavaScript.
a_(b) While a!=0, do b
a__(b) While a<code>!=% (undefined), do <code>b
I JSON object for program inputs, see I/O
O JSON object for program outputs, see I/O
[a0,a1,a2,...,aN;] Superposition of a0 through aN, see Superpositions

New functions can be created in Neg with the following syntax:

F(a)(b) = ([code goes here, without []];) //This will create a function F with arguments a and b. Note: A ; or \n will exit a function, returning the last expression (i.e. +.., ^+..., etc.)

Whitespace is allowed and ignored during interpretation.

I/O

Input and output in Neg are handled like so:

Input JSON formatting

The I JSON object is formatted like an array. At index 0 is the number of inputs (N) (inputs are usually numbers), and indices 1 to N are those inputs. All other indices are left undefined.

Output JSON formatting

The O JSON object is also formatted like an array, and all defined indices will have there values outputted (in least to greatest order).

This section really didn't need subcategories but I'm lazy and unprofessional so whatever...

Uh, just ignore this line and the one above.

Breaking math to define positive numbers

At first glance, Neg is a language that is designed to be impossible to use. It is, kind of.
After careful consideration of the built in functions and variables, it seems that the only way to get positive numbers is to have them inputted. However, if one allows the rules of mathematics to be slightly broken, he/she can define all positive numbers, with just a simple trick.

1^log(1)(-1) = -1 //There are many things wrong with this equation (log of a negative and log base 1), but if we take it by definition, it seems logical and slightly intuitive.

(1^log(1)(-1))^(1/log(1)(-1)) = -1^(1/log(1)(-1)) //Exponential property of equality

1^(log(1)(-1)/log(1)(-1)) = -1^(1/log(1)(-1)) //We cannot simply cancel the fractional exponent on the left, for we might mess something up by working with undefined values

1^log(-1)(-1) = -1^(1/log(1)(-1)) //Logarithmic change of base

1^O = -1^(1/log(1)(-1)), where O is any/every odd integer and every fraction with an odd denominator //-1 to an odd power is -1

1 = -1^1/log(1)(-1)) //1 to any real power is 1.

If you look closely, you can see that we can recreate the right side of the equation in Neg. With a bit of cheating, we can now create all positive values in Neg.

Here is the definition of 1:

1 = ^.^L...

which we can use to create any number we want. Here are some handy functions to create those numbers:

*(x)(y) = LL..^^L..xy //x*y = log(a)((a^x)^y))
+(x)(y) = LL..*^L..x^L..y //x+y = log(a)((a^x)*(a^y))

Superpositions

Superpositions are the only cool edition to this language (except for the strange way to define 1). A superposition in Neg is a variable (or function, if you really wanted to) that is equivalent to multiple different values at once, similar to a real life superposition. Here's an example (that requires a lot of defined numbers):

S = [0,1,2,3;] //This defines S as all whole numbers  (the ; tells the interpreter to try and continue the pattern)
S = +S1 //This redefines S as S+1, which is [1,2,3,4;], the set of all positive integers
S_() //Since S does not have a value equal to 0, this will create an infinite loop

Another example (that also requires a lot of defined numbers):

S = [0,1,2,3;]
S = +*S21 //S is now [1,3,5,7;], the set of odd integers
S = +S. //S is now [0,2,4,6;], the set of even integers

A superposition for all real numbers would be the following:

S = L11

Turing completeness

Neg is turing complete through translation to Brainfuck:

//append these lines to the start of the program
v = L..
1 = ^.^v.
*(x)(y) = Lv^^vxy
+(x)(y) = Lv*^vx^vy
P = +1.
T = {}
F = (TP__(;)TP=0;)
//insert BF program here, use following conversion table
Brainfuck Instruction Neg Code
+ F TP=+TP1
- F TP=+TP.
> P=+P1
< P=+P.
[ F TP_(
] )

Note: The . and , instructions are not required for turing completeness but can easily be translated. Also, this inplementation of BF allows for infinite cells to the left and right, but that does not harm computational class.

External Resources

  • None.