# What is $x=5$ called??

I have CS background, and I'm trying to teach fundamentals of programming to students. They seem to have difficulties in understanding the difference between x=5 and x==5. However, trying to explain, made me wonder what the meaning of $x = 5$ is in mathematics.

Is there a concept of assignment in mathematics? Or is this an equation/binding/statement/something else? What is its proper name? And does the use of the $=$ operator differ from its use in the function below?

$$f(x) = \begin{cases} \displaystyle 1 \quad \text{if } x \bmod 2 = 0\\ \displaystyle 0 \quad \text{if } x \bmod 2 = 1\\ \end{cases}$$

Is there a classification of the uses of equality operator in math? Or is it the same in every case, and I just fail to see it?

• Usually, in math we have not an "assignment" operation. Commented Jan 15, 2018 at 12:29
• In your example about $f(x)$ you can see how the (missing) "assignment" operation is circumvented using equality; the definition can be read as a sort of specification: "if $x=0$, then $f(x)=1$; if $x=1$, then $f(x)=0$". Commented Jan 15, 2018 at 12:31
• It's precisely because there is no assignment in mathematics that x=5 in computer programming is so misleading for newbies. That's also I guess a reason why some languages use := or <- instead. Some math authors have stolen this and write for instance $x:=5$ for a definition. Commented Jan 15, 2018 at 12:31
• If I wanted an assignment, I might say "Let $x=5$". Commented Jan 15, 2018 at 12:34
• Notation in mathematics is usually like functional programming. However it is not true that one cannot use $=$ to mean a destructive assignation. In most of my papers I use it in that way. The only thing is that I need to make the clarification, because it is not common usage. Commented Jan 15, 2018 at 12:35

In addition to the "identity equals" and "conditional equals" that B.Goddard suggests, you might also teach "Yoda conditions" so that if an '=' is inadvertently omitted, a syntax error would result.

They are named for the famous Jedi master whose syntax is often reversed. In C-type programming languages, x == 5 and 5 == x are equivalent. Some environments, like WordPress, have programming practices that include Yoda conditions.

For example, if you mean to code

if( x == 5 ) { /* code */ }


but accidentally type

if( x = 5 ) { /* code */ }


you will have hours of pain trying to find your error. However, if you intend to code a Yoda conditional like

if( 5 == x ) { /* code */ }


but on accident type

if( 5 = x ) { /* code */ }


an error will result. No debugging necessary; the system tells you where the error is.

In other words, the difference between x = 5 and x == 5 is unique to CS. Your students simply need practice with it to understand it. In my opinion, Yoda conditions will help avoid a common error until the understanding is deep enough that making such an error will no longer be an issue.

It's not just you. Traditional mathematical notation is filled with ambiguous notations that you just have to distinguish on a case by case basis, using the context to guide you.

Without context, I would guess that $x = 5$ is preceded by something like $x^3 - 3 = 122$. Then $x = 5$ is an equation and the student is expected to "solve for $x$."

In the context of an iterated operation, the equals symbol can be used as an initial (or ending) assignment operator, e.g., $$\prod_{x = 5}^{200} \frac{1}{x^2 - 1}.$$ Of course in such a case, most people would prefer to use $i$ or $k$ rather than $x$. But still, the equals sign is used where a programmer might prefer ":=".

As for your negated parity bit function, there is a different symbol you could use to clear up some of the ambiguity, the equivalence symbol. e.g., $f(x) = 1$ if $x \equiv 0 \bmod 2$.

This Wolfram page might be helpful: http://reference.wolfram.com/language/tutorial/Equations.html

For my freshmen, I make the distinction between "identity equals" and "conditional equals." It seems to clear up some confusions. Identity equals means the sentence is always true, and for my context, includes "assignment" and "definition". So if we say "Let $u = x^2+5$" then we mean that this is true for all $x$ (in the current setting.) And if we say "$\cos^2 x+\sin^2 x =1$" we mean this is true for all $x.$

Conditional equals is when we write an equation and want to know when it is true. As in, "Solve $x^2+5x-1=0$."

I've never found a need to split the hairs more finely (in undergrad math classes.)

In mathematics, the $=$ sign can be used as a simple statement of fact in a specific case ($x = 5$), to create definitions (let $x=3$), conditional statements (if $x = 2$, then …), or to express an universal equivalence: $$(x^2+2x+1 )= (x+1)^2$$

When used in computer programming, the $==$ is a relational operator testing for equality unlike the $=$ reserved for assignments (w. r. t C programming).

For more, you can see here.

• It's not the same. In programming, $x=y$ means that $x$ is overwritten with the value of $y$. In mathematics, $x=y$ and $y=x$ are usually equivalent, and there is not such thing as assignment, for a simple reason: "variables" are not "overwritten". There is no lexical scope and variables are not "modified". Commented Jan 15, 2018 at 12:34
• Yes but it's still a bit wrong: in C, you are right. In Pascal, assignment is := and equality testing is =. In R, assignement is <- and equality testing is ==. In Common Lisp, assignment is (setf variable value). I suspect there are other conventions. Commented Jan 15, 2018 at 12:37
• This doesn’t really answer the question, since the question is asking about the mathematics of an assignment operator.
– Paul
Commented Jan 15, 2018 at 12:38
• @Jean-ClaudeArbaut You can also use = for assignment in R, except in really old versions, so they're basically interchangeable. There is some trickery with return values and chaining assignments (a <- b <- c versus a = b = c) which makes them not entirely equivalent, and specifying named parameters in function calls must be done with =. Commented Jan 15, 2018 at 12:53
• @Arthur I know, I use R quite a bit... However, it's usually considered a bad habit. Commented Jan 15, 2018 at 12:54

Normally in mathematics a variable is not variable in the sense that it varies throughout the discussion. This means that there is no real difference between the interpretations. In programmer language the closest analogue would be that mathematical variables are constants.

The statement $x=5$ should be interpreted as a statement claiming that $x$ is equal to $5$. It may be that we haven't defined $x$ yet in which case such a claim would define $x$ (since we assume that there exist such an $x$).

As for assignment the normal way would be to consider a sequence of values that $x$ would take over time and then one normally add index to it. Like when a programmer writes x := x+1 a mathematician would write $x_{n+1} = x_{n}+1$