Adam Rumpf: Math Person

Over the years I have written a large number of Mathematica programs, and still continue to do so. These projects started as an effort to teach myself Mathematica while working as a TA. Things have gotten a little out of hand, and as of today I have accrued over 200 Notebook files, all written during my spare time to explore a wide variety of topics of personal interest. In order to establish my nerd cred a small sample of this collection is provided below, and more will be added over time. I encourage you to have a look around to see if anything interests you. At the very least there are some pretty pictures.

Some of these projects have been uploaded to the Wolfram Demonstrations Project, and can be found at my author page. Others have been remade as Jupyter Notebooks for viewing online, and can be found on this site's Jupyter Notebook page. This entire collection is contained in a GitHub repository released under the MIT License. You can also browse the collection below. Every project includes a link to download the Notebook file as well as any online distributions. The creation date indicates when my original version was completed, but all files have since been cleaned up to make them more user-friendly. All of the files below are meant to be usable in a classroom setting to act as visual, interactive demonstrations. Please feel free to use and modify these programs however you wish.

Mathematica Demonstrations

GitHub Link

Filter by tag:

Displaying ?? demonstrations.

Bézier Curves

Created 9/8/2017

Download Notebook

Bézier Curves are parametric curves defined by a sequence of control points. Most people would be familiar with them from simple graphics programs like MS Paint. They are commonly used for drawing smooth curves that are easily adjustable by clicking and dragging the control points. The process of drawing a Bézier curve can be imagined by moving points at constant speed between each pair of control points, defining a new, smaller set of moving control points. This process is then repeated with the new set of even fewer control points, repeating until reaching only a single control point. The path of this single control point is the curve.

There are some interesting mathematical properties and applications of Bézier curves, but my main interest was in watching their drawing process. This demonstration animates the process of drawing a Bézier curve for a given set of control points. I am not sure whether the program, itself, has much educational value, but it does look really cool.

Tags: Computational Mathematics, Just for Fun, Pretty Pictures

Bifurcation Analysis

Created 2/20/2017

Download Notebook

This Notebook contains a collection of examples of common types of bifurcation, including: saddle-node bifurcation, transcritical bifurcation, pitchfork bifurcation, and Hopf bifurcation. For each type of bifurcation an example ODE system is given, the bifurcation analysis is presented, and finally a Manipulate environment is given to show how manipulating the parameter causes the equilibria to change.

A bifurcation occurs in a dynamical system when changing a parameter causes the qualitative behavior of the system to change. Varying the parameters of an ODE system will of course always cause the exact solution to change, but in some cases these changes are so extreme that the fundamental behavior of the system is completely different. Equilibria may appear or disappear, or may switch from being stable to being unstable, or the directions of orbits may change. The different types of bifurcation mentioned above describe different types of qualitative change.

Bifurcation analysis highlights one of the major differences between a dynamical systems class and a differential equations class: both involve the study of differential equations, but dynamical systems classes tend to focus on describing qualitative behaviors of a system whereas differential equations classes tend to focus on methods of exact or numerical solution. I personally find that the dynamical systems approach is usually more interesting and more immediately useful, and I believe that most aspects of math education would benefit from focusing less on calculation and more on fundamental understanding.

Tags: Calculus, Complex Numbers, Differential Equations, Dynamical Systems

Comparison of Single-Winner Voting Systems

Created 10/31/2017

Download Notebook

Wolfram Demonstrations Link

This is based on an interactive Flash demonstration by Ka-Ping Yee, which is meant to show how different, reasonable-seeming methods of evaluating ballots can affect the outcomes of single-winner elections. It also shows some of the problems that certain systems can have, such as the spoiler effect and non-monotonicity.

Most people do not think very much about election systems, and if you asked them to come up with a system for how to run a single-winner election they would probably just suggest the one method they are familiar with: everyone votes for a single candidate and the candidate with the most votes wins. This method is called first-past-the-post, and although it makes intuitive sense, it has a great many problems. Other election systems like instant runoff voting, Borda count, and approval voting are meant to avoid these problems, although they have varying degrees of success.

Tags: Mathematical Modeling, Voting Theory

Cobwebbing

Created 11/4/2014

Download Notebook

Jupyter Notebook Remake

Cobwebbing is a graphical technique for evaluating the long-term behavior of a discrete dynamical system. This demonstration automatically generates cobweb plots for a variety of test systems, although the method is meant to be used by hand to quickly analyze such a system without the need for a computer.

Specifically, cobwebbing is used for discrete dynamical systems for which the next iteration is given as a function \(f\) of the previous iteration. We first plot both the function and the \(y = x\) line on the same set of axes. Given an initial value \(x_0\), the next value should be \(f(x_0)\), which we can eyeball from the plot by drawing a vertical line up from \(x_0\) on the \(x\)-axis until it touches the function curve. Intuitively, if we wanted to find the next iteration, we would need to transfer this value back onto the \(x\)-axis and then draw another vertical line up from it. However, because we already have the \(y = x\) line drawn, if we simply draw a horizontal line from our current position to it we will automatically reach the \(x\)-coordinate corresponding to our current \(y\)-coordinate. Then we can simply move vertically from this location. This process can be repeated as many times as needed to approximate the sequence of values produced by the system, alternating between moving vertically to the \(f\) curve to evaluate the update step, and then horizontally to the \(y = x\) line to convert the \(y\)-coordinate to an \(x\)-coordinate.

The points where the function curve passes through the \(y = x\) line are the fixed points of the system, and in general an initial solution will either approach or diverge from certain fixed points (or possibly enter a periodic orbit around them), which is how the long-term behavior of the system can be estimated. The result often ends up creating stair-step or spiral patterns which look like cobwebs, hence the name. In chaotic systems, like the discrete logistic map with large growth rates, it provides a very clear picture of how complicated and messy things can get.

Tags: Chaos, Discrete Mathematics, Dynamical Systems, Mathematical Modeling, Pretty Pictures

Complex Newton's Method

Created 2/23/2016

Download Notebook

This is a demonstration of how Newton's Method works for complex-valued functions. Most Calculus students will learn about Newton's Method for finding roots of real-valued functions, and may be surprised to learn that it also works for complex numbers. They may also learn that the method does not necessarily always converge to the root nearest the initial guess due to "overshooting" in unexpected ways. For real numbers this phenomenon is not very interesting to look at, but for the complex numbers we can generate fascinating and beautiful fractal basins of attraction.

The main function of this demonstration allows the user to specify a function and a few other parameters, and outputs a coloring of a portion of the complex plane demonstrating the basins of attraction of the different roots. Note that this may take a while to calculate for some large cases with many nodes. For this reason I would not recommend running the entire notebook, but rather running the initialization code and then evaluating one function at a time.

Tags: Analysis, Calculus, Chaos, Complex Numbers, Computational Mathematics, Fractal, Optimization, Pretty Pictures

Complex Operations

Created 3/20/2017

Download Notebook

This is a lightweight visual demonstration of how familiar mathematical operations (addition, multiplication, trigonometric functions, etc.) affect the complex numbers, displayed as vectors in the complex plane. The user can select an operation or function and then click and drag the input vector or vectors to see how this affects the output vector. In particular, it is interesting to look at how changing just the magnitude or just the angle of an input vector affects the output.

Tags: Complex Numbers, Linear Algebra

Continued Fraction Square Packing

Created 5/23/2018

Download Notebook

This is a program for constructing geometric pictures of continued fractions. A continued fraction is a way to represent a real number as a sequence of integers, similar to how a decimal expansion is a way to represent a real number as a sequence of integers. The way to interpret a decimal expansion like "3.14159" is to recognize that each digit tells us the coefficient in a series of decreasing powers of 10, so the leading 3 should be multiplied by 1, then the 1 should be multiplied by 1/10, then the 4 should be multiplied by 1/100, and so on, and all of these values should be added together. Some numbers (like 2 and 564 and 5/8) can be represented exactly with finitely many decimal values, while others (like 1/3 and \(\pi\) and \(\sqrt{2}\)) cannot, but they can at least be approximated by specifying the first few terms and truncating the rest.

The continued fraction representation of a number comes from iteratively taking its integer part and inverting its fractional part. Taking \(\pi\) as an example, the integer part is 3 and the fractional part is \(0.14159\ldots\), so the first digit in our continued fraction representation is 3. Then we invert the fractional part to get \(1/0.14159\ldots = 7.06251\ldots\). That has an integer part of 7, so our second digit is 7. The fractional part can be inverted to get \(1/0.06251\ldots = 15.99659\ldots\), and so the next digit is 15. Going through the same process again will yield 1 and then 292 as the next two digits. Much like with the decimal representation, since \(\pi\) is irrational this process will never end, so we must choose to truncate it at some point. If we chose to do that here, then our continued fraction approximation of \(\pi\) would be expressed as \([3; 7, 15, 1, 292]\), the sequence of digits that we just found. The way to interpret a continued fraction representation is to plug the digits into a sequence of nested fractions of the form 3+1/(7+1/(15+1/(1+1/292))).

There is a geometric interpretation of this process, and that is what this program generates. Imagine that we draw a rectangle with height 1 and width \(\pi\), and that we attempt to draw as many unit squares as we can inside this box. If we start at the lefthand side and continue to the right, we can fit exactly 3 squares before running out of room, and the remaining 1 by \(0.14159\ldots\) space will be empty. Now suppose that we wish to fit as many squares of side length \(0.14159\ldots\) as possible into this empty space. We can rescale by multiplying everything by \(1/0.14159\ldots\) (which is \(7.06251\ldots\)), in which case the problem becomes trying to fit as many unit squares as possible into a 1 by \(7.06251\ldots\) unit space. The solution is obviously 7, with a remaining 1 by \(0.06251\ldots\) space. This process of iteratively packing squares and rescaling the gap is analogous to the above process of taking the unit part and inverting the fractional part, and it will produce the same sequence of integers.

This box packing process is very much like the process for generating a golden spiral, and in fact if we begin with a rectangle whose dimensions are 1 by \(\phi\) (the golden ratio) the two processes are exactly the same. Because the golden spiral involves packing a single square in each iteration, this implies that the continued fraction representation of \(\phi\) is \([1; 1, 1, 1, 1, \ldots]\), which is indeed true. It is for this reason that \(\phi\) is occasionally referred to as the "most irrational" number. Because all of the digits in the continued fraction representation are inverted, large digits indicates that the term contributes a small value to the overall sum, and so truncating a large digit leads to smaller truncation error than truncating a small digit. Because all digits of \(\phi\)'s continued fraction are the smallest possible positive integer, truncating its continued fraction leads to the largest possible truncation error, making it the number with the worst possible rational approximations.

Tags: Discrete Mathematics, Geometry, Number Theory

Continuous Versus Discrete Logistic Growth

Created 11/4/2014

Download Notebook

This demonstration serves as a good example of how continuous and discrete analogs of the same model can produce drastically different behaviors, and it involves one of the most famous examples from chaos theory. The logistic growth model is a very simple dynamical systems model for population growth. There is both a continuous version (taking the form of a differential equation) and a discrete version (taking the form of a discrete map). Both attempt to model the situation of population being limited by finite resources.

At first glance the two models seem very similar, and for many students first learning about differential and difference equations it may seem like there is no significant difference between the two approaches. They even produce similar results under certain circumstances, and if anything the discrete model may seem intuitively easier to understand. However, the discrete model begins to exhibit some very strange and chaotic behavior if the intrinsic growth rate becomes large enough. This behavior is unique to the discrete model, and nothing like it occurs in the continuous model.

Tags: Calculus, Chaos, Differential Equations, Discrete Mathematics, Dynamical Systems, Fractal, Mathematical Modeling, Pretty Pictures

Crowd Escape Panic Model

Created 5/1/2018

Download Notebook

This is an interactive version of a model described in the following 2000 article:

D. Helbing, I. Farkas, and T. Vicsek. Simulating dynamical features of escape panic. Nature, 407:487-490, 2000.

The article describes a dynamical systems model for crowds of people attempting to run to a building exit during a panic. The model is similar to those used in fluid dynamics. Each person is treated as a particle with a certain radius. Each particle attempts to move toward the exit, but they also repel each other if they get too close (incredibly strongly if they are within crush distance of each other). For each particle we can define a total force function that includes its own desired movement, repulsion from other particles and obstacles, body forces from intersecting particles and obstacles, and sliding friction past particles and obstacles. The total force can then be used to define the particle's acceleration vector, which in turn defines a system of ordinary differential equations to determine each particle's position as a function of time.

This demonstration implements the model and displays an animation of the crowd as it tries to reach the exit. Controls allow the user to change the layout of the room, including obstacles and the size of the exit. Particles are colored according to the amount of crush force experienced from the surrounding particles, becoming more red as the force increases. A plot is also displayed in the corner of the animation, with the green line indicating the number of successful exits and the red line indicating the total crush force.

Tags: Calculus, Differential Equations, Dynamical Systems, Mathematical Modeling

Domino and Tromino Tiling

Created 10/16/2017

Download Notebook

Wolfram Demonstrations Link

This file combines two related puzzles that involve tiling a chess board. The main purpose of the puzzles is to figure out for yourself whether tilings exist under certain circumstances, and how you could go about finding these tilings. The tromino puzzle, in particular, is often used as an introduction to proof by induction. This program makes use of the puzzles' solutions to compute tilings and display the results.

Domino Puzzle

Consider the problem of attempting to tile a chess board with dominos, each of which covers two adjacent squares. The goal is to cover the entire chess board with no gaps, no overlap, and nothing hanging over the edges. Obviously this can be done since the dominos can be laid out in rows like bricks.

What if we remove some squares from the chess board? If we just remove one square then the tiling is obviously impossible. A chess board contains 64 squares, so removing 1 leaves 63, and there is no way to cover an odd number of total squares if each domino covers exactly two squares. What if we remove two squares? That leaves 62, which is even and thus not immediately ruled out. To make things simple, suppose we remove the opposite corners of the chess board. Can it be tiled with dominos? What pairs of squares could be removed while still allowing a domino tiling?

Tromino Puzzle

Consider the problem of attempting to tile a chess board with L-shaped trominos, each of which covers three adjacent squares. This is impossible on a standard chess board because 64 is not divisible by 3.

What if we remove a single square from the board? Then we would have 63 squares, which is divisible by 3, and thus might be possible. Suppose, for simplicity, that we remove a corner from the board. Can it be tiled with trominos? What squares could be removed while still allowing a tromino tiling?

Tags: Discrete Mathematics, Just for Fun, Pretty Pictures

Dragon Curve

Created 5/6/2016

Download Notebook

The dragon curve is my favorite fractal, and considering how much I love fractals that is really saying something. Like all fractals it looks cool and has some interesting properties, like being self-similar and tileable and being two-dimensional in the limit despite each finite iteration being one-dimensional. However, unlike many fractals it is fairly simple to approximate in real life, and the final shape is completely unexpected based only on the first few iterations.

One of the several equivalent constructions of the dragon curve involves taking a thin strip of paper and folding it in half, end-to-end, several times (the number of folds corresponds to the generation number). Then unfold the paper, open each crease to form a 90 degree angle, and look at the edge of the strip. The first fold simply creates an "L" shape. Starting over and adding a second fold creates a roughly "?" shape. Including additional folds one-at-a-time and observing the resulting curve produces shapes that are not very interesting, but after around 6 or 7 folds the shape begins to become incredibly intricate and complex.

This Notebook defines a function that applies a recursive algorithm to draw a specified generation of dragon curve. Due to the recursive nature, the computational time increases exponentially as the generation number increases, so I would not recommend trying to draw anything past approximately 18 generations. I would also not recommend running the entire notebook at once, and instead running only specific blocks one-at-a-time.

Tags: Fractal, Just for Fun, Pretty Pictures

Duverger's Law

Created 7/22/2015

Download Notebook

Duverger's law is an empirical rule which holds that first-past-the-post elections tend to result in a two-party system. This is the expected outcome from tactical voting, wherein supporters of third-party candidates are coerced into abandoning their favorite candidate in favor of their preferred major party candidate in order to avoid the spoiler effect.

This demonstration implements a simple tactical voting model based on a sequence of successive elections. We begin with a set of parties lying on a one-dimensional political spectrum, each with a given number of initial supporters. We then simulate a sequence of elections. The behavioral assumption is that, if a person's preferred candidate did not win, they will consider shifting their support to the most successful candidate on their half of the political spectrum (centrist voters may shift in either direction because of this). There are parameters to adjust how quickly this occurs, as well as for introducing slight randomization.

Tags: Mathematical Modeling, Voting Theory

Epsilon-Delta Limit Definition

Created 9/3/2021

Download Notebook

This is a demonstration meant for use in discussing the epsilon-delta definition for the limit of a function. Most calculus courses begin by discussing the limits of functions, since the derivative is defined as the limit of a difference quotient. For the purposes of an elementary calculus class it is enough to have an intuitive understanding of what the limit represents (that the value of the function get "closer and closer" to the limit as the input gets "closer and closer" to some value) without really needing a mathematically precise definition, but the explanation given in most classes might seem uncharacteristically wishy-washy and hand-wavey for mathematics, at which point they may or may not be introduced to the real definition of the limit.

Tags: Analysis, Calculus

Fractal Shoulder Angels and Devils

Created 3/15/2016

Download Notebook

This is a joke based on the shoulder angel/devil trope for representing a character's internal struggle over an ethical dilemma. Occasionally in films the idea of a shoulder angel is toyed with by giving the shoulder angel, itself, its own tiny shoulder angel and devil. I thought it would be funny to carry that out to its logical conclusion.

The program generates fractal arrangements of shoulder angels and devils with adjustable parameters, including the relative scaling and position of each generation.

Tags: Fractal, Just for Fun

Graph Untangler

Created 2/5/2016

Download Notebook

I wrote this as a tool for myself during my first graph theory course for the purposes of solving graph isomorphism problems. A common way to try to determine whether two different embeddings actually represent the same graph is to imagine that the vertices and edges can be moved around. If one graph can be manipulated to look like the other, then they must be isomorphic, and the physical movements which occurred are a physical representation of the bijection from one graph to the other.

This file contains a very simple function that accepts a Mathematica Graph object and produces a circular embedding of the graph. The vertices can be clicked and dragged to move them around.

Tags: Graph Theory

Karush-Kuhn-Tucker (KKT) Conditions

Created 5/7/2018

Download Notebook

Wolfram Demonstrations Link

This is a graphical demonstration of the KKT conditions applied to a constrained nonlinear optimization problem. The KKT conditions generalize the method of Lagrange multipliers to allow for inequality constraints as well as equality constraints. They provide a set of algebraic conditions involving the objective function, the constraint functions, and their derivatives, which give necessary (and under the right circumstances sufficient) conditions for optimality. This provides us with a solution method for the optimization problem, since we can simply solve the system of equations defined by the KKT conditions.

There are four parts to the KKT conditions: stationarity, primal feasibility, dual feasibility, and complementary slackness. Stationarity ensures local optimality, and essentially means that the objective function should "flatten out" at the optimal solution (specifically, this requires that the gradient of the objective function be either zero or collinear with the gradients of the constraint functions). Primal feasibility is obvious, and just means that the given constraints must be satisfied. Stationarity and primal feasibility are both present in the method of Lagrange multipliers, while dual feasibility and complementary slackness are unique to the KKT conditions, and are there to deal with the possibility of the optimal solution lying strictly inside of the feasible set rather than on its boundary. Specifically, dual feasibility ensures that an optimal solution lie on the correct side of the boundary, while complementary slackness ensures that an interior optimal solution has a stationary objective.

This demonstration shows a 2D constrained optimization problem with a single inequality constraint. In the top left window, the contour lines of the objective are shown in gray, the feasible set (with its contour lines) is shaded blue, and the optimal solution is shown as a red dot. The user can click and drag to select a solution, and the KKT conditions for that solution will be shown in the other windows. Try moving the selected point around and watching how the conditions change in response.

Tags: Calculus, Optimization

Linear Transformations

Created 6/3/2020

Download Notebook

I wrote this demonstration while helping to teach a precalculus class that touched on linear algebra. One of the important observations that makes it possible to understand how a matrix acts as a linear transformation is to look at how multiplication by that matrix affects the standard unit vectors \(\mathbf{i} = (1,0)\) and \(\mathbf{j} = (0,1)\). Those two transformations correspond to the columns of the matrix, and define a linear transformation of the entire 2D plane by shearing, rotating, and reflecting everything in it. This can more clearly be seen by drawing the transformed version of the unit lattice, and possibly also including some images and showing how they are transformed by the matrix.

All of this is a bit hard to visualize when you just look at still images on the screen, so I decided to make an interactive demonstration that allows the user to click and drag the two transformed unit vectors to see how it affects the rest of the 2D plane in real time. As a sample image the letter F is drawn (its lack of symmetry makes it more obvious when rotations and reflections have occurred). The determinant of the matrix is also displayed. Things to keep an eye on include when the determinant becomes 0 and when it becomes negative.

Tags: Geometry, Linear Algebra

Monte Carlo Method

Created 9/13/2016

Download Notebook

Monte Carlo methods are a type of computational method for numerical integration based on random experiments. If the goal is to calculate the area within a particular curve, then a Monte Carlo method consists of randomly sampling points within a region of known area that surrounds the region of interest. In expectation, the ratio of points within the region of interest to points outside of the region of interest should equal the ratio of the two regions' areas, and because the surrounding region's area is known, this ratio can be used to calculate the unknown region's area. Due to the random nature of the experiment the ratio will not be exact, and may vary between realizations, but as the number of sample points increases the ratio should converge to the correct value.

This Notebook includes a visual demonstration of the Monte Carlo method applied to calculating two separate areas: the area under an arbitrary curve, and the area of a unit circle (which should be exactly pi, making this method a way to numerically approximate pi). For each experiment, the user can select how many points to randomly sample. Running and re-running the command should produce slightly different results due to the randomness. There are also functions to plot the approximation error as the number of sample points increases, to show how it generally decreases as the number of iterations increases.

Tags: Calculus, Computational Mathematics

Pascal's Triangle Fractals

Created 6/28/2015

Download Notebook

Pascal's Triangle is a triangular array best known for the property that its rows consist of the binomial coefficients. There are many other lesser-known properties of Pascal's triangle, including its relationship to the fractal Sierpiński Triangle. This is one of my favorite examples of a fractal appearing in an unexpected place.

A Sierpiński triangle can be generated by highlighting all odd entries in Pascal's triangle. Using the fact that each entry of Pascal's triangle is the sum of the two preceding entries, we can think of Pascal's triangle as an elementary cellular automaton (specifically Rule 60).

This program generates an instance of Pascal's triangle with the specified number of rows, and can color the entries depending on whether they are divisible by a chosen value. Highlighting the entries not divisible by 2 (i.e. the odd entries) generates a Sierpiński triangle. Choosing values other than 2 results in different fractals.

Tags: Discrete Mathematics, Fractal, Number Theory

Pythagoras Tree

Created 1/6/2016

Download Notebook

This is a simple program containing a variety of Manipulate environments to generate Pythagoras tree fractals with various parameters. A Pythagoras tree is generated iteratively by beginning with a square and then stacking two smaller squares on top of it, leaning against each other and meeting at the corner. The same process is then repeated on top of the two new squares, and then on top of the four new squares, and so on. The relative sizes of the two squares (or equivalently the angle at which they meet) determines the shape of the tree.

There is not much mathematical content here. The main purpose of the program is simply to generate cool-looking fractals, and so most of the options are related to the display.

Tags: Fractal, Just for Fun, Pretty Pictures

Recamán's Sequence

Created 8/25/2018

Download Notebook

Recamán's Sequence (sequence A005132 in the OEIS) is defined by an iterative process beginning at 0, at step \(n=0\). In step \(n\), we either take \(n\) steps backward or \(n\) steps forward. We go backward if doing so would take us to a nonnegative number that has not yet been visited, and otherwise we go forward. It is conjectured that this sequence includes every nonnegative integer exactly once.

This program is mostly meant for drawing pictures of Recamán's Sequence. Because each step is 1 unit larger than the preceding step, the most common way to draw it is using semicircular arcs to trace the path of the sequence on the number line. Doing so leads to interesting spiral patterns that illustrate the phases of rapid increase and of repeatedly bouncing back and forth to fill in areas that were previously unexplored.

Tags: Discrete Mathematics, Number Theory, Pretty Pictures

Remainder Graphs

Created 10/10/2017

Download Notebook

Wolfram Demonstrations Link

I was inspired to write this program by an article by Presh Talwalkar. It demonstrates a cool trick for determining remainders after dividing a large number by a small number. Because this also allows calculating remainders of 0, this also encompasses the topic of divisibility tests. Testing for divisibility by 7 is famously tricky compared to the other small numbers, but this graphical method gives a fairly easy solution.

As an example, suppose we wish to know whether 42,959 is divisible by 7. The process begins by writing the numbers \(0, 1, \ldots, 6\) in a circle and connecting them in a cycle with black arrows. Next, for each of these numbers, we multiply it by 10 and then evaluate the remainder after division by 7, and draw a green arrow from the original number to the result. For example, for 2, we multiply by 10 to get 20, then divide by 7 to get 14 with remainder 6, which means that we should draw an arrow from 2 to 6. At the end of the process we will have 7 black arrows and 7 green arrows.

With this graph in place, we begin at position 0 and then read the digits of 42,959 from left to right. Each time we read a digit, we advance around the black circuit that number of steps. Between each digit, we follow the green arrow that leads out of the current position. In this case, we begin at 0 and read the first digit, "4". Then we advance 4 places to position 4, and then follow the green arrow to position 5. The next digit is "2", so we advance 2 to arrive at 0, and then follow the green arrow to remain at 0. Next we take "9" steps to 2, follow the green arrow to 6, advance "5" digits to 4, follow the green arrow to 5, and finally advance "9" digits to arrive back at 0. The final position is the remainder after division by 7. In this case it is 0, indicating that 42,959 is, indeed, divisible by 7.

The reasons for why this method works are worth figuring out for oneself (see the article linked above). It also generalizes to any modulus besides 7, and doing so produces some interesting graphical representations of why the well-known divisibility tests that students learn in basic arithmetic work. For example, the graphs resulting from 2, 5, and 10 all have the property that every green arrow points to 0, indicating that, no matter where the black arrows take us, we will always reset our position to 0 between steps. As a result only the final digit matters, which is exactly what students learn for 2, 5, and 10. The graphs resulting from 3 and 9 both have the property that every green arrow is a loop, making them essentially meaningless. As a result only the total number of steps taken on the black arrows (which is the sum of all digits) matters, and that is exactly what students learn for 3 and 9. 11 is also rather interesting.

Tags: Discrete Mathematics, Graph Theory, Number Theory

Spirograph

Created 10/27/2016

Download Notebook

This is an interactive version of a Spirograph which displays the path of a pen attached to a disk rolling around a larger disk. There are controls to adjust the relative sizes of the disks, whether the small disk is inside or outside the larger disk, and where the pen is positioned (even allowing it to be outside of the disk). There is also a feature that displays a disk rolling on its edge around in circles.

This was originally written while teaching Calculus, which is when many students are introduced to the concept of polar and parametric coordinates. Part of the course material mentions epicycloids and hypocycloids, both of which are interesting in their own right and both of which show up in nature in some unexpected places, but I thought that it would be more impactful to show how they can all be generalized using this type of rolling mechanism.

Tags: Calculus, Just for Fun, Pretty Pictures

Taylor and Fourier Series Approximations

Created 11/6/2017

Download Notebook

Jupyter Notebook Remake

This demonstration shows how a Taylor Series or a Fourier Series approximation of a given function changes as more terms are added to the series. The Taylor and Fourier series' are both ways of representing functions as linear combinations of simpler functions (polynomial functions for Taylor and trigonometric functions for Fourier). They also have important applications in computational mathematics, since taking only the first few terms of the series can provide a simple approximation of a potentially complicated function within a small neighborhood.

This program includes two Manipulate environments: one for Taylor series and one for Fourier series. Both include a dropdown menu of example functions and a slider to select the number of terms to include. The Taylor series also includes a slider to select the center of the approximation. These can be used to show how well the approximations model the original function near or far from the center, and how adding more terms changes things.

Tags: Analysis, Calculus, Computational Mathematics

Triangle Centers

Created 2/2/2016

Download Notebook

If someone asks you to define where the "center" of a square is, there is a straightforward and unambiguous answer. The same is true for a rectangle, and for an equilateral triangle. For a general triangle, however, there are several different, reasonable responses that could all be considered a "center" in some way. The Encyclopedia of Triangle Centers defines over 38,000(!) different notions of what a triangle's center might be.

This demonstration allows the user to click and drag the corners of a triangle to adjust its shape, and defines four different classical triangle centers: the orthocenter (intersection of altitudes), the circumcenter (center of circumscribed circle), the centroid (intersection of lines from vertices to opposite midpoints), and the incenter (center of inscribed circle). All coincide for equilateral triangles but generally differ for other triangles, and occasionally even lie outside of the triangle.

The orthocenter, circumcenter, and centroid also possess the property of always being collinear. The line through them is called the Euler line. The incenter in general does not lie on the Euler line, unless the triangle is isosceles.

Tags: Geometry

Vector Kinematics

Created 8/28/2017

Download Notebook

This demonstration is meant for elementary Calculus students encountering the concept of position, velocity, and acceleration vectors for the first time. It includes a series of Manipulate environments which describe various kinematic systems such as ballistic motion and rotational orbiting. Within each system there is a time slider to animate the system, and there is a toggle to select whether to display the position vector (with its \(x\)- and \(y\)-components), the velocity vector (with its \(x\)- and \(y\)-components), the acceleration vector (with its \(x\)- and \(y\)-components), and the velocity vector along with the acceleration vector. The purpose of these animations is to give a visual demonstration of how the velocity vector describes where the position vector is "about" to move to, and how the acceleration vector does the same for the velocity vector.

Tags: Calculus, Differential Equations, Dynamical Systems, Linear Algebra

Winner-Take-All Distortion

Created 11/26/2016

Download Notebook

This is a demonstration of how the preferences of the voter base can be distorted when their results are aggregated across a series of winner-take-all elections. For a variety of purposes voters are usually grouped into electoral districts. Rather than simply tabulating all individual votes, instead a separate winner-take-all election is run within each district, and only the district-level results are used to determine the overall result. For example, in the United States, presidential elections are carried out using the Electoral College where, in essence, each state runs its own statewide presidential election, and whomever wins in the state receives all of that state's support for the purposes of determining the overall result.

This can distort the actual preferences of the voters due to wasted votes. For the purposes of a winner-take-all election, winning with 51% of the vote is as good as winning with 100% of the vote, so winning by narrow margins in a large number of districts can cause a candidate's advantage to expand to far beyond what it would be if every individual were polled directly. If this occurs in enough districts it can change the outcomes of elections to allow someone to win even if another candidate receives more votes. This same effect can also occur for elections with multiple winners, like congressional elections, which may result in the numbers of congressional seats won by each party being significantly different from their actual support among the voter base.

Incidentally, the Electoral College also distorts results by directly giving a disproportionately large amount of weight to smaller states (and the Senate does the same thing to an even greater extent), but even if each state were to receive representation proportional to their population, the winner-take-all aspect of the election would still distort results. Among other things it tends to push out third party candidates, since the only way for a small party to win even a single seat would be to have a large enough amount of support concentrated in a single district to achieve a plurality there.

The net effect of all of this is that the geographic distribution of a party's voters can determine the party's success in an election. This also makes the system susceptible to things like gerrymandering, wherein electoral districts are drawn to intentionally distort results in favor of one party, but as this demonstration shows it can also occur even without intentional interference. There are different electoral systems, like direct representation and mixed-member proportional representation, which are immune to these issues, but at least within the United States a person's voting power is largely determined simply by where they happen to live.

Tags: Mathematical Modeling, Voting Theory