Manipulating Equations and Inequalities
"Defining Variables" discussed assignments such as x=y, which set x equal to y. Here we discuss equations, which test equality. The equation x==y tests whether x is equal to y.
In[1]:= 1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-vqr
Out[1]= 1

It is very important that you do not confuse x=y with x==y. While x=y is an imperative statement that actually causes an assignment to be done, x==y merely tests whether x and y are equal, and causes no explicit action. If you have used the C programming language, you will recognize that the notation for assignment and testing in the Wolfram Language is the same as in C.
In[2]:= 2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-n5l
Out[2]= 2

In[3]:= 3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-b7t
Out[3]= 3

In[4]:= 4

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-fka
Out[4]= 4

In[5]:= 5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-tvp
Out[5]= 5

In[6]:= 6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-nwl
The tests used so far involve only numbers, and always give a definite answer, either True or False. You can also do tests on symbolic expressions.
The Wolfram Language cannot get a definite result for this test unless you give x a specific numerical value:
In[7]:= 7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-pr5
Out[7]= 7

In[8]:= 8

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-yec
Out[8]= 8

Even when you do tests on symbolic expressions, there are some cases where you can get definite results. An important one is when you test the equality of two expressions that are identical. Whatever the numerical values of the variables in these expressions may be, the Wolfram Language knows that the expressions must always be equal.
In[9]:= 9

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-vzm
Out[9]= 9

The Wolfram Language does not try to tell whether these expressions are equal. In this case, using Expand would make them have the same form:
In[10]:= 10

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-x3k
Out[10]= 10

Expressions like x==4 represent equations in the Wolfram Language. There are many functions in the Wolfram Language for manipulating and solving equations.
In[11]:= 11

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-xe
Out[11]= 11

In[12]:= 12

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-few
Out[12]= 12

In[13]:= 13

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-iol
Out[13]= 13

An expression like x^2+2x-7==0 represents an equation in the Wolfram Language. You will often need to solve equations like this, to find out for what values of x they are true.
This gives the two solutions to the quadratic equation
. The solutions are given as replacements for x:

In[1]:=1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-s0i
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-jk4
Out[2]=2

You can get a list of the actual solutions for x by applying the rules generated by Solve to x using the replacement operator:
In[3]:=3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-djr
Out[3]=3

In[4]:=4

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ifl
Out[4]=4

Solve[lhs==rhs,x] |
solve an equation, giving a list of rules for
x
|
x/.solution | use the list of rules to get values for x |
expr/.solution | use the list of rules to get values for an expression |
Solve always tries to give you explicit formulas for the solutions to equations. However, it is a basic mathematical result that, for sufficiently complicated equations, explicit algebraic formulas in terms of radicals cannot be given. If you have an algebraic equation in one variable, and the highest power of the variable is at most four, then the Wolfram Language can always give you formulas for the solutions. However, if the highest power is five or more, it may be mathematically impossible to give explicit algebraic formulas for all the solutions.
The Wolfram Language can always solve algebraic equations in one variable when the highest power is less than five:
In[5]:=5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-uvj
Out[5]=5

In[6]:=6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-y6f
Out[6]=6

There are some equations, however, for which it is mathematically impossible to find explicit formulas for the solutions. The Wolfram Language uses Root objects to represent the solutions in this case:
In[7]:=7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-g7s
Out[7]=7

In[8]:=8

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-flc
Out[8]=8

In addition to being able to solve purely algebraic equations, the Wolfram Language can also solve some equations involving other functions.
In[30]:=30

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-k0ier
Out[30]=30

In[39]:=39

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-fbw

Out[39]=39

It is important to realize that an equation such as
actually has an infinite number of possible solutions. However, Solve by default returns just one solution, but prints a message telling you that other solutions may exist. You can use Reduce to get more information.

In[40]:=40

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-fv4

Out[40]=40

In[11]:=11

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-b2n
Out[11]=11

Solve can also handle equations involving symbolic functions. In such cases, it again prints a warning, then gives results in terms of formal inverse functions.
In[12]:=12

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-jqs

Out[12]=12

Solve[{lhs1==rhs1,lhs2==rhs2,…},{x,y,…}] | |
solve a set of simultaneous equations for x, y, … |
You can also use the Wolfram Language to solve sets of simultaneous equations. You simply give the list of equations and specify the list of variables to solve for.
In[13]:=13

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-iug
Out[13]=13

Here are some more complicated simultaneous equations. The two solutions are given as two lists of replacements for x and y:
In[14]:=14

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-b72
Out[14]=14

In[15]:=15

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-cc5
Out[15]=15

When you are working with sets of equations in several variables, it is often convenient to reorganize the equations by eliminating some variables between them.
In[16]:=16

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-vi0
Out[16]=16

If you have several equations, there is no guarantee that there exists any consistent solution for a particular variable.
There is no consistent solution to these equations, so the Wolfram Language returns {}, indicating that the set of solutions is empty:
In[17]:=17

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-y9z
Out[17]=17

In[18]:=18

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-whw
Out[18]=18

The general question of whether a set of equations has any consistent solution is quite a subtle one. For example, for most values of a, the equations {x==1,x==a} are inconsistent, so there is no possible solution for x. However, if a is equal to 1, then the equations do have a solution. Solve is set up to give you generic solutions to equations. It discards any solutions that exist only when special constraints between parameters are satisfied.
If you use Reduce instead of Solve, the Wolfram Language will, however, keep all the possible solutions to a set of equations, including those that require special conditions on parameters.
This shows that the equations have a solution only when a==1. The notation a==1&&x==1 represents the requirement that both a==1 and x==1 should be True:
In[19]:=19

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-e0a
Out[19]=19

This gives the complete set of possible solutions to the equation. The answer is stated in terms of a combination of simpler equations. && indicates equations that must simultaneously be true; indicates alternatives:
In[20]:=20

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ltw
Out[20]=20

In[21]:=21

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-uyx
Out[21]=21

In[154]:=154

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-lmz
Out[154]=154

Solve[lhs==rhs,x] | solve an equation for x |
Solve[{lhs1==rhs1,lhs2==rhs2,…},{x,y,…}] | |
solve a set of simultaneous equations for x, y, … | |
Eliminate[{lhs1==rhs1,lhs2==rhs2,…},{x,…}] | |
eliminate x, … in a set of simultaneous equations | |
Reduce[{lhs1==rhs1,lhs2==rhs2,…},{x,y,…}] | |
give a set of simplified equations, including all possible solutions
|
Reduce also has powerful capabilities for handling equations specifically over real numbers or integers. "Equations and Inequalities over Domains" discusses this in more detail.
In[23]:=23

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-wnp
Out[23]=23

In[24]:=24

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-u2s
Out[24]=24

In[25]:=25

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-q2y
Out[25]=25

The Wolfram System treats equations as logical statements. If you type in an equation like x^2+3x==2, the Wolfram System interprets this as a logical statement that asserts that x^2+3x is equal to 2. If you have assigned an explicit value to x, say x=4, then the Wolfram System can explicitly determine that the logical statement x^2+3x==2 is False.
If you have not assigned any explicit value to x, however, the Wolfram System cannot work out whether x^2+3x==2 is True or False. As a result, it leaves the equation in the symbolic form x^2+3x==2.
You can manipulate symbolic equations in the Wolfram System in many ways. One common goal is to rearrange the equations so as to "solve" for a particular set of variables.
In[1]:= 1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-fou
Out[1]= 1

You can use the function Reduce to reduce the equation so as to give "solutions" for x. The result, like the original equation, can be viewed as a logical statement:
In[2]:= 2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-j86
Out[2]= 2

The quadratic equation x^2+3x==2 can be thought of as an implicit statement about the value of x. As shown in the previous example, you can use the function Reduce to get a more explicit statement about the value of x. The expression produced by Reduce has the form x==r1x==r2. This expression is again a logical statement, which asserts that either x is equal to r1, or x is equal to r2. The values of x that are consistent with this statement are exactly the same as the ones that are consistent with the original quadratic equation. For many purposes, however, the form that Reduce gives is much more useful than the original equation.
You can combine and manipulate equations just like other logical statements. You can use logical connectives such as and && to specify alternative or simultaneous conditions. You can use functions like LogicalExpand, as well as FullSimplify, to simplify collections of equations.
For many purposes, you will find it convenient to manipulate equations simply as logical statements. Sometimes, however, you will actually want to use explicit solutions to equations in other calculations. In such cases, it is convenient to convert equations that are stated in the form lhs==rhs into transformation rules of the form lhsrhs. Once you have the solutions to an equation in the form of explicit transformation rules, you can substitute the solutions into expressions by using the /. operator.
Reduce produces a logical statement about the values of x corresponding to the roots of the quadratic equation:
In[3]:= 3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-e64
Out[3]= 3

ToRules converts the logical statement into an explicit list of transformation rules:
In[4]:= 4

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-u24
Out[4]= 4

You can now use the transformation rules to substitute the solutions for x into expressions involving x:
In[5]:= 5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ewl
Out[5]= 5

The function Solve produces transformation rules for solutions directly:
In[6]:= 6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-iui
Out[6]= 6

The main equations that Solve and related Wolfram Language functions deal with are polynomial equations.
In[1]:= 1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-spz
Out[1]= 1

In[2]:= 2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ka7
Out[2]= 2

The Wolfram Language can also find exact solutions to cubic equations. Here is the first solution to a comparatively simple cubic equation:
In[3]:= 3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-nrb
Out[3]= 3

For cubic and quartic equations, the results are often complicated, but for all equations with degrees up to four the Wolfram Language is always able to give explicit formulas for the solutions.
An important feature of these formulas is that they involve only radicals: arithmetic combinations of square roots, cube roots and higher roots.
It is a fundamental mathematical fact, however, that for equations of degree five or higher, it is no longer possible in general to give explicit formulas for solutions in terms of radicals.
There are some specific equations for which this is still possible, but in the vast majority of cases it is not.
In[4]:= 4

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-g48
Out[4]= 4

For a polynomial that factors in the way this one does, it is straightforward for Solve to find the roots:
In[5]:= 5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-wfl
Out[5]= 5

In[6]:= 6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-sjj
Out[6]= 6

The polynomial does not factor, but it can be decomposed into nested polynomials, so Solve can again find explicit formulas for the roots:
In[7]:= 7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-p0k
Out[7]= 7

Root[f,k] | the k th root of the equation f[x]==0 |
No explicit formulas for the solution to this equation can be given in terms of radicals, so the Wolfram Language uses an implicit symbolic representation:
In[2]:=2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-bfv
Out[2]=2

In[9]:= 9

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-n7w
Out[9]= 9

If what you want in the end is a numerical solution, it is usually much faster to use NSolve from the outset:
In[10]:= 10

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-xvr
Out[10]= 10

Root objects provide an exact, though implicit, representation for the roots of a polynomial. You can work with them much as you would work with Sqrt[2] or any other expression that represents an exact numerical quantity.
Here is the Root object representing the first root of the polynomial discussed previously:
In[6]:=6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-vv1
Out[6]=6

In[12]:= 12

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-bxo
Out[12]= 12

Round does an exact computation to find the closest integer to the root:
In[13]:= 13

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-b6n
Out[13]= 13

If you substitute the root into the original polynomial, and then simplify the result, you get zero:
In[14]:= 14

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-f3q
Out[14]= 14

In[15]:= 15

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-i84
Out[15]= 15

In[3]:=3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-u60
Out[3]=3

If the only symbolic parameter that exists in an equation is the variable that you are solving for, then all the solutions to the equation will just be numbers. But if there are other symbolic parameters in the equation, then the solutions will typically be functions of these parameters.
The solution to this equation can again be represented by Root objects, but now each Root object involves the parameter a:
In[7]:=7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-pdt
Out[7]=7

When a is replaced with 1, the Root objects can be simplified, and some are given as explicit radicals:
In[8]:=8

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-o2j
Out[8]=8

In[10]:=10

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-f7c
Out[10]=10

In[11]:=11

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-qw1
Out[11]=11

If you give Solve any
th‐degree polynomial equation, then it will always return exactly
solutions, although some of these may be represented by Root objects. If there are degenerate solutions, then the number of times that each particular solution appears will be equal to its multiplicity.


Solve gives two identical solutions to this equation:
In[21]:= 21

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ep2
Out[21]= 21

In[5]:=5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-y59
Out[5]=5

The Wolfram Language also knows how to solve equations that are not explicitly in the form of polynomials.
In[23]:= 23

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-cmk
Out[23]= 23

In[24]:= 24

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-xuu
Out[24]= 24

So long as it can reduce an equation to some kind of polynomial form, the Wolfram Language will always be able to represent its solution in terms of Root objects. However, with more general equations, involving, say, transcendental functions, there is no systematic way to use Root objects, or even necessarily to find numerical approximations.
In[25]:= 25

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-j9j
Out[25]= 25

In[26]:= 26

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-c4s

Out[26]= 26

In[27]:= 27

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-zgl
Out[27]= 27

Polynomial equations in one variable only ever have a finite number of solutions. But transcendental equations often have an infinite number. Typically the reason for this is that transcendental functions in effect have infinitely many possible inverses. With the default option setting InverseFunctionsTrue, Solve will nevertheless assume that there is a definite inverse for any such function. Solve may then be able to return particular solutions in terms of this inverse function.
The Wolfram Language returns a particular solution in terms of ProductLog, but prints a warning indicating that other solutions may be lost:
In[28]:=28

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-sv

Out[28]=28

If you ask Solve to solve an equation involving an arbitrary function like f, it will by default try to construct a formal solution in terms of inverse functions.
In[2]:=2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ps9

Out[2]=2

In[31]:= 31

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-rxb

InverseFunction[f] | the inverse function of f |
InverseFunction[f,k,n] | the inverse function of the n‐argument function f with respect to its k th argument |
In[32]:= 32

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-i2r
Out[32]= 32

In[33]:= 33

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-x53
Out[33]= 33

While Solve can only give specific solutions to an equation, Reduce can give a representation of a whole solution set. For transcendental equations, it often ends up introducing new parameters, say with values ranging over all possible integers.
In[105]:=105

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-x1m
Out[105]=105

In[106]:=106

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-zb7
Out[106]=106

As discussed at more length in "Equations and Inequalities over Domains", Reduce allows you to restrict the domains of variables. Sometimes this will let you generate definite solutions to transcendental equations—or show that they do not exist.
In[36]:= 36

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-mo8
Out[36]= 36

In[37]:= 37

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-biu
Out[37]= 37

Reduce knows there can be no solution here:
In[38]:= 38

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ft5
Out[38]= 38

Counting Roots of Polynomials
CountRoots[poly,x] | give the number of real roots of the polynomial poly in x |
CountRoots[poly,{x,a,b}] | give the number of roots of the polynomial poly in x with ![]() |
CountRoots accepts polynomials with Gaussian rational coefficients. The root count includes multiplicities.
In[1]:=1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-cewdfz
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-oqf
Out[2]=2

The roots of
in the vertical axis segment between
and
consist of a triple root at
and a single root at
:





In[3]:=3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-p8q
Out[3]=3

In[4]:=4

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-uum
Out[4]=4

In[5]:=5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-hm2kre
Out[5]=5

Isolating Intervals
A set
, where
is
or
, is an isolating set for a root
of a polynomial
if
is the only root of
in
. Isolating roots of a polynomial means finding disjoint isolating sets for all the roots of the polynomial.









RootIntervals[{poly1,poly2,…}] | give a list of disjoint isolating intervals for the real roots of any of the polyi, together with a list of which polynomials actually have each successive root |
RootIntervals[poly] | give disjoint isolating intervals for real roots of a single polynomial |
RootIntervals[polys,Complexes] | give disjoint isolating intervals or rectangles for complex roots of polys |
IsolatingInterval[a] | give an isolating interval for the algebraic number a |
IsolatingInterval[a,dx] | give an isolating interval of width at most dx |
RootIntervals accepts polynomials with rational number coefficients.
For a real root
, the returned isolating interval is a pair of rational numbers
, such that either
or
. For a nonreal root
, the isolating rectangle returned is a pair of Gaussian rational numbers
such that
and either
or
.









In[6]:=6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-erf
Out[6]=6

In[7]:=7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-mx9
Out[7]=7

In[8]:=8

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-g7b
Out[8]=8

Here are isolating intervals for the third- and fourth-degree roots of unity. The second interval contains a root common to both polynomials:
In[9]:=9

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-i9r
Out[9]=9

In[10]:=10

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-cw87kk
Out[10]=10

In[11]:=11

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-uh3
Out[11]=11

In[12]:=12

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-kl9
Out[12]=12

Root[f,k] | the k th root of the polynomial equation f[x]==0 |
When you enter a Root object, the polynomial that appears in it is automatically reduced to a minimal form:
In[37]:=37

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-glf
Out[37]=37

In[2]:= 2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-bm9
Out[2]= 2

Root objects are the way that the Wolfram Language represents algebraic numbers. Algebraic numbers have the property that when you perform algebraic operations on them, you always get a single algebraic number as the result.
In[38]:=38

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-cog
Out[38]=38

In[39]:=39

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-f55
Out[39]=39

In[40]:=40

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-xt9
Out[40]=40

Again this can be reduced to a single Root object, albeit a fairly complicated one:
In[41]:=41

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-brq
Out[41]=41

RootReduce[expr] | attempt to reduce expr to a single Root object |
ToRadicals[expr] | attempt to transform Root objects to explicit radicals |
In this simple case, the Root object is automatically expressed in terms of radicals:
In[7]:= 7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-x7h
Out[7]= 7

When cubic polynomials are involved, Root objects are not automatically expressed in terms of radicals:
In[42]:=42

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-vkr
Out[42]=42

In[9]:= 9

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-gt6
Out[9]= 9

If Solve and ToRadicals do not succeed in expressing the solution to a particular polynomial equation in terms of radicals, then it is a good guess that this fundamentally cannot be done. However, you should realize that there are some special cases in which a reduction to radicals is in principle possible, but the Wolfram System cannot find it. The simplest example is the equation
, but here the solution in terms of radicals is very complicated. The equation
is another example, where now
is a solution.



This gives a Root object involving a degree-six polynomial:
In[43]:=43

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-kc6
Out[43]=43

Even though a simple form in terms of radicals does exist, ToRadicals does not find it:
In[44]:=44

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-gqi
Out[44]=44

Beyond degree four, most polynomials do not have roots that can be expressed at all in terms of radicals. However, for degree five it turns out that the roots can always be expressed in terms of elliptic or hypergeometric functions. The results, however, are typically much too complicated to be useful in practice.
In[46]:=46

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-x2r
Out[46]=46

In[47]:=47

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ou6
Out[47]=47

In[48]:=48

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-jyw
Out[48]=48

RootApproximant[x] | converts the number x to one of the "simplest" algebraic numbers that approximates it well |
RootApproximant[x,n] | finds an algebraic number of degree at most n that approximates x |
In[2]:=2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-fgkflp
Out[2]=2

In[49]:=49

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-iwc63m
Out[49]=49

In[50]:=50

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-bzjdcu
Out[50]=50

You can give Solve a list of simultaneous equations to solve. Solve can find explicit solutions for a large class of simultaneous polynomial equations.
In[1]:= 1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-bql
Out[1]= 1

Here is a more complicated example. The result is a list of solutions, with each solution consisting of a list of transformation rules for the variables:
In[2]:= 2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-v68
Out[2]= 2

In[3]:= 3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-wez
Out[3]= 3

Even when Solve cannot find explicit solutions, it often can "unwind" simultaneous equations to produce a symbolic result in terms of Root objects:
In[6]:=6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-bp4
Out[6]=6

You can then use N to get a numerical result:
In[5]:= 5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-cyv
Out[5]= 5

The variables that you use in Solve do not need to be single symbols. Often when you set up large collections of simultaneous equations, you will want to use expressions like a[i] as variables.
In[6]:= 6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-vmx
Out[6]= 6

In[7]:= 7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-dtu
Out[7]= 7

Solve[eqns,{x1,x2,…}] | solve eqns for the specific objects xi |
Solve[eqns] | try to solve eqns for all the objects that appear in them |
If you do not explicitly specify objects to solve for, Solve will try to solve for all the variables:
In[8]:= 8

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-fth
Out[8]= 8

■ Solve[{lhs1==rhs1,lhs2==rhs2,…},vars] |
■ Solve[lhs1==rhs1&&lhs2==rhs2&&…,vars] |
■ Solve[{lhs1,lhs2,…}=={rhs1,rhs2,…},vars] |
Ways to present simultaneous equations to Solve.
If you construct simultaneous equations from matrices, you typically get equations between lists of expressions:
In[9]:= 9

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-s1u
Out[9]= 9

Solve converts equations involving lists to lists of equations:
In[10]:= 10

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-irs
Out[10]= 10

You can use LogicalExpand to do the conversion explicitly:
In[11]:= 11

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-dqz
Out[11]= 11

In some kinds of computations, it is convenient to work with arrays of coefficients instead of explicit equations. You can construct such arrays from equations by using CoefficientArrays.
If you have an equation like 2x==0, it is perfectly clear that the only possible solution is x0. However, if you have an equation like ax==0, things are not so clear. If a is not equal to zero, then x0 is again the only solution. However, if a is in fact equal to zero, then any value of x is a solution. You can see this by using Reduce.
In[1]:= 1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-yo7
Out[1]= 1

Reduce, on the other hand, gives you all the possibilities, without assuming anything about the value of a:
In[2]:= 2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-rmh
Out[2]= 2

A basic difference between Reduce and Solve is that Reduce gives all the possible solutions to a set of equations, while Solve gives only the generic ones. Solutions are considered "generic" if they involve conditions only on the variables that you explicitly solve for, and not on other parameters in the equations. Reduce and Solve also differ in that Reduce always returns combinations of equations, while Solve gives results in the form of transformation rules.
Solve[eqns,vars] | find generic solutions to equations |
Reduce[eqns,vars] |
reduce equations, maintaining all solutions
|
This is the solution to an arbitrary linear equation given by Solve:
In[3]:= 3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-lki
Out[3]= 3

Reduce gives the full version, which includes the possibility a==b==0. In reading the output, note that && has higher precedence than :
In[4]:= 4

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-6f
Out[4]= 4

Here is the full solution to a general quadratic equation. There are three alternatives. If a is nonzero, then there are two solutions for x, given by the standard quadratic formula. If a is zero, however, the equation reduces to a linear one. Finally, if a, b and c are all zero, there is no restriction on x:
In[5]:= 5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-hfx
Out[5]= 5

When you have several simultaneous equations, Reduce can show you under what conditions the equations have solutions. Solve shows you whether there are any generic solutions.
In[6]:= 6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ex8
Out[6]= 6

In[7]:= 7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-kfm
Out[7]= 7

The solution is not generic, and is rejected by Solve:
In[8]:= 8

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-wr3
Out[8]= 8

In[9]:= 9

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-xpc
Out[9]= 9

In[10]:= 10

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-2r
Out[10]= 10

This is the kind of result Solve returns when you give an equation that is always true:
In[11]:= 11

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-dzh
Out[11]= 11

When you work with systems of linear equations, you can use Solve to get generic solutions and Reduce to find out for what values of parameters solutions exist.
In[12]:= 12

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-wju
Out[12]= 12

In[13]:= 13

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-nz2
Out[13]= 13

In[14]:= 14

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-l20
Out[14]= 14

Solve reports that there are no generic solutions:
In[15]:= 15

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-nn8
Out[15]= 15

Reduce, however, shows that there would be a solution if the parameters satisfied the special condition a==2b-c:
In[16]:= 16

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-wxv
Out[16]= 16

For nonlinear equations, the conditions for the existence of solutions can be much more complicated.
In[17]:= 17

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-b8o
Out[17]= 17

Solve shows that the equations have no generic solutions:
In[18]:= 18

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-m84
Out[18]= 18

Reduce gives the complete conditions for a solution to exist:
In[19]:= 19

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-il0
Out[19]= 19

When you write down a set of simultaneous equations in the Wolfram Language, you are specifying a collection of constraints between variables. When you use Solve, you are finding values for some of the variables in terms of others, subject to the constraints represented by the equations.
Solve[eqns,vars,elims] | find solutions for vars, eliminating the variables elims |
Eliminate[eqns,elims] | rearrange equations to eliminate the variables elims |
In[1]:=1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-tlx
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-n34
Out[2]=2

In[3]:=3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-uc0
Out[3]=3

If you only want to solve for x, however, you have to specify whether you want to eliminate y or a or b. This eliminates y, and so gives the result in terms of a and b:
In[4]:=4

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-hr4
Out[4]=4

In[5]:=5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-cux
Out[5]=5

In some cases, you may want to construct explicitly equations in which variables have been eliminated. You can do this using Eliminate.
In[6]:=6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-edl
Out[6]=6

In[7]:=7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-syh
Out[7]=7

As a more sophisticated example of Eliminate, consider the problem of writing
in terms of the "symmetric polynomials"
and
.



To solve the problem, simply write f in terms of a and b, eliminating the original variables x and y:
In[8]:=8

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-gzf
Out[8]=8

In dealing with sets of equations, it is common to consider some of the objects that appear as true "variables", and others as "parameters". In some cases, you may need to know for what values of parameters a particular relation between the variables is always satisfied.
SolveAlways[eqns,vars] | solve for the values of parameters for which the eqns are satisfied for all values of the vars |
In[9]:=9

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-fpw
Out[9]=9

In[10]:=10

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-i0leyf
Out[10]=10

In[11]:=11

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-jqe
Out[11]=11

x==y |
equal (also input as
xy
)
|
x!=y |
unequal (also input as
x≠y
)
|
x>y | greater than |
x>=y |
greater than or equal to (also input as
x≥y
)
|
x<y | less than |
x<=y |
less than or equal to (also input as
x≤y
)
|
x==y==z | all equal |
x!=y!=z |
all unequal (distinct)
|
x>y>z
, etc.
|
strictly decreasing, etc.
|
In[1]:= 1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-wvd
Out[1]= 1

Not all of these numbers are unequal, so this gives False:
In[2]:= 2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-v84
Out[2]= 2

In[3]:= 3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-srp
Out[3]= 3

Since both of the quantities involved are numeric, the Wolfram Language can determine that this is true:
In[4]:= 4

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-d5c
Out[4]= 4

In[5]:= 5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-sep
Out[5]= 5

!p |
not (also input as
¬
p
)
|
p&&q&&… |
and (also input as
p∧q∧…
)
|
pq… |
or (also input as
p∨q∨…
)
|
Xor[p,q,…] |
exclusive or (also input as
p⊻q⊻…
)
|
Nand[p,q,…] and Nor[p,q,…] | nand and nor (also input as ⊼ and ⊽) |
If[p,then,else] | |
LogicalExpand[expr] | expand out logical expressions |
In[6]:= 6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-pjp
Out[6]= 6

You should remember that the logical operations ==, && and are all double characters in the Wolfram Language. If you have used a programming language such as C, you will be familiar with this notation.
In[7]:= 7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ow3
Out[7]= 7

In[8]:= 8

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-jd9
Out[8]= 8

You can use LogicalExpand to expand out the terms:
In[9]:= 9

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-cpc
Out[9]= 9

When you give a list of equations to Solve, it assumes that you want all the equations to be satisfied simultaneously. It is also possible to give Solve more complicated logical combinations of equations.
In[1]:= 1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-cws
Out[1]= 1

In[2]:= 2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-bl5
Out[2]= 2

This specifies that either x+y==1 or x-y==2. Solve gives two solutions for x, corresponding to these two possibilities:
In[3]:= 3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-xol
Out[3]= 3

Solve gives three solutions to this equation:
In[4]:= 4

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-s3x
Out[4]= 4

In[5]:= 5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-rym
Out[5]= 5

Here is a slightly more complicated example. Note that the precedence of is lower than the precedence of &&, so the equation is interpreted as (x^3==x&&x!=1) x^2==2, not x^3==x&&(x!=1 x^2==2):
In[6]:= 6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-f67
Out[6]= 6

When you use Solve, the final results you get are in the form of transformation rules. If you use Reduce or Eliminate, on the other hand, then your results are logical statements, which you can manipulate further.
In[7]:= 7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-tfy
Out[7]= 7

This finds values of x that satisfy x^5==x but do not satisfy the statement representing the solutions of x^2==x:
In[8]:= 8

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ceu5as
Out[8]= 8

The logical statements produced by Reduce can be thought of as representations of the solution set for your equations. The logical connectives &&, and so on then correspond to operations on these sets.
eqns1eqns2 | union of solution sets |
eqns1&&eqns2 | intersection of solution sets |
!eqns | complement of a solution set |
Implies[eqns1,eqns2] | the part of eqns1 that contains eqns2 |
You may often find it convenient to use special notations for logical connectives, as discussed in "Operators".
In[9]:= 9

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-w04
Out[9]= 9

Just as the equation x^2+3x==2 asserts that x^2+3x is equal to 2, so also the inequality x^2+3x>2 asserts that x^2+3x is greater than 2. In the Wolfram Language, Reduce works not only on equations, but also on inequalities.
Reduce[{ineq1,ineq2,…},x] | reduce a collection of inequalities in x |
In[1]:=1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-bgp
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-w5u
Out[2]=2

When applied to an equation, Reduce[eqn,x] tries to get a result consisting of simple equations for x of the form x==r1, …. When applied to an inequality, Reduce[ineq,x] does the exactly analogous thing, and tries to get a result consisting of simple inequalities for x of the form l1<x<r1, ….
In[3]:=3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-zdw
Out[3]=3

In[4]:=4

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-sui
Out[4]=4

You can think of the result generated by Reduce[ineq,x] as representing a series of intervals, described by inequalities. Since the graph of a polynomial of degree
can go up and down as many as
times, a polynomial inequality of degree
can give rise to as many as
distinct intervals.




In[5]:=5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-uop
Out[5]=5

In[6]:=6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-brt
Out[6]=6

Solving this inequality requires introducing ProductLog:
In[7]:=7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-qij

Out[7]=7

Transcendental functions like
have graphs that go up and down infinitely many times, so that infinitely many intervals can be generated.

In[8]:=8

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-o0a
Out[8]=8

This is how Reduce represents infinitely many intervals:
In[107]:=107

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-wfz
Out[107]=107

In[10]:=10

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-kh7
Out[10]=10

If you have inequalities that involve <= as well as <, there may be isolated points where the inequalities can be satisfied. Reduce represents such points by giving equations.
In[11]:=11

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-cfk
Out[11]=11

In[12]:=12

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-yvk
Out[12]=12

Reduce[{ineq1,ineq2,…},{x1
,
x2
,
…
}]
| reduce a collection of inequalities in several variables |
For inequalities involving several variables, Reduce in effect yields nested collections of interval specifications, in which later variables have bounds that depend on earlier variables.
In[13]:=13

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-shm
Out[13]=13

In geometrical terms, any linear inequality divides space into two halves. Lists of linear inequalities thus define polyhedra, sometimes bounded, sometimes not. Reduce represents such polyhedra in terms of nested inequalities. The corners of the polyhedra always appear among the endpoints of these inequalities.
In[14]:=14

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-etn
Out[14]=14

In[15]:=15

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-nc6
Out[15]=15

Lists of inequalities in general represent regions of overlap between geometrical objects. Often the description of these can be quite complicated.
In[16]:=16

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-l7
Out[16]=16

In[17]:=17

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-k7f
Out[17]=17

In[18]:=18

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-d6b
Out[18]=18

In[19]:=19

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-g0i
Out[19]=19

If you have inequalities that involve parameters, Reduce automatically handles the different cases that can occur, just as it does for equations.
In[20]:=20

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ob7
Out[20]=20

In[21]:=21

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-di0
Out[21]=21

Reduce tries to give you a complete description of the region defined by a set of inequalities. Sometimes, however, you may just want to find individual instances of values of variables that satisfy the inequalities. You can do this using FindInstance.
FindInstance[ineqs,{x1,x2,…}] | try to find an instance of the xi satisfying ineqs |
FindInstance[ineqs,vars,n] | try to find n instances |
In[22]:=22

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-tao
Out[22]=22

In[23]:=23

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-tcf
Out[23]=23

FindInstance is in some ways an analog for inequalities of Solve for equations. Like Solve, it returns a list of rules giving specific values for variables. But while for equations these values can generically give an accurate representation of all solutions, for inequalities they can only correspond to isolated sample points within the regions described by the inequalities.
Every time you call FindInstance with specific input, it will give the same output. And when there are instances that correspond to special, limiting points of some kind, it will preferentially return these. But in general, the distribution of instances returned by FindInstance will typically seem somewhat random. Each instance is, however, in effect a constructive proof that the inequalities you have given can in fact be satisfied.
If you ask for one point in the unit disk, FindInstance gives the origin:
In[24]:=24

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-27
Out[24]=24

In[47]:=47

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-e2r
In[48]:=48

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-z9
Out[48]=48

The Wolfram Language normally assumes that variables that appear in equations can stand for arbitrary complex numbers. But when you use Reduce, you can explicitly tell the Wolfram Language that the variables stand for objects in more restricted domains.
Reduce[expr,vars,dom] | reduce eqns over the domain dom |
Complexes | complex numbers ![]() |
Reals | real numbers ![]() |
Integers | integers ![]() |
In[1]:=1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-b3m
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ts4
Out[2]=2

In[3]:=3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-maq
Out[3]=3

A single polynomial equation in one variable will always have a finite set of discrete solutions. And in such a case, one can think of Reduce[eqns,vars,dom] as just filtering the solutions by selecting the ones that happen to lie in the domain dom.
But as soon as there are more variables, things can become more complicated, with solutions to equations corresponding to parametric curves or surfaces in which the values of some variables can depend on the values of others. Often this dependence can be described by some collection of equations or inequalities, but the form of these can change significantly when one goes from one domain to another.
In[4]:=4

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-jtn
Out[4]=4

In[5]:=5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-skl
Out[5]=5

In[6]:=6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-dek
Out[6]=6

If your input involves only equations, then Reduce will by default assume that all variables are complex. But if your input involves inequalities, then Reduce will assume that any algebraic variables appearing in them are real, since inequalities can only compare real quantities.
In[7]:=7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-f1r
Out[7]=7

For systems of polynomials over real and complex domains, the solutions always consist of a finite number of components, within which the values of variables are given by algebraic numbers or functions.
In[17]:=17

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-prj
Out[17]=17

In[18]:=18

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-via
Out[18]=18

While in principle Reduce can always find the complete solution to any collection of polynomial equations and inequalities with real or complex variables, the results are often very complicated, with the number of components typically growing exponentially as the number of variables increases.
In[10]:=10

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-itr
Out[10]=10

As soon as one introduces functions like Sin or Exp, even equations in single real or complex variables can have solutions with an infinite number of components. Reduce labels these components by introducing additional parameters. By default, the
th parameter in a given solution will be named C[n]. In general, you can specify that it should be named f[n] by giving the option setting GeneratedParameters->f.

In[11]:=11

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-y08
Out[11]=11

Reduce can handle equations not only over real and complex variables, but also over integers. Solving such Diophantine equations can often be a very difficult problem.
In[12]:=12

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ini
Out[12]=12

In[13]:=13

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-sur
Out[13]=13

In[14]:=14

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-whj
Out[14]=14

Reduce can solve any system of linear equations or inequalities over the integers. With
linear equations in
variables,
parameters typically need to be introduced. But with inequalities, a much larger number of parameters may be needed.



In[102]:=102

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-f2x
Out[102]=102

With two variables, Reduce can solve any quadratic equation over the integers. The result can be a Fibonacci‐like sequence, represented in terms of powers of quadratic irrationals.
In[103]:=103

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-frl
Out[103]=103

The actual values for specific C[1] as integers, as they should be:
In[104]:=104

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-vxj
Out[104]=104

Reduce can handle many specific classes of equations over the integers.
Here Reduce finds the solution to a Thue equation:
In[18]:=18

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-bhp
Out[18]=18

In[19]:=19

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ne4
Out[19]=19

Equations over the integers sometimes have seemingly quite random collections of solutions. And even small changes in equations can often lead them to have no solutions at all.
For polynomial equations over real and complex numbers, there is a definite decision procedure for determining whether or not any solution exists. But for polynomial equations over the integers, the unsolvability of Hilbert's tenth problem demonstrates that there can never be any such general procedure.
For specific classes of equations, however, procedures can be found, and indeed many are implemented in Reduce. But handling different classes of equations can often seem to require whole different branches of number theory, and quite different kinds of computations. And in fact it is known that there are universal integer polynomial equations, for which filling in some variables can make solutions for other variables correspond to the output of absolutely any possible program. This then means that for such equations there can never in general be any closed‐form solution built from fixed elements like algebraic functions.
If one includes functions like Sin, then even for equations involving real and complex numbers the same issues can arise.
Reduce here effectively has to solve an equation over the integers:
In[20]:=20

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-vle
Out[20]=20

Since there are only ever a finite number of possible solutions for integer equations modulo n, Reduce can systematically find them.
In[21]:=21

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-uyo
Out[21]=21

Reduce can also handle equations that involve several different moduli.
In[22]:=22

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-cid
Out[22]=22

Reduce[expr,vars,dom] | specify a default domain for all variables |
Reduce[{expr1,…,x1∈dom1,…},vars] | explicitly specify individual domains for variables |
In[23]:=23

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-pjg
Out[23]=23

Reduce normally treats complex variables as single objects. But in dealing with functions that are not analytic or have branch cuts, it sometimes has to break them into pairs of real variables Re[z] and Im[z].
In[24]:=24

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-j2o
Out[24]=24

In[25]:=25

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-yrb
Out[25]=25

Reduce by default assumes that variables that appear algebraically in inequalities are real. But you can override this by explicitly specifying Complexes as the default domain. It is often useful in such cases to be able to specify that certain variables are still real.
In[26]:=26

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-jcn
Out[26]=26

In[27]:=27

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-fmu
Out[27]=27

In[28]:=28

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-btx
Out[28]=28

In[29]:=29

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ont
Out[29]=29

FindInstance[expr,{x1,x2,…},dom] | try to find an instance of the xi in dom satisfying expr |
FindInstance[expr,vars,dom,n] | try to find n instances |
Complexes | the domain of complex numbers ![]() |
Reals | the domain of real numbers ![]() |
Integers | the domain of integers ![]() |
Booleans |
Reduce always returns a complete representation of the solution to a system of equations or inequalities. Sometimes, however, you may just want to find particular sample solutions. You can do this using FindInstance.
If FindInstance[expr,vars,dom] returns {} then this means that the Wolfram Language has effectively proved that expr cannot be satisfied for any values of variables in the specified domain. When expr can be satisfied, FindInstance will normally pick quite arbitrarily among values that do this, as discussed for inequalities in "Inequalities: Manipulating Equations and Inequalities".
Particularly for integer equations, FindInstance can often find particular solutions to equations even when Reduce cannot find a complete solution. In such cases it usually returns one of the smallest solutions to the equations.
In[30]:=30

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-twm
Out[30]=30

One feature of FindInstance is that it also works with Boolean expressions whose variables can have values True or False. You can use FindInstance to determine whether a particular expression is satisfiable, so that there is some choice of truth values for its variables that makes the expression True.
In[31]:=31

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-uhf
Out[31]=31

In[32]:=32

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-e9p
Out[32]=32

Any combination of equations or inequalities can be thought of as implicitly defining a region in some kind of space. The fundamental function of Reduce is to turn this type of implicit description into an explicit one.
An implicit description in terms of equations or inequalities is sufficient if you just want to test whether a point specified by values of variables is in the region. But to understand the structure of the region, or to generate points in it, you typically need a more explicit description, of the kind obtained from Reduce.
In[1]:= 1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-xdk
Out[1]= 1

In[2]:= 2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-k66
Out[2]= 2

Reduce gives a more explicit representation of the region:
In[3]:= 3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-otf
Out[3]= 3

If you pick a value for x consistent with the first inequality, you then immediately get an explicit inequality for y:
In[4]:= 4

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-csa
Out[4]= 4

Reduce[expr,{x1,x2,…}] is set up to describe regions by first giving fixed conditions for x1, then giving conditions for x2 that depend on x1, then conditions for x3 that depend on x1 and x2 and so on. This structure has the feature that it allows you to pick points by successively choosing values for each of the xi in turn—in much the same way as when you uses iterators in functions like Table.
In[5]:= 5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-l2s
Out[5]= 5

In some simple cases, the region defined by a system of equations or inequalities will end up having only one component. In such cases, the output from Reduce will be of the form e1&&e2…, where each of the ei is an equation or inequality involving variables up to xi.
In most cases, however, there will be several components, represented by output containing forms such as u1u2…. Reduce typically tries to minimize the number of components used in describing a region. But in some cases, multiple parametrizations may be needed to cover a single connected component, and each one of these will appear as a separate component in the output from Reduce.
In representing solution sets, it is common to find that several components can be described together by using forms such as …&&(u1u2)&&…. Reduce by default does this so as to return its results as compactly as possible. You can use LogicalExpand to generate an expanded form in which each component appears separately.
In generating the most compact results, Reduce sometimes ends up making conditions on later variables xi depend on more of the earlier xi than is strictly necessary. You can force Reduce to generate results in which a particular xi only has minimal dependence on earlier xi by giving the option BacksubstitutionTrue. Usually this will lead to much larger output, although sometimes it may be easier to interpret.
In[6]:= 6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-o41
Out[6]= 6

In[7]:= 7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-c04
Out[7]= 7

CylindricalDecomposition[expr,{x1,x2,…}] | |
generate the cylindrical algebraic decomposition of the region defined by expr | |
GenericCylindricalDecomposition[expr,{x1,x2,…}] | |
find the full-dimensional part of the decomposition of the region defined by expr, together with any hypersurfaces containing the rest of the region | |
SemialgebraicComponentInstances[expr,{x1,x2,…}] | |
give at least one point in each connected component of the region defined by expr |
For polynomial equations or inequalities over the reals, the structure of the result returned by Reduce is typically a cylindrical algebraic decomposition or CAD. Sometimes Reduce can yield a simpler form. But in all cases, you can get the complete CAD by using CylindricalDecomposition. For systems containing inequalities only, GenericCylindricalDecomposition gives you "most" of the solution set and is often faster.
In[8]:=8

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-diuxxo
Out[8]=8

In[9]:=9

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ju9f1f
Out[9]=9

In[10]:=10

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-cfyeur
Out[10]=10

In[12]:=12

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-p2j7gz
Out[12]=12

In a statement like x^4+x^2>0, the Wolfram Language treats the variable x as having a definite, though unspecified, value. Sometimes, however, it is useful to be able to make statements about whole collections of possible values for x. You can do this using quantifiers.
ForAll[x,expr] | expr holds for all values of x |
ForAll[{x1,x2,…},expr] | expr holds for all values of all the xi |
ForAll[{x1,x2,…},cond,expr] | expr holds for all xisatisfying cond |
Exists[x,expr] | there exists a value of x for which expr holds |
Exists[{x1,x2,…},expr] | there exist values of the xi for which expr holds |
Exists[{x1,…},cond,expr] | there exist values of the xi satisfying cond for which expr holds |
You can work with quantifiers in the Wolfram Language much as you work with equations, inequalities or logical connectives. In most cases, the quantifiers will not immediately be changed by evaluation. But they can be simplified or reduced by functions like FullSimplify and Reduce.
This asserts that an x exists that makes the inequality true. The output here is just a formatted version of the input:
In[1]:= 1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-czl
Out[1]= 1

FullSimplify establishes that the assertion is true:
In[2]:= 2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ip4
Out[2]= 2

In[3]:= 3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-rt8
Out[3]= 3

The Wolfram Language supports a version of the standard notation for quantifiers used in predicate logic and pure mathematics. You can input
as \[ForAll] or EscfaEsc, and you can input
as \[Exists] or EscexEsc. To make the notation precise, however, the Wolfram Language makes the quantified variable a subscript. The conditions on the variable can also be given in the subscript, separated by a comma.


∀xexpr | ForAll[x,expr] |
∀{x1,x2,…}expr | ForAll[{x1,x2,…},expr] |
∀x,condexpr | ForAll[x,cond,expr] |
∃xexpr | Exists[x,expr] |
∃{x1,x2,…}expr | Exists[{x1,x2,…},expr] |
∃x,condexpr | Exists[x,cond,expr] |
Given a statement that involves quantifiers, there are certain important cases where it is possible to resolve it into an equivalent statement in which the quantifiers have been eliminated. Somewhat like solving an equation, such quantifier elimination turns an implicit statement about what is true for all x or for some x into an explicit statement about the conditions under which this holds.
Resolve[expr] | attempt to eliminate quantifiers from expr |
Resolve[expr,dom] | attempt to eliminate quantifiers with all variables assumed to be in domain dom |
In[4]:= 4

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-pbn
Out[4]= 4

In[5]:= 5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-y09
Out[5]= 5

Resolve can always eliminate quantifiers from any collection of polynomial equations and inequations over complex numbers, and from any collection of polynomial equations and inequalities over real numbers. It can also eliminate quantifiers from Boolean expressions.
In[6]:= 6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-bbbyu5
Out[6]= 6

In[7]:= 7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-g6a
Out[7]= 7

You can also use quantifiers with Reduce. If you give Reduce a collection of equations or inequalities, then it will try to produce a detailed representation of the complete solution set. But sometimes you may want to address a more global question, such as whether the solution set covers all values of x, or whether it covers none of these values. Quantifiers provide a convenient way to specify such questions.
In[8]:= 8

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-fh8
Out[8]= 8

In[9]:= 9

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-i8h
Out[9]= 9

In[10]:= 10

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-fxu
Out[10]= 10

In[11]:= 11

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-yd6
Out[11]= 11

In[12]:= 12

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-hfa
In[13]:= 13

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-nqi
Out[13]= 13

Although quantifier elimination over the integers is in general a computationally impossible problem, the Wolfram Language can do it in specific cases.
In[14]:= 14

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-czf
Out[14]= 14

In[15]:= 15

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-q9t
Out[15]= 15

Minimize[expr,{x1,x2,…}] | minimize expr |
Minimize[{expr,cons},{x1,x2,…}] | minimize expr subject to the constraints cons |
Maximize[expr,{x1,x2,…}] | maximize expr |
Maximize[{expr,cons},{x1,x2,…}] | maximize expr subject to the constraints cons |
Minimize and Maximize yield lists giving the value attained at the minimum or maximum, together with rules specifying where the minimum or maximum occurs.
In[1]:= 1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-mmh
Out[1]= 1

In[2]:= 2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-cuf
Out[2]= 2

In[3]:= 3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-fv8
Out[3]= 3

Minimize[expr,x] minimizes expr allowing x to range over all possible values from
to
. Minimize[{expr,cons},x] minimizes expr subject to the constraints cons being satisfied. The constraints can consist of any combination of equations and inequalities.


In[4]:= 4

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-qm8
Out[4]= 4

In[5]:= 5

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-xw2
Out[5]= 5

In[23]:=23

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-f8q
Out[23]=23

In[7]:= 7

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-l94
Out[7]= 7

Minimize and Maximize can solve any linear programming problem in which both the objective function expr and the constraints cons involve the variables
only linearly.

In[8]:= 8

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-dxi
Out[8]= 8

They can also in principle solve any polynomial programming problem in which the objective function and the constraints involve arbitrary polynomial functions of the variables. There are many important geometrical and other problems that can be formulated in this way.
This solves the simple geometrical problem of maximizing the area of a rectangle with fixed perimeter:
In[9]:= 9

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-i2v
Out[9]= 9

In[10]:= 10

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-mss
Out[10]= 10

An important feature of Minimize and Maximize is that they always find global minima and maxima. Often functions will have various local minima and maxima at which derivatives vanish. But Minimize and Maximize use global methods to find absolute minima or maxima, not just local extrema.
In[62]:=62

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ioh
Out[62]=62

Maximize finds the global maximum:
In[12]:= 12

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-uzx
Out[12]= 12

If you give functions that are unbounded, Minimize and Maximize will return
and
as the minima and maxima. And if you give constraints that can never be satisfied, they will return
and
as the minima and maxima, and Indeterminate as the values of variables.




One subtle issue is that Minimize and Maximize allow both nonstrict inequalities of the form
, and strict ones of the form
. With nonstrict inequalities there is no problem with a minimum or maximum lying exactly on the boundary
. But with strict inequalities, a minimum or maximum must in principle be at least infinitesimally inside the boundary.



With a strict inequality, the Wolfram Language prints a warning, then returns the point on the boundary:
In[13]:= 13

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-h42

Out[13]= 13

Minimize and Maximize normally assume that all variables you give are real. But by giving a constraint such as x∈Integers you can specify that a variable must in fact be an integer.
In[14]:= 14

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-c42
Out[14]= 14

Minimize and Maximize can compute maxima and minima of linear functions over the integers in bounded polyhedra. This is known as integer linear programming.
In[6]:=6

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-dugo6
Out[6]=6

Minimize and Maximize can produce exact symbolic results for polynomial optimization problems with parameters.
In[2]:=2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-iium0o
Out[2]=2

MinValue[{f,cons},{x,y,…}] | give the minimum value of f subject to the constraints cons |
MaxValue[{f,cons},{x,y,…}] | give the maximum value of f subject to the constraints cons |
ArgMin[{f,cons},{x,y,…}] | give a position at which f is minimized subject to the constraints cons |
ArgMax[{f,cons},{x,y,…}] | give a position at which f is maximized subject to the constraints cons |
Maximize gives both the value and the position of a maximum:
In[1]:=1

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-i073oq
Out[1]=1

Use MaxValue if you only need the maximum value:
In[2]:=2

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-ctpalh
Out[2]=2

In[8]:=8

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-bgts72
Out[8]=8

In[24]:=24

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-dld3i
Out[24]=24

ArgMax gives a position at which the maximum value is attained:
In[3]:=3

✖
https://wolfram.com/xid/02t7eqho541fsrn3yy-kk0gam
Out[3]=3
