On 12/08/2017 11:22 PM, Richard B. Kreckel wrote:
You're right that this is unexpected. GiNaC first does a square-free factorization and finds the terms (2*x-l)^2 and the expanded form of all the rest, i.e. of (-1+6*x-l)*(-1+3*x-l)*(-2+4*x-l)*(1+4*x-l)*(4*x-l)*(2+4*x-l). The factorization of the rest then fails, depending on the order it finds the symbols x and l.
Yes, this expand()ing seems unfortunate.
No idea why it doesn't factor the product term by term, first. I suppose this is an easy and risk-free optimization!
One potential risk I see is if you factor() each of the pre-existing factors separately, then identical factors of each part may not get re-combined properly. Not that current factor() ever provided such a guarantee. I also can't seem to find a good counter-example, so maybe it's a non-issue.
Can you try to send a patch? I'ld be happy to review it and help, but have not the time to do it myself, I'm afraid.
I'm attaching a brute force approach, see if you like it. (Does this list accept attachments?).