vermaseren / form

The FORM project for symbolic manipulation of very big expressions
GNU General Public License v3.0
1.15k stars 136 forks source link

Fix WorkSpace issues with expression optimization #535

Open jodavies opened 3 months ago

jodavies commented 3 months ago

Here are two changes to make the optimizer easier to use.

The first is to dynamically allocate memory in Horner_tree, if the WorkSpace does not have enough space. There is no particular reason that the workspace should be used for the sort, here, other than that it exists, and might have capacity.

The second, is to re-use the same WorkPointer for every call of Generator when the optimized expression is placed into FORM's output. Generator modifies AT.WorkPointer internally, so each term which was added here was placed further and further into the buffer, unnecessarily.

In principle, if you arrive in generate_expression with a very-nearly full WorkSpace there could still be a crash. But this should be rare (?) .

These changes pass pySecDec's test suite.

coveralls commented 3 months ago

Coverage Status

coverage: 49.977% (-0.02%) from 49.999% when pulling 603737dc3ad1ec2b678de4cac73b16798cd572fc on jodavies:opt-dynamic-workspace into 83e3d4185efca2e5938c665a6df9d67d6d9492ca on vermaseren:master.