vermaseren / form

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

Fortran output problem #311

Closed gkdgoutam closed 5 years ago

gkdgoutam commented 5 years ago

Hi, I am trying to export an expression into in DoubleFortran output.

  Format DoubleFortran;
  Bracket CF,CA,NF;
 .sort
  #Write <test.f> "exp= ( %E )\n", exp

The output I am getting has the following weird form

      + CF*NF**2 * ( 16.D0/27.D0)
     &     + 448.D0/135.D0  + ...
      _ = _ + CF*CA**2 (2D0/3D0 + ...)
     &     +    ...
      _ = _ + CF**2*NF * (5D0 )

I want to know why this pattern _=_ is coming which probably should not come! Is there any bug in this? I would have expected & in place of _=_. If I remove the lines

        Bracket CF,CA,NF;
       .sort

the number of such occurrences are reduced but not zero.

Thanks.

tueda commented 5 years ago

Perhaps this is because use of brackets forces FORM to insert new lines, though I'm not sure if this is intended or not. Note that Fortran standards (I guess even in Fortran 2018) have a limitation of continuation lines for a single statement, so FORM has to split a long expression anyway (see also the ContinuationLines setup parameter). In the #write instruction, you can specify an expression name for continuous lines:

S x1,...,x4;
L F = (x1+...+x4)^3;
B x1,x2;
.sort
Format DoubleFortran;
#write "      expr = %E", F(expr)
.end
      expr =  + x2 * ( 3*x4**2 + 6*x3*x4 + 3*x3**2 )
      expr = expr + x2**2 * ( 3*x4 + 3*x3 )
      expr = expr + x2**3 * ( 1 )
      expr = expr + x1 * ( 3*x4**2 + 6*x3*x4 + 3*x3**2 )
      expr = expr + x1*x2 * ( 6*x4 + 6*x3 )
      expr = expr + x1*x2**2 * ( 3 )
      expr = expr + x1**2 * ( 3*x4 + 3*x3 )
      expr = expr + x1**2*x2 * ( 3 )
      expr = expr + x1**3 * ( 1 )
      expr = expr + x4**3 + 3*x3*x4**2 + 3*x3**2*x4 + x3**3

To compactify code for numerical computation, #optimize probably does a better job than bracket.

gkdgoutam commented 5 years ago

Indeed these appear due to new lines inserted after the bracket is taken. But putting expression name does the job. Thanks.