nedoPC.org

Electronics hobbyists community established in 2002
Atom Feed | View unanswered posts | View active topics It is currently 28 Mar 2024 12:20



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


14 Aug 2008 04:38
Reply with quote
Hello all,

below is the Java Class file which can be used for ternary
addition and multiplication.


Ternary API.
TernaryMath.class
This contains following methods:
Compiled from "TernaryMath.java"
class TernaryMath extends java.lang.Object{
TernaryMath();
java.lang.String add_rule(java.lang.String, java.lang.String);
java.lang.String add(java.lang.String[], java.lang.String[]);
java.lang.String subtract(java.lang.String[], java.lang.String[]);
java.lang.String multyply(java.lang.String[], java.lang.String[]);
}
http://TernaryMath.class


Usage:
The input:
Please provide input only as array of trits.


Also,
Please post your views on same.

Thanks,


18 Aug 2008 00:50
Retired

Joined: 03 Aug 2003 22:37
Posts: 1474
Location: Moscow
Reply with quote
It would be just great if you can also provide link to source code of the class.

Please correct method name from multyply to multiply.


18 Aug 2008 02:40
Profile
Reply with quote
Below is the location of the source file:

http://tvm.manojky.net/tmath.php
or
http://tvm.manojky.net/TernaryMath.java
TernaryMath.java

Corrected multyply to multiply.
class TernaryMath extends java.lang.Object{
TernaryMath();
java.lang.String add_rule(java.lang.String, java.lang.String);
java.lang.String add(java.lang.String[], java.lang.String[]);
java.lang.String subtract(java.lang.String[], java.lang.String[]);
java.lang.String multiply(java.lang.String[], java.lang.String[]);
}


18 Aug 2008 03:52
Reply with quote
Hello All,

Now that i can perform addition and multiplication, can any one suggest me how should i store the information in the file in ternary format, Basically I am looking for file format for ternary.

I have already selected the Tryte codes for Ascii Chars, they are available at following location,

http://manojky.net/terPrj/TernaryWithCharC.htm


18 Aug 2008 23:48
Maniac

Joined: 17 Sep 2012 13:36
Posts: 277
Location: 81.170.128.52
Reply with quote
In tunguska, I store the integer values in an array type signed short, which is subsequently compressed with zlib when saved to a file.

This has the advantage of being very fast and very space effective (since a memory image will have lots of zeros).

I suppose you can also save the individual trits in pairs of bytes in a short. This is harder to manipulate, since you need to juggle around a lot of bits to extract and set values.


19 Aug 2008 00:53
Profile
Retired

Joined: 03 Aug 2003 22:37
Posts: 1474
Location: Moscow
Reply with quote
Quote:
I have already selected the Tryte codes for Ascii Chars, they are available at following location,


It does not look very effective, since you do not use negative part of diapason that could be easily used for lower case letters and fractional numbers (1/2, 1/3, etc). Also I see no letters for Cyrillic (Russian, Ukrainian, and so on) and Greek alphabets. And some more mathematical symbols have to be added.


19 Aug 2008 01:20
Profile
Reply with quote
Hi,

I am planning for use following format,
Image
<hr>
I will store the instructions/definition/method into the METADATA file to read the DATA File, it will help the users to use their own file formats.


Mostly the METADATA file will be in XML Format
Please post your views.


19 Aug 2008 01:37
Reply with quote
Yes, I agree, I intentionally left it for future use, as nothing was striking to my mind,

If you can help me in preparing/utilizing the negative part, it will be great.


19 Aug 2008 01:41
Reply with quote

Quote:

I have already selected the Tryte codes for Ascii Chars, they are available at following location,



It does not look very effective, since you do not use negative part of diapason that could be easily used for lower case letters and fractional numbers (1/2, 1/3, etc). Also I see no letters for Cyrillic (Russian, Ukrainian, and so on) and Greek alphabets. And some more mathematical symbols have to be added.




Yes, I agree, I intentionally left it for future use, as nothing was striking to my mind,

If you can help me in preparing/utilizing the negative part, it will be great.


19 Aug 2008 01:43
Reply with quote
I'll be going with the below mentioned table.
http://tvm.manojky.net/csv/TernaryWithCharC.htm


22 Aug 2008 04:35
Reply with quote
Hello All,

Finally I have prepared an applet which converts the ASCII text to tryte, and displays it based on the table mentioned above....

http://tvm.manojky.net/TryteEditor/


Please visit and post your views.


25 Aug 2008 01:55
Novelist

Joined: 20 Oct 2005 18:46
Posts: 34
Reply with quote
Here http://trinary.ru/projects/bttencoder/ you can find a coder which do the same that your applet, but it use more effective algorithm (Saved space 33% vs 25%).
To see result press blue button.
You will see code in bytes In the first column and in trytes in the second column.
We use -0+ as equivalent of -1 0 1.

P.S.: The english version of the coder on plan. )) Don't use IE (it's not supported)
Good luck! :)


26 Aug 2008 03:26
Profile
Reply with quote
Hi,

Its not possible to save space more or less than 25%,
its a constant value, b'coz,
1 char = 8 bits (1 Byte)
= 6 trits(1 Tryte),

so every time you add a char, you will save only
(1-6/8) ie. .25 = 25%, i am not sure if the application you mentioned works on ternary representation.
please varify.

btw it looks better than mine :-)

Thanks,


26 Aug 2008 08:47
Novelist

Joined: 20 Oct 2005 18:46
Posts: 34
Reply with quote
Hi!

It is possible :)
2^8 = 256 variations, аnd 3^6 = 729 variations, when you code 8 bits into 6 trits 729-256 = 473 variations are not used.
It is too much.
In our coder we code every 3 bits into 2 trits.
In this case only one variation is not used (3^2 - 2^3 = 9-8 = 1).
That's why we have 33% economy (1-2/3).

What do you think about it?


26 Aug 2008 11:27
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 2 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.