RE: rules for Sign[_]^n
- To: mathgroup at smc.vnet.net
- Subject: [mg26355] RE: [mg26337] rules for Sign[_]^n
- From: "Ingolf Dahl" <f9aid at fy.chalmers.se>
- Date: Wed, 13 Dec 2000 02:41:16 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hi! I would recommend that you add Real to the specification of your variables, otherwise you might get problems with complex numbers: {(Sign[_Real])^(y_?EvenQ) :> 1, (Sign[x_Real])^(y_?OddQ) :> Sign[x]} You know, Sign[I]^2 == -1. This works if you apply the rule to numbers, which is not very useful, since you then are able to calculate Sign anyway. Probably you want to apply the rules to symbolic variables that are known to be real, and then the above approach will not work. In that case, you can define z to be real by z /: Im[z] = 0; (see Help for Add-on Standard Package Algebra`ReIm`, but this package does not seem to be necessary) Then the following rule seems to work {(Sign[x_ /; Im[x] == 0])^(y_?EvenQ) :> 1, (Sign[x_ /; Im[x] == 0])^(y_?OddQ) :> Sign[x]} If you want to teach Mathematica to apply this rule, you have to modify Power: Unprotect[Power]; Power[Sign[x_ /; Im[x] == 0], y_?EvenQ] := 1; Power[Sign[x_ /; Im[x] == 0], y_?OddQ] := Sign[x]; Protect[Power]; Maybe the package Algebra`ReIm` could be useful for you, check the help. I hope that I have got everything right Kind regards Ingolf Dahl Chalmers University > Adalbert Hanssen [hanssen at Zeiss.de] wrote in [mg26337] rules for Sign[_]^n: Hi, MathGroup, dealing with Sign, it would be useful, if Mathematica knew {(Sign[_])^(y_?EvenQ):>1, (Sign[x_])^(y_?OddQ):>Sign[x]} How can I teach Mathematica this rule (in Init.m), such that it automaticly applies it in Simplify, Expand and the like whenever applicable? kind regards Dipl.-Math. Adalbert Hanszen