Symbolic variables

Hi people,

the thing is that I don't know how to create a symbolic varible in c++ and work with it. For example, make the program run a process that in the end outputs an equation like: x + 5. So, how do we create a symbolic varible like "x" and how do we make operations with it? For example, x + x = 2x. Or, x square time x to the power of 3 is equal to x to the power of 5.

Thanks in advance!
it totally depends on what you want to do....

if you want beginner stuff then you can take a var, a operation and a number like this

1
2
cout<<"Enter the variable,operator and the number in form x+num=";
cin>>var>>oper>>num;


or if you want some advance stuff you can take a string and evaluate it later

for the calculation part I think you should check github, they got this crazy calculation stuff....
But the thing is that in the program I have to make, there is no value for anything. I have to work strictly with the variable, as if I was doing algebra.

closed account (48bpfSEw)
I think I understand what you mean: type in wolfram e.g.: x+y

x and y are symbols and it shows you some cool stuff!

https://www.wolframalpha.com/



I think you need first a knowledge base about the mathematic formulas.
Then you have to substitute the used symbols.

An example what I mean:

The knowledge base contains this formula :
y = x^2
x = sqrt(y)
z = 2x

You type y = 2

and your code subsitutes the known formulas

2 = x^2

x = sqrt (2)

z = 2 * sqrt(2)
Last edited on
Use a library, perhaps. For instance, GiNaC http://www.ginac.de/
But the code must do the math without values known. I mean, the code must know that x + x = 2x for example. So, with a certain recurrent formula, the code must run a process that makes the algebra dividing, multiplying, substracting and adding equations. The result must also be an equation, without having substituted any values.

For example:

If the code must solve this formula: (x^2-1)/(x+1), he must output x - 1, without having substituted the variables with any values. That's why it has to work symbolically.
Topic archived. No new replies allowed.