14
$\begingroup$

I have the following simple expression

Exp[(Log[1 + x]^2 - Log[x]^2)/Log[1 + 1/x]] - x^2

that can be shown to simplify to x for positive x (and same for $x < -1$ if principal branch of log is taken, $\log (x) = i \pi + \log (-x)$). However, none of the following

Simplify[Exp[(Log[1 + x]^2 - Log[x]^2)/Log[1 + 1/x]] - x^2]
FullSimplify[Exp[(Log[1 + x]^2 - Log[x]^2)/Log[1 + 1/x]] - x^2]
Simplify[Exp[(Log[1 + x]^2 - Log[x]^2)/Log[1 + 1/x]] - x^2, 
 Assumptions -> {x > 0}]
FullSimplify[Exp[(Log[1 + x]^2 - Log[x]^2)/Log[1 + 1/x]] - x^2, 
 Assumptions -> {x > 0}]

finds this simplification. Why is that? To show that the expression simplifies accordingly, use $a^2 - b^2 = (a+b)(a-b)$ formula inside the exponential and in the denominator $\log (1+1/x) = \log (1+x) - \log(x)$. Some stuff cancels out and you'll be left with $\exp \log (x+x^2) - x^2 = x$. I have no clue why MMA didn't choose to go down this route, I assumed that the common formulas like $a^n - b^n$ are known to it. I tried Simplify[Log[1 + 1/x] + Log[x], Assumptions -> {x > 0}] and it correctly returned log[1+x], so this might not be the issue here.

This specific expression came up in some wider context, I frequently use MMA to simplify expressions after integration to get some nicer form and was surprised that this couldn't be simplified.

$\endgroup$
8
  • $\begingroup$ I tried with Maple and it can do it. $\endgroup$ – Mariusz Iwaniuk Jan 3 at 10:09
  • $\begingroup$ While it isn't Simplify at least Reduce[Exp[(Log[1+x]^2-Log[x]^2)/Log[1+1/x]]-x^2==x && x>0,x] returns 0<x<Infinity but it says it cannot accomplish this when given x < -1 which I am guessing is because of the principal branch issue. $\endgroup$ – Bill Jan 3 at 10:12
  • $\begingroup$ Somewhat relevant mathematica.stackexchange.com/q/207506/9469 $\endgroup$ – yarchik Jan 3 at 10:54
  • $\begingroup$ Marius, I'm not familiar with Maple, sorry :) @Bill this is reassuring, there is a way to verify it after all! The region $x < -1$ is not that important to me, in my application $x$ was positive anyway, I mentioned it only for completeness. However, I'm more interested in applications that yield the result, rather than verifying something I already worked out manually outside of MMA... $\endgroup$ – user16320 Jan 3 at 11:12
  • 7
    $\begingroup$ PowerExpand[Factor[#]]&//@ex seems to work, where ex is your expression. $\endgroup$ – Simon Woods Jan 3 at 11:32
5
$\begingroup$

Let y be your expression. Here is the way to establish the desired fact:

a = Assuming[x > 0, D[y, x] // FullSimplify]
(* 1 *)
b = Limit[y, x -> 1]
(* 1 *)
Y = DSolveValue[{z'[x] == a, z[1] == b}, z, x];
Y[x]
(* x *)

Of course, it is an indirect albeit mathematically rigorous way.

Explanation Assume we would like to simplify a function $y(x)$.The function $y(x)$ is such that direct simplification is not possible. However, the derivative of it is better handled by MA. Denote $$ a(x)=y'(x)\\ b=y(p). $$ Then the simplified function can be obtained by solving the ODE $$ \frac{\mathrm{d}y(x)}{\mathrm{d}x}=a(x),\quad y(p)=b. $$

Organizing into a function

AltSimplify[f_, x_, p_, assump_] := 
Assuming[assump, 
  DSolveValue[{z'[x] == FullSimplify[D[f, x]], z[p] == Limit[f, x -> p]}, z, x][x]]

AltSimplify[y, x, 1, x > 0]
(* x *)
$\endgroup$
2
  • $\begingroup$ I am sorry, I just fail to see how this is related to my question at all :O What differential equation are you solving, and why? Care to explain? $\endgroup$ – user16320 Jan 3 at 11:15
  • $\begingroup$ @user16320 See edits $\endgroup$ – yarchik Jan 3 at 11:22
5
$\begingroup$

Change the complexity function so that it discourages log powers and log sums, which in turn converts $\log(a)+\log(b)$ into $\log(a b)$ and $\log(a)^2-\log(b)^2$ into $(\log(a)+\log(b))(\log(a)-\log(b))$:

FullSimplify[E^((-Log[x]^2 + Log[1 + x]^2)/Log[1 + 1/x]) - x^2,
  Assumptions -> x > 0,
  ComplexityFunction -> Function[LeafCount[#] + 
    100 Count[#, Log[_] + Log[_], {0, Infinity}] + 
    100 Count[#, Log[_]^_, {0, Infinity}]
  ]
]
(* x *)

Note that it works with the assumption $x<-1$ as well.

$\endgroup$
2
  • $\begingroup$ I'm not familiar with LeafCount, but this sounds promising! Thanks! (also, I just realized that (* x *) looks like a cute face) $\endgroup$ – user16320 Jan 5 at 1:50
  • $\begingroup$ Very nice solution. By the way, you can post it as an answer to my old unanswered question mathematica.stackexchange.com/q/207506/9469. $\endgroup$ – yarchik Jan 5 at 10:12
4
$\begingroup$

As stated in the documentation for Simplify:

Simplify tries expanding, factoring, and doing many other transformations on expressions, keeping track of the simplest form obtained.

For some simplifications, such as yours, the required transformations actually increase complexity (as measured by Mathematica) before the cancellations can occur. This can be seen by using the default complexity function Simplify`SimplifyCount:

Simplify`SimplifyCount[Log[1 + 1/x]]
(* 7 *)

Simplify`SimplifyCount[Log[1 + x] - Log[x]]
(* 10 *)

Simplify`SimplifyCount[Log[1 + x]^2 - Log[x]^2]
(* 14 *)

Simplify`SimplifyCount[(Log[1 + x] - Log[x])(Log[1 + x] + Log[x])]
(* 18 *)

I don't believe the details of Simplify's algorithm are publically documented, but it appears likely that it abandons these transformations due to the increasing complexity, before getting to the point where the simplification can occur.

For more discussion on simplification look at some of the highly rated answers with the tag: https://mathematica.stackexchange.com/search?tab=votes&q=%5bsimplifying-expressions%5d%20is%3aa

$\endgroup$
3
$\begingroup$
expr = Exp[(Log[1 + x]^2 - Log[x]^2)/Log[1 + 1/x]] - x^2;

FullSimplify[expr, x > 0, ComplexityFunction -> StringLength@*ToString]

FullSimplify[expr, 
  TransformationFunctions -> {Automatic, PowerExpand[#, Assumptions -> x > 0] &}]

x
x

$\endgroup$
1
  • $\begingroup$ Definitely a very neat solution! Am I understanding it right, ComplexityFunction sets the criterion for what the Simplify should aim as a "good simplified expression"? From Simon's answer it seems that MMA gives up too quickly before even having a chance to discover that "x" is the simplification, because it first has to expand the expression before it shrinks to x ("it has to get worse before it gets better"). However, with the ComplexityFunction you provided it simplified to x. By the way, what is the last command for? For me, Simplify with provided ComplexityFunction did the job already... $\endgroup$ – user16320 Jan 6 at 2:32

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.