As a result of some lengthy calculations, Mathematica gave me the following expresssion:

$$ \frac{xy^2+(1 + y)\sqrt{1 + y(2 + y + xy)}}{(1 + y)^2} $$

I tried all sorts of simplifications, but none of them did anything useful. How can I get Mathematica to turn this into

$$ x(\frac{y}{1+y})^2+\sqrt{1+x(\frac{y}{1+y})^2}? $$

I know that simplicity and prettiness is not always objective, but I almost didn't see that my expression has the form f(x,y/(1+y)) which is actually super useful for my next steps (and I have a bunch of expressions that are even more complicated that I believe hide some valuable treasures like this) Here is the code I tried https://www.wolframcloud.com/obj/17534701-7be6-443e-b7c5-f8564e04d225

Assuming[{x>0,y>0},FullSimplify[(x y^2+(1 + y) Sqrt[1 + y(2 + y + x y)])/(1 + y)^2]]

(x y^2 + (1 + y) Sqrt[1 + y (2 + y + x y)])/(1 + y)^2

PS: the site always complains about code that is not formatted as code when I try to post maths. On previous questions, other users could just edit the code bits out, in case someone wants to give it a try? See "Your post appears to contain code that is not properly formatted as code" with math blocks

  • $\begingroup$ xy is not the same as x*y or x y. You need a star or a space between x and y to indicate multiplication. $\endgroup$ – Roman Jul 27 '19 at 21:27
  • $\begingroup$ Please copy-paste what Mathematica actually spits out instead of converting to $\LaTeX$. $\endgroup$ – Roman Jul 27 '19 at 21:28
  • $\begingroup$ @Roman I used the correct mathematica code $\endgroup$ – Bananach Jul 27 '19 at 21:29
  • $\begingroup$ @Roman you can click the link to wolframcloud. I also added the exact Mathematica code I tried to the question. $\endgroup$ – Bananach Jul 27 '19 at 21:29
  • $\begingroup$ @Roman thanks for editing the question. This is really frustrating... $\endgroup$ – Bananach Jul 27 '19 at 21:33
Experimental`OptimizeExpression[(x y^2 + (1 + y) Sqrt[
  1 + y (2 + y + x y)])/(1 + y)^2]
  Experimental`OptimizedExpression[Block[{Compile`$2}, Compile`$2 = 1 + y;
      (x*y^2 + Compile`$2*Sqrt[1 + y*(2 + y + x*y)])/Compile`$2^2]]

This figures out that 1+y is common, and pulls it out of the main expression. For a more complicated expression, it probably would see more such patterns. However, `OptimizeExpression` is about computational efficiency, not human insight. Human insight requires human reasoning here.

  • $\begingroup$ I tried that before but since it doesn't figure out that there is a (1+y)^2 in the square root though, it's not very helpful $\endgroup$ – Bananach Jul 28 '19 at 17:51

As mentioned above, it is hard to do this universally.

But you could write some specialized rules and apply them. This below is just an example. This is not meant to be universal solution.

ClearAll[x, y, any, any1];
rule2 = (1 + 2 x_ + x_^2) :> (1 + x)^2;
rule1 = (Sqrt[any_]/any1_) :> Sqrt[Simplify[(Expand[any] /. rule2)/any1^2]];
expr = (x y^2 + (1 + y) Sqrt[1 + y (2 + y + x y)])/(1 + y)^2

Mathematica graphics

Collect[expr, Denominator[expr]] /. rule1

Mathematica graphics

Note that rule1 above which move term under the sqrt, as in $\frac{1}{x}$ to $\sqrt{\frac{1}{x^2}}$ is valid only when x is positive of course.

  • $\begingroup$ Appreciate the input, but what I gather from this and the other answer is "Mathematica can't do this". $\endgroup$ – Bananach Jul 28 '19 at 13:48

A substitution would work: setting $z=x\left(\frac{y}{1+y}\right)^2$,

Assuming[y > 0 && z > 0,
  (x y^2 + (1 + y) Sqrt[1 + y (2 + y + x y)])/(1 + y)^2 /. x -> z ((1 + y)/y)^2 // FullSimplify]
(*    z + Sqrt[1 + z]    *)
  • $\begingroup$ Figuring out that` z=x(y/(1+y))^2` is the right substitution here is as hard as doing everything by hand to begin with, and I believe the same is true for the more complicated expressions I am facing $\endgroup$ – Bananach Jul 27 '19 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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