Reputation: 961
I currently have a large expression with many terms of the form
Abs[-2 b + 2 d1 m + l Tan[\[Theta]]]
I know, from the geometry of my problem, that
-2 b + 2 d1 m + l Tan[\[Theta]] > 0
However, when I try to simplify my expression,
Simplify[Abs[-2 b + 2 d1 m + l Tan[\[Theta]]], -2 b + 2 d1 m + l Tan[\[Theta]] > 0]
I just get back
Abs[-2 b + 2 d1 m + l Tan[\[Theta]]]
How can I make Mathematica simplify out the unnecessary absolute value?
EDIT 1
The full expression which I'm trying to simplify is
-(1/(2 (m - Tan[\[Theta]])))
Sqrt[1 + m^2] (B2 Sqrt[(-2 b + 2 d1 m + l Tan[\[Theta]])^2] +
B4 Sqrt[(-2 b + 2 d2 m + l Tan[\[Theta]])^2] +
B5 Sqrt[(2 b + 2 d3 m + l Tan[\[Theta]])^2] +
B7 Sqrt[(2 b + 2 d4 m + l Tan[\[Theta]])^2] +
B1 Sqrt[(2 b - 2 (d1 + l) m + l Tan[\[Theta]])^2] +
B3 Sqrt[(2 b - 2 (d2 + l) m + l Tan[\[Theta]])^2] +
B6 Sqrt[(-2 (b + (d3 + l) m) + l Tan[\[Theta]])^2] +
B8 Sqrt[(-2 (b + (d4 + l) m) + l Tan[\[Theta]])^2])
The terms being squared under each of the radicals is known to be a positive real number.
Upvotes: 6
Views: 6594
Reputation: 442
I'm constantly stimied by things like Abs[a]^2
, and stuff like using Assuming
with a\[Element]Reals
doesn't help.
I found some help here WolframMathWorld - Absolute Square with
ComplexExpand[Abs[a]^2, TargetFunctions -> {Conjugate}]
, but sometimes it still returns stuff like Conjugate[Sqrt[a^2 + b^2]]
and I've found wrapping a second ComplexExpand
(without parameters) around that helps.
Upvotes: 1
Reputation: 12817
If you only wish to remove specific instances of absolute value, you could do something along these lines:
Clear[removeAbs]
removeAbs[expr_, r_] := expr /. {Sqrt[r^2] :> r, Abs[r] :> r}
That way it only removes the absolute value from any expressions you specify:
In: removeAbs[Abs[x] + Abs[y], x]
Out: x + Abs[y]
I'll see if I can find a nicer looking solution than this.
Upvotes: 1
Reputation: 42225
Since the terms are all known to be real and positive, squaring and taking the square-root will only give you the same number. Hence, you could do something like
expr /. Sqrt[(x___)^2] :> x
where expr
is your giant expression above.
Upvotes: 6
Reputation:
Here are two ideas:
1)
Simplify[Abs[-2 b + 2 d1 m + l Tan[\[Theta]]],
0 < \[Theta] < \[Pi]/2 && l > 0 && 2 d1 m > 0 && -2 b > 0]
2)
f[e_] := 100 Count[e, _Abs, {0, Infinity}] + LeafCount[e]
Simplify[Abs[-2 b + 2 d1 m + l Tan[\[Theta]]], -2 b + 2 d1 m +
l Tan[\[Theta]] > 0, ComplexityFunction -> f]
Th complexity function f makes Abs more expensive than Times. See docu for Simplify. Does that help?
Upvotes: 4