# How to make wolfram simplify sqrt[x^2] when x > 0? [closed]

when x>0, Sqrt[x^2] equals x, how to do it in wolfram?

It seems can't even simplify Sqrt[x^4]

• Assuming[x > 0, Sqrt[x^2] // Simplify] or Assuming[x > 0 && n \[Element] Integers, Sqrt[x^(2 n)] // Simplify] Aug 6, 2022 at 15:32
• I've never seen // Simplify syntax before, what does it mean?
– omg
Aug 6, 2022 at 15:33
• The // operator is called a "post-fix" notation, a notation in which the operation to be performed is placed at the end rather than at the begining. For example x^2//Sqrt is the same as Sqrt[x^2]. Post-fix operation is sometimes convenient when you add a final operation on a result, e.g., RandomVariate[NormalDistribution[],1000]//Mean. Aug 6, 2022 at 15:38
• @BobHanlon In my case the expression I want to simplify is 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 put Assuming[r1>0&&r2>0&&r3>0, in front of it, it just hangs up.
– omg
Aug 6, 2022 at 15:56

$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} *)

• I am new to Wolfram, so would you please explain this line FullSimplify[sol2 /. Sqrt[expr_] :> (r1*Sqrt[expr/r1^2])] and this one LeafCount /@ {sol1, sol2, sol3, sol4}?
– Diaa
Nov 18, 2022 at 18:09
• @Diaa - In 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. Nov 18, 2022 at 18:39
• Thanks, so what are the names of the following operators to look for in the documentation of Wolfram: /. and :>?
– Diaa
Nov 18, 2022 at 20:53
• @Diaa - Use the online documentation. In Mathematica, hover over the operator/command and look at the tooltip. Or highlight the operator/command and press F1 for help. /. is ReplaceAll and :> is RuleDelayed` Nov 18, 2022 at 23:08