Ternary VM (TVM)
Moderator: haqreu
Re: Ternary VM (TVM)
Ok, so internally you are using binary operations,thats nice,
What I am planning is to have TVM with virtual processor.Mostly I will try to have all the calculation in Ternary, Of course it will be slow one. But for now its ok.
I am planning for a network based distributed model for this, so that its speed will not be an issue, i.e. clustering will be possible and simple.
Thanks,
What I am planning is to have TVM with virtual processor.Mostly I will try to have all the calculation in Ternary, Of course it will be slow one. But for now its ok.
I am planning for a network based distributed model for this, so that its speed will not be an issue, i.e. clustering will be possible and simple.
Thanks,
-
- Maniac
- Posts: 277
- Joined: 17 Sep 2012 13:36
- Location: 81.170.128.52
Re: Ternary VM (TVM)
But, won't this sort of application scale badly? Since every cycle will be very short, and in almost all cases depend on previous ones, the overhead will be huge. With the synchronization between cycles (which will be unescapable) taking as much time as several hundred cycles would.
Re: Ternary VM (TVM)
Yes you are right,Actually the distributed model is ready with me(Platform Independent), only thing is the implementation of the ternary logic is required, Also my intention here is towards AI not for general purpose, b'coz decision making with ternary logic is more logical than just saying "true" or "false" in binary, so i am just aiming to have it completed.
I will try to work on the basic mathematical operations through the ternary mathematics.
And of course I'll need help from you.
Thanks,
I will try to work on the basic mathematical operations through the ternary mathematics.
And of course I'll need help from you.
Thanks,
-
- Retired
- Posts: 1474
- Joined: 03 Aug 2003 22:37
- Location: Moscow
Re: Ternary VM (TVM)
You can examine source codes of Ternary machine emulator written by Roman. Link to it is available somewhere in the forum 

-
- Maniac
- Posts: 277
- Joined: 17 Sep 2012 13:36
- Location: 81.170.128.52
Re: Ternary VM (TVM)
Wouldn't fuzzy logic be preferable for AI applications? I imagine you can still benefit from ternary logic by making the fuzzy logic ternary.
Instead of having binary fuzzy logic, where you have {0.0, 1.0} = {false, true} ; you have {-1.0, 0.0, 1.0} = {false, unknown, true}.
Being more of a particle physicist than a computer scientist, I can't help but wish to extend the idea of spin matrices to the realm of logic. I wrote up a draft of my idea in LaTeX (because it's such a pain to format mathematics in HTML). -> http://nedopc.org/ternary/tunguska/fuzzyternary.pdf
Instead of having binary fuzzy logic, where you have {0.0, 1.0} = {false, true} ; you have {-1.0, 0.0, 1.0} = {false, unknown, true}.
Being more of a particle physicist than a computer scientist, I can't help but wish to extend the idea of spin matrices to the realm of logic. I wrote up a draft of my idea in LaTeX (because it's such a pain to format mathematics in HTML). -> http://nedopc.org/ternary/tunguska/fuzzyternary.pdf
Re: Ternary VM (TVM)
Fuzzy Logic is fine, But i am trying for Genetic Algorithm,
b'coz its closest to Human Behavior and decisions makings.
Actually my programs are developed in pieces and now i need to connect them.
Ternary processing is required for storing the data....Actually things are not very clear to me in my mind... i am just writing codes as and when i get some idea.

b'coz its closest to Human Behavior and decisions makings.
Actually my programs are developed in pieces and now i need to connect them.
Ternary processing is required for storing the data....Actually things are not very clear to me in my mind... i am just writing codes as and when i get some idea.

Re: Ternary VM (TVM)
Hi,
I need help in preparing Java program for (FOR TVM)
1). Ternary addition for Trytes,(6Trit)
2). Ternary Subtraction for Trytes,
3). Ternary multiplication and,
4). Ternary Div.
Pls reply if anyone has the source in Java.
Consider following:

I need help in preparing Java program for (FOR TVM)
1). Ternary addition for Trytes,(6Trit)
2). Ternary Subtraction for Trytes,
3). Ternary multiplication and,
4). Ternary Div.
Pls reply if anyone has the source in Java.
Consider following:
-
- Maniac
- Posts: 277
- Joined: 17 Sep 2012 13:36
- Location: 81.170.128.52
Re: Ternary VM (TVM)
I don't have java installed at the moment, but I can give you an addition algorithm written in python. Keep in mind that the trit order is reversed, so the least significant trit is first, and the most significant trit is last.
It works both addition and subtraction. If you want to subtract, just multiply all the trits in b with -1.
It works both addition and subtraction. If you want to subtract, just multiply all the trits in b with -1.
Code: Select all
#Balanced ternary addition algorithm
def add(a, b):
result = [0, 0, 0, 0, 0, 0, 0]; # Note that the array is 7 trits long, and the last one is carry.
for i in range(0, 6):
result[i] = result[i] + a[i] + b[i];
result[i+1] = result[i]/2;
result[i] = (result[i]+1)%3 - 1;
return result
# Test code:
#
#
# Reverse trit order
# 0 1 2 3 4 5
r1 = [1, 0, -1, 1, 0, 0]; # 1 - 9 + 27
r2 = [1, 1, 0, 0, 0, 0]; # 4
r = add(r1, r2);
for i in range(0, 7):
print r[i]; # Print trits in reverse order
Re: Ternary VM (TVM)
Thanks, for the code,
Its a nice, I tested it ,its working fine, i will convert it into Java now.
How about multiplication and division !
Thanks,
Its a nice, I tested it ,its working fine, i will convert it into Java now.
How about multiplication and division !

Thanks,
Re: Ternary VM (TVM)
Following is the Code in Java For addition and subtraction of trytes:
----------------------------------------------------
import java.io.*;
import java.util.*;
public class Tryte_math{
public static void main(String args[])
{
String[] r1 = {"1","-1", "0", "0", "0", "0"}; //-2 //trits in reverse order
String[] r2 = {"1","1", "0", "0", "0", "0"}; // 4
System.out.println("Tryte 1:"+"1,-1, 0, 0, 0, 0");
System.out.println("Tryte 2:"+"1,1, 0, 0, 0, 0");
System.out.println("Result of add in Reverse order:"+(add(r1,r2)));
System.out.println("Result of subtract in Reverse order:"+(subtract(r1,r2)));
}
static String add(String[] a, String[] b)
{
String result_s="";
int[] result = {0, 0, 0, 0, 0, 0, 0}; // // J Note that the array is 7 trits long, and the last ONe is cArry M.
for (int i=0;i<6;i++){
result = result + Integer.valueOf(a) + Integer.valueOf(b);
result[i+1] = result/2;
result = (result+1)%3 - 1;
result_s=result_s+Integer.toString(result);
}
return result_s;
}
static String subtract(String[] a, String[] b)
{
String result_s="";
int[] result = {0, 0, 0, 0, 0, 0, 0}; // J Note that the array is 7 trits long, and the last one is carry M.
for (int i=0;i<6;i++){
result = result + Integer.valueOf(a[i]) + Integer.valueOf(b[i]);
result[i+1] = result[i]/2;
result[i] = (result[i]+1)%3 - 1;
result_s=result_s+Integer.toString((-1)*result[i]);
}
return result_s;
}
}
----------------------------------------------------
----------------------------------------------------
import java.io.*;
import java.util.*;
public class Tryte_math{
public static void main(String args[])
{
String[] r1 = {"1","-1", "0", "0", "0", "0"}; //-2 //trits in reverse order
String[] r2 = {"1","1", "0", "0", "0", "0"}; // 4
System.out.println("Tryte 1:"+"1,-1, 0, 0, 0, 0");
System.out.println("Tryte 2:"+"1,1, 0, 0, 0, 0");
System.out.println("Result of add in Reverse order:"+(add(r1,r2)));
System.out.println("Result of subtract in Reverse order:"+(subtract(r1,r2)));
}
static String add(String[] a, String[] b)
{
String result_s="";
int[] result = {0, 0, 0, 0, 0, 0, 0}; // // J Note that the array is 7 trits long, and the last ONe is cArry M.
for (int i=0;i<6;i++){
result = result + Integer.valueOf(a) + Integer.valueOf(b);
result[i+1] = result/2;
result = (result+1)%3 - 1;
result_s=result_s+Integer.toString(result);
}
return result_s;
}
static String subtract(String[] a, String[] b)
{
String result_s="";
int[] result = {0, 0, 0, 0, 0, 0, 0}; // J Note that the array is 7 trits long, and the last one is carry M.
for (int i=0;i<6;i++){
result = result + Integer.valueOf(a[i]) + Integer.valueOf(b[i]);
result[i+1] = result[i]/2;
result[i] = (result[i]+1)%3 - 1;
result_s=result_s+Integer.toString((-1)*result[i]);
}
return result_s;
}
}
----------------------------------------------------
Re: Ternary VM (TVM)
Hi,
Below is the Applet link for Tryte representation of the ascii characters:
http://manojky.net/tvm/
http://manojky.net/
Its a applet where you type the char and get the value of integer, and tryte.
Also the Ternary clock of of the "Java Apps Secton" has been placed on TOP.
Below is the Applet link for Tryte representation of the ascii characters:
http://manojky.net/tvm/
http://manojky.net/
Its a applet where you type the char and get the value of integer, and tryte.
Also the Ternary clock of of the "Java Apps Secton" has been placed on TOP.
Re: Ternary VM (TVM)
Hello,
Below is the link for Applet for ternary addition.
pls provide CSV values, and 6trit only.
http://manojky.net/tvm/tmath.php
Below is the link for Applet for ternary addition.
pls provide CSV values, and 6trit only.
http://manojky.net/tvm/tmath.php
-
- Maniac
- Posts: 277
- Joined: 17 Sep 2012 13:36
- Location: 81.170.128.52
Re: Ternary VM (TVM)
I don't know about division (it's hard to make an algorithm that isn't extremely ugly), but here's an algorithm for multiplication, O(n^2+n)-ish:
Code: Select all
def mul(a, b):
result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
# Calculate the result without rounding down to
# ternary (i.e. make an array that allows for values with
# a magnitude greater than 1)
for i in range(0, 6):
for j in range(0, 6):
result[i+j] = result[i+j] + a[i]*b[j];
# Transform this array into an array with magnitude limit 1:
for i in range(0, 11):
result[i+1] += result[i] + 1 - (result[i]+1) % 3;
result[i] = (result[i] + 1) % 3 - 1;
return result;
def add(a, b):
result = [0, 0, 0, 0, 0, 0, 0];
for i in range(0, 6):
result[i] = result[i] + a[i] + b[i];
result[i+1] = result[i]/2;
result[i] = (result[i]+1)%3 - 1;
return result
# Reverse trit order
# 0 1 2 3 4 5
r1 = [1, 0, -1, 1, 0, 0]; # 1 - 9 + 27
r2 = [1, 1, 0, 0, 0, 0]; # 4
r = mul(r1, r2);
for i in range(0, 12):
print r[i];
Re: Ternary VM (TVM)
I, also implemented the same in Java, but i have changed code for addition:
This code is "rule based" addition, as in our previous code we required to have "/" division and "%" mod operators.
now we have no mathematical operators now in below code.
This code is "rule based" addition, as in our previous code we required to have "/" division and "%" mod operators.
now we have no mathematical operators now in below code.
Code: Select all
----------------------------------------
String add(String[] a, String[] b)
{
String result_s="";
int lcv=0;
int[] result = {0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // J Note that the array is N+1 trits long, and the last one is carry M.
if(a.length>b.length)
{
lcv=a.length;
}else{
lcv=b.length;
}
for(int i=0;i<lcv;i++)
{
int a1=Integer.valueOf(a[i]);
int b1=Integer.valueOf(b[i]);
if(((a1==1)&&(b1==1))||((a1==-1)&&(b1==-1))){
String[] tryte_=(add_rule(a[i],b[i])).split(",");
int temp=(Integer.parseInt(tryte_[0]));
if(((temp==1)&&(result[i]==1))||((temp==-1)&&(result[i]==-1))){
String[] tryte_1=(add_rule(Integer.toString(result[i]),Integer.toString(temp))).split(",");
result[i]=(Integer.parseInt(tryte_1[0]));
result[i+1]=(Integer.parseInt(tryte_1[1]));
}else{
result[i]=Integer.parseInt((add_rule(Integer.toString(result[i]),Integer.toString(temp))));
}
temp=(Integer.parseInt(tryte_[1]));
if(((temp==1)&&(result[i+1]==1))||((temp==-1)&&(result[i+1]==-1))){
String[] tryte_1=(add_rule(Integer.toString(result[i+1]),Integer.toString(temp))).split(",");
result[i+1]=(Integer.parseInt(tryte_1[0]));
//result[i+1]=(Integer.parseInt(tryte_1[1]));
}else{
result[i+1]=Integer.parseInt((add_rule(Integer.toString(result[i+1]),Integer.toString(temp))));
}
}
else
{
int temp=(Integer.parseInt((add_rule(a[i],b[i]))));
if(((temp==1)&&(result[i]==1))||((temp==-1)&&(result[i]==-1))){
String[] tryte_1=(add_rule(Integer.toString(result[i]),Integer.toString(temp))).split(",");
result[i]=(Integer.parseInt(tryte_1[0]));
result[i+1]=(Integer.parseInt(tryte_1[1]));
}else{
result[i]=Integer.parseInt((add_rule(Integer.toString(result[i]),Integer.toString(temp))));
}
}
result_s=result_s+Integer.toString(result[i]);
}
result_s=result_s+Integer.toString(result[lcv]);
return result_s;
}
----------------------------------------
-
- Maniac
- Posts: 277
- Joined: 17 Sep 2012 13:36
- Location: 81.170.128.52
Re: Ternary VM (TVM)
Ok, cool. Though you may want to use [ code ] tags to keep indentation in the sources. It's so hard to read otherwise.