4
$\begingroup$

The responses to my previous question "Are there any tips/tricks to improve simplification..." were very helpful, but as I move forward in the same personal project mentioned in that question I've now encountered expressions that aren't being meaningfully simplified by Wolfram Engine even when using the commands suggested in those answers, but which I am still able to manually simplify.

As an example, Wolfram Engine spit out the 2,285-character, 1,317-leaf expression

(r*(4*(4*(24*Sqrt[10 - 4*Sqrt[2] + (6 - 4*Sqrt[2])*U^2] + 
34*Sqrt[5 - 2*Sqrt[2] + (3 - 2*Sqrt[2])*U^2] - 5*Sqrt[8*(7 + 4*Sqrt[2]) - 
16*(-3 + Sqrt[2])*U^2 + (70 - 48*Sqrt[2])*U^4 + (34 - 24*Sqrt[2])*U^6] - 
7*Sqrt[4*(7 + 4*Sqrt[2]) - 8*(-3 + Sqrt[2])*U^2 + (35 - 24*Sqrt[2])*U^4 + 
(17 - 12*Sqrt[2])*U^6]) + 4*U^2*(3*Sqrt[10 - 4*Sqrt[2] + (6 - 4*Sqrt[2])*U^2] + 
8*Sqrt[5 - 2*Sqrt[2] + (3 - 2*Sqrt[2])*U^2] - Sqrt[8*(7 + 4*Sqrt[2]) - 
16*(-3 + Sqrt[2])*U^2 + (70 - 48*Sqrt[2])*U^4 + (34 - 24*Sqrt[2])*U^6] - 
Sqrt[4*(7 + 4*Sqrt[2]) - 8*(-3 + Sqrt[2])*U^2 + (35 - 24*Sqrt[2])*U^4 + 
(17 - 12*Sqrt[2])*U^6]) + U^4*(-32*Sqrt[10 - 4*Sqrt[2] + (6 - 4*Sqrt[2])*U^2] + 
46*Sqrt[5 - 2*Sqrt[2] + (3 - 2*Sqrt[2])*U^2] + U^2*(86 - 61*Sqrt[2] + 
(41 - 29*Sqrt[2])*U^2)*Sqrt[5 - 2*Sqrt[2] + (3 - 2*Sqrt[2])*U^2] - 
Sqrt[8*(7 + 4*Sqrt[2]) - 16*(-3 + Sqrt[2])*U^2 + (70 - 48*Sqrt[2])*U^4 + 
(34 - 24*Sqrt[2])*U^6] + Sqrt[4*(7 + 4*Sqrt[2])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34 - 24*Sqrt[2])*U^6] + 8*Sqrt[4*(7 + 4*Sqrt[2]) - 8*(-3 + Sqrt[2])*U^2 + 
(35 - 24*Sqrt[2])*U^4 + (17 - 12*Sqrt[2])*U^6]))))/(2*Sqrt[15 - 6*Sqrt[2] + 
(9 - 6*Sqrt[2])*U^2]*(-8*(22 + 15*Sqrt[2]) - 4*(22 + 5*Sqrt[2])*U^2 + 
6*(-18 + 11*Sqrt[2])*U^4 + (-138 + 97*Sqrt[2])*U^6 + (-58 + 41*Sqrt[2])*U^8))

which I was able to rework down to the 65-character, 41-leaf expression

r*Sqrt[2/3]*(1 - (4 + c*(2 + Sqrt[2]))/(4 + (6 - 4*Sqrt[2])*U^2))

for almost a 97.2% reduction in length and almost a 96.88% reduction in leaf count. Wolfram Engine seems to be getting caught up in the square-roots-of-sub-experssions and failing to recognize that they cancel out, even when I specify that $U$ is a real number and use options like Extension and TransformationFunctions to extend the search space and try to get it to factor them out. Several of my attempted commands on the long expression also apparently failed because it has a pole and thus is not a pure polynomial.

Are there any tricks that will make Wolfram Engine reliably find such drastically-shorter equivalent forms when dealing with expressions with poles and cancellable square roots?

Background

The part of my project that this comes from is finding the center-point of a circle that passes through three known points, for which I am following the steps in this Mathematics Stack Exchange post. The three points on the circle have the following coordinates:

A = {
    r/Sqrt[3]*(Sqrt[2]*Q*(2 - U^2) + 2 - Sqrt[2]/4*c*U^2)/(Q*(2 - U^2) - 2), 
    r/Sqrt[1]*((c*(Q - 1) - 1)*U)                        /(Q*(2 - U^2) - 2), 
    r/Sqrt[6]*(Sqrt[2]*Q*(2 - U^2) + 2 - Sqrt[2]/4*c*U^2)/(Q*(2 - U^2) - 2)
}

B = {
    r/Sqrt[3]*(Sqrt[2]*Q*(1 - U^2) + 3 - 1/2*c*(1 + U^2))/(Q*(1 - U^2) - 2), 
    r/Sqrt[1]*(-(1 + c)*U)                               /(Q*(1 - U^2) - 2), 
    r/Sqrt[6]*(Sqrt[2]*Q*(1 - U^2)*(1 + 2*c*Q) + 2*c)    /(Q*(1 - U^2) - 2)
}

C = {
    r/Sqrt[3]*(Sqrt[2]*Q*(1 - U^2) + 1 + c*(Sqrt[2]*Q*(1 - U^2) + 1))/(Q*(1 - U^2) - 2), 
    r/Sqrt[1]*(-(1 + c)*U)                                           /(Q*(1 - U^2) - 2), 
    r/Sqrt[6]*(Sqrt[2]*Q*(1 - U^2) + 4 + c*((1/2 + Q)*(1 - U^2) - 2))/(Q*(1 - U^2) - 2)
}

where r is a positive real number, U is a real number in the interval $[-1, 1]$, c is a real number in the interval $[0, 1]$, and Q := (2 - Sqrt[2])/4.

The example expression in this question comes from the very last step in the linked post and gives the $x$-coordinate of the center-point, Ax + (bx)/2*(ux) + (h)*(vx), where Ax is the $x$-coordinate of point A and where

bx := -2*r*(1 + c*(Q*(1 - U^2) - 1))/Sqrt[1 + 16*(1 - Q)^2 + 2*U^2*(1 + 2*Q^2*(1 + U^2))]

ux := 1/Sqrt[3]*2*(1 + Q*U^2)/Sqrt[1 + 16*(1 - Q)^2 + 2*U^2*(1 + 2*Q^2*(1 + U^2))]

h  := -r*(1 + c*(Q*(1 - U^2) - 1))/Sqrt[4*Q^2*(1 + U^2) + 1]

vx := 1/Sqrt[3]*(-8*(1 - Q)^2 - 1/2*U^2)/Sqrt[(1 + 4*Q^2*U^2)*(1 + 16*(1 - Q)^2 + 2*U^2*(1 + 2*Q^2*(1 + U^2)))]

(The above definitions were all simplified using the responses to my previous question.)

$\endgroup$
10
  • $\begingroup$ It does not seem to be true saying: "I've now encountered expressions that aren't being meaningfully simplified" like if you encountered it by a chance. Rather it seems that the expression was constructed artificially for the purpose so that Mathematica fails at simplifying it. It is easy to construct such expressions. Start with simple expression then manipulate it so that it becomes convoluted but still numerically same as the original. You end up with a complicated expression that is hard to simplify to the original form if you do not know the steps that were made to make it complicated. $\endgroup$ Commented 2 days ago
  • 2
    $\begingroup$ It is like mixing tea and milk together and then demanding to separate them. The former is easy the latter is hard, if not impossible. $\endgroup$ Commented 2 days ago
  • $\begingroup$ I've used Mathematica do get compact expressions for some very nasty tensor calculus, but the trick there was to not take immediate advantage of the simplification engine, in fact I barely used it at all. Instead I allowed Mathematica to manipulate compound expressions, e.g. I could multiply A**F where A and F stood in for some more complicated expression, and then I supplied some general simplification rules for my specific tensors, and only after the main classes of simplifications were handled did I expand things back out to simplify. This is, generally, a hard problem for any CAS $\endgroup$ Commented 2 days ago
  • $\begingroup$ @azerbajdzan I promise I absolutely was not trying to set up a simplification failure. The example expression came directly from a personal project where I am attempting to find the coordinates of the center-point of a circle in 3D space by following this post. $\endgroup$ Commented yesterday
  • $\begingroup$ @Lawton So maybe you should have written it in OP as there may be easier way to simplify it if we know where the problem came from. $\endgroup$ Commented yesterday

1 Answer 1

11
$\begingroup$

Definition of expr should be taken from OP.

This depends on choosing correct extension for factorization.

The additional extension ext was discovered by solving one of the surds appearing in expr (except obvious Sqrt[2]).

Solve[5 - 2 Sqrt[2] + (3 - 2 Sqrt[2]) U^2 == 0] // 
  RootReduce // ToRadicals

enter image description here

ext = {Sqrt[7 + 4 Sqrt[2]], I};

Cases[expr, Sqrt[___] | Power[___, -1/2 | 1/2], All] // Union;

FactorTerms@% /. Sqrt[x_] :> Sqrt[Factor[x, Extension -> {Sqrt[2]}]];

% /. x : Sqrt[_] :> FullSimplify[x, U \[Element] Reals];

expr /. Thread[%%% -> %];

% /. {Sqrt[x___] :> Sqrt@Factor[x, Extension -> ext], 
     Power[x___, y : 1/2 | -1/2] :> Factor[x, Extension -> ext]^y} // 
   Cancel // FullSimplify;

Factor[%, Extension -> ext] // FullSimplify

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ (+) This is an amazing solution. Each step is very clear. This approach can probably be applied to many questions here. It should be added that for general complex $U$ the initial and the final expressions are not equivalent, but that's a different story. $\endgroup$ Commented yesterday
  • $\begingroup$ (+1) Great answer. The way you uncover the required algebraic extension and only then factor is particularly elegant. $\endgroup$ Commented yesterday

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.