[GiNaC-list] factor() hangs on a simple expression, randomly

Vitaly Magerya vmagerya at gmail.com
Wed Dec 13 17:05:31 CET 2017


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?).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ginac-factor.diff
Type: text/x-patch
Size: 3167 bytes
Desc: not available
URL: <http://www.cebix.net/pipermail/ginac-list/attachments/20171213/2786faed/attachment.bin>


More information about the GiNaC-list mailing list