Talk:Unary
From Esolang
Heh, cool. I once made something like this, but quickly scapped it. Now I just have to write an Unary interpreter or something. XD Hmm. Apparently hello world is 0x2924924962924922924924914914000F94A15124925224A14A00924924924928624A36DB71B6DB6E150C 0's.
YET ANOTHER edit here. I just made a brainfuck-to-unary converter in Thue. http://www.filenotfunny.com/bf2un.t Please notify me of any bugs blah blah etc. EDIT: You guessed it, unary-to-brainfuck converter in Thue. http://www.filenotfunny.com/un2bf.t --BodyTag 18:25, 11 Sep 2005 (GMT)
- Great, now how to run it without running out of memory :) --Aardwolf 20:46, 11 Sep 2005 (GMT)
- Well there's the obvious approach. Make shorter programs. :P --BodyTag 21:01, 11 Sep 2005 (GMT)
Contents |
[edit] One character language
Hey, this finally gave me the idea how to create a language that uses only one character! Yihaaaaa! I've been so stupid for not seeing it before.. --User:Keymaker
- But this language has two symbols: 0 and EOF. The fact that it uses one character is merely a technical detail. --Graue 21:27, 11 Sep 2005 (GMT)
- Oh please.. :) Would it be necessary to count in the EOF for some reason when making one character language? --User:Keymaker
- Yeah, EOF is part of the program data, but this would count not only for Unary but also for all other languages. Then BF has not 8 but 9 symbols, since when the end of BF code is reached, it is interpreted as finish program. This is then also something to be considered in the BF minimization page. --Aardwolf 14:36, 20 Oct 2005 (GMT)
- Iota and Unlambda don't require EOF. --Ihope127 15:20, 20 Oct 2005 (GMT)
- Use meta-data, as I said. In Javascript, use document.forms.name.field.value.length, in Java use String.length(). EOF is just a way of representing the end of a file as a character, for languages that don't provide any other way of finding the length/end of a file (or don't have an exception system, so want a call to a next() method to always return), or for programmers who know that a while(c>-1) loop runs faster than a while(!eof()) loop. --Safalra 14:56, 20 Oct 2005 (GMT)
- OK, then how do you propose storing that metadata with one symbol? --Graue 15:00, 20 Oct 2005 (GMT)
- It's meta-data, so it doesn't get stored as part of the program - it's an implementation detail and can be stored in any way. The program code is an abstraction - if I compress a Unary program, the compressed file may use a variety of symbols, but the Unary program it represents still contains just one symbol. Saying that EOF is part of the language is like saying a 2D language needs a end-of-row symbol as well - of course we could instead use an end-of-column symbol, or specify that the program is padded so that it's width and height are prime numbers, with its width being greater than its height. The point I'm making is that these implementation details are all meta-data, and not part of the program. --Safalra 16:38, 20 Oct 2005 (GMT)
- Definitely agree with that. --User:Keymaker
- EOF isn't a printable symbol in this programming language, yet in some way it seems to be semantically significant, therefore it must exist in some form. If a Unary program were to be printed on paper, the EOF would be the end of the paper, or the space where the next 0 would be, if there was a next 0 in the first place. Therefore IMO, Unary has 2 symbols. Many of you don't want to thus change the definition of Brainfuck as being a language consisting of 9 symbols, but this is probably just humans being resistant to change. We've defined it as 8 symbols for so long, why change it now..? :) Also, I just wondered.. we could construct a language implementing the same semantics, but with an infinite amount of symbols. Just let the Unary program be represented instead by a positive integer whose value is the number of zeroes. --Anonymous
[edit] Joke Language
Should Unary be considered a joke language, since in a way it's unique. --Aardwolf 15:00, 22 Oct 2005 (GMT)
[edit] Attempt at Python converter
I've tried to make a Brainfuck to Unary converter in Python(currently at [1] However, I'm having two problems with it. The first is that I don't know how to convert numbers from binary to unary in Python. The second is that I can't get the programs to show up right in the Unary to Brainfuck converter if I convert the number by hand.
Does anyone have a clue on how to fix this? 83.109.228.9 16:14, 1 April 2008 (UTC)
- For binary to unary, start with a number at zero, then repeatedly double it if the first digit of the binary is a 0, and double it and add 1 if the first digit of the binary is a 1, going through all the digits of the binary number in order; that will give you the length of the unary output you need to produce. (You'll need to use an unbounded integer to do this, otherwise the number will overflow.)
[edit] How can a Unary Number System possibly exist?
Read above. Essentially, Unary being base 1 must include all the Whole Numbers up to but not including 1. Thus, we have a range of {0}. Now, using this system, we create an arbitrary number, say 000000 which would be (what we think) the equivalent of 6d or 00000110b. However, if we evaluate our unary number, we come to a problem: 000000 = 0*1^5 + 0*1^4 + 0*1^3 + 0*1^2 + 0*1^1 + 0*1^0 = 0 This is of course a problem, because we cannot use only 0's as we will never have a value other than 0 (being the multiplicative dead) and if we use a 1 then this turns into binary by virtue of the existence of two symbols and the fact that it includes all the whole numbers up to but not including two.
So, from the above, is Unary merely a fancy term for "tally using 0's", otherwise I cannot see a way it can possibly function. -- Hiato 11:24, 4 April 2008 (UTC)
- Unary generally refers to a number system where the number of digits represents the size of the number; there is usually only one digit, but that digit is usually 1 (thus an example number would be 111111 = 1*1^5 + 1*1^4 + 1*1^3 + 1*1^2 + 1*1^1 + 1*1^0 = 6). This doesn't exactly follow the pattern used by the other number systems, though. (The base really determines the base of the exponent, rather than the digits used; think about base -2, for instance, which uses 2 digits but has -2 as the base for exponents when calculating digits.) --ais523 09:20, 5 April 2008 (UTC)
In this program we use zeros but they say unary is uaually 1's. One way to do it, is you can use any characters you want in the program, the interpreter will ignore the actual contents of the file and read only the size of the file. This will break if the file has a newline or EOF mark at the end, but the programs that do that can be fixed. In this way, you can also make sparse files in a NTFS file system that are larger than the drive can contain, and it will still work. Of course, even the file size field might not store a large enough number, but the other conversion programs are no better. --Zzo38 14:22, 5 April 2008 (UTC)
- Oh, I see - thanks. So essentially Unary is just a fancy tally (as 1^n = 1, n e Q) as opposed to a "true" base n number system. Is this to say that what I put forth would be some kind of Nullary (Base 0 number system?) -- Hiato 20:27, 13 April 2008 (UTC)
[edit] Inefficient conversion to number
Instead of adding a 1 before each number when converting to binary, you could let 8 instead of 0 represent '<'.
So you get:
| Brainfuck | Binary |
|---|---|
>
| 8 (1000) |
<
| 1 (001) |
+
| 2 (010) |
-
| 3 (011) |
.
| 4 (100) |
,
| 5 (101) |
[
| 6 (110) |
]
| 7 (111) |
Then convert the sequence of numbers as if they were written in base 8 (big endian). In other word: calculate the sum of a*8^n for each number a, where n is the position in the bf-code code counting from the right.
If the above was confusing, here is an example:
If you want to convert +>,< into Unary2 you first convert each character into a number according to above:
+>,< -> {2,8,5,1} then add it together to get the number of digits: 2*8^3 + 8*8^2 + 5*8 + 1 = 1577. So +>,< in Unary2 is 1577 zeroes.
With this approach every sequence of zeros has a corresponding brainfuck code, which is not achived with normal Unary.
--Anka 20:24, 3 January 2009 (UTC)
- Surely you can't use the digit 8 in base 8? Phantom Hoover 15:01, 5 January 2010 (UTC)
- Yes, you cna't use the digit 8 in base 8. Instead, you could change around the order to make 0 mean the ] instruction and put the least significant numbers the first command, and the most significant numbers the last command. So, the zero will always be the last command and can be used as termination, too, in case of not inside of a loop the ] can be used to mark end of a program. And now, if you needed to add on input to the program you could do it in the same way --Zzo38 01:00, 9 January 2010 (UTC)
- None of this changes the fact that using digit 8 actually works though. --Ørjan 10:39, 9 January 2010 (UTC)
- It does, but it's not using base 8. Phantom Hoover 21:06, 12 January 2010 (UTC)
- Well there is balanced ternary, so this might be "hyperimbalanced" octal. Actually Wikipedia calls it bijective base-k numeration. --Ørjan 23:47, 12 January 2010 (UTC)
- It does, but it's not using base 8. Phantom Hoover 21:06, 12 January 2010 (UTC)
- None of this changes the fact that using digit 8 actually works though. --Ørjan 10:39, 9 January 2010 (UTC)
[edit] 1 symbol
I've never really been happy with that, and not just because of the EOF. I suppose it comes down to the definition of "symbol" — by this definition of "symbol" more or less all languages have exactly two symbols: 1 and 0. Phantom Hoover 13:32, 20 March 2010 (UTC)
[edit] 99 bottles of beer
The 99-bottles-of-beer program
>>>>>>>>>>++++++++++[-<++++++++++>]<-<<<<<<<<<++++++++++[->++++>++++>+++ +>++++<<<<]++++++++[->>>++++++++>++++++++<<<<]++++[->>>>++++<<<<]+++++++ +++>-------->++++>>>>>>>[<<<<+++>+>++<<[>>>>[[->+>+<<]>>[-<<+>>]<[>+++++ +++++[->>+>+<<<]<[>>>[-<<<-[>]>>>>[<[>]>[---------->>]<++++++[-<++++++++ >]<<[<->[->-<]]>->>>[>]+[<]<<[->>>[>]<+[<]<<]<>>]<<]<+>>[->+<<+>]>[-<+>] <<<<<]>>[-<<+>>]<<]>[-]>>>>>>[>]<[.[-]<]<<<<<<]>+<<[>]>>[<<<<<<<++++++.+ .------->>>>>>>>>]<[-]<[-]<<<<<<<<<.>>------.+++++++++++++.>----..<---.- ------.>>>>>>->>>+<<<[>]>>[<<<<<<<<-.+>>>>>>>]>-<<<+<<<<<<<<.>>>-----.<+ .<<.>>----.+++..>+++.<+++>++++++>>[<<<<<.>>+++++++.-.<<.>>>----.<------. ---.<<.>>>+++.<----.+++++++++++..---->+>>-]<<<<.<<.>>>>>>>-[>]>>[-<<<<<- ---.<-------.>---------.<++++.<<.>>>++++.-.<.<<.>>-.>+.++++++++.-------- -.<<<.>>---.>.<+++.<<.>>>++.<---.>+++..<<<.>>++++++++.>+.<<<.>>--------. >--.---.++++++.-------.<+++.++++>++++++++++<<.<<.>>----------->>>>+>>>>] <<<<<-]>>+<<<<<<<.>>+++++++++++>>>>>>>]
is represented in Unary as a string of
325639678472417068822939875156474133601604199695311805459089882092281292 320021959505273992278098266269511623093421446786535577912162057464703117 510613456476283544768091483691050380134353082413584417237050508186170311 100841758475294808822182897650558939889181821968359721314718466765453544 642917705283465122416321901781623594919162207226465487108911718755078561 258397319468795144125849589702335828364689893204973341033492024695611620 630251915376043695257250405459896426236766476054881147140737211608267502 071035082611987546796166597621183311452085996664573566015407455499558986 329235961518840901288913840735765978638808714474372075845072241192251838 014337491535621715532385499208500869158941559378141072165437305878437850 878695018487992734730233885948276901724490150298159234876718327828396339 142881148637400648433892457677190096164128393288567742613801869417478826 68978930079236103
zeroes. Wow. Jleedev 18:05, 31 May 2010 (UTC)
- In fact unless I'm mistaken the length of that number should be approximately log 8/log 10 ~ 0.903 of the length of the brainfuck program. --Ørjan 08:19, 1 June 2010 (UTC)

