3
$\begingroup$

How can I simplify big exponents like $10^{39}$ in the solution of a second order equation:

fX = -239.45310106083443` - 30.94796765327525` x + (-246.9477552131551` + 
  2.000074549828356` y) x^2; sol1 = Solve[fX == 0, x]; Simplify[x /. sol1[[1]]]

One gets the simplified solution only solving with separated coefficients and classical formula:

{c, b, a} = CoefficientList[fX, x]; sol = Simplify[(-b + Sqrt[b^2 - 4 a c])/(2 a)]

Such expressions come as result of an equation giving the warning message:

"Solve::ratnz: Solve was unable to solve the system with inexact coefficients. The answer was obtained by solving a corresponding exact system and numericizing the result."

This expression is needed for further calculations. Large exponents make the estimation slower.

$\endgroup$
3
$\begingroup$

This is in reaction to a comment:

A closer example to my application is this: 1.*10^-22 Sqrt[1.035998097490982*^47 - 6.518057203453232*^45 x]. Rationalize[] does not give a substantial simplification.

In this case the scenario is quite different than in the original formulation of the question which would suggest that the numbers involved are still very simple in decimal base. In the latter case others have already provided the best approaches but if it's simply that the numbers are large, with no particular bound to decimal base, then probably the best you can do is force Mathematica to merge the prefactor into the square root simply like this:

splfy[x_] := Sqrt[Expand[x^2]]

splfy[1.*10^-22 Sqrt[1.035998097490982*^47 - 6.518057203453232*^45 x]]
(* Sqrt[1036. - 65.1806 x] *)
(* Precision is retained, as seen in InputForm: Sqrt[1035.998097490982 - 65.18057203453232*x] *)

This also works in the other examples provided. It stays within exact arithmetic where all numbers are exact:

splfy[Sqrt[3 10^45 + x 10^47]/(1 10^22)]
(* Sqrt[30 + 1000 x] *)

and converts a relevant part of the output to approximate numbers when a part of the input is:

splfy[Sqrt[3.1 10^45 + x 10^47]/(1 10^22)]
(* Sqrt[31. + 1000 x] *)

Note that approximate numbers get printed using the scientific notation while exact numbers will be expanded at output:

splfy[Sqrt[3.1 10^45 + x 10^47]/(1 10^2)]
(* Sqrt[3.1 10^41 + 10000000000000000000000000000000000000000000 x]

This is the default behaviour, if it's an inconvenience and your calculation does not need exact arithmetic then the notation of powers of ten can be recovered everywhere wrapping the definition of splfy in N.

| improve this answer | |
$\endgroup$
2
$\begingroup$

Hopefully someone can come up with a better way to do this. If I understand correctly, the issue is that

Simplify[Sqrt[3 10^45 + x 10^47]/(1 10^22)]

gives a nice and short result, with no large powers of 10,

(* Sqrt[30 + 1000 x] *)

while this

Simplify[Sqrt[3.1 10^45 + x 10^47]/(1 10^22)]

(* Sqrt[3.1*10^45 + 1.*10^47 x]/10000000000000000000000 *)

does not. The difference is that one expression has all rational numbers, and the other has a floating point number in there. So we convert the base into a rational number.

simpLargeExp[expr_] := 
 expr /. a_?
     NumberQ :> ((Rationalize[#1]*10^#2 &) @@ MantissaExponent[a]) // 
  Simplify

simpLargeExp@(Sqrt[3.1 10^45 + x 10^47]/(1 10^22))
(* Sqrt[31 + 1000 x] *)

It would be easier if we could just apply Rationalize to the whole expression, but it doesn't work so well with such large exponents. Consider these two examples,

Rationalize[3.1 10^16, 0]
Rationalize[3.1 10^45, 0]
(* 31000000000000000 *)
(* 3099999999999999877321390993177413894038093824 *)
| improve this answer | |
$\endgroup$
  • $\begingroup$ @Karsten7. - right, there's those approximate numbers lol. I didn't check the second argument of Rationalize, but yeah, it fails in this case: Map[Rationalize[#, 0] &, Sqrt[3.1 10^45 + x 10^47]/(1 10^22), Infinity] $\endgroup$ – Jason B. May 3 '16 at 11:04
  • 1
    $\begingroup$ A closer example to my application is this: 1.*10^-22 Sqrt[1.035998097490982*^47 - 6.518057203453232*^45 x Rationalize[] does not give a substantial simplification $\endgroup$ – Horia-Eugen Porteanu May 3 '16 at 11:16
  • 1
    $\begingroup$ @Horia-EugenPorteanu In that case, if you're guaranteed that the input will always be similar, I'd just go with a forced expansion. Simplify[a^2]^(1/2) where a is your expression. $\endgroup$ – The Vee May 3 '16 at 11:46
  • $\begingroup$ @Karsten7. - Yeah, that one is a bit embarrassing.... $\endgroup$ – Jason B. May 3 '16 at 11:46
  • $\begingroup$ @TheVee - you should post that as an answer, it's the only one that really fits the bill here for 1.*10^-22 Sqrt[ 1.035998097490982*^47 - 6.518057203453232*^45 x]; $\endgroup$ – Jason B. May 3 '16 at 11:54
2
$\begingroup$

Instead of a combination of Rationalize and MantissaExponent, as shown in the answer by JasonB, one can use a combination of FromDigits and RealDigits:

Sqrt[3.1 10^45 + x 10^47]/(1 10^22) /. x_Real :> Sign[x]*FromDigits@RealDigits[x] // Simplify

$\ $Sqrt[31 + 1000 x]

| improve this answer | |
$\endgroup$
  • $\begingroup$ I like this better than my solution, but I'm confused about what happens when there are a lot of digits. If you take the example given in the comments, expr = 1.*10^-22 Sqrt[ 1.035998097490982*^47 - 6.518057203453232*^45 x]; and look at {expr, expr /. x_Real :> FromDigits@RealDigits[x] // Simplify} /. x -> 1.0 there is a significant difference $\endgroup$ – Jason B. May 3 '16 at 11:58
  • $\begingroup$ @JasonB It was a sign issue. RealDigits discards the sign. Should be fixed now. $\endgroup$ – Karsten 7. May 3 '16 at 13:06
  • $\begingroup$ Excellent! I couldn't understand such a big difference on the basis of numerical error $\endgroup$ – Jason B. May 3 '16 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.