Made with Mathematica
Pascal’s triangle is an infinite triangle of numbers with many internal patterns.
Start by creating a list of “1’s” in an upside-down V-pattern as seen in the figure above and imagine that this pattern goes on forever and ever to the lower left and lower right.
Next, using the two “1’s” in the second row, add them to get and place this “2” in the middle of the third row (halfway between the two “1’s” above it).
Next, move on to adding successive numbers in the third row and placing the sums underneath each pair and halfway between them: since in the fourth row, place a “3” halfway between the “1” and “2”; and since in the fourth row, place another “3” halfway between the “2” and “1” .
Continue in this manner: add successive numbers in the fourth row and place the sums underneath each pair and halfway between them in the fifth row: and
In the sixth row, the new numbers are and
Imagine continuing this process forever. Of course, you can’t literally do such a thing. However, given enough time, in theory, you could compute any of the infinitely many rows in this triangle. After all, infinity is really big!
There are many interesting patterns in this triangle, as well as interesting relationships to other parts of mathematics. For example, see if you can find the so-called triangular numbers in Pascal’s triangle.
Before getting into a description of how to use Wolfram Research’s Mathematica computer algebra system to make a dynamic version of this triangle, I will describe one of the most common applications, especially for young people: finding binomial coefficients and using the Binomial Theorem.
Binomial Coefficients
First off, you need to understand that a “binomial” is any mathematical expression of the form where and are symbols that can represent any “numerical quantity”: they could be particular real numbers, complex numbers, variables, or even matrices of the same dimension (they would each have the same number of rows and the same number of columns). Note that this expression has two “terms” (the and the ) — thus, the name, “binomial”.
For sake of comparison, a “trinomial” is a mathematical expression of the form having three terms. In general, if the number of terms in the expression is not specified, it is called a “polynomial“.
If multiplication of such numerical quantities is “allowed”, then powers of such a binomial can be “expanded”. For example, using the distributive property, we can write:
If multiplication is commutative, as it is in most “ordinary” number systems (it is not commutative for matrix multiplication), then so that where in the last step, as is common to do, I have dispensed with using a dot for multiplication and am just using “juxtaposition” (“implied multiplication”).
Therefore, if multiplication is commutative, In the last step, I went back to using a dot because I wanted to emphasize the “coefficients” of the answer. Notice that these coefficients are the same as the numbers in the third row of Pascal’s triangle. This is no accident.
Let’s see if the pattern continues. Expand the cube of a binomial: By the distributive property, we see that so Notice that this is the same as and that these coefficients are the same as the numbers in the fourth row of Pascal’s triangle.
For a fourth power, you should take the time to check that the answer is:
In general, to “expand” for use the numbers from row of Pascal’s triangle as the coefficients. Since is a binomial, these numbers can be called “binomial coefficients“.
There are a few different special notations for these numbers. For an integer and another integer the number in the row of Pascal’s triangle is mostly commonly denoted by the two notations and
For example, and
It turns out that these numbers are also of foundational importance in the field of combinatorics (part of discrete mathematics) and that where the exclamation point “!” represents the factorial function ( when and by definition). They occur with the fundamental idea of a “combination” of objects chosen from a group of objects, and the quantity is often called “n choose k“.
Binomial Theorem
With this notation in hand, we can write the following equation for any integer and it represents the conclusion of the Binomial Theorem:
A Dynamic Version of Pascal’s Triangle in Mathematica
The video in the title of this post is embedded below. In it, I describe how to create a dynamic version of Pascal’s triangle in Mathematica. The dynamic aspect refers to the number of rows of Pascal’s triangle that are displayed in the output. This can be changed by the user with a slider.
The first step to creating a dynamic (changeable) version of Pascal’s triangle in Mathematica is to create a static (unchangeable) version; and the first steps in creating a static version is to understand how to use Mathematica to compute binomial coefficients and to make “lists”.
Mathematica comes with many built-in “functions” or “commands”. One of them is “Binomial“. The syntax is Binomial[n,k]. If you enter this, with specific numbers plugged in for and , then the output will be the binomial coefficient For example, the input Binomial[7,4] returns an output of
Next, we want to know how to create a “list” of such values. A “list” in Mathematica is an expression of the form {a,b,c,…}, where the finitely-many a, b, c, etc… can be any kinds of objects, including numbers, matrices, polynomials, graphs, and even other lists. The most fundamental way to create a list using a “formula” is with the Table function. The general syntax Table[expression,{i,imin,imax}] generates a “list” of the values of expression as i runs from imin to imax in increments of 1 unit at a time.
For example, Table[i^2,{i,4,7}] will generate the list {16,25,36,49} of squares of 4, 5, 6, and 7 as output.
An example relevant for the task of creating Pascal’s triangle is the input Table[Binomial[5,k],{k,0,5}]. This generates the list which consists of the numbers in the sixth row of Pascal’s triangle.
We can even use Table in a nested way, either as Table[Table[Binomial[n,k],{k,0,5}],{n,0,5}], or more simply as Table[Binomial[n,k],{n,0,5},{k,0,5}] to generate a list of lists: {{1,0,0,0,0,0},{1,1,0,0,0,0},{1,2,1,0,0,0},{1,3,3,1,0,0},{1,4,6,4,1,0},{1,5,10,10,5,1}}, which includes all of the first six rows of Pascal’s triangle, plus some additional zeros (by “default”, Binomial[n,k] gives an output of 0 when n < k).
How can we get rid of the zeros? By making sure that, for each value of the value of only varies from 0 to (rather than 0 to 5). The input Table[Binomial[n,k],{n,0,5},{k,0,n}] will generate the output {{1},{1,1},{1,2,1},{1,3,3,1},{1,4,6,4,1},{1,5,10,10,5,1}}, which excludes the zeros.
The only thing left to do to create a static version of Pascal’s triangle is to “stack” these lists in a “column” and “center” them. This is accomplished with the function Column and the option Center with the following syntax: Column[Table[Binomial[n,k],{n,0,5},{k,0,n}],Center].
In fact, this last bit of code was used to generate the figure at the start of this post.
Finally, we need to make the output dynamic. We would like to allow the user to move a slider to change the number of rows. The key Mathematica function to accomplish this feat is Manipulate. In general, the syntax Manipulate[expression,{u,umin,umax}] will generate output animating the “values” of expression (which don’t have to be numbers), as the “animation parameter” u varies in a “continuous” way from umin to umax. If we want the output to be animated in a “discrete” way as u varies from umin to umax in increments of 1, we can modify the syntax to be Manipulate[expression,{u,umin,umax,1}]. We can also add the option LabelStyle -> Large at the very end so that the slider label (the animation parameter) will be “large”.
For the task at hand, the relevant code that will generate the first 11 rows in a dynamic fashion is: Manipulate[Column[Table[Binomial[n,k],{n,0,rows-1},{k,0,n}],Center],{rows,1,11,1},LabelStyle->Large]. Notice that the animation parameter here is “rows“.
We end with a gif of the output of this code: