vermaseren / form

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

Efficiently work out exponentiation with mixed commutative and non-commutative variables #40

Open benruijl opened 8 years ago

benruijl commented 8 years ago

The following code with mixed commutative and non-commutative variables generates too many intermediate terms:

CF a;
NF d, e;

L A = (a+d+e)^10;
.end

Time =       0.03 sec    Generated terms =      59049
               A         Terms in output =       2047
                         Bytes used      =      89916

The solution is simple: split the terms into a group of commutative terms and non-commutative terms, compute the binonium, and multiply the results. Alternatively, replace all the non-commutative terms by a placeholder.

CF a;
NF d, e;
L B = (a+d)^10;
id d = (d+e);

Print +s;

.end

Time =       0.04 sec    Generated terms =       2047
               B         Terms in output =       2047
                         Bytes used      =      89916

This should be done internally.

vermaseren commented 8 years ago

Hi Ben,

One of the ‘philosophies’ in FORM is to not touch the input. If wildcarding is involved things may develop differently than it seems (or FORM can guess). Wildcarding can take commuting objects into noncommuting ones at vise versa. Hence the interpretation is left to the user. Also tampering with the input changes the order in which the terms are generated. At the moment, even though you may not be aware of it, the user has control over it. I like FORM to be as deterministic and predictable as possible. There are other things that one could do, but FORM doesn’t: L F = (a+b+c-a)^20; will obviously generate too many terms. Again, if the user does not like this, it is easy to do something about it. Example:

$f = a+b+c-a;

L F = $f^20; Because the above cases are relatively rare, checking for it would also involve an overhead. This is also not appreciated.

Jos

On 31 jul. 2015, at 10:05, Ben Ruijl notifications@github.com wrote:

The following code with mixed commutative and non-commutative variables generates too many intermediate terms:

CF a; NF d, e;

L A = (a+d+e)^10; .end

Time = 0.03 sec Generated terms = 59049 A Terms in output = 2047 Bytes used = 89916 The solution is simple: split the terms into a group of commutative terms and non-commutative terms, compute the binonium, and multiply the results. Alternatively, replace all the non-commutative terms by a placeholder.

CF a; NF d, e; L B = (a+d)^10; id d = (d+e);

Print +s;

.end

Time = 0.04 sec Generated terms = 2047 B Terms in output = 2047 Bytes used = 89916 This should be done internally.

— Reply to this email directly or view it on GitHub https://github.com/vermaseren/form/issues/40.