nedoPC.org

Community of electronics hobbyists established in 2002

...
Atom Feed | View unanswered posts | View active topics It is currently 21 Sep 2018 10:37



Reply to topic  [ 82 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
[Ternary] Ternary VM (TVM) 
Author Message
Reply with quote
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,


05 Aug 2008 07:02
Maniac

Joined: 17 Sep 2012 14:36
Posts: 277
Location: 81.170.128.52
Reply with quote
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.


05 Aug 2008 15:34
Profile
Reply with quote
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,


06 Aug 2008 02:06
Retired

Joined: 03 Aug 2003 23:37
Posts: 1481
Location: Moscow
Reply with quote
You can examine source codes of Ternary machine emulator written by Roman. Link to it is available somewhere in the forum :)


06 Aug 2008 12:21
Profile
Maniac

Joined: 17 Sep 2012 14:36
Posts: 277
Location: 81.170.128.52
Reply with quote
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


06 Aug 2008 13:21
Profile
Reply with quote
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.
:-(


06 Aug 2008 14:46
Reply with quote
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:
Image


07 Aug 2008 09:20
Maniac

Joined: 17 Sep 2012 14:36
Posts: 277
Location: 81.170.128.52
Reply with quote
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.

Code:
#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


07 Aug 2008 11:38
Profile
Reply with quote
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,


08 Aug 2008 03:43
Reply with quote
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[i] = result[i] + 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(result[i]);
}


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[i] = result[i] + 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;
}
}
----------------------------------------------------


08 Aug 2008 04:59
Reply with quote
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.


08 Aug 2008 06:33
Reply with quote
Hello,
Below is the link for Applet for ternary addition.

pls provide CSV values, and 6trit only.

http://manojky.net/tvm/tmath.php


09 Aug 2008 03:58
Maniac

Joined: 17 Sep 2012 14:36
Posts: 277
Location: 81.170.128.52
Reply with quote
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:

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];



10 Aug 2008 11:01
Profile
Reply with quote
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.
Code:
----------------------------------------
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;
}
----------------------------------------


11 Aug 2008 07:57
Maniac

Joined: 17 Sep 2012 14:36
Posts: 277
Location: 81.170.128.52
Reply with quote
Ok, cool. Though you may want to use [ code ] tags to keep indentation in the sources. It's so hard to read otherwise.


12 Aug 2008 08:29
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 82 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.