I need to read in a Polynom and transform it into normalized form.
For example I read in 4*x * (x^2 + 4x + 3)
and it has to be transformed to 4*x^3 + 16*x^2 + 12*x
.
Is there some tricky algorithm for it or do I have to think of something myself. I think basically this is just expanding the term.
I am parsing the term recursively and generate a parse tree, so the normalization operations will be applied to this parse tree.
Thanks to everybody who helps me
Asked
Active
Viewed 90 times
-1

jvh
- 341
- 3
- 15
-
answer is hidden in the matrix... – philippe lhardy Dec 19 '14 at 19:27
-
2There's no tricky algorithm. I'm afraid you'll have to think. – The Archetypal Paul Dec 19 '14 at 19:35
-
After you generate the tree, you will have to build a set of rules to modify the tree (multiply polynomials, add exponents, etc.). – gab06 Dec 23 '14 at 23:58
-
As @Paul says, this is not an easy thing. – gab06 Dec 24 '14 at 00:00
1 Answers
1
This can be the expression binary tree that represents the expression 4*x * (x^2 + 4x + 3)
:
*
/ \
* +
4 x / \
^ +
x 2 / \
* 3
4 x
Now you have to multiply 4x
with x^2+4x+3
, that can end in a binary tree like this, just like we humans do:
+
/ \
+ *
/ \ * 3
* * 4 x
/ \ / \
* ^ * *
4 x x 2 4 x 4 x
Then continue multiplying numbers and x's
adding exponents. You have to search for each operator in the tree and look for it's childs to apply the respective algebraic rules.
Hope this helps.

gab06
- 578
- 6
- 23