I want to make a tree of functions in C, which would look like this: http://scr.hu/5rq/vdja0
So basically I want the result to be like this: http://scr.hu/5rq/f04uu
where x
is an variable which I can provide (float). The F0 to F6 are random functions which take two arguments (functions like multiplying, adding, or giving random number).
So my exact question is: how i can do that?
I know that it can be done easily, by storing exact value given by each function in arrays.
But then it gets complicated when it comes to getting different "x" value.
My initial thought was to create function which attaches random function to each node in the tree, but then, i am unsure how should be done structure which makes that tree,
typedef struct drzewo typ;
struct drzewo {
typ *right;
typ *left;
typ *up;
float *value; //what to do with this ?
};
I would like to somehow change line "float *value;" into something that could store a function like Function1(left->value,right->value);
but not runned, and not exact value of function with given arguments, and where Function1()
or Function2()
means function which divides both arguments or multiplies them or so on.
No it is not for school, and yes this is my miserable try to use genetic programming.