Git Teaching

I’m back in Santa Cruz again, where the Fall quarter just began.  Fall in Santa Cruz means warm weather, busy surf on weekends, and time to Git Teaching!

Overhead surf wrapping around the Lane, September 24, 2016.

In the programming community, Git and GitHub are popular tools for version control and sharing.  As a pair, they accelerate project development and collaboration.  I didn’t use them for writing the book (regrettably), but I decided to use them to create and share teaching materials.  Thanks to the Udacity course on Git/GitHub, I was able to pick up the basics in about 5 hours.  So what do I mean by using Git for teaching?  I now have two public Git repositories on GitHub.

Git Lesson Plans

The first contains my lesson plans for the quarter.  Since this is at least the 10th time I’ve taught this material, I usually prepare for class by scribbling down a half-page of notes to myself.  I wanted something almost as quick as scribbling, but which would be easy to share with the world (and perhaps to polish later).  So I made a little lesson plan template, made 20 copies (for 20 lectures), and put it up on GitHub.  Using Markdown is almost as quick as scribbling, since I can edit it right in my web browser at GitHub (then print a copy for class).  You can see my first lesson plan, from last Thursday.

Git Assessment Generator

The second repository is more ambitious.  Since I’m teaching 70+ students, I want to create quizzes with some randomly generated questions.  I considered ad-hoc solutions with PythonTex, started poking around, and realized that there isn’t a sufficiently general Python package for creating and rendering questions for math assessments.  Webwork has PGML and MathObjects.  But this is PERL-based, oriented towards calculus and online assessments, and not as flexible as I wanted in the creation and rendering of questions and answers.  I found myself a bit over my head in programming, but a contribution from Janis Lesinskis got things off the ground.  His began the project at his GitHub repository.  I forked the project at my repository and added code for flexible Python-generated questions.  It’s not close to ready for the public, but I think Janis set up a great foundation on which I can build something useful.  I’ll build it further as I write the first quizzes for my class, and I hope to leverage the power of LaTeX, Python, and the Jinja for templating.

How are these related to the Illustrated Theory of Numbers?

The Illustrated Theory of Numbers is a text, designed primarily for print media.  It is not open-source, though I am sharing some excerpts and some methods I used to create it.  On the other hand, I want to build an open community to share resources related to teaching number theory — lesson plans, assessments, and resources outside of the text I’m writing.  My own lesson plans might be helpful to instructors who wish to teach out of the book I’m writing, and so I’m happy to post them for the world to see.  Similarly, writing quizzes is time-consuming, and I think that sharing assessments is a good way to build a community.

Unlike the calculus textbook industry, I don’t want to put out new editions every year, charge for online accessories, etc..  I hope that by the time the book appears in print (mid-2017?), students and faculty can find a great set of free complementary resources online.



Colorful programming

A few months ago, I signed up for CS 101 at  This provided a wonderful introduction to the Python programming language.  I was a pretty good Turbo Pascal programmer in high-school (early 1990s), but my programming since then had only involved short snippets in R (for statistics), SAGE (for research mathematics), and a bit of experimentation in javascript.  With Python, I finally feel like I can playfully program again.   I don’t have to worry about declaring various classes and main() things to control window objects.  Programming is fun and simple again, even if I’m only using basic functional programming constructs.

Beyond the fun, Python is useful to me in two ways. First, SAGE is wisely built upon Python, so by learning Python I can do much more in SAGE. Second, by using a Python script to output TikZ code (nothing fancy – just some string manipulations), I can create data-dense PDF graphics with mathematical precision and quality typography and color.  In other words, I have control over the graphics in my book.  Any ugliness or error is my own. An example of a graphic created with a Python script, TikZ, and LaTex, is the opening graphic for Chapter 3 found below. The Sieve of Eratosthenese is visualized by different color-filters for each prime; multiples of 2 (starting with 4) are sieved with a red line, multiples of 3 with a blue line, etc.. The white-space remaining is prime. But to see the resulting primes at the end, I switch to black-and-white, and reverse the white-space of the primes to thin black lines for the primes. This allows the reader to see the distribution of primes between 2 and 577, irregular jumps and all. To label the vertical axis, I have minimized ink by placing labels only at primes; there is no use labeling 100, 200, 300, or placing additional tick marks, when the primes themselves can be used for the same purpose.  Some fine-tuning might still be in order.

2-page spread, opening of Chapter 3
Click to enlarge the opening of Chapter 3

Now that I’ve become a Python advocate, I decided to go one step further and give Python code snippets throughout the Illustrated Theory of Numbers. You can see one in the margin on the right page. Inserting these snippets of code raises a lot of natural questions.

Why insert Python code instead of some universal pseudo-code? I am actively advocating Python, since I think the reader can benefit from learning Python, especially for future work in SAGE. Python is freely available and cross-platform. A C++ or Java programmer should be able to read Python code and translate easily enough into his or her native language.  Also, Python is surprisingly fast for an interpreted language!

Why insert code at all? Why not just make a download freely available? I plan to eventually post all code in the book, fully commented and a bit expanded (for exception-handling). This way, readers will be able to download the python script, import it, and compute to their heart’s content. But personally, I find something satisfying about personally typing short snippets of code and then clicking RUN. Maybe it reminds me of programming 20 years ago. It might be an issue of pacing. I like writing on the chalkboard as I lecture, because it sets a deliberate thoughtful pace. When I type in a code snippet myself, I think about each line and why it works. I hope readers can enjoy typing and modifying the short (5-15 lines) code snippets on their own.

Don’t existing software packages work better? The answer is certainly yes. I have not given code snippets which are perfectly optimized. I have aimed for a balance between readability and speed. Hopefully a reader can learn Python by experimenting with these snippets, and a reader with programming background can understand exactly how the snippets work. Optimizing code requires a sacrifice in clarity, or much more space for explanation. On the other hand, I have tried to give code that works well in practice, for a student of number theory. You’re not going to factor 50-digit numbers with the included code, but 10-digit numbers should factor very quickly. The included sieve code makes a list of prime numbers up to 1 million in 0.07 seconds on my MacBook Pro. This should be a good start for students, and if they want more power they can use PARI and SAGE, or maybe NZMath if they want pure Python.

A final word about the code-snippets: I still have not figured out how to properly attribute them. The Sieve of Eratosthenes snippet on the 2-page spread above is based on code posted by Robert William Hanks to StackOverflow on July 27, 2010. I will be asking the publisher for suggestions on how to make code citations in a wildly open-source world, and I appreciate any suggestions along the way.