Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern matching with sets, and (ex-)PolyRatFun CFunction #55

Closed
jodavies opened this issue Nov 19, 2015 · 3 comments
Closed

Pattern matching with sets, and (ex-)PolyRatFun CFunction #55

jodavies opened this issue Nov 19, 2015 · 3 comments
Labels
bug Something isn't working

Comments

@jodavies
Copy link
Collaborator

I have been trying to print expressions with sub-bracketed terms (using dum_) and wanted the first term to have a +ve sign, ie, take an overall - out of the dum_ if we have to (printed expressions destined for some scripts to produce LaTeX).

I tried:

PolyRatFun coeff;
Normalize dum_;
.sort
PolyRatFun;
.sort
Identify coeff(x?neg_,y?) = -coeff(-x,y);
Identify coeff(x?,y?)*dum_(z?) = dum_(x/y * z);
.sort

which doesn't work, which is something to do with coeff being, at some point, a PolyRatFun.

This example, I think, exemplifies the issue. If you replace the final Identify with the commented pair, (no set in the pattern match) it works as expected.

#-
Off Statistics;

CFunction coeff,coeff2;
Symbol x,y,z;
Symbol ca,cf,zeta2;

Local test1 = + dum_( - 7117/81 - 64/9*zeta2)*ca^2*cf;
Local test2 = + dum_(1 + 576/7117*zeta2)*coeff(- 7117,81)*ca^2*cf;
.sort


Identify coeff(x?neg_,y?) = -coeff(-x,y);
Identify dum_(z?)*coeff(x?,y?) = dum_(z * x/y);
Print +s;
.sort


PolyRatFun coeff;
Normalize dum_;
Print +s;
.sort
PolyRatFun;
.sort

Identify coeff(x?neg_,y?) = -coeff(-x,y);
*Identify coeff(x?,y?) = coeff2(x,y);
*Identify coeff2(x?neg_,y?) = -coeff2(-x,y);

Print +s;
.end

Additionally, if you comment out the Identify statements in the second module, in the third module both expressions are the same (but one has a coeff from PolyRatFun, and the other already had it). In this case, the Identify statement in the final module works on test2, but not on test1.

@vermaseren
Copy link
Owner

Hi Josh,

There is always a little problem like this.
What you can do is use Normalize and MakeInteger.
MakeInteger makes integer coefficients but pays no attention to the sign.
Normalize makes the sign of the first term one.
Hence what you could do is
Normalize coeff,1;
MakeInteger coeff,1;
and if there is still an overall factor you could try to pull it back in.
The sign can be sample as the sign over the whole term at this point.

I hope this helps

Jos

On 19 nov. 2015, at 17:45, jodavies [email protected] wrote:

I have been trying to print expressions with sub-bracketed terms (using dum_) and wanted the first term to have a +ve sign, ie, take an overall - out of the dum_ if we have to (printed expressions destined for some scripts to produce LaTeX).

I tried:

PolyRatFun coeff;
Normalize dum_;
.sort
PolyRatFun;
.sort
Identify coeff(x?neg_,y?) = -coeff(-x,y);
Identify coeff(x?,y?)*dum_(z?) = dum_(x/y * z);
.sort
which doesn't work, which is something to do with coeff being, at some point, a PolyRatFun.

This example, I think, exemplifies the issue. If you replace the final Identify with the commented pair, (no set in the pattern match) it works as expected.

#-
Off Statistics;

CFunction coeff,coeff2;
Symbol x,y,z;
Symbol ca,cf,zeta2;

Local test1 = + dum_( - 7117/81 - 64/9_zeta2)ca^2_cf;
Local test2 = + dum
(1 + 576/7117_zeta2)_coeff(- 7117,81)_ca^2*cf;
.sort

Identify coeff(x?neg_,y?) = -coeff(-x,y);
Identify dum_(z?)*coeff(x?,y?) = dum_(z * x/y);
Print +s;
.sort

PolyRatFun coeff;
Normalize dum_;
Print +s;
.sort
PolyRatFun;
.sort

Identify coeff(x?neg_,y?) = -coeff(-x,y);
*Identify coeff(x?,y?) = coeff2(x,y);
*Identify coeff2(x?neg_,y?) = -coeff2(-x,y);

Print +s;
.end

Reply to this email directly or view it on GitHub #55.

@tueda tueda added the bug Something isn't working label Jul 10, 2017
@tueda
Copy link
Collaborator

tueda commented Jul 10, 2017

A simple and complete example:

CF frac;
S x,y;
L F = - 2/3*x;
P;
.sort(PolyRatFun=frac);
*.sort;  * putting .sort is useless for this bug
*argument frac,1;endargument;  * workaround
id frac(x?neg_,y?) = - frac(-x,y);  * doesn't match
P;
.end

which gives

FORM 4.2.0 (Jul  6 2017, v4.2.0) 64-bits         Run: Mon Jul 10 15:41:37 2017

   F =
      x*frac( - 2,3);

   F =
      frac( - 2,3)*x;

@tueda
Copy link
Collaborator

tueda commented Jul 10, 2017

My old print.h (for form2tex) used

id frac(x?,y?) = frac(abs_(x),y) * sig_(x);

which somehow works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants