# How to simplify this huge expression to get a known smaller expression?

I have the following massive expression

A = ((8 - 2 Sqrt[(8 - 7 q) q] + q (-6 + 3 Sqrt[(8 - 7 q) q] + q (-17 + 12 q - 4 Sqrt[(8 - 7 q) q])))/Sqrt[(8 - 7 q) q] + (Sqrt (24 + 2 Sqrt[(8 - 7 q) q] + q (-5 (10 + 3 Sqrt[(8 - 7 q) q]) + q (-95 + 7 Sqrt[(8 - 7 q) q] + q (323 - 196 q + 12 Sqrt[(8 - 7 q) q])))))/Sqrt[-q (-8 + 7 q) (2 + 2 Sqrt[(8 - 7 q) q] + q (-10 + 21 q - 7 Sqrt[(8 - 7 q) q]))])/(8 (-1 + q) (-1 + 2 q))


I have reason to believe that this is simply equal to

B =(4 - 16 q^2)/(3 q - 4 Sqrt[8 - 7 q] q^(3/2) + Sqrt[(8 - 7 q) q])


for $0 < q < 1/2$. Numerically, they agree to 100 digits and their plots look identical. My question is: how can I use FullSimplify (or the like) on the first expression to get something of the same complexity as the second expression? In other words, I'm more interested in simplifying the first expression than I am actually checking that it's equal to the second. I've tried modifying the complexity function to Composition[StringLength, ToString] but it doesn't really get there.

• You mean how would we simplify if we didn't already know the simpler expression? – Szabolcs Sep 11 '18 at 17:33
• @Szabolcs Yes, exactly. I'm hoping to apply the simplification method to other expressions I have, where I don't have a good guess for the simpler form. – Mr. G Sep 11 '18 at 17:36
• Sometimes it's more productive to look at how the expression was derived, go back to the starting point, and try to write the starting point in a simpler form. E.g., identify common subexpressions such as Sqrt[(8-7q)q], and use a more compact notation (single letter) for them during the derivation. I find that manual derivations often give more insight than automated ones precisely because we tend to keep track of "meaningful subexpressions". – Szabolcs Sep 11 '18 at 17:44
• For what it's worth, FullSimplify[A == B, 0 < q < 1/2] returns True in seconds. – bbgodfrey Oct 2 '18 at 4:52
• ComplexityFunction -> cf, with cf[e_] := LeafCount[e] + 100 Count[e, Power[__, z_] /; z != -1, Infinity] does not help either. – bbgodfrey Oct 2 '18 at 22:19

Use substitution of variables and let a = Sqrt[(8-7q)q]

Then there is an intermediate step of:

((8 - 2 a + q (-6 + 3 a + q (-17 + 12 q - 4 a)))/a +
(Sqrt
(24 + 2 a + q (-5 (10 + 3 a) + q (-95 + 7 a + q (323 - 196 q + 12 a))))) /
Sqrt[-q (-8 + 7 q) (2 + 2 a + q (-10 + 21 q - 7 a))])/(8 (-1 + q) (-1 + 2 q))


You can then do more algebra.

Perhaps on your domain Sqrt[-q (-8 + 7 q)] will be related directly to a.

The remaining algebra can be done by those interested.

• Did you mean to add something more to this post? – Henrik Schumacher Sep 11 '18 at 19:27
• I edited the post to clarify. I think there are a number of further simplifications that can be made, but I just don't have time to do that right now. – JosephDoggie Sep 11 '18 at 19:31
• This turned out to be essentially the solution; identify terms that show up often and replace them with something simpler. – Mr. G Jun 7 '19 at 17:22

THIS IS AN EXTENDED COMMENT RATHER THAN AN ANSWER

A = ((8 - 2 Sqrt[(8 - 7 q) q] +
q (-6 + 3 Sqrt[(8 - 7 q) q] + q (-17 + 12 q - 4 Sqrt[(8 - 7 q) q])))/
Sqrt[(8 - 7 q) q] + (Sqrt[
2] (24 + 2 Sqrt[(8 - 7 q) q] +
q (-5 (10 + 3 Sqrt[(8 - 7 q) q]) +
q (-95 + 7 Sqrt[(8 - 7 q) q] +
q (323 - 196 q + 12 Sqrt[(8 - 7 q) q])))))/
Sqrt[-q (-8 + 7 q) (2 + 2 Sqrt[(8 - 7 q) q] +
q (-10 + 21 q - 7 Sqrt[(8 - 7 q) q]))])/(8 (-1 + q) (-1 + 2 q));

B = (4 - 16 q^2)/(3 q - 4 Sqrt[8 - 7 q] q^(3/2) + Sqrt[(8 - 7 q) q]);


Both A and B have almost the same domain, differing only at q == 8/7

FunctionDomain[#, q] & /@ {A, B}

(* {0 < q < 1/2 || 1/2 < q < 1 || 1 < q < 8/7,
0 < q < 1/2 || 1/2 < q < 1 || 1 < q <= 8/7} *)

Plot[{A, B}, {q, 0, 8/7},
Exclusions -> {0, 1/2, 1, 8/7},
PlotStyle -> {Thick, Dashed},
PlotPoints -> 200,
PlotLegends -> Placed[{"A", "B"}, {.25, .2}]] As seen in the plot above, A and B are equal in the restricted domain 0 < q < 1/2

A == B // FullSimplify[#, 0 < q < 1/2] &

(* True *)

• I do not think that RootReduce does anything in this case. A === A2 yields True. Moreover, the Out forms of both look the same, even though the In forms doe not.. – bbgodfrey Oct 2 '18 at 12:57
• @bbgodfrey - Thanks. My mistake -- up too late last night. – Bob Hanlon Oct 2 '18 at 14:45