vermaseren / form

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

Integer coefficients in Format Fortran90 #216

Closed tueda closed 5 years ago

tueda commented 7 years ago

I know that for Format Fortran (and DoubleFortran, QuadFortran) an integer coefficient is not translated to a floating-point number (the second term in the following example):

Symbol x;
L F = 1/2 + 2*x;
.sort
Format DoubleFortran;
#write "%e", F
.end
FORM 4.2.0 (Jul  6 2017, v4.2.0) 64-bits         Run: Mon Jul 10 16:23:02 2017

1.D0/2.D0 + 2*x

but this is not the case for Fortran90:

Symbol x;
L F = 1/2 + 2*x;
.sort
Format Fortran90,.0_wp;
#write "%e", F
.end
FORM 4.2.0 (Jul  6 2017, v4.2.0) 64-bits         Run: Mon Jul 10 16:23:35 2017

1.0_wp/2.0_wp + 2.0_wp*x
vermaseren commented 5 years ago

This was just brought up in a different way. A complaint that in expressions like 2/(5+4n) the integers are printed as integers while here it was preferred as 2.D0/(5.D0+2.D0n). In the versions of 2014 and before this is what it does. Maybe the best solution is to make a flag that can be set with on/off to select which of these two systems one prefers. Any comments?

vermaseren commented 5 years ago

It seems that in the code there is an option pfortran which is undocumented. It is a bit different in representations, but still not completely sane. It looks like the code there needs at least some commentary and an extension

tueda commented 5 years ago

OK, at least 087a772e613db4c75293a99c2b0c4491a85303ab can give all-floating-point-number output for DoubleFortran and QuadrupleFortran. Now

    Format Fortran;

1./2. + 2*x
    Format DoubleFortran;

1.D0/2.D0 + 2*x
    Format DoubleFortran;
    Format allfloat;

1.D0/2.D0 + 2.D0*x
    Format QuadrupleFortran;

1.Q0/2.Q0 + 2*x
    Format QuadrupleFortran;
    Format allfloat;

1.Q0/2.Q0 + 2.Q0*x
    Format Fortran90,.0_wp;

1.0_wp/2.0_wp + 2.0_wp*x

Other combinations or different ordering would give output that the user may not expect.