Mathematica Asked on May 23, 2021
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.
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 *)
Answered by yarchik on May 23, 2021
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 simplifying-expressions tag: https://mathematica.stackexchange.com/search?tab=votes&q=%5bsimplifying-expressions%5d%20is%3aa
Answered by Simon Woods on May 23, 2021
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.
Answered by Soner on May 23, 2021
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
Answered by chyanog on May 23, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP