# Software that does naïve or formal simplification of mathematical expressions

Devil-may-care that I am, suppose that I wanted to 'simplify' the following expression, utterly ignoring the fact that it's very naughty to raise various kinds of numbers to arbitrary powers or to divide by zero.

$$\frac{0.125567841}{d^{2.25}} = \frac{2.513274d+0.10053+2.11\pi}{d+0.04}$$

This is to say, I would like to:

• substitute $$x^4$$ for $$d$$,
• 'cross-multiply' the two sides of the equation, and
• replace the floating point, 2.25, with 9/4.

I want to pretend I'm back in school. Is there software that will do this for me?

EDIT: Where I wrote the 4th root of x I should have had the 4th power of x. My apologies for so much inconvenience!

• Have you looked at Sympy? – Christian Clason Oct 25 '17 at 19:01
• @ChristianClason: Yes, thank you. Sympy checks that it wouldn't be doing anything mathematically unreliable before proceeding. For instance, it won't 'cancel' an exponent of 9/4 and 4 because the 9/4, when applied to its operand, might not be legitimate in the first place. – Bill Bell Oct 25 '17 at 19:06
• It will if it knows (or you tell it) that it's safe -- look at assume. – Christian Clason Oct 25 '17 at 19:09
• @ChristianClason: Will do that! Hadn't noticed that, was relying on someone else's advice. Thanks. – Bill Bell Oct 25 '17 at 19:13
• Note the real=True in the second line of @nicoguaro's answer, which does the same at the time of definition. There are more properties like positive, rational, nonzero, or integer; see docs.sympy.org/latest/modules/… – Christian Clason Oct 25 '17 at 19:30

What you are looking for is a Computer Algebra System. You should be able to do that in Mathematica, Maple, Maxima or SymPy. Particularly, I show an example in SymPy below.

import sympy as sym

d, x = sym.symbols("d x", real=True)
eq = sym.Eq(0.12556841/d**2.25, (2.513274*d + 0.10053 + 2.11*sym.pi)/(d + 0.04))
eq_new = sym.nsimplify(eq).subs(d, x**4)


and the result would be

$$\frac{12556841 \left|{x}\right|}{100000000 x^{10}} = \frac{1}{x^{4} + \frac{1}{25}} \left(\frac{1256637 x^{4}}{500000} + \frac{10053}{100000} + \frac{211 \pi}{100}\right)$$

• I'm sorry, nicoguaro. To a considerable extent I misstated my particular requirements. But I haven't thought through the possibility of somewhere trying to take the negative root of a real number in a more general situation. – Bill Bell Oct 25 '17 at 19:43
• @BillBell, note that it simplifies $(x^4)^{9/4}$ if you specify that the domain of the variable is real. – nicoguaro Oct 25 '17 at 20:03
• And now to simplify? Ideally I would like the software to produce a (pure) polynomial that Sympy can solve. (No absolute value invocations.) – Bill Bell Oct 25 '17 at 20:27
• @BillBell, you can't turn that equation into a polynomial if $x$ is real. It might seem to you that simplification is a trivial task, but it is not. Even if you transform an expression into a polynomial, in general, you won't be able to solve it unless the higher power is 4. – nicoguaro Oct 25 '17 at 21:11
• I might have said something like that until I saw the trick that written as code in my answer. – Bill Bell Oct 25 '17 at 23:03

Thanks for the answer and the comments. They definitely helped. This code gets me at least part of the way and may serve to explain what I was seeking.

Defining both of the symbols to be real and positive made it possible for sympy to allow the operations on exponents involved, at least for this situation.

The result is indeed a polynomial.

>>> from sympy import *
>>> x = Symbol('x', real=True, positive=True)
>>> d = Symbol('d', real=True, positive=True)
>>> (0.125567841*(d+0.04)-d**Rational(9,4)*(2.513274*d+0.10053+2.11*pi)).subs(d, x**4)
-x**9*(2.513274*x**4 + 0.10053 + 2.11*pi) + 0.125567841*x**4 + 0.00502271364
>>> (-x**9*(2.513274*x**4 + 0.10053 + 2.11*pi) + 0.125567841*x**4 + 0.00502271364).expand()
-2.513274*x**13 - 2.11*pi*x**9 - 0.10053*x**9 + 0.125567841*x**4 + 0.00502271364