I want to implement a general tree data structure in C # that has a Tree<E> class that references a root TreeNode<E> object that contains a linked list of children and one parent of the same node type. This is a basic tree structure, and I have no problem implementing this part.
I want to expand this tree structure by creating a Function that extends Tree<double> along with its addition of node type Expression , which extends TreeNode<double> accordingly. I want to use this structure to represent mathematical functions that can be evaluated using appropriate variables.
I am now at the design stage of this project, so there are many ways to implement this, but I am looking for a design that has an appropriate level of abstraction to cover all types of functions, while keeping their parameter signatures tight. For example, I should be able to create Function during the execution of mathematical functions:
f() = 42 , f(x) = x^2 , f(x, y) = x/y + 5 , etc.
If each Expression has its own list of children (subexpressions that are broken down to determine the function process based on its arguments), then Expression should use some kind of evaluation method that takes double values ββand splashes out their scalar values ββ(or, if possible, extracts them to the Vector level).
I'm not too experienced with functional languages ββlike LINQ, but if anyone is there, will there be an easy and powerful way to implement what I plan to use? It would be great if I did not have to create specific classes for each basic operation (for example, SinExpression(X) or AdditionExpression(X,Y) ), but instead one could define mathematical functions on the fly, which could potentially be stored in the Dictionary, provided that all variables are either different expressions or are reduced to floating point values. At this point, concrete function classes could extend these abstract ones if I just needed to define an evaluation function in the base constructor.
I also want to note that it is important to maintain a tree structure, because I plan to use these expressions in a separate program that will directly modify the tree of function expressions (changing nodes, deleting branches, etc.).
Can someone point me in the right direction? I would be very grateful.