# Question:how to correctly find leading sign on expression?

## Question:how to correctly find leading sign on expression?

Maple 2019

8/24/19. Updated question the bottom

I need to find if expression has  a "-" in front of it or not.  This is for formatting purposes for something I am doing, that is all.

I was using the command sign() for this, and it seems to work OK, but sometimes a Maple error is generated or not leading term sign is returned.

The sign function computes the sign of the leading coefficient of expr.

Is there a better and more robust way to do this other than using sign() or Am I using sign wrong?

 > restart;
 > expr:=-sin(x)/ln(y)+1; op(expr);

 > #why this gives 1 as sign for the above? sign(expr);

 > #workaround? sign(op(1,expr))

 > expr:=sin(x)/ln(y)+1; sign(expr);

 > expr:=-x; sign(expr);

 > expr:=-LambertW(exp(p))+1; sign(expr)

 > expr:=-LambertW(exp(p))/(1+LambertW(exp(p)))+1; sign(expr)

Error, invalid argument for sign, lcoeff or tcoeff

 > #it seems the following is a work around for the above case #but why it is needed just here? sign(op(1,expr))

 >

UPDATE

Thanks to comment below about using frontend. I never used this before except for now. It seems a very useful command and I think I will be using it a lot more from now on.

Just to clarify again what I want. I am just looking to see if there is a leading negative sign in front of an expression. I am not looking to find if the expression itself can be postive or negative when evaluated or anything more subtle or deep than that.

I simply want to check if there is literally a "-" in front of the maple expression. That is all.

Only issue left, is why Maple still gives Error, invalid argument for sign, lcoeff or tcoeff for the last example below? Here is the updated worksheet.

 > restart;
 > expr:=-sin(x)/ln(y)+1; frontend(sign,[expr]);

 > expr:=sin(x)/ln(y)+1; frontend(sign,[expr]);

 > expr:=-x; frontend(sign,[expr]);

 > expr:=-LambertW(exp(p))+1; frontend(print,[expr]); frontend(sign,[expr]);

 > expr:=-LambertW(exp(p))/(1+LambertW(exp(p)))+1 ; frontend(print,[expr]); frontend(sign,[expr]);

Error, invalid argument for sign, lcoeff or tcoeff

 >