vermaseren / form

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

brackets and #write #262

Closed vsht closed 6 years ago

vsht commented 6 years ago

I would like to use brackets to simplify the output of FORM before passing it to other programs. However, it seems that the brackets do not survive a #write instruction, even if there is no intermediate sort inbetween. Consider for example

off statistics;
S a,b,z,y;
L exp = a*y^2 + 3*a + z*b+ z^3*b;
.sort
bracket a, b;
print exp;
#$a1 = exp;
#write <exp.frm> "%$",$a1;
.end

the print statement produces

   exp =
       + b * ( z + z^3 )

       + a * ( 3 + y^2 );

which is exactly what I want, but the content of my exp.frm is nevertheless

b*z+b*z^3+3*a+a*y^2

A naive workaround is to use a "fake" collect

off statistics;
S a,b,z,y;
CF head;
L exp = a*y^2 + 3*a + z*b+ z^3*b;
.sort
bracket a, b;
.sort
collect head;
.sort
print exp;
#$a1 = exp;
#write <exp.frm> "%$",$a1;
.end

and remove head in a later step. However, this probably would not work for very large expressions and in general appears to be an ugly hack. I believe that I'm not the first person to encounter this complication, so I wonder what is the recommended workaround.

Cheers, Vladyslav

vermaseren commented 6 years ago

Hi,

The bracket statement does not work for dollar expressions. If you use %e instead, at least for me it works. As in: S a,b,c; L F = (a+b+c)^10; B b; .sort

write " F = %e",F

.end What goes wrong in your code is also that the preprocessor gets to do its thing before the ‘algebra’ run. Hence, the #write gets executed before your expression has passed the running and hence the bracketting.

Cheers

Jos

On 8 Feb 2018, at 07:31, Vladyslav Shtabovenko notifications@github.com wrote:

I would like to use brackets to simplify the output of FORM before passing it to other programs. However, it seems that the brackets do not survive a #write instruction, even if there is no intermediate sort inbetween. Consider for example

off statistics; S a,b,z,y; L exp = ay^2 + 3a + zb+ z^3b; .sort bracket a, b; print exp;

$a1 = exp;

write "%$",$a1;

.end the print statement produces

exp =

  • b * ( z + z^3 )

  • a * ( 3 + y^2 ); which is exactly what I want, but the content of my exp.frm is nevertheless

bz+bz^3+3a+ay^2 A naive workaround is to use a "fake" collect

off statistics; S a,b,z,y; CF head; L exp = ay^2 + 3a + zb+ z^3b; .sort bracket a, b; .sort collect head; .sort print exp;

$a1 = exp;

write "%$",$a1;

.end and remove head in a later step. However, this probably would not work for very large expressions and in general appears to be an ugly hack. I believe that I'm not the first person to encounter this complication, so I wonder what is the recommended workaround.

Cheers, Vladyslav

— 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/262, or mute the thread https://github.com/notifications/unsubscribe-auth/AFLxEibrvQW50SrSkIfOybiNmCF_AJbCks5tSpS5gaJpZM4R93Vk.

vsht commented 6 years ago

Perfect, many thanks!