when x>0, Sqrt[x^2] equals x, how to do it in wolfram?
It seems can't even simplify Sqrt[x^4]
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this community$Version
(* "13.1.0 for Mac OS X x86 (64-bit) (June 16, 2022)" *)
Clear["Global`*"]
Options[Solve]
(* {Assumptions :> $Assumptions, Cubics -> Automatic, GeneratedParameters -> C,
InverseFunctions -> Automatic, MaxExtraConditions -> 0, Method -> Automatic,
Modulus -> 0, Quartics -> Automatic, VerifySolutions -> Automatic,
WorkingPrecision -> ∞} *)
In later versions of Mathematica, Solve
takes the option Assumptions
. With your problem, including the assumptions in Solve
significantly slows Solve
. Separate the simplification from the solve operation.
sol1 = Solve[
D[(a21 a32 b13 r1 r2 r3 t1)/(a12 a23 b31 + a23 b31 r1 t1 +
a21 b31 r1 r2 t1 + a21 a32 r1 r2 r3 t1) - t1, t1] == 0, t1];
sol2 = Assuming[r1 > 0 && r2 > 0 && r3 > 0,
Simplify[sol1]]
(* {{t1 -> -((a12 a23^2 b31^2 r1 + a12 a21 a23 b31^2 r1 r2 +
a12 a21 a23 a32 b31 r1 r2 r3 + √(a12 a21 a23 a32 b13 b31 r1^3 \
r2 r3 (a23 b31 + a21 r2 (b31 + a32 r3))^2))/(r1^2 (a23 b31 +
a21 r2 (b31 + a32 r3))^2))}, {t1 -> -((a12 a23^2 b31^2 r1 +
a12 a21 a23 b31^2 r1 r2 +
a12 a21 a23 a32 b31 r1 r2 r3 - √(a12 a21 a23 a32 b13 b31 r1^3 \
r2 r3 (a23 b31 + a21 r2 (b31 + a32 r3))^2))/(r1^2 (a23 b31 +
a21 r2 (b31 + a32 r3))^2))}} *)
Looking at the effect of simplification:
LeafCount /@ {sol1, sol2}
(* {485, 163} *)
EDIT: If you want further simplification, use FullSimplify
instead of Simplify
sol3 = Assuming[r1 > 0 && r2 > 0 && r3 > 0, FullSimplify[sol1]]
(* {{t1 -> -((a12 a23 b31 r1 (a23 b31 +
a21 r2 (b31 +
a32 r3)) + √(a12 a21 a23 a32 b13 b31 r1^3 r2 r3 (a23 b31 +
a21 r2 (b31 + a32 r3))^2))/(r1^2 (a23 b31 +
a21 r2 (b31 + a32 r3))^2))},
{t1 -> (-a12 a23 b31 r1 (a23 b31 + a21 r2 (b31 +
a32 r3)) + √(a12 a21 a23 a32 b13 b31 r1^3 r2 r3 (a23 b31 +
a21 r2 (b31 + a32 r3))^2))/(r1^2 (a23 b31 +
a21 r2 (b31 + a32 r3))^2)}} *)
EDIT 2: Include some manual manipulation,
sol4 = Assuming[r1 > 0 && r2 > 0 && r3 > 0,
FullSimplify[sol2 /. Sqrt[expr_] :> (r1*Sqrt[expr/r1^2])]]
(* {{t1 -> -((a12 a23 b31 (a23 b31 + a21 r2 (b31 +
a32 r3)) + √(a12 a21 a23 a32 b13 b31 r1 r2 r3 (a23 b31 +
a21 r2 (b31 + a32 r3))^2))/(r1 (a23 b31 +
a21 r2 (b31 + a32 r3))^2))},
{t1 -> (-a12 a23 b31 (a23 b31 + a21 r2 (b31 +
a32 r3)) + √(a12 a21 a23 a32 b13 b31 r1 r2 r3 (a23 b31 +
a21 r2 (b31 + a32 r3))^2))/(r1 (a23 b31 +
a21 r2 (b31 + a32 r3))^2)}} *)
Comparing the results,
LeafCount /@ {sol1, sol2, sol3, sol4}
(* {485, 163, 141, 135} *)
FullSimplify[sol2 /. Sqrt[expr_] :> (r1*Sqrt[expr/r1^2])]
and this one LeafCount /@ {sol1, sol2, sol3, sol4}
?
$\endgroup$
sol2
there are terms of the form Sqrt[coef * r1^3]
which, to aid in the simplification, I want converted to r1 Sqrt[coef*r1]
(valid since r1 > 0
). This is accomplished with the replacement rule Sqrt[expr_] :> (r1*Sqrt[expr/r1^2])]
. The LeafCount
of an expression is a measure of the expression's complexity. LeafCount /@ {sol1, sol2, sol3, sol4}
maps LeafCount
onto the solutions to show the reduction in complexity as the simplification progressed.
$\endgroup$
Nov 18, 2022 at 18:39
/.
and :>
?
$\endgroup$
F1
for help. /.
is ReplaceAll
and :>
is RuleDelayed
$\endgroup$
Nov 18, 2022 at 23:08
Assuming[x > 0, Sqrt[x^2] // Simplify]
orAssuming[x > 0 && n \[Element] Integers, Sqrt[x^(2 n)] // Simplify]
$\endgroup$// Simplify
syntax before, what does it mean? $\endgroup$x^2//Sqrt
is the same asSqrt[x^2]
. Post-fix operation is sometimes convenient when you add a final operation on a result, e.g.,RandomVariate[NormalDistribution[],1000]//Mean
. $\endgroup$Simplify[Solve[D[(a21 a32 b13 r1 r2 r3 t1)/(a12 a23 b31 + a23 b31 r1 t1 + a21 b31 r1 r2 t1 + a21 a32 r1 r2 r3 t1)-t1, t1]==0,t1]]
, if I putAssuming[r1>0&&r2>0&&r3>0,
in front of it, it just hangs up. $\endgroup$