0
$\begingroup$

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

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

New contributor
omg is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
4
  • 1
    $\begingroup$ Assuming[x > 0, Sqrt[x^2] // Simplify] or Assuming[x > 0 && n \[Element] Integers, Sqrt[x^(2 n)] // Simplify] $\endgroup$
    – Bob Hanlon
    Aug 6 at 15:32
  • $\begingroup$ I've never seen // Simplify syntax before, what does it mean? $\endgroup$
    – omg
    Aug 6 at 15:33
  • 1
    $\begingroup$ 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. $\endgroup$ Aug 6 at 15:38
  • $\begingroup$ @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. $\endgroup$
    – omg
    Aug 6 at 15:56

1 Answer 1

2
$\begingroup$
$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} *)
$\endgroup$
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.