Unary To Binary (back Again, An Objects Journey) (part 1)

unary to binary (back again, an objects journey) (part 1)

ok, so last time I didn't actually get to converting from unary to binary again.

So I guess I will do that here. (HAHA I JUST GOT IT TO DIVIDE WITH REMAINDER. APPLYING THAT TO THE CONVERSION IN PART 2)

so to do this we have to find the largest power of two not greater than the number,  then the largest power of two not greater then what is remaining of the number, and repeat until we reach zero.

OR we can

find the largest power of two not greater than the number, then for each power of two less than the number, if it is not greater than it, use a 1 and subtract it from the remaining number.

and then for both of these, of course, reverse the result at the end so it is in the right order. 

I think so far the second one of these sounds better.

but come to think of it, repeated integer division by two might work well.

that is, instead of repeated doubling, and then checking which one is larger, it might be faster to do repeated halving. (with a remained of either zero or one)

this could be then used to make a integer base 2 logarithm, with a remainder thing.

and instead of checking each power of two less than it, we could just find the integer base 2 log, and the base 2 log of the "remainder" and the base 2 log of THAT remainder and so on.

that seems like its the best way to me so far, but how do we take the integer logarithm AND get the log remainder thing?

getting the logarithm is fairly simple, just keep dividing by the number until you reach 1.

but how do you get the remainder part? and also how do you do the integer division in the first place with these number like things that we have created?

well lets answer the first of those questions first.

It seems like the remainder of the logarithm is probably related to the remainders of the divisions that make it up.

so lets look at taking the integer base 2 logarithm of 9:

9 4 (rem 1) 2 1

that took 3 halvings, and there was one remainder of one.

what if we try on 10 or something though?

10 5 2 (rem 1) 1

that also took 3 steps and one remainder, but the remainder was on a different step.

now lets try 11

11

5 (rem 1) 2 (rem 1) 1 (rem 0)

now wait, theres a pattern here, which might allow for converting it even faster.

the remainders of the divisions are the remainders of the logs expressed in binary!

we COULD turn them back into unary, so we could take the log of it again,

but what we are doing it converting it into binary anyway! (so that would be a silly step)

so if we look at what we were doing with the repeated division again, but looking at the numbers in binary, it will be pretty evident how to convert it in a better way.:

lets try 9 again (which is 1001)

1001

100 (rem 1) 10 (rem 0) 1 (rem 0) 0 (rem 1)

whats that? the remainders are the number we want in binary?

and now that I think of that it was kind of obvious?

yes. I for some reason did not think of that earlier.

so yeah, thats what we will do, we will repeatedly integer divide the number by 2 until we reach zero, and the remainders will be the number in binary.

but wait, we haven't even written out how to divide the number by two in the first place!

well turns out its not actually that hard to do.

in a loop (that keeps looping provided the number is not zero) subtract one, and if its still not zero, subtract one again. if it is zero after the first subtracting, the remainder of that division is 1. (only the last loop will cause the remainder to be 1) count the number of times where 2 was subtracted. 

so like for 5 that would be

5 3 1 1 2 0 2 (remainder 1)

so that gives the correct answer (2 with remainder zero)

ok, now to implement this integer division by 2 in drocta ~ATH (wow! already? that was fast! /sarcasm)

//given that NUM is the variable that has the name we are halving BIFURCATE [NUM,NUM]2NUM; BIFURCATE 2NUM[NUMCPY,JUNK]; BIFURCATE [BLAH,BLAH]2BLAH; BIFURCATE 2NULL[SUBCOUNT,REMAINDER]; ~ATH(NUMCPY){ BIFURCATE 2BLAH[UNEVEN,JUNK]; BIFURCATE NUMCPY[JUNK,NUMCPY]; BIFURCATE [NUMCPY,NUMCPY]2NUMCPY; BIFURCATE 2NUMCPY[NUMCPYCPY,JUNK]; ~ATH(NUMCPYCPY){ BIFURCATE [BLAH,SUBCOUNT]SUBCOUNT; BIFURCATE NUMCPY[JUNK,NUMCPY]; BIFURCATE 2NULL[UNEVEN,NUMCPYCPY]; } ~ATH(UNEVEN){ BIFURCATE [BLAH,REMAINDER]REMAINDER; BIFURCATE 2NULL[UNEVEN,JUNK]; } } BIFURCATE [NUMCPY,NUMCPY]2NUMCPY; BIFURCATE 2NUMCPY[NUMDIV2,JUNK]; 

ok, that should divide the number by 2, put the result in NUMDIV2, and put the remainder in REMAINDER.

this takes linear time based on the size of the unary number. (provided I didn't make a mistake)

so now it is time to make sure it works, hold on a second while I check it. (I mean, im not going to post this until after I check it, so it doesn't really make sense to tell you to wait, because you just keep reading, but as I am writing this, I am about to test it.)

ok, I tested it. and it didn't seem to work, but then I realized that I made a mistake in making the test. (I checked the wrong variable)

but yeah, turns out that works...

ok, so now we need to repeatedly divide the number by two to get the remainders.

and we need to store these remainders in a list or something.

More Posts from Learn-tilde-ath and Others

4 years ago

okay, this might be a liiittle specific, and more HS oriented, but still. can you power a First Guardian using ~ATH? and if so, what are some ways?

This is a slightly off of the usual topic of this blog, which is more about a language which I made up and is based on and named after the language in the comic, and attempts to be as close to the comic while still being possible to implement and use, (the language in the comic is not particularly well documented), but I’ll answer it to the best of my abilities.

I’m not sure what you mean by “power”.

“Can I write a first guardian character that has some of their behavior be based on ~ATH in some ways?” : I don’t see any reason why not. If you can do ectobiology with a puppet and a cueball, why not with a computer running a program?

“Can I make a first guardian character who is a first guardian because of the continual execution of a ~ATH script?” : While you can of course write whatever you want, I’m not sure that this is consistent with what is said in acts 1-7 (I have chosen to disregard everything after act 7) about first guardians. It seems like an entity either is or is not a first guardian, and that this fact is established at the time of that entity’s creation. It seems to me like what happens with first guardians is: using ectobiology, the genetic code from some players’ subconscious-or-whatever is combined with some other source(s), and the result is a first guardian.

Oh, I suppose if you just mean “an entity has the powers of a first guardian as a result of a ~ATH script”, then, uh, I guess that doesn’t contradict anything. How would I depict such a script? Well, I don’t know that anything that we’ve seen of the language gives any particularly clear direction for what such a script would look like. If you want it to just have the keywords we’ve seen, possibly re-interpreted to mean something different, I guess one idea could be to like, say bifurcate an existing first guardian into parts with names that seem relevant, and also whatever entity is to have the abilities of a first guardian, and then like, un-bifurcate (unbifurcation is not something shown in the comic, but is something I’ve added to my language, in order to make it usable) the other entity, but with some component of the first guardian mixed in somehow? Though if you did that, you would probably want to justify why, if ~ATH can do that that easily, why it doesn’t happen all the time.

There is very little in terms of rules that the story gives for how ~ATH behaves. If you want to have a ~ATH script “power” a first guardian, just make up some stuff. If you want to depict the actual script, then look at all the pages of the comic that depict code from it, see what it says they do, and just make something up that seems to aesthetically fit.

The language that I have defined (”drocta ~ath”) does not provide any means of doing this, because the language I designed was designed to technically be usable, while also resembling the language in the comic.

I suppose that, as all first guardians get their power from the green sun, and the green sun was created by the circumstantially simultaneous destruction of, uh, either universes A and B, or specifically of A2 and B1, not sure which, and this was in some ways tied to the Möbius Double Reacharoud virus, you could argue that all first guardians get their powers from, something somewhat connected to a ~ATH script.

Why can’t I add tags to an answer to an ask?


Tags
12 years ago

I am so bad at updating. (and a side note)

I am still intending to update this.

but I am not good at time management.

I have like 2 hours of free time after school, (because of certain inefficiencies on my part) so that's my stupid excuse.

I am working on writing some responses to some requests for clarification, and then I will do the second part of the converter TO binary.

the print command can have the end of a loop in.

The contents of the print command can be executed.

so if you say:

import blah A; import bleh B; ~ATH(A){ ~ATH(B){ print heh } ~ATH(NULL){ print giant frogs alert; B.DIE(); } }  

it should print

"heh } ~ATH(NULL){ print giant frogs alert giant frogs alert"

this of course, is not particularly useful as far as I can tell, except possibly for quines, and possibly obfuscation. but really, is it possibly to write anything in ~ATH that isn't obfuscated?

speaking of not obfuscated, I have started working on adding a feature for user defined functions. I have it pretty much worked out how it will work, but I am not sure how I want to make the user DEFINE the functions. so I haven't been doing NOTHING with regards to this.


Tags
3 years ago

yeah, can i make ~ATH continue to generate variables? like if one part of the program dies it generates another variable? because i've been trying to do that lmfao

Hi. Not sure what you mean by continue to generate variables. If you mean like how in lisp you can like, automatically generate a new variable name and then use that variable name, then no, drocta ~ATH doesn't have a feature like that, but I'm guessing that's not what you mean.

Variables are just like, names in your program. If you want more objects, you can just continue bifurcating objects to get more objects.

drocta ~ATH does not support parallelism or concurrency or whatever (though presumably canonical ~ATH would, in some sense. At least, it appears to handle circumstantial simultaneity.), So, if you are referring to drocta ~ATH, then I'm not sure what you mean when you refer to part of the program dying. Though, given that in canonical ~ATH, there is the expression

[THIS,THIS].DIE();

then it seems like, presumably, it should be possible to have something like

THIS.DIE();

in order to describe part of the program dying (ending), without another part doing so.

But, again, drocta ~ATH does not support anything like that. Feel free to make a fork of it which does though. Please let me know if you do!


Tags
12 years ago

Syntax explanation post completed, and Hello, World.

I have completed the syntax explanation post, and I think it is fairly clear now.

If you find any part of the post to be unclear, and that it requires further explanation,  please say so so that I can improve it.

Now that that post is in an acceptable form, We can get on to writing our first few ~ATH programs.

print Hello, World.; THIS.DIE(); 

That wasn't so hard, was it?

I feel I should note that the syntax of the print command is not entirely finalized, it might change sometime later.

EXPLANATION:

The first line of the program says to output the text "Hello, World." 

The 2nd line of the program says to end the program. This is because the variable THIS initially points to a object that is only alive when the program is running. If the object is ever not alive, the program stops.

oh gosh why is this a bullet-ed list I am not good with tumblr

To run a drocta ~ATH program, you need the interpreter (available from the github), and python 2.7 (the interpreter can be easily modified to run with python 3, but it is written to work in 2.7)

Open interp_2.py with python, and when the program comes up, type in the filename of the ~ATH program, and hit enter, this will run the ~ATH program.

With this example, it should output the text

Hello, World.

Now, of course, this is a relatively simple program, but at least its something.

Depending on how you are running the interpreter, the program might close immediately after outputting the text.

That might not be what we want.

To make the program not close until we specifically tell it to, we use the following:

print Hello, World.; ~ATH(THIS){ } THIS.DIE(); 

EXPLANATION:

The first line is the same as in the first program. It outputs "Hello, World."

The second line is different, this says to start a loop, which will continue until the object pointed to by the variable THIS is dead.

The third line says to go back to the corresponding ~ATH statement.

The fourth line is never executed, because the loop above it will continue until the object pointed to by THIS dies, and if that object dies the program ends. If it were to be executed it would make the object pointed to by THIS die, and the program would end as a result.

This program should be the same, except that it will keep running until you close it manually.

Now you have hello world written in two different ways!


Tags
8 years ago

This blog still exists

Hi, I haven’t posted much here in quite some time.

So, is this blog abandoned? I wouldn’t say so. I intend to post more ~ATH content here at some point. I have other projects and obligations, which is why I’ve been not doing as much with it recently (”recently”: understatement of the year), but if anyone has any questions about drocta ~ATH, or would like to request that I do something in particular with it, I think I’ll probably respond within a reasonable amount of time.

Right now though I thought I would link to two blogs that I think you are likely to appreciate if you like this blog.

The first is @sbahjsic http://sbahjsic.tumblr.com/ which is for a programming language and assorted connected software meant to be, well, sbahjsic . like sweet bro and h---- jeff. (Warning though, that blog has some javascript alerts when you view it. Also it has moving parts which might be bad if you get nauseous easily or something? idk.) The blog theme there is a work of art to behold. This is likely to appeal because it is also a homestuck related programming language, and also it is great.

The second is @tilde-he which is where I post most of my non ~ATH related tumblr posts. This is somewhat likely to maybe appeal because it is by the same person as this blog (me).

Again, if you have any questions or comments about my version of ~ATH, or, really, any version that you can point out, feel free to send them, and I’ll try to respond within a reasonable amount of time.

Alright, cheers


Tags
3 years ago

Happy 10/25

Today is the 10 year anniversary of the destruction of the universe frog. Such an occasion is traditionally celebrated by destroying the universe.


Tags
12 years ago

I couldn't help but notice that out of some of the best things you could do, no link to the download in the sidebar? You may want to do that...

uh, yes. that would be good to do.

I put a link in the about section, but I don't actually know how to put links in the sidebar outside of that.

do you think you could explain that for me?(I am not particularly experienced with tumblr)

EDIT:Nevermind, my friend from school told me where the feature is.

12 years ago

I've realized that my tutorials haven't been tutorial-y enough

I've realized that recently, my tutorial posts have been too much code and not enough explanation. That was a mistake on my part, so I am going to go back now and give better explanations.

Also, I have started to make a table of contents page.

I figured that if someone wanted to read the tutorial after a significant part of it were finished, that they might have trouble, because it would kind of be in reverse order.

So TABLE OF CONTENTS AHOY!

Yeah.

So uh, any suggested changes to the format of the TOC page?

Why cant I mark this as a post that can be answered? I can let people photo reply, but once it goes in drafts I can't let people answer this question? Or is it too long?

What is with this interface?


Tags
12 years ago

Bug fixed

Fixed the bug. The problem was that it was seeing

\n}\nD.DIE();

 and it was checking if the text up to the next semicolon ended with .DIE() and if it did, using the stuff before the . as the variable name.  When it should have been seeing the } and jumping back.

Also there may have been a problem with the {} matching. If so, that was fixed too. It was not the last part to be fixed.

BUT ANYWAY: The bug is fixed now.

runs in python 2.7

If you have a different version of python, and it is incompatible, please tell me. If a sufficient number of people want it in a different python version I might make a version of it for multiple python versions. 


Tags
12 years ago

Heyho, I now red alot of your sources and i started to understand your interpretation of ~ATH. You do alot of things with the bifurcate command.. I actually thought that bifrucate JUST splits the programm in different colors like here : "bifurcate THIS[THIS(red), THIS(blue)]; " I think that you can actually split your script into N colors while N > 0. like this: bifrucate THIS[THIS(COLOR(0),THIS(COLOR(1),THIS(COLOR(2),THIS(COLOR(3),THIS(COLOR(4),THIS(COLOR(5),THIS(COLOR(6)] and so on.

Yes. I do use BIFURCATE often.

Personally, I doubt that one could say

BIFURCATE A[D,B,C]; (for some names and colors for a b c and d),

because of the "Bi" part of the word "bifurcate", meaning two. (or in some cases, "both")

Further, I would defend my use of it to BIFURCATE things other than  THIS with http://mspaintadventures.com/?viewmap=6 which, for the start of act 5, says

BIFURCATE ACT_5[red(ACT_1), blue(ACT_2)];

which seems to indicate that things other than THIS can be BIFURCATED.

To split something into more than 2 parts, I would just bifurcate it multiple times. *

I don't know what the etiquette is for whether I should click publish or answer privately, so I am going to pick one and hope for the best.

Loading...
End of content
No more pages to load
learn-tilde-ath - Learn ~ATH
Learn ~ATH

News and tutorials on drocta ~ATH by drocta. interpreter here A brief summary of how to write code in the language (but also see the table of contents)

38 posts

Explore Tumblr Blog
Search Through Tumblr Tags