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

Illegal subterm while writing #363

Open zhaoli-IHEP opened 4 years ago

zhaoli-IHEP commented 4 years ago

We were trying to extract the coefficients of the multivariate polynomial. And below is the sample code.

#-
symbol x,y,a,b,c;
Table,sparse,[test_table](1);

Local expr = b*x^2*y+c*x*y^2+a*x*y;
.sort

bracket x,y;
.sort

Local coeff1 = expr[x*y];
Local coeff2 = expr[x^2*y];
Local coeff3 = expr[x*y^2];
.sort

fill [test_table](1) = coeff1;
fill [test_table](2) = coeff2;
fill [test_table](3) = coeff3;
.sort

TableBase "test_table.tbl" create;
TableBase "test_table.tbl" addto [test_table];
.sort

.end

However, it gives the error message "Illegal subterm while writing". We also tried the approach

bracket x, y;
.sort
collect Coeff;
.sort

But in the practical code, the coefficients could be so long that it cannot be solved by increasing the option "maxtermsize". Therefore, we are looking for an alternative approach to avoid the limit of "maxtermsize".

vermaseren commented 4 years ago

The problem here is that the RHS in a fill statement is not worked out until the table element gets used. This means that your elements are unexpanded expressions which do not exist by the time you want to use the elements. Hence ‘illegal’. The way around this is to use the FillExpression statement. That is also usually much less work for the programmer. The opposite, to convert tables into expressions, exists also with the table_ function.

Jos

On 18 Jul 2020, at 05:47, zhaoli-IHEP notifications@github.com wrote:

We were trying to extract the coefficients of the multivariate polynomial. And below is the sample code.

-

symbol x,y,a,b,c; Table,sparse,test_table;

Local expr = bx^2y+cxy^2+axy; .sort

bracket x,y; .sort

Local coeff1 = expr[xy]; Local coeff2 = expr[x^2y]; Local coeff3 = expr[x*y^2]; .sort

fill test_table = coeff1; fill test_table = coeff2; fill test_table = coeff3; .sort

TableBase "test_table.tbl" create; TableBase "test_table.tbl" addto [test_table]; .sort

.end However, it gives the error message "Illegal subterm while writing". We also tried the approach

bracket x, y; .sort collect Coeff; .sort But in the practical code, the coefficients could be so long that it cannot be solved by increasing the option "maxtermsize". Therefore, we are looking for an alternative approach to avoid the limit of "maxtermsize".

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/vermaseren/form/issues/363, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJPCETPEIHV3OONATSE4UDR4ELO5ANCNFSM4O7KOWNQ.

tueda commented 4 years ago

The manual also says (for the fill statement) that this (right-hand-side expressions) can be avoided by the use of $-variables expanded at compile-time (in preprocessor).

zhaoli-IHEP commented 4 years ago

The problem here is that the RHS in a fill statement is not worked out until the table element gets used. This means that your elements are unexpanded expressions which do not exist by the time you want to use the elements. Hence ‘illegal’. The way around this is to use the FillExpression statement. That is also usually much less work for the programmer. The opposite, to convert tables into expressions, exists also with the table_ function. Jos

Thank you. I think we will go back to use fillexpression.