In this chapter, we discuss Pascal’s triangle and explain the relevance of its entries to number theory.
As you are probably aware, n!, or n factorial, is the product of the first n positive integers, that is,
We define 0! to be 1. There are n! permutations of n distinct objects.
Let us consider the following problem. Given n distinct objects, in how many ways can we select k of them where order does not matter? If I have three extra tickets to a baseball game and I have 10 friends, in how many ways can I select the lucky trio of friends who will receive free tickets? Here, order does not matter. The choice Newton, Archimedes and Euclid is the same as the choice Euclid, Newton and Archimedes.
We begin with the first k factors of n!, namely, . This is because there are n ways to pick the first object, n − 1 ways to pick the second object, and so on till the last choice (the kth object), which can be made in (n − k + 1) ways.
The expression is too big to be the answer to our problem. To see this, consider the number of combinations of three objects from among six distinct objects. Let the six objects be the letters A through F. The three-letter choice ACD, for example, will be counted six times instead of once. It will appear in the list of permutations as ACD, ADC, CDA, CAD, DCA, and DAC. But we only want it (and all the other combinations such as ACE, etc.) listed once in the list of combinations. So we divide by 6—the number of permutations of three objects. This suggests the following procedure for the number of combinations of k objects chosen from among n distinct objects. Divide the product by k!. In symbols,
The symbol on the left of Equation 3.1 is pronounced “n choose k.” If we multiply the numerator and denominator by (n − k)!, we obtain the alternative formula
The numerator of the middle expression in (3.2a) is seen to be n! after we expand the (n − k)!, thereby realizing it supplies all the factors of n! that were missing in the numerator of 3.1.
Let’s rewrite (3.2a) without the middle expression:
The numbers k and n − k in the denominator of (3.2b) are called complements because they add up to n. If we replace each k by its complement, n − k, we obtain
or, more simply,
After all, choosing a meal of k dishes from a menu of n is equivalent to indicating the n − k dishes not chosen. Thus, to evaluate , it is easier to evaluate .
Observe that “n choose n” yields two answers, which may be compared. On the one hand, it is, using formula (3.2b), , while on the other hand, common sense tells us that the answer must be 1. (There is only one way to choose all n objects.) It follows that 0! must be 1. Moreover, it follows that .
Another useful observation is that .. This could, of course, be verified without the help of Equation 3.1 by using common sense. There are n ways to choose one item among n distinct items.
There is an ancient array of numbers called Pascal’s triangle, shown below up to the seventh row. (The name of the row is given by the second entry, printed in bold.)
Each entry is the sum of the two entries immediately above it. Thus, the first 35 in the seventh row is the sum of the 15 and 20 in the sixth row. You should have no trouble obtaining the entries of the eighth row using this method of generation.
Now, it is amazing that the entries of the nth row of Pascal’s triangle consist of the n + 1 combinatorial numbers:
These combinatorial numbers are the coefficients in the expansion of (a + b)n and are often called binomial coefficients. Moreover, the third entry of each row, that is, the numbers of the form , are the sums of the positive integers from 1 to n − 1, as can be seen by using equation 1.2 in Chapter 1, after replacing n by n −1. These numbers are triangular.
The principle used to generate the (n + 1)st row from the nth row can be written as
An asterisk (*) indicates that the exercise can be developed into a research project.
Iterative Factorial
<!DOCTYPE HTML>
<html>
<meta charset="UTF-8">
<head>
<title>Factorial Iterative</title>
<script>
function fac(ns){
var n = parseInt(ns);
var start = new Date();
var startmm = start.getTime();
var ans = 1;
for (var j=1;j<(n+1);j++){
ans *= j;
}
var now = new Date();
nowmm = now.getTime();
var elapsed = nowmm - startmm;
alert("ans is "+ans+" performed in "+elapsed+" msec.");
return ans;
}
</script>
</head>
<body>
Choose limit <br/>
<form name="f" onsubmit="return fac(this.num.value);">
<input type="text" name="num" value=" "/>
<input type="submit" value="Submit a number "/>
</form>
<p id="place">
The answer will go here.
</p>
</body>
</html>
Recursive Factorial
<!DOCTYPE HTML>
<html>
<meta charset="UTF-8">
<head>
<title>Factorial Recursive</title>
<script>
function fac(ns){
var n = parseInt(ns);
var start = new Date();
var startmm = start.getTime();
var ans = worker(n);
var now = new Date();
nowmm = now.getTime();
var elapsed = nowmm - startmm;
alert("ans is "+ans+" performed in "+elapsed+" msec.");
return ans;
}
function worker(n){
if (n<=1) { return 1;}
else {return n*worker(n-1);}
}
</script>
</head>
<body>
Choose limit <br/>
<form name="f" onsubmit="return fac(this.num.value);">
<input type="text" name="num" value=" "/>
<input type="submit" value="Submit a number "/>
</form>
<p id="place">
The answer will go here.
</p>
</body>
</html>
Pascal’s Triangle
<title>Pascal's Triangle</title>
<script>
function triangle(ns){
var limit = parseInt(ns);
var output = "<center>";
output +="1<br/>";
var last = [1];
var lastext;
var next;
var val;
limit––;
while (limit>=0) {
//unshift and push each change the array itself.
//Each returns new length
count = last.unshift(0);
last.push(0);
next = [];
for (var i=0;i<count;i++){
val = last[i]+last[i+1];
next.push(val);
output+=String(val)+" ";
}
output+="<br/>";
last = next;
limit––;
}
output+="</center>";
document.getElementById("place").innerHTML = output;
return false;
}
</script>
</head>
<body>
Choose limit <br/>
<form name="f" onsubmit="return triangle(this.num.value);">
<input type="text" name="num" value=" "/>
<input type="submit" value="Submit a number "/>
</form>
<p id="place">
The answer will go here.
</p>
</body>
</html>