vermaseren / form

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

Output simplification #349

Open gkdgoutam opened 4 years ago

gkdgoutam commented 4 years ago

I wanted to ask if there is any option to write/print fractional expression for polynomials in the output.

#-
S x,y,z;
Local test = x/y + x/y^2 - (2*x*z)/y^2 + z/y^2 - (3*z^2)/(2*y^2);
print test;
.end

whose default output is

test = y^-2*z - 3/2*y^-2*z^2 + x*y^-2 - 2*x*y^-2*z + x*y^-1;

whereas the numerical numbers by default takes fractional form like 3/2 in this case, the polynomials do not i.e. the first term in the output is not written as z/y^2 i.e. in the following form:

test = z/y^2 - 3/2*z^2/y^2 + x/y^2 - 2*x*z/y^2 + x/y;

Is there any way to change to this behavior?

vermaseren commented 4 years ago

Unfortunately this possibility was never considered. It is probably possible to build it in with not too much effort. Looks like a good project for the Form workshop that we are planning (but while we were in the planning stages the virus hit and we do not have a new safe date yet).

Jos

On 12 Jun 2020, at 11:24, Goutam Das notifications@github.com wrote:

I wanted to ask if there is any option to write/print fractional expression for polynomials in the output.

-

S x,y,z; Local test = x/y + x/y^2 - (2xz)/y^2 + z/y^2 - (3z^2)/(2y^2); print test; .end whose default output is

test = y^-2z - 3/2y^-2z^2 + xy^-2 - 2xy^-2z + xy^-1; whereas the numerical numbers by default takes fractional form like 3/2 in this case, the polynomials do not i.e. the first term in the output is not written as z/y^2 i.e. in the following form:

test = z/y^2 - 3/2z^2/y^2 + x/y^2 - 2x*z/y^2 + x/y; Is there any way to change to this behavior?

— 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/349, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJPCEXXUXOBYXASKJW3KQTRWHX5JANCNFSM4N4FCEGQ.

tueda commented 4 years ago

Maybe you can make it with some easy scripting, like:

S x,y,z;
L F = x/y + x/y^2 - (2*x*z)/y^2 + z/y^2 - (3*z^2)/(2*y^2);

.sort
CF num,den;
repeat id x? = num(x);
repeat id 1/x? = den(x);

P;
.end

and then (with GNU sed)

form test.frm | sed -z 's/num(\([^)]*\))/\1/g;s/\*den(\([^)]*\))/\/\1/g;s/den(\([^)]*\))/1\/\1/g'

which gives

   F =
       - 2*x*z/y^2 + x/y + x/y^2 - 3/2*
      z^2/y^2 + z/y^2;