r/learnprogramming • • Apr 28 '22

If everything is ultimately binary, does't that just make programs a specific number?

I did the CS50 course a while ago and they covered binary in there. I did binary back in 2006 when I was at college too so understood the logic behind it already. It's either on or off!

When a C program compiles, it goes through it's phases and compiles to assembly and then ultimately machine code i.e binary.

Let's say our program is 5,000,000 pages of 1's and 0's. All of those 1's and 0's make up a single number....albeit a super long number.

Does that mean that the entire Linux operating system, for example, can be represented by an actual number?

If so, why are we not storing programs as a number because that would take up less space than the 5,000 pages of 1's and 0's.

110101000101011111011011111110111100 = 57000443836 in decimal. So why don't we store programs in decimal and convert that to 1's and 0's in real time?

Storage would be much less. Is that how compression works?

These may be crazy questions but it just entered my head earlier when thinking about what the binary of a program can represent.

Even shorter than decimal is HEX.... So why don't we store programs in Hex?

Any help appreciated on this one so I can wrap my head around it.

1.7k Upvotes

346 comments sorted by

View all comments

Show parent comments

1.0k

u/captainAwesomePants Apr 28 '22 edited Apr 28 '22

No worries, this is really fun stuff. The whole "oh my god programs are data" revelation leads to a lot of amazing thoughts.

For example, pi is an infinite, nonrepeating decimal - meaning that every possible number combination exists somewhere in pi. Any program you write can be expressed as a decimal number. That means that your program exists somewhere in pi. Instead of storing the program itself, I could just tell you which digit of pi it starts on!

There was a controversy many years ago when someone published a small program that could decode DVDs. There were arguments and lawsuits basically claiming that the program was illegal. In response, some programmers found a prime number with 1401 digits that, in binary, was a gzip file containing the source code to the program. They argued that declaring a prime number illegal was ridiculous.

That stuff is fun and mind-blowing, but there are practical thoughts too. Once you realize that your program is a number, and you realize that programs are good at manipulating numbers, you'll probably realize that your program can do operations on programs, including on itself!

241

u/l_am_wildthing Apr 28 '22

every possible number combination exists somewhere in pi

Not to be pedantic but this is a misconception about the infinite-ness of pi... just because it is infinite and non-repeating doesnt mean it has every possible number. 1.101001000100001000001... is infinite and non-repeatable but doesnt contain every number. Pi is obviously different but the same applies

81

u/matthewapplle Apr 29 '22

Something something monkey typewriter Shakespeare??

69

u/InnerBanana Apr 29 '22

This comment is one of the failed attempts from that very experiment

0

u/[deleted] Apr 29 '22

[deleted]

10

u/goahnary Apr 29 '22

All of them actually. Including this one. These monkeys are hilariously self-aware while… also not self aware??

Does the monkey learn and grow as it types? If it does I think it would take it significantly less time to learn/type Shakespeare.

28

u/p43- Apr 29 '22

Let me neatly summarise this whole comment thread:

7463662637483720304057371719

6

u/Mollyarty Apr 29 '22

Or more time, if the monkey learns and grows it'll likely develop its own style that might not align with Shakespeare

→ More replies (2)
→ More replies (4)

83

u/captainAwesomePants Apr 29 '22

Totally fair. We also have to show that pi is normal, and although I'd bet it is, that is certainly not a given.

33

u/Sufficient_Drop5013 Apr 29 '22

It may very well be a misconception, but you can't prove it's not true.

40

u/jcb088 Apr 29 '22

Until he can! If he can! Maybe that's his life's work!

This conversation might be the start of something incredible!

39

u/schoolmonky Apr 29 '22

Depending on what exactly you mean by "it," you totally can, and /u/l_am_wildthing did.

If by "it" you meant the statement "Pi doesn't contain every possible number," then yes, that's currently believed to be false, and therefore unprovable.

But if you read carefully, that's not the statement that /u/l_am_wildthing is arguing against. What they actually say is that the facts that a number (in this case, pi) is infinite and non-repeating do not imply that it contains every possible number. He's not making a claim about whether pi has all numbers in it, but instead about the logical relationship between whether pi is infinite and non-repeating and whether pi contains all numbers.

→ More replies (8)

30

u/nimbledaemon Apr 29 '22

If you start believing everything you can't prove to be false, you're going to end up believing a lot of bullshit.

→ More replies (3)

24

u/Putnam3145 Apr 29 '22

Sure, but you can't claim it like it's a known fact either. Lots of people suspect P != NP but I'm not gonna go around proclaiming it.

→ More replies (3)
→ More replies (25)

23

u/green_meklar Apr 29 '22

Instead of storing the program itself, I could just tell you which digit of pi it starts on!

But on average the index number would be about as long as the program itself. So you still can't get an informational free lunch that way.

10

u/gaspronomib Apr 29 '22

Yes, but the index number itself would be in Pi, so you could just give the index to the index number. And if that index number was too long, well then it exists in Pi as well.

It's index numbers all the way down.

→ More replies (1)

8

u/oakteaphone Apr 29 '22

Instead of storing the program itself, I could just tell you which digit of pi it starts on!

Please do! joke

9

u/captainAwesomePants Apr 29 '22

It starts at bit 186282. For security, I've also encrypted the program with a one time pad.

8

u/EmpyrealSorrow Apr 29 '22

There was a controversy many years ago when someone published a small program that could decode DVDs. There were arguments and lawsuits basically claiming that the program was illegal. In response, some programmers found a prime number with 1401 digits that, in binary, was a gzip file containing the source code to the program. They argued that declaring a prime number illegal was ridiculous.

Can I just clarify something that's confusing me with this? Is it important for the program that it is a prime number? Or is it just a series of values that happens to contain the number equivalent of the programme and, by virtue of being one of the largest prime numbers known, is automatically archived and therefore protected?

11

u/rcxdude Apr 29 '22

Is it important for the program that it is a prime number?

Only to make it a bit of a stunt to represent it as such, making the argument appear to have a bit more weight, because prime numbers are 'mathsy'. (it would more naturally be a slightly different number which wasn't prime: what they did was basically have a part of the file which could take any value they wanted without affecting the functionality, then try random values in there until the result became a prime. Because primes are still fairly dense at these very large numbers, this doesn't really take too long for a computer)

→ More replies (1)

4

u/Roxolan Apr 29 '22

They argued that declaring a prime number illegal was ridiculous.

Relevant blog post: What Colour are your bits?

The problem is that there are two conflicting sets of rules there. Under the lawyer's rules, Colour is not a mathematical function of the bits that you can determine by examining the bits. It matters where the bits came from. The scrambled file still has the copyright Colour because it came from the copyrighted input file. It doesn't matter that it looks like, or maybe even is bit-for-bit identical with, some other file that you could get from a random number generator. [...] To a computer scientist, on the other hand, bits are bits are bits and it is absolutely fundamental that two identical chunks of bits cannot be distinguished. [...]

This idea of Colour is a problem for communication between those of us who work in the world of computers, where Colour does not exist, and those of us who work in the law, where Colour exists and is important. Lawyers will ask computer scientists questions about how to determine the Colour of bits [...], and computer scientists will find it difficult to say anything in response that the lawyers can comprehend - because a big part of computer science is about understanding that Colour does not exist.

3

u/twbluenaxela Apr 29 '22

What? How is that possible? How did the source code for a program be in a prime number

61

u/captainAwesomePants Apr 29 '22 edited Apr 29 '22

Here is a prime number with 1401 digits:

48565078965 7397829309 8418946942 8613770744 2087351357 9240196520 7366869851 3401047237 4469687974 3992611751 0973777701 0274475280 4905883138 4037549709 9879096539 5522701171 2157025974 6669932402 2683459661 9606034851 7424977358 4685188556 7457025712 5474999648 2194184655 7100841190 8625971694 7970799152 0048667099 7592359606 1320725973 7979936188 6063169144 7358830024 5336972781 8139147979 5551339994 9394882899 8469178361 0018259789 0103160196 1835034344 8956870538 4520853804 5842415654 8248893338 0474758711 2833959896 8522325446 0840897111 9771276941 2079586244 0547161321 0050064598 2017696177 1809478113 6220027234 4827224932 3259547234 6880029277 7649790614 8129840428 3457201463 4896854716 9082354737 8356619721 8622496943 1622716663 9390554302 4156473292 4855248991 2257394665 4862714048 2117138124 3882177176 0298412552 4464744505 5834628144 8833563190 2725319590 4392838737 6407391689 1257924055 0156208897 8716337599 9107887084 9081590975 4801928576 8451988596 3053238234 9055809203 2999603234 4711407760 1984716353 1161713078 5760848622 3637028357 0104961259 5681846785 9653331007 7017991614 6744725492 7283348691 6000647585 9174627812 1269007351 8309241530 1063028932 9566584366 2000800476 7789679843 8209079761 9859493646 3093805863 3672146969 5975027968 7712057249 9666698056 1453382074 1203159337 7030994915 2746918356 5937621022 2006812679 8273445760 9380203044 7912277498 0917955938 3871210005 8876668925 8448700470 7725524970 6044465212 7130404321 1826101035 9118647666 2963858495 0874484973 7347686142 0880529443

Consider this as a number. This is its decimal representation, but you could also write it in binary as a number with 4500ish bits. You could save those bits in order as a file. If you were to do that, you would in this case find that it is a gzip file, and if you opened that gzip, you would find the source code to a program that breaks the encryption on DVDs.

→ More replies (33)
→ More replies (7)
→ More replies (25)