Can't get Mathematica to simplify an expression
A few things of note:
- Like @m_goldberg suggested, it is wise to explicitly state
d ∈ Reals, s ∈ Reals
. - Because you introduced
.
's after your numbers, you force mathematica to treat your integers as floats, which introduces rounding errors, removing these helps. - Simplification introduces absolutes variable epxressions, taking these to be positive or negative helps.
Positive:
FullSimplify[expr,
Assumptions -> {d ∈ Reals,
s ∈
Reals, -6 d^2 +
16 d^3 + (1 + Sqrt[8 d^2 + (1 - 2 s)^2] - 2 s) (-1 + 2 s) -
4 d (1 + Sqrt[8 d^2 + (1 - 2 s)^2] - 2 s) (-1 + 2 s) > 0}]
$$\frac{1+\sqrt{8d^2+\left(1-2s\right)^2}-2s}{2\sqrt{8d^2+\left(1-2s\right)^2}}$$
Negative:
FullSimplify[expr,
Assumptions -> {d ∈ Reals,
s ∈
Reals, -6 d^2 +
16 d^3 + (1 + Sqrt[8 d^2 + (1 - 2 s)^2] - 2 s) (-1 + 2 s) -
4 d (1 + Sqrt[8 d^2 + (1 - 2 s)^2] - 2 s) (-1 + 2 s) < 0}]
$$\begin{cases} -1 & \left(1+4d\right)\left(1+\sqrt{8d^{2}+\left(1-2s\right)}-2s\right)\left(-1+2s\right)\ge2d^{2}\left(3+8d\right)\\ \frac{2d\left(d-sd^{2}+2\left(1+\sqrt{8d^{2}+\left(1-2s\right)^{2}}\right)\right)\left(-1+2s\right)}{-8d^{2}+\left(1+\sqrt{8d^{2}+\left(1-2s\right)^{2}}-2s\right)\left(-1+2s\right)} & Else \end{cases}$$
Yielding an in total 3 cases environment.
Following from your expression expr
:
exact = Rationalize[expr]
vars = Variables[expr]
Refine[exact, Element[vars, Reals]]
Simplify[%, Element[vars, Reals]]
(* substitution picked by me and copy-pasted from the last output *)
% /. Sqrt[8 d^2 + (1 - 2 s)^2] -> x1
(* another such substitution *)
% /. (1 - 2 s + x1) -> x2
Just one approach, and not necessarily the kind of result you want:
expr (* your expression *)
FullSimplify[Rationalize[%], Variables[%] ∈ Reals];
out = Experimental`OptimizeExpression[%];
new = Symbol /@ CharacterRange[63396, 63421];
old = DeleteDuplicates@Cases[out, s_Symbol /; Context[s] === "Compile`", {-1}]
Extract[out, {1, 2}, Defer] /.
Cases[Flatten[{old, new}, {2}], {o_, n_} :> (o :> n)]