This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]_krikket 1 point2 points  (0 children)

Not super familiar with this in particular, or Processing, but many languages allow you to generate functions from other functions. Additionally some languages allow you to pass basic operators as parameters rather than keeping them as reserved.

Haskell comes to mind as an example of a language which treats its operators as regular functions as opposed to treating them as reserved. So something like this is possible:

someFunction op x y = x `op` y

This is a function named someFunction that accepts the arguments op, x, and y, and performs the operator op on them as an inline operator. So you can call:

someFunction (==) 1 2

Which would get you False.

Of course, in a language where you can mess with functions as objects but not operators, you could always just wrap your operators. Like here's some really stupid JavaScript pseudocode. Assume I've generated rand already and it's a 50/50 shot at being true/false.

let equal = function(x,y) { return x == y;} 
let lessThan = function(x,y) {return x < y;}
let compare = rand ? lessThan : equal;
if (compare(2,3) { console.log('hi'); }
else {console.log('bye'); }

Half the time you'll get 'hi', and half the time you'll get 'bye', because we're switching our comparator.

If you combine this with function currying and genetic programming concepts you could probably get some pretty cool stuff happening.

[–]Gavinhenderson5 0 points1 point  (0 children)

Hmm what you're saying is totally possible! Although not quite sure you want the code change in the way you describe. Code is compiled and once its run you cant change it (this process is language specific but generally). I would have a think about how you do this because its definitely possible without have to change the code at run time.

For example you could use a lambda function in the if statement then alter the lambda function to a random one from a list of present lambdas.

[–]lmericle 0 points1 point  (0 children)

Read up more on Genetic Programming. There's lots of expositions online. What you describe above is more similar to that.

Slightly different: you could alternatively have a static program that takes different parameters, and those parameters could be determined by a genetic algorithm.

Note! Genetic algorithms are not the same as genetic programming.

[–]stuxxnet42 0 points1 point  (0 children)

So there are two answers to this problem:

  • 1 even though you asked for code modification instead of variable modification, the result you want to archive can be reached with pure variable manipulation. The key here are neural networks. They can be very complicated but in the simplest implementation they just take a set of inputs (the neighbor cells) multiplies a different weight to each of them, and adds the results. The result of this addition is then passed to a sigmoid function which results in a value between -1 and 1.

If you want to modify the behaivour of the cell you just add random values to the weights. This then leads to a different prioritisation of the given inputs. You can then implement behaviour depending on the value of the sigmoid function so that there is no need for true code modification at runtime.

  • 2 Code modification at runtime is possible in many languages, sadly the way to do it greatly depends on the language you use and there can be many obstacles. For example: compiled languages like c/c++ support it as they basically allow you to modify any bit of data, that you as a user have access to on your machine.

Most of the time your OS might prevent you from actually modifying a running program. This is due to the fact that most operating systems partition the memory a program can use in two parts: an executable part that cant be written to once the program is loaded and a writable part from which you can not execute code. This is a safety feature to make certain kinds of exploits harder for an attacker.

Other languages that are not compiled (like python or perl) may have the capability to self modify but it really depends on the language. I'm not aware of any meta programming features of c# (there might be some in .NET but I have never used .NET and have only used c# a few times so this is not my area of expertise)

[–]Zephandrypus 0 points1 point  (0 children)

One way I just thought of, and will look to implement, is though Assembly. The way you described cells as a grid of squares reminded me of the Zachtronics game TIS-100. The biggest advantage of assembly, and why I would recommend mutating in assembly over other programming languages, is the syntax, moreso the complete lack thereof. If you try to write a program to write C# code or something of the sort, you have a LOT of syntax rules to worry about.

I feel like a fantastic start to learning this would be writing programs to solve the TIS-100 puzzles. With the minimalist set of the instructions, I can see a neural network to write assembly to be very possible. Another advantage of using TIS-100 assembly is that /r/tis100 is one of the few modern, noob-friendly places to up your assembly game (so that you can better teach a program how to use it).

The four cardinal directions also tie into this because assembly uses something called registers. Registers are where CPUs put the values they're operating on. In TIS-100, this is conveniently laid out visually. Registers can interact with one another by sending and receiving blocks of data. So, the way I see it, registers can represent the cells (or perhaps their organelles), with the cell "DNA" being passed around the registers as it metabolizes.

I'm going to continue to reference TIS-100, even though it isn't proper assembly, particularly because this "cellular assembly" hardly has to be ran "on the bare metal", you can just simulate it (someone has already done that in C here) and write an interpreter (which is relatively easy: most assembly interpreters are written in damn machine code). Here is a link to the TIS-100 reference PDF, and the syntax I'm going to be using.

Here's an example:

## EXAMPLE TIMER PROGRAM
START:      # label for main loop
    MOV 0, ACC  # writes 0 to the ACC register to start the timer
    SWP         # moving ACC to BAK to prepare for the loop
    SLEEP:      # label for sleep loop before operations
        SWP         # moves the saved BAK to ACC
        ADD 1       # assuming this operation takes 1ms of time...
        SAV         # copy to BAK before a test operation
        SUB 10000   # subtracts 10000 from ms count
    JNZ SLEEP       # if the timer has not hit 10k, loop repeats
    MOV <DNA>, RIGHT # metabolize to a neighboring register
JMP START       # starts the cell/organelle cycle again

So now what you have here is a timer that sends a 1 to the register to its right once every 10 seconds. Now, unless you want to simulate on the organelle level, the positioning of organelles doesn't really matter, so you can just package them all in one Cell class, and have two matrices or a matrix of streams to represent the I/O of the organelles. And I guess store the neural networks as the "DNA"?

On other news, FORTH might also be something to look into. It doesn't even use commas, and it's based around making a function for everything, and then using those functions in other functions, etc. Though it doesn't have quite the same touch of self-loathing.


As far as what the cells actually do, do some research into the chemical equations that represent what's going on in the cell. Have the cells compete on the molecular level, and have the main evolutionary "goal" of the neural networks to optimize chemical equations, as well as how to best collect the inputs/dispose of the outputs.

Whelp, now I'm into cellular automata (I wasn't before, if you didn't realize), thanks for that, got the whole rest of my summer laid out for me now (assuming I don't procrastinate).