Equations

"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.

This tests whether 2+2 and 4 are equal. The result is the symbol (RefLink[True, paclet:ref/True]):

2+2==4

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.

Assignments and tests.

This assigns x to have value 4:

x=4

If you ask for x, you now get 4:

x

This tests whether x is equal to 4. In this case, it is:

x==4

x is equal to 4, not 6:

x==6

This removes the value assigned to x:

x=.

The tests we have used so far involve only numbers, and always give a definite answer, either (RefLink[True, paclet:ref/True]) or (RefLink[False, paclet:ref/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:

x==5

If you replace x by the specific numerical value 4, the test gives (RefLink[False, paclet:ref/False]):

%/.x->4

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.

The two expressions are identical, so the result is (RefLink[True, paclet:ref/True]), whatever the value of x may be:

2 x+x^2==2 x+x^2

The Wolfram Language does not try to tell whether these expressions are equal. In this case, using (RefLink[Expand, paclet:ref/Expand]) would make them have the same form:

2 x+x^2==x (2+x)

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

This is an equation in the Wolfram Language:"Solving Equations" discusses how to solve it for x:

x^2+2 x-7==0

You can assign a name to the equation:

eqn=%

If you ask for eqn, you now get the equation:

eqn