       RE: Getting rid of annoying zeroes in algebraic expressions

• To: mathgroup at smc.vnet.net
• Subject: [mg15237] RE: [mg15228] Getting rid of annoying zeroes in algebraic expressions
• From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
• Date: Sun, 27 Dec 1998 03:58:30 -0500
• Sender: owner-wri-mathgroup at wolfram.com

```Sean Ross wrote,
_________________
>
>Let xx be the result of some algebraic manipulations
>which, for some reason, mathematica thinks the real
>zeroes ought to be kept and I think
>they ought to be dropped.
>
>xx=0. + (a*f)/(0. + f) + (b*f)/(0. + f) + (c*f)/(0. + f)
>
>xx/.Plus[0.,q_]->q
>
>returns
>
>0. + (a*f)/(0. + f) + (b*f)/(0. + f) + (c*f)/(0. + f)
>
.....

I don't understand your question, and I don't know if I could answer it
if I did understand it, but consider the following.

In:=
xx=0. + (a*f)/(0. + f) + (b*f)/(0. + f) + (c*f)/(0. + f) Out= 0. +
(a*f)/(0. + f) + (b*f)/(0. + f) + (c*f)/(0. + f)

In:=
q=5;

In:=
xx/.Plus[0.,q_]->q
Out=
5

You don't get what you wanted for Out. You do get what you want if
you use (->) instead of (:>) as below.

In:=
xx/.Plus[0.,q_]:>q
Out=
(a*f)/(0. + f) + (b*f)/(0. + f) + (c*f)/(0. + f)

I always say never use (lhs->rhs) when (lhs) has a named pattern that is
needed for (rhs).  Instead use (lhs:>rhs).

Examples:

This first example is OK because (x) isn't used on the right side of
(->). (x_?Positive) -> 0
_____________

These can give you trouble:
(a_Rational) -> Floor[a]
foo[args__] -> Max[args]
(x_?Positive) -> Round[x]

(a_Rational) :> Floor[a]
foo[args__] :> Max[args]
(x?Positive) :> Round[x]
_____________

In a similar manner when (lhs) has a named pattern use (lhs:=rhs)