Mutated computer program

39 posts / 0 new
Last post
Nyarlathotep's picture
Mutated computer program

Valiya, remember when you told me that all that [I] have to do is show [you] an example of a computer which took on new functions by adding bits?

So I got bored at work and wrote a little program. This program (let's call it program A) takes a different program (program B) and alters it randomly by replace 1 letter with a random letter. It then tries to run program B, and spits out interesting results. I ran it 2000 times (that is it started with the original code and mutated it once, then tried to run it, rinse repeat 2000 times).

The unmodified program B is:
def f(x,y):
print x+y
f(3,7)
Or simply, print the sum of 3 and 7.

After 'mutation':

About 90% of the time, program B crashes (which program A is protected against), so nothing is returned.

About 5% of the time, program B runs, but fails to print anything.

About 2% of the time program B runs as expected. Often times this is because a character was inserted that does nothing, like an extra space in many locations won't produce a noticeable difference in the output of function B.

About 2% of the time, one of the numbers being input in to Program B got altered (like maybe the 3 got changed to an 8).

About 1% of the time, program B runs but outputs something very unexpected. I expected to see certain mutations, and I actually saw very few of those. But I did see several very weird one. Below is a list of the ones I thought were interesting. It displays the new mutated version of the function, the output it gave, the mutation number when this occurred, and my description of the mutation.

--------------------
def f(x,y):
print x-y
f(3,7)
output = -4
mutation number: 59
Notes: Turned the addition function into a subtraction function. This is one of the few I actually anticipated.
--------------------
def f(x,y):
print -+y
f(3,7)
output = -7
mutation number: 252
Notes: This one returns the negative of y. Similar mutation in 1923.
--------------------
def f(x,y):
print 8+y
f(3,7)
output = 15
mutation number: 315
Notes: This one changed to a function that just returns y + 8, similar mutation occurred in 382, 384, 491, 11, 15, 1004, 1161, 1283, 1328, 1502, 1538, 1583, 1591, 1698, 1938.
--------------------
def z(x,y):
print x+y
f(3,7)
output = False
mutation number: 828
Note: This one renamed the function to z (instead of f), so when it tried to call it, it used the wrong name which returns the output: False
--------------------
def f(x,y):
print x%y
f(3,7)
output = 3
mutation number: 936
Notes: This mutation changes the function from calculating the sum of the 1st and 2nd number, to calculating their modulo.
--------------------
def f(x,y):
print x

Subscription Note: 

Choosing to subscribe to this topic will automatically register you for email notifications for comments and updates on this thread.

Email notifications will be sent out daily by default unless specified otherwise on your account which you can edit by going to your userpage here and clicking on the subscriptions tab.

ThePragmatic's picture
Nice work. An extremly

Nice work. An extremly simplefied example, but simple is good.

(I might start using this at work, randomly mutating my code to get improvements. :)

Nyarlathotep's picture
LOL! Yeah, I want to do more

LOL! Yeah, I want to do more with it when I got the chance. Maybe put in other kinds of mutations (insertions, deletions, duplications), but first I really need to work on a better system for processing the output (if any), because I suspect it will take quite a few iterations to find anything interesting, and I can't be reading though the outputs by hand. I'm not much of a programmer just a dabbler, mostly I just write very simple programs to solve math problems.

Rohan M.'s picture
You know, the way you said

You know, the way you said that reminds me of the 3 different types of mutations in DNA sequences, which I learned about very recently in my biology class. Is that what you’re referring to? Because I like that analogy. It clearly demonstrates how it is possible for mutations in DNA to affect the resulting protein that is translated from the tRNA. Nice.

Also, another thing I’ve noticed about computer code and genetic code: if there is an error in genetic code (which is supposed to be the code that was allegedly written by God), then it will still work, sometimes resulting in a deadly cancer, but if there is an error in computer code (which we know was written by us humans), then it will just not work at all, and will make no difference on the output (since there would be none in the first place), and you would instead be prompted to change the broken code.

Oh, did I just destroy Intelligent Design? Whoops! Hehe...

Nyarlathotep's picture
Yeah, I tried to make it

Yeah, I tried to make it similar to mutations in nature.

Yeah, in my very limited experience, you want a computer program that has an error to fail immediately, and loudly. When you have a machine that is doing millions or even billions of things a second, you don't want it to be wrong. /e In fact that is why I eventually abandoned this project; it's basically running random code, and I was always scared it might do something totally crazy a few million times.

Nyarlathotep's picture
Valiya - "From what i can

Valiya - "From what i can understand, the mutation has just thrown out some random numbers.... i don't see it as specified complexity. This doesn't prove anything at all... if you remember my challenge I as asking for a random process creating specified complexity... unless there is some specified complexity in the characters that i am missing."

It isn't throwing out random numbers, it is changing what the function does (most of these changes were fatal, but occasionally we got a new working function). You said you wanted to see an example of a computer which took on new functions by adding bits...

The original function output the sum of 2 inputs.

Function 59 outputs the difference of inputs. A subtraction function has been created by a random process.
Function 252 outputs the negation of one of the inputs. A negation function has been created by a random process.
Function 936 output the modulo of the inputs. A modulo function has been created by a random process.
Function 1854 outputs one of its inputs. A 'copying' function has been created by a random process.
Function 1682 has two outputs, each one a copy of an input. A 'double copying' function has been created by a random process.

It made tiny random changes to a function, and occasionally this resulted in a new function.

Valiya's picture
Hi Nyarl

Hi Nyarl

Although this can be equated to the cancer example - because a cancer also creates a new function, just that it upsets the normal functions of the cell... i can only say that unless i get a deeper understanding into how exactly you triggered the mutation process and all that, i guess i can't say anything about this.... but thanks Nyarl... you have given me fresh food for thought. I will ruminate over it, and may be if i hit upon something, i will let you know.

Nyarlathotep's picture
I'll tell you how the

I'll tell you how the mutation process was "triggered". Program A choose a random position in program B. Then replaced the character at that position with a random character. This process causes program B to crash in a vast majority of places (since the change caused the code to become gibberish). But in a few cases the change was not actually gibberish and in a small percentage of those cases the program starting preforming a function it did not have before.

Valiya's picture
Please don't think I am being

Please don't think I am being difficult... but i am just curious. It sounds interesting, even outside of our debate.

How did program A choose a random position in program B. Was there some command you gave for that?

Nyarlathotep's picture
Yes, that part of the program

Yes, that part of the program is on line 4 of the link.

Valiya's picture
this is what i found in line

this is what i found in line 4

random_letter_position = random.randint(0,len(original_code)-1)

what things does it specify...how does it tell the computer to choose a random position in program b...

Valiya's picture
this is what i found in line

this is what i found in line 4

random_letter_position = random.randint(0,len(original_code)-1)

what things does it specify...how does it tell the computer to choose a random position in program b...

Nyarlathotep's picture
that is the correct line of

that is the correct line of code...

random_letter_position is the name of a variable where we will be storing the random location (the program will need this later to make the switch)

random.randint(a,b) is a call to a python random module telling it to choose a random integer between a (the starting point) and b (the end point)
for example random.randint(4,10)... Would give back one of the following: 4 5 6 7 8 9 10

In the actual program our starting point was 0
In the actual program out ending point was len(original_code)-1

len(a) takes the string a, and returns the length of the string, so for example

len("dog") would return 3, since "dog" has 3 letters.

original_code is a string where the original copy of program B (the thing we are going to mutate) is stored.

so len(original_code) just tells how how many characters are in the original copy of program B

I'm not going to explain the -1 other than to say, it is required because different things are counted in different ways, and we need this to convert from one way to another.
-------------------
Putting it all back together it says, pick a random number between 0 and the number of characters in the original code and store this number under the variable name random_letter_position for later use (line 6 will need this number to preform that actual swap).

Spewer's picture
"I'm not going to explain the

"I'm not going to explain the -1 other than to say, it is required because different things are counted in different ways, and we need this to convert from one way to another."

You're right, but unless I'm mistaken, the explanation is short: The reason for the -1 is that the starting point is 0 instead of 1. If you didn't subtract the 1, you could go past the end, which would crash as a boundary violation.

Anyway, fascinating stuff you have here.

Nyarlathotep's picture
yes exactly... The length of

yes exactly... The length of the string "dog" is 3. However the "d" is the 0th character, the "o" is the 1st character, and the "g" is the 2nd character. So if you want to use length to find the last character, you need to subtract 1 from the length. Otherwise (like you suggested) all hell will break loose when you try to find the 3rd character in "dog" which does not have a 3rd character.

Valiya's picture
how does the computer

how does the computer understand the command 'pick a random number"? I am wondering if the computer is actually using free will!!!! remember last time, when there was a discussion on free will, and i gave the example of computer picking a random number, you said that it's not random actually.

Nyarlathotep's picture
the method of generating

the method of generating pseudo-random numbers differs from operating system to operating system. I know Linux uses the last digit of the voltage to seed the function (and other things like the system clock).

This method is used everywhere: from the encryption your bank uses, numerical solutions methods in mathematics and science, and even by the casinos. Heh, I hope you aren't suggesting that this is responsible for the results you don't like :P. That dog don't hunt.

Valiya's picture
Nyarl... i am trying to

Nyarl... i am trying to figure out what makes the computer make the random choice... if it's scouring through a list of numbers, what makes it stop at a number... there should be something that triggers it... what is it?

Nyarlathotep's picture
I just told you, simply

I just told you, simply speaking when it needs a number it grabs several numbers from unpredictable sources (last digits of the voltage, last digit of the temperature, last digit of the time, ect). These values are measured to several decimal places and vary wildly between every tick of the processor, making them extremely difficult to predict.

Valiya's picture
is the last (digit, time etc)

is the last (digit, time etc) according to command? therefore, what is unpredictable is only factors like temp, time etc....whereas, we can predict it is going to be last digits of these factors. Is that right?

Nyarlathotep's picture
the last digit from the heat

the last digit from the heat sensor (a physical device), or voltage sensor (a physical device), or the system clock. Listen, you want me to drop $2000 on a true random number generator, just to post results that you won't be able to tell the difference between? Not going to happen. However, I do have a list of random numbers from one of those machines I could use... But you (and no one else for that matter) will be able to tell the difference. So why don't you save us all some time and move on to your next complaint.

Valiya's picture
Look i am not complaining...

Look i am not complaining... as i said, i am just trying to gain some insight into this whole thing...give me some time to think it over...and i will respond... fine?

Nyarlathotep's picture
Ok sure. Meanwhile I've been

Ok sure. Meanwhile I've been working on a new version that has duplication, deletion, insertion, and substitution mutations; that will be multi generational. Maybe take the starting function, mutate a random number of times with the mutation type being random, producing say 1000 offspring. Then prune those offspring for code that don't run. Then do it again for each of those, rinse repeat. Although I'm starting to get scared to run the code after the crazy results I got from this last version. So I'm looking into ways to protect my operating system and files as much as possible.

CyberLN's picture
Partitioning the hard drive

Partitioning the hard drive might help, set up a virtual machine.

Nyarlathotep's picture
that is one of the things I

that is one of the things I've considered!

mysticrose's picture
That is really interesting. I

That is really interesting. I wish I can make such programs too.

mdeepm's picture
Very interesting and a good

Very interesting and a good implementation that is easy to understand. If you could hook up the results of the mutation to a fitness function or a program that evaluates the fitness of the mutated program based on some set criteria, then one could see the programs evolving. I've been wanting to build something of that sort and have simple user applications automatically evolve based on a selective pressure rendered by a program that evaluates the fitness of the variants of the application. Some of the fitness measures for a user application can be - fast response times, minimum user clicks to an action, less memory usage etc.

ThePragmatic's picture
It is a really interesting

It is a really interesting experiment.

I used a newer version of Nyarlathotep's code and adapted it to try to calculate PI. The closer it gets to PI, the higher chance of getting selected for reproduction. Those selected from the new generation get to reporoduce again, and so on.
I also had to add a criteria that counteracts the code getting bloated, otherwise it quickly grew out of control and slowed down the process way too much.

Sometimes they die out, sometimes they get never get to PI in 30000 generations, sometimes they get it right after just a few hundred generations.

Kreston's picture
Friends. I absolutely agree

Friends. I absolutely agree with you that academic help for a student is undoubtedly very useful. Now is the time to find great professionals online who will always help with college assignments. Personally, I find programming assignments very difficult to complete, so I use help to do my programming homework at codinghomeworkhelp. In general, the specified site has a lot of useful information for students who are looking for online support related to programming and IT, so see if anyone has difficulties in their studies.

salimakhan888's picture
Indeed, very good that this

Indeed, very good that this computer did not mutate when collaborating with altricial intelligence. Otherwise we might have had a horror movies in real life.

carlmarx's picture
That's all the fantasies of

That's all the fantasies of those movies screenwriters. Because any artificial intelligence is, in the first place, a collection of software, stitched together in the right consequence. The key to solving any risk is selecting the right software development company. So these machine learning solutions for the retail industry are perfectly capable to fullfil the task correctly.

Pages

Donating = Loving

Heart Icon

Bringing you atheist articles and building active godless communities takes hundreds of hours and resources each month. If you find any joy or stimulation at Atheist Republic, please consider becoming a Supporting Member with a recurring monthly donation of your choosing, between a cup of tea and a good dinner.

Or make a one-time donation in any amount.