# Algebra/Chapter 2/Variables

| ------------------------ | Algebra Chapter 2: An Introduction to Algebra Section 1: Mathematical Expressions | Mathematical Sentences |
2.1: Mathematical Expressions
In this section, we review the definitions and applications of variables and expressions. In case this is not review, we will attempt to go over the ideas carefully enough so that this section may serve as a first introduction.

## Algebra

Throughout the rest of the book, we will be talking about unknown values.

## Numerical and Algebraic Expressions

An expression is a collection of symbols you could put into a calculator and get a number. To be precise, an expression is a well-formed formula, but don't worry about the formal details. Expressions are things we can evaluate, and I like to call them "numbers in fancy clothing."
* Example 2.1.1: Determine which of the following below are expressions.
* ${\begin{aligned}{\text{4}}+2\\\end{aligned}}$
* This is an expression, since we can simply add $4+2$ and get $6$ .
* ${\begin{aligned}{\text{}4+10)/8\\\end{aligned}}$
* This is also an expression, since it can be evaluated to $14/8=7/4$.
* ${\begin{aligned}{\text{}*3+2\\\end{aligned}}$
* This is not an expression. Note that $3$ is not being multiplied by anything, and there is no right parenthesis to match left one.
* ${\begin{aligned}{\sqrt {-4}}\end{aligned}}$
* While ${\sqrt {-4}}$ cannot be evaluated, it is still an expression since it follows the rules of the order of operations.
All of the expressions in Example 2.1 above, along with the ones that we have worked with in Chapter 1 are referred to as numerical expressions. These are expressions that involve a set of numbers being placed together utilizing addition, subtraction, multiplication, and division. In these scenarios, we knew about the number values to work with. However, when working with mathematics or science problems it is frequently necessary to talk about numbers whose value you do not know immediately.
For example, suppose you are asked how many 1 × 1 squares fit inside a rectangle that measures 9 squares by 10 squares? In this case the number we do not know is "the number of squares." Some people answer correctly right away by saying "The number of squares that fit inside the rectangle is 90."
But how did they find this? They could say "The number of squares in the rectangle is equal to the number of squares of its length times the number of squares of its width. The rectangle is 9 squares long and 10 squares wide, so it contains 90 squares." This is a lot of words. We could express ourselves mathematically by writing:
${\begin{aligned}{\text{Area}}&={\text{Length}}*{\text{Width}}\\{\text{Length}}&=9{\text{ and }}{\text{Width}}=10\\{\text{Area}}&=9*10\\{\text{Area}}&=90\end{aligned}}$
For mathematicians, this is still a lot of writing. Mathematicians usually choose to name each unknown with just a single letter, mostly out of a need for conciseness (that is, shortness), since writing one letter is easier than writing a word. A variable is the letter (or symbol) we are using to represent an unknown number. We could rewrite the calculations above as:
${\begin{aligned}{\text{A}}&=L*W\\{\text{L}}&=9{\mbox{ and }}W=10\\{\text{A}}&=9*10\\{\text{A}}&=90\end{aligned}}$
Now that you're familiar with what expressions look like, let's consider a practical example.
* Example 2.1.2: A cup of coffee at my favorite café costs $2.00. I drink 4 cups of coffee a day. I want to calculate how much money I spent on coffee this week, and in all of this year.
* Let's start with figuring out how much I spend on coffee in a week.
* Let's call the total number of cups of coffee I drink in a week T. We can give a name to how much money I spend, lets call it C (for cost). C is an expression, but we need a more useful one involving T. Every cup of coffee costs $2.00, so:
* 0 cups of coffee costs $0, as 0×2 is 0.
* 1 cup of coffee costs $2, as 1×2 is 2.
* 2 cups of coffee costs $4, as 2×2 is 4.
* T cups of coffee costs ... $2T.
* So, 2T is an expression representing the cost of T cups of coffee.
* This is the first step in figuring out how much I spend on coffee in a week. To get further we need to know the value of T: how many cups of coffee I drink in a week. If I drink 4 cups a day, and there are 7 days in a week, this must mean that
* T = 4 × 7 = 28.
* By replacing T with the number we calculated we can see that
* C is the same as 2.00 × 28 = 56.00.
* So I spend $56.00 a week on coffee! Maybe I should cut back!
* What about how much I spend in a year? Well, we figure this out in the same way. Let's first think about a year, if we keep our names the same we still have that
* C is the same as 2.00 × T.
* But now there are 365 days in a year, so the total number of cups of coffee (that is the number T) changes. We can calculate it just as we did before, drinking 4 cups a day leads to:
* T = 365 × 4 = 1,460.
* Now that we know the value of T we can see that:
* C is the same as 2.00 × 1,460 = 2,920.00.
* Now I can see that I spend $2,920.00 a year on coffee. Yes, I need to cut back!!
Notice that solution of these two problems is basically the same, the only things that changes is the values of C and T. This is why they are called variables, because the exact numbers varied. Some of the numbers we used in this calculation do not change. For example, the number of days in a week is always 7. We may still use a letter to represent the number of days in a week if we want, but since the number is not going to change, we simply leave it as 7. Letters or symbols that represent specific unchanging numbers are called constants.
In practical situations what you think of as a constant sometimes depends on how you think about the problem. A careful reader may point out that there are not always 365 days in a year: on leap years there are 366. Since I was working out how much I spent for the year 2010, the number of days in the year is constant and equal to 365. If I wanted to make a table of how much I spent on coffee in the last 10 years, then it might be better to use a variable to represent the number of days in a year.
Another example, which might be familiar from physics, is the amount of acceleration of a falling object due to gravity. For most problems this acceleration is treated as a constant g = 9.8 m/s$^2$. However, for problems involving objects that aren't on Earth this may be a bad approximation. The value we used for g in equations concerning objects on other planets may not be considered constants. The problems here are not going to ask us to worry about when it is OK to treat the acceleration due to gravity as a constant, as that is much more appropriate for a physics course. For us, constants are going to be those numbers fixed in the problem and that do not change like the price of coffee in the example above or in some cases some very well known fixed numbers may come up (such as the number of cards in a deck, the number of days in a week, etc.).
Variables are typically written using letters, such as x, t, or C. For cultural reasons x is an extremely common choice for the name of a variable. But when naming a variable or constant yourself it is best to choose something connected to the problem such as C for cost, T for total, etc. This makes it much easier to make sense of the equations you end up looking at. Constants are typically written as the numbers themselves, such as 2, -5, and 0.75, or in some cases may be represented by letters, such as g (from above) and π.
As you can imagine, equations that come up are often more complicated than the equation in the preceding example. We are going to need some vocabulary for the different parts of the equations we encounter. For example, if I let G be the amount of gas I spend driving to the café each day, then the expression for how much I spend C might look like:
    2.00 × T + G × D
Now C is the sum of two things called terms. In this case there are two terms in the expression, namely 2.00 × T and G × D. A term of a sum is just one of the pieces we are adding together. In the expression 2.00 × T + G × D − 7 there are three terms. Two of the terms are 2.00 × T and G × D. There are two possibilities for handling − 7. The first possibility is to consider subtraction the same as addition and consider 7 to be the third term. The second possibility is that we think of subtracting 7 as adding −7. In this case we might say that the terms are 2.00 × T, G × D, and −7. To be honest, it doesn't really matter much how we choose to think of things, but we should try to be consistent. Since we used the word "sum" in the definition of term above, we shall try to consistently use the second possibility to describe terms that are subtracted instead of added.

### Coefficients

There are many ways to indicate that two numbers should be multiplied. You are probably most familiar with using the symbol ×, in equations such as 2 × 2 = 4. But because mathematics developed in many places, there are other symbols that sometimes get used and this becomes particularly important in algebra. Why have more than one notation? Believe it or not, for convenience! For cultural reasons the most common letter to choose for a variable is x, but now things can look confusing when we try to write out expressions like x × 2. It is just an unfortunate fact of life that our variable and our multiplication symbol look a lot alike. Add poor penmanship to this and you're asking for trouble! There are two common ways to deal with this. The first is to introduce another symbol for multiplication, namely a dot written in the middle of the line. For example instead of writing 2 × 2 = 4 one can write 2 · 2 = 4. Another even more common strategy is to do away with writing anything at all! Suppose I want to multiply x by 2. Since it can lead to confusion I do not want to write 2 × x. I could write, with our new dot notation 2 · x, or I could just be concise and decide you'll know what it means if I write 2x. That's right, I skipped writing any symbol for multiplication at all! This is known as implied multiplication, because I never really said I was multiplying, I just implied it. This is by far the most common way to express multiplying in algebra.
At first this may seem a crazy way to do things, but it works particularly well with our intuition about units. We are taught from elementary school that if I have 1 apple and someone gives me 1 apple then I have 2 apples. In the same way it seems very natural to write 1x + 1x = 2x. If I have 1 x and someone gives me 1 x then I will just have 2 x's. Because variables have such a strong similarity to our units in simple examples like this, it has been culture to never place the variable before the number in implied multiplication. While it may be in some technical sense correct, to write x2 for the product of 2 and x, people may not understand what it means. So always place explicit numbers before the variables when using implied multiplication.
Implied multiplication is also frequently used between two different variables, or even two whole expressions (provided you use parentheses). So we may encounter expressions like xy for the product of x and y, or x(a + b) for the product of x and a + b. Because implied multiplication is so common it gives us even more reason to use single letters for variables. While it might have been nice to use a variable YC for the yearly cost for my coffee, if I were not very careful to explain what I meant some readers may think this represents some variable Y multiplied by another variable C. On the other hand in complicated situations with lots of variables sometimes it is worth risking confusion to choose variable names that make sense.
Finally, you can use implied multiplication between two numbers. Just try it, if we wanted to write 2 × 2 = 4 using implied multiplication we would end up writing 22 = 4, but twenty-two is not four! Instead, we write one or both constants in parentheses: 2(2) = 4 or (2)(2) = 4. Both forms are correct. Follow what your teacher says when in doubt.

## Evaluating Expressions

We treat variables just like numbers — numbers that maybe we do not know at the beginning, but numbers nonetheless. When we know what the numbers associated with a variable are we can figure out what some expression we have written before equals. Suppose we are asked to find the value of x − 5 when x = 7. To do this we substitute 7 for x. This means we rewrite the expression, except everywhere we would write x we write 7. So we get 7 − 5, and now we can use simple arithmetic to figure out that the expression equals 2. If you look back to discussion analyzing my coffee drinking habits, you'll see see we substituted a few times already. Let's look at some more examples.
* Example 2.1.3: Find the value of xy − 9 when x = 2 and y = 3.
* We will do this in two steps. First we will substitute 2 for x to get:
* 2 · y − 9.
* Now we will substitute 3 for y to get:
* 2 · 3 − 9 = 6 − 9 = -3.
In the last line, since we had gotten to a problem of arithmetic we simply used the rules of arithmetic we are already familiar with. One time to be a little bit careful is when implied multiplication is involved. Consider the following example. We needed to use our precedence rules to work the simple arithmetic in the right order in order to figure out that the expression equals 2.
* Example 2.1.4: Evaluate 2x + 2 when x = 4.
* Solution. Substituting 4 for x we get:
* 2 · 4 + 2 = 8 + 2 = 10.
Notice a very subtle change when I rewrote the expression. Specifically I inserted a multiplication symbol where there was an implied multiplication. Imagine that I hadn't: the last line would have started 24 + 2, which is not what we meant! We wanted to multiply x by 2, since x = 4, that means we wanted multiply 4 by 2. The number 24 shouldn't be part of our calculation.
It is very important when evaluating expressions to follow the correct order of operations (Don't forget "Please excuse my dear aunt Sally"). For example
* Example 2.1.5: Simplify the expression 3x$^2$(2z+k) given that x is 2, z is 1/2 and k is 1.
* Solution. Writing first by substituting for x, we have
* 3 · 2$^2$ · (2z+k)
* Now substiting for z
* 3 · 2$^2$ · (2 · 1/2 + k)
* Finally we substitute for k to get:
* 3 · 2$^2$ · (2 · 1/2 + 1).
* First we need to figure out the value inside the parentheses, that is we need to calculate 2 · 1/2 + 1. The correct order to do this in is to first multiply, then add. That is 2 · 1/2 + 1 = 1 + 1 = 2.
* Now that we have figured out what is inside the parentheses, the problem is now to calculate:
* 3 · 2$^2$ · (2).
* We do the exponentiation first to get
* 3 · 4 · (2).
* Now we simply multiply, and our answer is 24.