# What is the nature of the term 'variable', and is it used differently in math, computer science, and logic?

Say I'm given an expression and talk about x changing what do we really mean by this linguistically? What inferences can be drawn about the nature of variables from their practical usage?

When we talk about 'different' values of x is this simply values we give to x in our domain of discourse, we often encounter 'assignment' on variables by writing 'x=...' do we interpret that the variable is some constantly changing thing that takes these values or just more that 'if we had a number written instead of this letter'? How do we express the idea of 'variable' logically to understand these ideas more than in the formalism of substitution?

Why do we use this way of treating variables (in the most simple form)

We have an expression for example

3x+1

We can talk about this in a general way, what values do we expect this quantity to take for differing values.

We might write y=3x+1, we then write something like

'if x = 3'

and we'll say y = 10 but y is being used as a general term and we jump between these 'contexts', this seems odd to me, I understand the idea but it seems strange all the same.

In the same way, having

3x+1=10 is a statement and we can talk about it generally where x is no particular number, and even quantify over it using quantification logic, but again we may write

if 'x = 3' and we will write then 10=10 and the statement is true.

It seems strange to use this notation 'x=...' and to use 'if' or 'when' because are these 'variables' really changing or are we really just expressing the structure for where there is a specific number instead of a placeholder?

It begs the question, is it just a placeholder for 'some' value, or does it almost represent something that is somehow changing by itself (how can it do so on a piece of paper), if it is simply a place holder, saying 'when x=' or if 'x=1' seems strange to me, would we not perhaps best define some kind of 'replacement' operation instead of this kind of 'assignment'? Does x somehow have a value at all times? Or are we constantly jumping from context to context?

What is a variable, and how is it used?

• "variables" are not mathematical entities; they are symbols of the language used to describe mathematical objects. Commented Mar 15, 2022 at 12:52
• Does this answer your question? Ontological status of variables Commented Mar 15, 2022 at 12:53
• @MauroALLEGRANZA it does to a fair extent, I wrote my question badly, I think I've narrowed it to one simpler to understand. Commented Mar 15, 2022 at 16:30
• My favorite example is a polynomial: ax^2 + bx + c. In this case 'x' is the variable and 'a', 'b', and 'c' are constants. I am not sure if I could put into words why this is so, but it's perfectly obvious nonetheless. Commented Apr 29, 2022 at 22:23

The comments by Mauro are good. They get at the fact that the 'x', prior to replacement, is a different "type" of entity (that word being used loosely here) as compared to the 'x' which is assigned the value 3. The unbound 'x' is called a 'free variable', whereas the one with 'x=3' is called bound. That these are called variables is a misnomer: in the unbound case it simply a symbol, and in the bound case it is simply a name for the constant to which it is bound. To reiterate: the 'x' (bound or unbound) is a symbol not in the domain (model), whereas the 3 is a constant within the domain (model) under discussion.

What you seem to be indicating by 'replacement' actually is how the operation would be understood formally: the unbound 'x' is replaced with a constant '3' as far as the truth-definition is concerned, and then the (bound, definite) formula is evaluated. The unbound 'x' is, as you suggest, a 'placeholder'. That this operation is commonly called "assignment" is probably part of the confusion.

Any introductory text on formal logic will help clarify this for you by formalizing:

• A computable truth definition
• What "variables", both bound and unbound, are
• What it means to substitute a value for a variable, and how this fits into the truth definition

These are fundamental to any logic, and so will be found right near the beginning of all except the most gentle texts.

Good introductory logic books that I don't see recommended enough are Goldfarb's "Deductive Logic" and Chiswell+Hodges "Mathematical Logic". Or if you want a freely available PDF, I'll unashamedly promote the text I helped write, with the reservation that it focuses on combinatorial examples and eschews discussion of philosophical issues: https://www.cis.upenn.edu/~weinstei/PQT.pdf

The truth definition is due to Tarski: see https://plato.stanford.edu/entries/tarski-truth/ for a discussion. The original papers are in Polish, so this is likely a better starting point than the primary source if you wanted to learn more.

• One question, why is x bound in x=3? surely I can substitute anything that's not three and yield something with a false truth value? Commented Mar 15, 2022 at 23:19
• is it that we assume the truth value to be true in the case of the assignment, e.g a solution x=3, x is free as x=3 is a proposition, but the assignment x=3 is different? Commented Mar 15, 2022 at 23:32
• So in math, variables do not vary, but in computer programs, they do. Maybe math should pick a better name. Commented Apr 29, 2022 at 23:15
• @ScottRowe Well, I think that's more a bias of the task than the language. So, if you know the difference between an imperative and a declarative computer language (C++ vs. SQL), then it's fair to say that in SQL more variables are unknowns that are meant to be found, because the intent of the language is to query. C++ is used for telling a computer what to do, so more of the variables are used to complete a goal according to defined parameters. Languages are languages. It seems to me you confuse the nature of variables with the nature of thinkers. :D
– J D
Commented Apr 30, 2022 at 14:05
• You make more a statement about what you want to do with your time, methinks, than comment on the nature of variables. ; )
– J D
Commented Apr 30, 2022 at 14:07

I'm not entirely satisfied with any answers here, and I think I understand what you're asking. First, understand from semiotics the triangle of reference. Essentially, you have the notion of the 'symbol' and the 'referent'. For instance in the statement `x=3`, The `x` by convention is the symbol and 3 is the value to which the symbol refers. Yes, technically in one sense, they are both symbols (the term grapheme is used in linguistics), but by convention letters are used to indicate the use of a grapheme that will reference other graphemes. (The ancient Greeks used letters for numbers, so that wasn't really possible as a convention.) In fact, the letters `x` and `n` are used so frequently, they've become a shorthand for the notion of a variable itself.

Now, why use a letter to indicate a quantity? Well, simply put, in mathematics and logic, we often don't know what value we are discussing. In this usage, `x` is called an unknown. This is an important distinction because in common mathematical usage, a lot of people call unknowns variables, which isn't technically true. An unknown is a quantity that we do not know, and it can be represented by anything. A letter is just a convenient fiction, a place holder; it would be confusing to use digits to represent unknowns, because we use digits for known values. Digits name values. But, here is an important point. An unknown might not vary. It might be a constant. So, letters which represent unknowns are sometimes constants. And when we discover the values, they are known constant values even if they are represented by a letter. One example is the letter `e` as in 'e the mathematical constant'.

Another example is given the statement `2x+1=5`, at the start of the problem 'find the value x', `x` is an unknown. `x` IS NOT A VARIABLE! (But many people call it that erroneously thought 'the value' literally means one, constant, not changing quantity.) But following through on the steps, we find `x=2`. Now `x` is a known. And despite the fact that we used the letter `x`, at no point was `x` variable! But then, in the next math problem, a math teacher may write the function `f(x)=x^2` and tell you the domain is all reals. Now `x` is a variable and with assignment, is always known! Then in a third problem, It might be stated `f(x,y)=xy` find the partial derivative with respect to `x`, and then with `y`, which in calculus means, with the same equation, first hold one of the letters constant, than the other! And in the notation, none of this is indicated because one just has a letter.

There are some ways to deal with this. For instance, consider the ordered pair `(x,y)`. Is this a point? a line? a plane? Well, it's ambiguous notation since a point would require both to be constant, a line for one to vary, and a plane for both to vary over a domain of discourse. But we can use some logic notation to clarify:

`(x,y) ∃!x,y∈ℝ` read as 'the ordered pair x,y there is a unique (constant) x and y in the reals.
`(x,y) ∀x,∃!y∈ℝ` read as 'the ordered pair x,y for all x reals (the variable x) there is a unique (constant) y.
`(x,y) ∀x,y∈ℝ` read as 'the ordered pair x,y for all x and y in the reals (x and y are both variables).

The first is the definition of a point where `(2,4)` qualifies as 2 and 4 are constant in the expression. The second is a horizontal line `(x,4)` through `{(1,4),(2,4)}` usually just written as `y=4`. And the last has two variables so it would be defined by the plane determined by `(x,4) ∩ (3,y)` since there is a point `(x,y)` for any two real values assigned to `x` and `y`.

So to keep things straight, letters may be constant or variable, known or unknown, and generally mathematicians and logicians either tangentially mention or don't explicitly state it at all presuming from context you understand (because they understand, and if they understand, then everyone should understand)!

There's nothing magical about this; it's just that it's not convention to indicate the two dimensions of a variable in the symbolic notation. Sometimes when I teach, I put a small dot under a letter to indicate it's an unknown constant. For instance, if I were to write `ax + b`, I'd put a dot below both `a` and `b` to make it clear that we vary x, and not the constant terms of the polynomial, but most practitioners don't go out of their way. They presume you infer that the difference between `{a,b,c}` and `{x,y,z}` is that the former are used as constants and the latter are used as variables. Another common convention is to use `k` as in the equation `F(x)=-kx` which is an equation that describes the force of a spring. Here, `k` is a constant of proportionality.

The real take away is that many people call `x` a variable when they mean unknown or constant instead. They see the letter, say it's a variable, and give no thought to the context. Does `x` vary in the problem? Yes? It's a variable. If it doesn't, then it's not. But when you call all `x`s variables and then look at a problem where it is a constant, you are sure to get confused.

If you're really interested variables and reference, some additional articles you might read are "Sense and reference, "Type system", and "Anaphora". The first is the philosophical investigation of reference outside of semiotics, the second is understanding what computer compilers and interpreters model to allow for translation of programming instructions, and the last is the linguistics take on context and reference.

EDIT

can we have a statement 2x-5 be neither true nor false and have 'x' as a variable that provides either 'true' or 'false' for different value of x? (as in predicates)

The difference between `2x-5` and `2x-5<7` or in logic, `p^q` and `p^q≡T` is that both have variables, but the former are expressions, the latter statements. Expressions cannot be true or false because they don't predicate. You can think of all statements that are truth-conditional as implying predication. For instance, `Statement s is true such that s is '2+2=4'.` True! `Statement s is true such that s is 'T^F≡T'.` False! `Statement s is true such that s is 'p^q` Unknown! Depends! It is usually statement that gives the nature of the grapheme context. `2x-5`, `x` is unknown, and we don't know if it's a constant or a variable because there's no context. `2x-5<7`, `x` is a variable such that `x` is any number less than 6. `π` is a constant in an expression or a statement by definition. `2x-5<7 : x=100` is a statement with no unknown, because `x` is defined as a constant. In this sense, it's a placeholder for a value, not truly a variable.

we can still have sentences like 2x+5=15 without x being 'unknown' or 'constant' as long as we know the truth value of the statement can vary

We use a letter as a placeholder, as where it is known. E.g., `2x+5=15:x=5`. Here, x is known and is constant. E.g., `2x+5<15:x=5` Here, x is known and is constant. An expression with unknowns has no truth value and an indeterminate mathematical value. An expression with all knowns has no truth value and a determinate mathematical value. E.g., `2x+5`. Is `x` a constant or variable? No context. Who knows! but `2*3 +5`, while not true or false is clearly equivalent to 11. In the case of the statement `2x+5>y`, the truth value is indeterminate, and the nature of the two unknowns is unknown. If you were to see `2x+5>k`, you might suspect that `k` is a constant and x is a variable, but context would have to confirm.

Be careful here. `2x+5=15` has two unknowns at play, one explicit as `x` in which case if we can solve `x` and find a single variable the unknown is a constant. The other is the truth value of the statement itself! Until x is known, we cannot confirm or deny the veracity of the sentence. After solution, `x=5` shows us are unknown is now a known constant. But we also have the implicit unknown of the truth value of the statement `Is the statement s true such that s is '2x+5=15' when 'x=5'?` Yes! That is `s≡T`. So every math statement might contain math unknowns, and the veracity of the statement if represented by 'p' might be a logical unknown. We almost never write out the logical names of statements in mathematics, except in mathematical logic, like in model theory where we are primarily interested in the various truth values of a collection of statements.

(one last thing), you've quantified over y there, is that because y is a variable from a (Logical) point of view but a 'parameter' in the context of a line or plane? (In logic the only thing which is a constant is literally a name that refers to a number all the time like a =5 )

Parameters and arguments, at least in computer science are another word for variables and values assigned to it. One can write a function `String strOutputToConsole; System.out.println( strOutputToConsole );` and `strOutputToConsole` is a variable. We can assign any string we want to it. The moment we write `strOutputToConsole = "Hello, world!";` then `"Hello, world!" becomes the parameter. You can think the same way in mathematical functional notation, though I haven't heard it spoken as such. `Given y=f(x), let x be 6`would make`x`the variable and 6 the parameter. 'Qualification and quantification over' defines the nature of a binding of a symbol to a referent.`Let s be all statements regarding color`says, that whatever`s`is, it is a statement that has to invoke the concept of color. 'I'm happy' is not in`s`. Lastly, [existential quantification][12] makes a claim about the existence of something and is evaluated under truth-conditional semantics. One doesn't even have to use the symbol. `There exists something that contains something else.` Here, 'something' and 'something else' as an unknowns, and simply says that 'It is true that 'something' and 'something else' exist, and they have this relationship of containment'.

• Thanks for this, on the 'unknown' vs 'variable' thing can we have a statement 2x-5 be neither true nor false and have 'x' as a variable that provides either 'true' or 'false' for different value of x? (as in predicates) Commented Apr 30, 2022 at 9:38
• we can still have sentences like 2x+5=15 without x being 'unknown' or 'constant' as long as we know the truth value of the statement can vary? Commented Apr 30, 2022 at 9:40
• (one last thing), you've quantified over y there, is that because y is a variable from a (Logical) point of view but a 'parameter' in the context of a line or plane? (In logic the only thing which is a constant is literally a name that refers to a number all the time like a =5 ) Commented Apr 30, 2022 at 9:48
• I've edited to respond. Just remember that the exact technical usage isn't usually followed, and people just use 'variable' to mean a 'symbol which represents an unknown'. People just have lazy tongues, though for those of us who experience strong cognitive dissonance, it can be annoying to hear people play so fast and furious with meanings. Just look at the context to see if something is unknown, true, false, variable, constant, etc.
– J D
Commented Apr 30, 2022 at 14:16
• Is your definition of an 'unknown' anything which can be constant or a variable? So if we have a statement regardless of whether x is constant or variable its still unknown if we need to solve it? Commented Apr 30, 2022 at 14:33

I think the easiest way to explain this is by analogy. Imagine you have a machine, some kind of cosmic money exchanger. It has the following features:

1. A couple of slots that say "Insert Bills" and "Insert Coins"
2. A few dials that allow you to select the denomination and nationality of the money you get back (100 Euro bills, American 20s, 1000 Yen notes, etc)
3. A slot at the bottom where the exchanged money comes out

You set the dials, press the 'Go!' button, drop in money, and voila: currency exchanged.

So, °1 are variables, in which we can dump any currency we like. °2 are constants which we set to specific values before the operation begins. °3 is the functional outcome, which takes on a specific value dependent on the other two. Technically speaking, °3 isn't a constant or a variable; it's a representation of the internal process of the machine, the mechanism by which the input and the settings produce the exchanged currency. But we often refer to it as a variable because (frequently) the product of the mechanism becomes the input to something else, and thus acts like a variable.

These are the same whether we are doing math or science or programming. The main difference is that math and science are result-oriented while computer work is process-oriented. Math/science are largely atemporal. Like the machine above, we expect that when we set the constants, toss in values for the variables, and hit the 'Go!' button, we can go chug, chug, chug through the function or equation and produce a singular result. Of course, doing proofs and chaining functions in math becomes more process-oriented, since we have to do each step before we can do the next, but even that is generally aimed at some specific result. By contrast, programming flow is always temporal and usually cyclical, a constant loop through steps of code looking for changes in variables that will alter program flow. Because of this temporality, we end up with conditionals and control statements that don't generally appear in math/science (and when they do are usually handled a-temporally by listing out all conditions within the function).

This is what causes the confusion with the assignment operator (=). The assignment operator is used two ways in math:

• As a means for labeling a function for later use.
• f(x)=3x+1 means that the label 'f(x)' will represent the function '3x+1'
• As a means of indicating that two functions are equivalent.
• 3x+1=10 involves counterpoising two ostensible functions — f(x)=3x+1 and g(x)=10 (notice here that a constant is treated as a function with a single value) — so that they can be rationalized against each other

Because of the process orientation of computer science, however, these two uses become a bit blurred. In programing, the assignment operator becomes a storage operator: it indicates that the results of a particular instantiation (a single execution) of a function will be stored for later use in program flow. In most programming languages there are subroutines or functions that work act exactly the way functions work in mathematics, but they do it without the assignment operator. In other words, we'll have something like:

``````aResult = aFunction(alpha, beta)
``````

where 'aFunction' is a routine defined elsewhere, and the assignment operator stores an instantiation of that routine in 'aResult'.