This is a pretty complex task. You need to work not with the digital, but with symbolic calculations.
The field of computing is called
Computer Algebra System (
CAS, see
http://en.wikipedia.org/wiki/Computer_algebra_system[
^]).
You need to parse your expression symbolically into an expression tree. Your operations should be represented as the nodes, your sub-expressions should be the node children, and your terminal nodes should be the objects representing expression arguments or constants.
Good news: with your v.4.0 you can get expression trees right from your C# code in the form of lambda expression:
http://msdn.microsoft.com/en-us/library/bb397951.aspx[
^].
Everything beyond that is much more difficult: you will need to develop a system which performs mathematical operations over a tree. Your algebra operations should be the operations over an expression of the tree; they will takes expression tree(s) as an argument and build resulting expression tree for return value. For example, differentiation function takes two parameters: a reference to argument to differentiate by and the expression tree representing a function to be differentiate, the result will be a new expression tree representing the derivative; due to the property of the derivative the function should be recursive.
Why did I explain the example of derivative? Simply because this is the simplest non-trivial operation in all Computer Algebra! Simplification of expressions is already much more difficult. You can develop simplification algorithm for some partial cases, but a general case is quite difficult.
Good luck,
—SA