I need to implement a program where I will have a base variable x and its extensions like exp(x), ln(x), exp(5ln(x)) etc. I have thought of having an interface IExtensible, but I’m not sure how to implement the variables. The option I have considered is using some list for keeping the sequence and type of extensions. But I’m not sure this kind of implementation will be easy to deal with: I need to use these extensions as variables in a rational function.
EDIT: I’ve added a small sample of what I need to have in the end:
x^2 + 3exp(ln(2x)) – ln(x^4)
This kind of expression is passed to a function F which will perform some calculations.
The function F needs to know exactly what extensions there are.
What you need is a math parser and it so happens I created a math parser for .NET and you can download it from here. It has full source code and it lets you set up custom delegate functions for creating built in operations. In addition it has variable support so you can define a variable (such as
xin your example) and you can make that variable equal anything you want. Check it out