Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

ExTeX --- Variables, Sets, and Tuples

Score:0/0/0
Actions:

Variables, Sets, and Tuples

Math Refresher 2, Bernd Gärtner(12 July, 2023)

1Variables

What is the sum of all numbers between 11 and 55? Let’s simply compute it: 1+2+3+4+5=151+2+3+4+5=15. What is the sum of all numbers between 11 and 100100? Let’s make the pupils spend an hour to compute it. At least this is what the teacher of Carl Friedrich Gauß intended when he gave this task to his class. Gauß, however, came back with the correct answer 50505050 almost immediately. He had realized that the sum can be written as follows:

1+2++50+100+99++51\displaystyle \begin {array}{crcrcccr}& 1 & + & 2 & + & \cdots & + & 50 \\ + & 100 & + & 99 & + & \cdots & + & 51\end {array}
As the two numbers above each other always sum up to 101101, and there are 5050 such pairs of numbers, the sum of all numbers is 50101=505050\cdot 101=5050. Gauß later became a famous mathematician. Here, he had cleverly used the fact that in summing up numbers, we can order and group the numbers as we like. The math terminology for this is that addition is commutative and associative. The order 1+2+...+1001+2+...+100 given by the teacher is much less practical than the order and grouping (1+100)+(2+99)++(50+51)(1+100)+(2+99)+\cdots + (50+51) that Gauß came up with. In fact, reordering and regrouping things in order to simplify computations is the mathematician’s bread and butter.

Mathematicians immensely like the argument of Gauß but at the same time see more behind it. In fact, whether we sum up to 100100, or to some other even number (for example 10001000) doesn’t really matter—the argument is always “the same.” Hence, mathematicians will try to prove a general theorem (a mathematical statement), involving a variable. The answer for the concrete number 100100 (or for 10001000, or for a milllion) can then be derived by plugging the concrete number into the variable. This would look as follows.

Theorem 1 (Kleiner Gauß, even version).

Let nn be a positive even number. Then the sum of all numbers between 11 and nn is n(n+1)/2n(n+1)/2.

We note that n(n+1)n(n+1) is the lazy mathematician’s shortcut for the multiplication n(n+1)n\cdot (n+1), and // stands for division. In an offset formula (such as the following) where we have more vertical space, we would write n(n+1)/2n(n+1)/2 as a fraction

n(n+1)2.\displaystyle \frac {n(n+1)}{2}.

Proof.Following Gauß, we write the sum as follows:

1+2++n/2+n+n1++n/2+1\displaystyle \begin {array}{cccccccc}& 1 & + & 2 & + & \cdots & + & n/2 \\ + & n & + & n-1 & + & \cdots & + & n/2 +1\end {array}
As the two numbers above each other always sum up to n+1n+1, and there are n/2n/2 such pairs of numbers, the sum of all numbers is (n/2)(n+1)=n(n+1)/2(n/2)\cdot (n+1)=n(n+1)/2.

The little box on the right indicates the end of a proof. In some older textbooks (and in math fiction), the end of a proof is sometimes denoted by q.e.d., quod erat demonstrandum, Latin for what was to be shown.

In this theorem and its proof, the symbol nn is a (mathematical) variable. It is a placeholder for an actual number, and the theorem tells us what numbers we are allowed to plug in (“Let nn be a positive even number.”) For example, when we plug in 100100, the sum is 100(100+1)/2=5050100\cdot (100+1)/2=5050, as we already know. For 10001000, we do not need to repeat the proof but simply plug in 10001000 to get that the sum of the numbers between 11 and 10001000 is 500500500500.

The cool feature of a theorem is that it gives the answer for infinitely many numbers, with only one proof; in this case we get the answer for all positive even numbers. But in fact, the numbers between 11 and nn always sum up to n(n+1)/2n(n+1)/2, also for a positive odd number nn such as 101101. We invite you to come up with your own argument for this. Even for n=0n=0, the theorem works if we use the convention that there are no numbers “between 11 and 00”, so the sum is 00 in this case. This means, we in fact have

Theorem 2 (Kleiner Gauß).

Let nn be a natural number. Then the sum of all numbers between 11 and nn is n(n+1)/2n(n+1)/2.

There is the related concept of a (mathematical) constant that simply gives a short name to a long number. For example, if we keep talking about the number 299792458299792458 (the speed of light in m/sm/s), we could start with “Let c=299792458c=299792458,” and then simply say cc whenever we mean 299792458299792458.

Variables are not only used in theorems. Mathematicians use them whenever they want to say something about all numbers (or other mathematical objects) of some kind. A typical use case is a sentence such as “We use x\sqrt {x} to denote the square root of a nonnegative number xx.” This tells us what 5\sqrt {5} means, but also 1.3\sqrt {1.3} or 0\sqrt {0}, as the variable xx can stand for all these numbers. In fact, in the first reading assignment we have already used variables such as S1S_1 and S2S_2 standing for true‐false statements. Back then, we called them placeholders, but the term variable is more appropriate for (mathematical) grown‐ups.

Exercise 3.

Place yourself into the mind of Carl Friedrich Gauß and answer the following questions (in less than an hour, preferably).

  1. What is the sum of the even numbers between 11 and 100100, i.e.

    2+4++100?\displaystyle 2+4+\cdots +100?

    Input (Number)

    Enter a number in the box. You can enter

    • a natural number, such as 22,

    • an integer, such as ‐7,

    • a quotient, such as 22/7, or

    • a terminating decimal, such as 3.14285.

    There may be more than one correct solution.

  2. What is the alternating sum of the numbers between 11 and 100100, i.e.

    12+34++99100?\displaystyle 1-2+3-4+\cdots +99-100?

    Input (Number)

    Enter a number in the box. You can enter

    • a natural number, such as 22,

    • an integer, such as ‐7,

    • a quotient, such as 22/7, or

    • a terminating decimal, such as 3.14285.

    There may be more than one correct solution.

2Sets

A set is a “bag” of elements, possibly infinitely many. These elements are typically numbers or some other entities. They are in the bag in no particular order, but no element occurs more than once. Sets are written in curly braces, and in between, we just list the elements. For example, the set of even numbers between 11 and 1010 is {2,4,6,8,10}\{ 2,4,6,8,10\} , and the set of odd numbers between 11 and 1010 is {1,3,5,7,9}\{ 1,3,5,7,9\} .

We can also write this as {1,7,5,9,3}\{ 1,7,5,9,3\} , as order doesn’t matter. But typically, the elements are displayed as a familiar sequence, just to make it more readable. We could even write {1,3,3,1,5,7,7,9,9}\{ 1,3,3,1,5,7,7,9,9\} , and this would mean the same thing as {1,3,5,7,9}\{ 1,3,5,7,9\} , since duplicates are simply ignored. If a set has many elements, we use abbreviations. For example, the set of numbers between 11 and 100100 is typically written as {1,2,...,100}\{ 1,2,...,100\} , and the set of odd numbers between 11 and 100100 as {1,3,...,99}\{ 1,3,..., 99\} , or {1,3,5,...,99}\{ 1,3,5,..., 99\} to make the pattern even clearer. As the dots notation is very practical but not mathematically rigorous, we have to be careful to avoid misunderstandings.

The set of integers between 11 and nn is {1,2,...,n}\{ 1,2,...,n\} , so variables can also naturally be used in sets.

The empty set (a bag containing nothing) is written as {}\{ \} or \emptyset . Elements may also be (text) symbols, such as in {,,,}\{ \uparrow ,\downarrow ,\rightarrow ,\leftarrow \} , or {True,False}\{ \text {True}, \text {False}\} .

Just as for numbers, there are also set variables and set constants, as in “Let SS be a set of nn numbers,” or “Let S={1,3,5,7,9}S=\{ 1,3,5,7,9\} .” Sets are usually denoted with upper‐case letters, sometimes calligraphic letters such as S{\mathcal S}.

Sets of numbers.So far, when we said “numbers”, we in fact meant natural numbers, the numbers we use for counting. There are infinitely many natural numbers. We could write the set of natural numbers as {0,1,2,...}\{ 0,1,2,...\} (computer scientists typically start counting from 00 instead of 11). For the set of all integers (positive or negative), something like {...,2,1,0,1,2,...}\{ ...,-2,-1,0,1,2,...\} would work. But this notation is a bit cumbersome, so it is more common to use standard names for such sets: N\N for the set of natural numbers and Z\Z for the set of integers.

The symbol R\R denotes the set of real numbers (the infinite bag containing all numbers that we typically deal with, including integers, decimal numbers such as 0.5,0.3460.5, 0.346, fractions such as 12,37\frac {1}{2},\frac {3}{7}, square and third roots such as 2\sqrt {2}, 153\sqrt [3]{15}, and other special numbers such as π=3.1415926...\pi =3.1415926...

By R+\R _+, we denote the set of nonnegative real numbers (numbers greater or equal to 00); R\R _- is the set of nonpositive real numbers (numbers smaller or equal to 00). There are also more exotic numbers, called complex numbers, and in fact, the number of possible kinds of numbers that mathematicians can come up with is infinite. But we will only need N,Z,R\N ,\Z ,\R , sometimes R+\R _+ and R\R _-.

As it is not always clear what we mean when talking about “a number”, we should generally say what kind of number we mean. For example, the Theorem “Kleiner Gauß” can without ambiguity be stated as follows: Let nn be a natural number. Then the sum of all natural numbers between 11 and nn is n(n+1)/2n(n+1)/2. But in this case, the extra precision is unnecessary. By “all numbers between 1 and nn”, even mathematicians mean the natural numbers 1,2,...,n1,2,...,n.

Variables that stand for natural numbers or integers are in most cases called i,j,k,,m,ni,j,k,\ell ,m,n. Variables that stand for real numbers are often called x,y,zx,y,z.

Exercise 4.

Which of the following sets are equal to {1,2,3,4}\{ 1,2,3,4\} ?

Input (Multiple Choice)

  • {3,2,1,4}\{ 3,2,1,4\}
  • {2,2,1,3}\{ 2,2,1,3\}
  • {1,2,1,3,1,4}\{ 1,2,1,3,1,4\}
  • {1,4,3,16}\{ 1,\sqrt {4},3,\sqrt {16}\}

Decide which of the provided answers are correct and select them by clicking on the corresponding boxes, thus marking them with a blue border like so:

  • Unselected
  • Selected
  • Unselected
  • Selected

Any number of the provided answers can be correct, including zero.

Exercise 5.

How many elements do the following sets have?

Inputs (Number)
{1,2,3}\{ 1,2,3\}
{3,2,2,1}\{ 3,2,2,1\}
{2,3,...,10}\{ 2,3,...,10\}
\emptyset

Enter a number in the box. You can enter

  • a natural number, such as 22,

  • an integer, such as ‐7,

  • a quotient, such as 22/7, or

  • a terminating decimal, such as 3.14285.

There may be more than one correct solution.

Exercise 6.

Let’s look at sets where all elements are between 1 and 10. For example, {1,2,3}\{ 1,2,3\} is such a set, {4,9}\{ 4,9\} is another one, and so on. How many such sets are there? The empty set \emptyset also counts. (You may first want to count the sets with elements between 11 and 22, and then add 33, and so on.)

Input (Number)

Enter a number in the box. You can enter

  • a natural number, such as 22,

  • an integer, such as ‐7,

  • a quotient, such as 22/7, or

  • a terminating decimal, such as 3.14285.

There may be more than one correct solution.

The mathematician immediately sees a general theorem here: Let nn be a natural number. There are 2n2^n sets with elements between 11 and nn. In fact, as we already have a symbol N\N for the set of natural numbers, we can use it and abbreviate “Let nn be a natural number” by “Let nNn\in \N .” Here, the symbol \in stands for “element of”, so that the abbreviation literally says “Let nn be an element of N\N .” The theorem then reads as follows.

Theorem 7.

Let nNn\in \N . There are 2n2^n sets with elements between 11 and nn.

3Tuples

A set is an unordered bag of elements. When we care about the order, we use tuples. A tuple is a “list” of elements where elements may also occur more than once. Tuples are written between normal braces. For example (2,5,2,6,3)(2,5,2,6,3) has five elements and is called a 5‐tuple. Here 22 comes first on the list, then 55, then 22 again, and so on. You can for example imagine that this tuple records the results of rolling a dice five times.

Hence, (2,5,2,6,3)(2,5,2,6,3) is not the same as (5,2,2,6,3)(5,2,2,6,3). 2‐tuples are also called pairs, 3‐tuples are triples, and 4‐tuples are quadruples (a term already less common). You occasionally still hear about quintuples, but anyone saying sextuple or septuple is probably a nerd. There are 1‐tuples and even 0‐tuples, written as ()(), but they are rarely needed. The dots notation (1,2,...,10)(1,2,...,10) naturally also applies to tuples, and even (1,1,...,1)(1,1,...,1) makes sense if we also say how many elements the tuple has. There are no infinite tuples; lists with infinitely many elements are called sequences.

Tuples are typically denoted by lower‐case letters (“Let p=(1,2)p=(1,2)”), sometimes in bold to distinguish them from numbers (“Let p=(1,2)\mathbf {p}=(1,2)”).

There is a fundamental difference between sets and tuples; even if {1,2}\{ 1,2\} and (1,2)(1,2) seem to be the same, they aren’t. In {1,2}\{ 1,2\} , there is no order between 11 and 22, while in (1,2)(1,2), 11 comes before 22. This isn’t just mathematical sophistry, it really lets you express different things; for example, if you want to say who competed in the 2018 world chess championship, you would write {Carlsen,Caruana}\{ \text {Carlsen},\text {Caruana}\} , but if you want to talk about the outcome, you would write (Carlsen,Caruana)(\text {Carlsen},\text {Caruana}).

Exercise 8.

How many elements do the following tuples have?

Inputs (Number)
(1,1,1)(1,1,1)
(6,5,6,4,3)(6,5,6,4,3)
(2,3,...,10)(2,3,...,10)
(x,y)(x,y)

Enter a number in the box. You can enter

  • a natural number, such as 22,

  • an integer, such as ‐7,

  • a quotient, such as 22/7, or

  • a terminating decimal, such as 3.14285.

There may be more than one correct solution.

Exercise 9.

How many different triples are there with all elements between 1 and 10? For example, (1,2,3)(1,2,3) is such a triple, (9,4,4)(9,4,4) is another one, and so on.

Input (Number)

Enter a number in the box. You can enter

  • a natural number, such as 22,

  • an integer, such as ‐7,

  • a quotient, such as 22/7, or

  • a terminating decimal, such as 3.14285.

There may be more than one correct solution.

Here is the mathematical theorem behind the previous exercise, this time with 22 variables.

Theorem 10.

Let n,kNn,k\in \N . There are nkn^k kk‐tuples with all elements between 11 and nn.

Exercise 11.

Which of the following statements are true?

Input (Multiple Choice)
  • 55 is the 44‐th element of {2,3,...,10}\{ 2,3,...,10\} .
  • A pair is a set with two elements.
  • (Ich,bin,ein,Berliner)(\text {Ich}, \text {bin}, \text {ein}, \text {Berliner}) is a 4‐tuple.
  • (1,2,...)(1,2,...) is a tuple.

Decide which of the provided answers are correct and select them by clicking on the corresponding boxes, thus marking them with a blue border like so:

  • Unselected
  • Selected
  • Unselected
  • Selected

Any number of the provided answers can be correct, including zero.

A tuple such as (6,5,6,4,3)(6,5,6,4,3) whose elements are numbers is typically called a vector. In contrast to tuples such as (Ich,bin,ein,Berliner)(\text {Ich}, \text {bin}, \text {ein}, \text {Berliner}), we can compute with vectors, but we will get to this only in later reading assignments. Vector variables are typically called u,v,wu,v,w.