Computer For Number

From Esolang
(Redirected from CFN)
Jump to navigation Jump to search

Computer For Number
A function for "a natural number",actually an array of interger.
All operations are on numbers,includes values,codes,variable for judgment,and instruction address.

Components

Length(L): the range of each number.The number will be from -L to L-1 .
if a number becomes outsize of the range ,it should be made inside by add or sub by 2L
arr: An arr of intergers.
arr[Index]: The interger at n.Values are also able to be indexs.
C: arr[0] , The instruction address.
P: arr[1] , The variable for judgment.

Operation

loop to do the function until halt.

get C as arr[0] (referance,operations on these are the same as on values,not get value)
if C == 0 halt.
P as arr[1] (referance)
C1 as arr[C]
C2 as arr[C+1]
V1 as arr[C1] (referance)
V2 as arr[C2]
if P>=0 { set V1 as V1-V2 }
P=-P
C=C+2

C# code (I believe you can know what it is)(return true means halt)

bool ComputerForNumberFn(Array arr) {
    ref int c =ref arr[0];
    if (c==0) return true;
    ref int p =ref arr[1];
    if (p<0) {
        int C1 = arr[c];
        int C2 = arr[c+1];
        ref int V1 =ref arr[C1];
        int V2 = arr[C2];
        V1 = V1 - V2;
        //arr[arr[c]] +=arr[arr[c + 1]];
    }
    p = -p;
    c = c + 2;
    return false;
}

notice C1,C2 are also can be 0,or 1.

Computer For Number Marked

This language makes us able to know better about CFN program.
We can set a name for a number, and make use of it to make the program better.

Only match

<A:B>

All the texts didn't matched are annotation.

<Length:128>

Set the Length as 128

<Index(Name):Value>

Set a Name for the Index,and set arr[index] as Value.
(Name) is optional
Index is default to be last index +1
Value is default to be 0
<:> is required.
Value is also able to be Name,and it will be replaced by the index.
for example

<100(A):B> just a text
<(B):>

is equals to

<100(A):101>
<101(B):0>

Specially FromIndex=>ToIndex

...
<(TestFnAGotoB):C> jump to TestFnB
<:TestFnAGotoBV>
...
<(TestFnB):...>
...
<(TestFnAGotoBV):TestFnAGotoB=>TestFnB>

FromIndex=>ToIndex will be replaced to the value for goto
Specially <BitLength:BL> equals to <Length:2BL-1>
because it is easy to be implemented.

Examples

Multiplication

<BitLength:20>
<0(C):MulStart>
<(P):>

<(EndC):0><:EndV><(EndV):EndC=>0> Makes <C> <C> does halt
<(V1):1>

<10(MulV1):95>
<(MulV2):82>   arguments
<(MulRes):>    result,=MulV1*MulV2

<(MulTempV1):><(MulTempV2):><(MulGotoEndV):MulGotoEnd=>MulEnd><(MulGotoLoopV):MulGotoLoop=>MulLoop>

<(MulStart):MulTempV1><:MulV2>  <:MulTempV2><:MulTempV1>  <:MulV2><:MulV2>  <:MulV2><:MulTempV2>  <:MulTempV2><:MulTempV2>  <:MulTempV1><:MulTempV1>Set MulV2 Neg

<:MulV1><:V1>

<(MulLoop):P><:P>  <:P><:P>  <:MulRes><:MulV2>  <:MulV1><:V1> MulRes+ ,V1-=1 

<:P><:MulV1>

<(MulGotoLoop):C><:MulGotoLoopV> if V1>=0 Loop

<:P><:P>  if V1<0 end

<(MulGotoEnd):C><:MulGotoEndV>

<(MulEnd):MulV2><:MulV2>

<:C><:C>

Conventions

You can choose one
Cleaning programing: If you used a value,you'd better clear it after using.
Defensing programing:If you need a value,you'd better clear it at first.

Thinking

It is obviously turing complete

ComputerForNumber

This is a function for a number.(a)=>(a+1) is also a function for a number.Why CFN is turing complete but some not?

When ∞

when Length=∞
The operated numbers can be a Real number.
"the sharpened number" is actually a FUNCTION,"+1" is actually +dx

Chaitin's value

when Length isn't ∞ we can calculate it's Chaitin's value.

Implement

https://github.com/Xx-xXXxX/ComputerForNumber