       Re: how implement a rule

• To: mathgroup at smc.vnet.net
• Subject: [mg112585] Re: how implement a rule
• From: "Carl K. Woll" <carlw at wolfram.com>
• Date: Tue, 21 Sep 2010 02:04:52 -0400 (EDT)

```On 9/20/2010 4:43 AM, Murray Eisenberg wrote:
> I want to define a function abs (mimicking Abs) with various properties.
> One part of the definition is:
>
>     abs[c_ z_ /; c \[Element] Reals] = Abs[c] abs[z]
>
> Given that, how might I express that abs[z] is always real in such a way
> that the result of
>
>     abs[1/abs[z]^2]
>
> will be 1/abs[z]^2 -- WITHOUT explicitly introducing, say:
>
>     abs/: abs[1/abs[z_]^2] =  1/abs[z]^2
>
> ?
>
>

One can use Refine to help here:

nonnegQ[expr_] := Module[{foo = Cases[expr, _abs, Infinity]},
Refine[expr >= 0, Thread[foo > 0]]
]

abs[c_?nonnegQ ] := c
abs[c_?nonnegQ z_] := c abs[z]

In:= abs[1/abs[z]^2]

Out= 1/abs[z]^2

Carl Woll
Wolfram Research

```

• Prev by Date: should Positive[ complexNumber ] return undefined instead of False?
• Next by Date: Summing above diagonal in a tensor
• Previous by thread: how implement a rule
• Next by thread: Root Finding Methods Gaurenteed to Find All Root Between (xmin, xmax)