And sorry for messing up the subject! On 06.09.2018 08:47, Patrick Schulz wrote:
Hi all!
I'm working with polynomials in one variable, where i want to compare coefficients and remove some (simplification). For this, i need to iterate over the individual coefficients, but in order to compare them, i need them to be in a standard form. Since only terms with products and sums are involved, i expand the expressions to remove any nested expressions, e.g. R1 * (C1 + C2) -> R1 * C1 + R1 * C2. This works well, but sometime terms of nth power also exist, which are not expanded:
GiNaC::symbol R1("R1"); GiNaC::symbol R2("R2"); GiNaC::symbol C1("C1"); GiNaC::symbol C2("C2"); GiNaC::ex e = (R1 + R2) * (C1 + C2 * (R1 * C1)); std::cout << e << '\n' << e.expand() << '\n';
Here we get a term R1^2 * C1 * C2, which does not comply with my "standard form".
In the end, ideally i would like to have only a sum of products, no deeper nesting:
R1 * C1 + R1 * R1 * C1 * C2 + R2 * C1 + R1 * R2 * C1 * C2
Is there a way to do this?
Maybe some information what i'm trying to acchieve: I solve spice netlists and extract transfer functions in s-space. For the simplification (the removal of individual terms) i want to look at the coefficients of the numerator and the denominator polynoms. This is easy, since i use ex::coeff(). So now i have expressions for each power of s. Then i want to store the individual elements in a vector, which makes up the individual products. These are again stored in another vector making up the sum of the polynoms. This works, kinda, but i have to parse the ginac expression, which does not always behave in a way i can foresee. Also i have a strong feeling that there is a better way to do this, given that ginac has already many functions dealing with polynoms. I'm happy to get some pointers on this topic :)
Thank you for your help!
Greetings, Patrick _______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list