6

I'm trying to simplify an expression, and my guess would be like this:

FullSimplify[Sqrt[1 - Cos[θ]^2/sign[r Cos[ϕ] Sin[θ]]^2], sign[_]^2 == 1]

Apparently, as I get unchanged expression back, FullSimplify doesn't understand what I mean. (sign is deliberately not a system Sign function here).

I do realize that I could simply switch to a replacement like expr /. sign[_]^2 -> 1, but I suppose in general simplification with a pattern could be more useful. E.g. when sign[...]^n would have n==4 or whatever. Also in this case the rule I mentioned wouldn't work, since it should instead be sign[_]^-2 -> 1 here.

So my question is: how do I use patterns in assumptions of Simplify family of functions?

Ruslan
  • 7,152
  • 1
  • 23
  • 52

2 Answers2

11

How about this?

Power[sign[x_], n_?EvenQ] ^= 1;
FullSimplify[Sqrt[1 - Cos[θ]^2/sign[r Cos[ϕ] Sin[θ]]^2]]
Stitch
  • 4,205
  • 1
  • 12
  • 28
6

A combination of TranformationFunctions and UpSetDelayed (for the pattern matching) is useful here.

t[sign[x_]] ^:= 1

FullSimplify[Sqrt[1 - Cos[θ]^2/sign[r Cos[ϕ] Sin[θ]]^2], 
 TransformationFunctions :> {Automatic, t}]   
(* Sqrt[Sin[θ]^2] *)
chuy
  • 11,205
  • 28
  • 48
  • 1
    Not exactly. You are assuming that sign[x_] is always 1, but we need only even exponents, so a slight correction is needed t[Power[sign[x_], n_?EvenQ]] := 1 – Stitch Nov 18 '16 at 22:41