# Reducing expressions to simpler form using a known equality

I generally have a lot of trouble getting Mathematica to produce readable versions of solutions.

For example, today, when solving a symbolic system of homogenous ODEs (with boundaries provided as constants), Mathematica provides one of the two of my solutions with the following output form:

exp =  (p0 (E^((I k z (Ωc^2 + Ωd^2 -
Sqrt[Ωc^4 -
2 Ωc^2 Ωd^2 +
4 E^(I θc +
I θd) Ωc^2 Ωd^2 + \ Ωd^4]))/(2 Den L)) Ωc^2 -
E^((I k z (Ωc^2 + Ωd^2 +
Sqrt[Ωc^4 -
2 Ωc^2 Ωd^2 +
4 E^(I θc +
I θd) Ωc^2 Ωd^2 + \ Ωd^4]))/(2 Den L)) Ωc^2 -
E^((I k z (Ωc^2 + Ωd^2 -
Sqrt[Ωc^4 -
2 Ωc^2 Ωd^2 +
4 E^(I θc +
I θd) Ωc^2 Ωd^2 + \ Ωd^4]))/(2 Den L)) Ωd^2 +
E^((I k z (Ωc^2 + Ωd^2 +
Sqrt[Ωc^4 -
2 Ωc^2 Ωd^2 +
4 E^(I θc +
I θd) Ωc^2 Ωd^2 + \ Ωd^4]))/(2 Den L)) Ωd^2 +
E^((I k z (Ωc^2 + Ωd^2 -
Sqrt[Ωc^4 -
2 Ωc^2 Ωd^2 +
4 E^(I θc +
I θd) Ωc^2 Ωd^2 + \ Ωd^4]))/(
2 Den L)) √(Ωc^4 -
2 Ωc^2 Ωd^2 +
4 E^(I θc +
I θd) Ωc^2 Ωd^2 + \ Ωd^4) +
E^((I k z (Ωc^2 + Ωd^2 +
Sqrt[Ωc^4 -
2 Ωc^2 Ωd^2 +
4 E^(I θc +
I θd) Ωc^2 Ωd^2 + \ Ωd^4]))/(
2 Den L)) √(Ωc^4 -
2 Ωc^2 Ωd^2 +
4 E^(I θc +
I θd) Ωc^2 Ωd^2 + \ Ωd^4)))/(2 √(Ωc^4 -
2 Ωc^2 Ωd^2 +
4 E^(I θc +
I θd) Ωc^2 Ωd^2 + \ Ωd^4)); exp2 =


In my opinion this is "messy." If you look at the output, you can see visually that there are some very "big" terms (which are actually the eigenvalues of the ODE system) that are repeated instead of being simplified.

Ideally I would like to have Mathematica self-identify that these expressions and do the simplification for me. But if that's not possible, then I just want to come up with symbols that reduce my system into a more readable form. Any tips or ideas how I can do that?

Here are some of my unsuccessful attempts to try to get Mathematica to put it in a better form:

Refine[exp,    Element[#,
Reals] & /@ {Ωc, Ωd, θc, \ θd, k, p0, s0, L, Den}] Simplify[exp2, √(Ωc^4 -
2 Ωc^2 Ωd^2 +
4 E^(I θc +
I θd) Ωc^2 Ωd^2 + \ Ωd^4) == b]


One way to make the expression more visually appealing is to introduce a parameter in place of the square root.

First, check that there is only one radicand in the whole expression:

α = Cases[exp, Sqrt[_], ∞] // DeleteDuplicates;
β = Cases[exp, Power[_, 1/2], ∞] // DeleteDuplicates
γ = Cases[exp, Power[_, -1/2], ∞] // DeleteDuplicates


$$\left\{\sqrt{4 \text{\Omega c}^2 \text{\Omega d}^2 e^{i \text{\theta c}+i \text{\theta d}}+\text{\Omega c}^4-2 \text{\Omega c}^2 \text{\Omega d}^2+\text{\Omega d}^4}\right\}$$

$$\left\{\frac{1}{\sqrt{4 \text{\Omega c}^2 \text{\Omega d}^2 e^{i \text{\theta c}+i \text{\theta d}}+\text{\Omega c}^4-2 \text{\Omega c}^2 \text{\Omega d}^2+\text{\Omega d}^4}}\right\}$$

Make a quick check that $$\alpha$$, $$\beta$$, $$\gamma$$ contain the exact same radicands with

α*γ == β*γ == {1}
(*  True  *)


Now introduce the parameter μ = α[] by multiplying each of the radicals in the expression by one in the form of μ/α[] or α[]/μ. With $$\mu$$ so defined, the following substitutions do not change the value of exp

exp2 = exp /. {
Sqrt[a_] :> (μ Sqrt[a] / α[]),
Power[a_, 1/2] :> (μ Power[a, 1/2] / α[]),
Power[a_, -1/2] :> (Power[a, -1/2] α[] / μ)} // Simplify


$$\frac{\text{p0} e^{-\frac{i k z \left(\mu -\text{\Omega c}^2-\text{\Omega d}^2\right)}{2 \text{Den} L}} \left(\mu \left(1+e^{\frac{i k \mu z}{\text{Den} L}}\right)-\left(\text{\Omega c}^2-\text{\Omega d}^2\right) \left(-1+e^{\frac{i k \mu z}{\text{Den} L}}\right)\right)}{2 \mu }$$

The factors of k μ / (2 Den L) prompt us to introduce a new parameter, $$\lambda$$, to eliminate $$\mu$$ and its associated factors. We make the following simplification:

exp3 = exp2 /. μ -> (2 Den L λ/k ) // ExpToTrig // FullSimplify


$$\frac{\text{p0} e^{\frac{i k z \left(\text{\Omega c}^2+\text{\Omega d}^2\right)}{2 \text{Den} L}} (2 \text{Den} \lambda L \cos (\lambda z)-i k (\text{\Omega c}-\text{\Omega d}) (\text{\Omega c}+\text{\Omega d}) \sin (\lambda z))}{2 \text{Den} \lambda L}$$

The same approach could be used to introduce symbols that represent the eigenvalues.

One approach is to just visually check the output of your expression for large-and-repeated terms. I found three of them, and (by copy-pasting them into the following), replaced them with A, B, and R, respectively:

exp2=exp /.
{(I*k*z*(-Sqrt[4*\[CapitalOmega]c^2*\[CapitalOmega]d^2*E^(I*\[Theta]c + I*\[Theta]d) + \[CapitalOmega]c^4 - 2*\[CapitalOmega]c^2*\[CapitalOmega]d^2 + \[CapitalOmega]d^4] +
\[CapitalOmega]c^2 + \[CapitalOmega]d^2))/(2*Den*L) -> A,
(I*k*z*(Sqrt[4*\[CapitalOmega]c^2*\[CapitalOmega]d^2*E^(I*\[Theta]c + I*\[Theta]d) + \[CapitalOmega]c^4 - 2*\[CapitalOmega]c^2*\[CapitalOmega]d^2 + \[CapitalOmega]d^4] +
\[CapitalOmega]c^2 + \[CapitalOmega]d^2))/(2*Den*L) -> B,
\[CapitalOmega]c^4 - 2*\[CapitalOmega]c^2*\[CapitalOmega]d^2 + 4*E^(I*\[Theta]c + I*\[Theta]d)*\[CapitalOmega]c^2*\[CapitalOmega]d^2 + \[CapitalOmega]d^4 -> R}//Simplify


$$\frac{\text{p0} \left(e^A \left(\sqrt{R}+\text{\Omega c}^2-\text{\Omega d}^2\right)+e^B \left(\sqrt{R}-\text{\Omega c}^2+\text{\Omega d}^2\right)\right)}{2 \sqrt{R}}$$

where

$$A=-\frac{i k z \left(\sqrt{2 \text{\Omega c}^2 \text{\Omega d}^2 \left(-1+2 e^{i (\text{\theta c}+\text{\theta d})}\right)+\text{\Omega c}^4+\text{\Omega d}^4}-\text{\Omega c}^2-\text{\Omega d}^2\right)}{2 \text{Den} L}$$ $$B=\frac{i k z \left(\sqrt{2 \text{\Omega c}^2 \text{\Omega d}^2 \left(-1+2 e^{i (\text{\theta c}+\text{\theta d})}\right)+\text{\Omega c}^4+\text{\Omega d}^4}+\text{\Omega c}^2+\text{\Omega d}^2\right)}{2 \text{Den} L}$$ and $$R=2 \text{\Omega c}^2 \text{\Omega d}^2 \left(-1+2 e^{i (\text{\theta c}+\text{\theta d})}\right)+\text{\Omega c}^4+\text{\Omega d}^4$$