Mathematics and Digital Art: Final Update (Fall 2017)

Yes, it is the end of another semester of Mathematics and Digital Art!  It was a very different semester than the first two, as I have mentioned in previous posts, since I began the semester with Processing right away.  There are still a few wrinkles to iron out — for example, we had a lab project on interactivity (involving using key presses to change features of the movie as it is running) which was quite a bit more challenging than I expected it would be.  But on the whole, I think it was an improvement.

So in this final post for Fall 2017, I’d like to share some examples of student work.  In particular, I’ll look at some examples from the Fractal Movie Project, as well as examples of Final Projects.

Recall that the Fractal Movie Project involves using linear interpolation on the parameters in affine transformations in order to make an animated series of fractal images.  One student experimented with a bright color palette against a black background.  As the fractal morphed, it actually looked like the red part of the image rotated in three dimensions, even though the affine transformations were only two-dimensional.

MAK

 

Cissy wanted to explore the motion of rain in her movie.  Although she began with bright colors on a black background, once she saw her fractal in motion, she decided that more subtle colors on a white background would be better suited to suggest falling raindrops being blown about by the wind.MCissy

 

Sepid also incorporated movement in her movie — she created a rotating galaxy with a color palette inspired by the colors of the Aurora Borealis.  In addition, she learned how to use the Minim library so she could incorporate sound into her movie as well.  Here is a screen shot from her movie.

MSepid

 

Now let’s take a look at a few Final Projects.  Recall that these projects were very open-ended so that students could go in a direction of their choice.  Some really got into their work, with truly inspirational results.  The presentation that Sepid gave at a recent meeting of the Bay Area Mathematical Artists was actually work she was doing on her Final Project (read about it here).

Terry took on an ambitious project. She based her work on a Bridges paper by Adam Colestock, Let the Numbers Do the Walking: Generating Turtle Dances on the Plane from Integer Sequences (read the paper here).  Terry did have some programming experience coming into the course, and so she decided to code all of Adam’s turtle graphics algorithms from scratch! This was no simple task, but she worked hard and eventually accomplished her goal.

Here is a screen shot from one of her movies; Terry wanted to create an interesting visual effect by overlaying multiple copies of the same turtle path.  Since this particular path was not too dense in the plane, she was able to work with thicker lines.

FPTerry

Tera created a movie which involved rotating triangles and moving dots.  Her movie had a strong sense of motion, and incorporated a vibrant color palette. She remarked that working with color in this project was both fun and quite challenging. In her words, “Playing nicely with hot pink is not an easy feat.”

FP_TG

 

I would also like to share the fact that Professor Roza Aceska of Ball State University (Muncie, Indiana) will be teaching a course about digital art next semester using Processing which will be incorporating a lot of my course materials.  I am very excited about this!  Many faculty who come to my talks say they are interested in teaching such a course, but getting Department Chairs and Deans to approve such courses is sometimes an uphill battle.

Professor Aceska’s course will be a bit different from mine — her course is in the Honors Program, and as such, does not count as a mathematics credit.  So she will not have most of the mathematics assignments and quizzes that I had in my course.  But she will still be emphasizing the fascinating relationship between mathematics, programming, and art.  I hope to write more about her course sometime during the next semester.

One final remark — I am helping to organize a Mathematical Art Exhibition at the Golden Section Meeting of the Mathematical Association of America on February 24, 2018 at the California State University, East Bay.  So if you’re reading this and are in the Bay Area and would like to submit some mathematical art for inclusion in our exhibit, please let me know!

 

Knights and Rogues

 

They were dark times in the Kingdom of Verdoon.  A band of fierce Rogues was terrorizing the local hamlets.  King Buford was very displeased — he had no other option but to send out a legion of Brave Knights and Loyal Knights to round up the Rogues and deliver them to the castle dungeons.

So he chose seven of his bravest Brave Knights, and seven of his most loyal Loyal Knights, and dispatched them across Mount Kerchoo to the hamlet of Dunken, where the Rogues were last reported to have been wreaking havoc.

The Knights were capable Knights, and soon rounded up seven of the fiercest Rogues, including their leader, Thorn Yackley.  Now they had the difficult task of escorting the Rogues back through the narrow, winding path over Mount Kerchoo.

The Rogues were so fierce, no single sword could subdue any of them, nor could a single mace.  But they were no match for both a sword and a mace.

Now the Brave Knights carried a single sword, and the Loyal Knights a single mace.  So on the trek back to the castle — where they had to walk single file, the path was so narrow — it was vital that each Rogue be flanked by both a Brave Knight and a Loyal Knight in the event the Rogue tried to escape.

The question:  In how many ways could the Brave Knights, Loyal Knights, and the Rogues be lined up so that on the treacherous way back, each Rogue was flanked by both a Brave Knight and a Loyal Knight?

(For this problem, consider the Brave Knights indistinguishable from each other; similarly for the Loyal Knights and Rogues.)

Recently, I had been challenged to create a lesson which involved problem-solving with binomial coefficients.  But I didn’t want to create just any lesson — I wanted something interesting and novel.

Now if you’ve ever taught combinatorics and counting, you know that there is a deluge of problems about binomial coefficients — from choosing committee members, sitting people around a circular table, lining up books on shelves, etc.  So it’s not an easy task to come up with something you think might be new.

That was the genesis of Knights and Rogues.  Of course it may very likely not be new, since it really is difficult to come up with a combinatorics problem no one has thought about before.  But I did ask a colleague who knows a lot about problem solving, and he hadn’t seen it before.

The story is just to get students interested.  Combinatorially, we could state the problem as follows:

Given p 0’s, q 1’s, and r 2’s, in how many ways can you line them up so that each 2 is surrounded by both a 0 and a 1?

It turns out that there is a lot going on in this problem.  With three parameters, the analysis is far from straightforward.

There are a few restrictions on the parameters.  For example, we need p+q>r, or there are not enough Knights to flank the Rogues.  We also need

p,q\ge\left\lceil\dfrac r2\right\rceil,

or else there wouldn’t be enough Brave Knights and Loyal Knights to flank the Rogues.  For example,  if p = 2, q = 1, and r = 3 (so that q just falls short of the above inequality), you can see the problem — the one 1 can flank at most two 2’s, and so there is one 2 without an adjacent 1.  But if increase q to 2, we can have either the sequence 0212021 or 1202120.

Of course it is possible to consider specific examples, but it is also possible to consider infinite families of parameters — we’ll look at the case p = 2, qn, and r = 2 to give you an idea of the reasoning involved.

Now when n = 1, there is only one possibility:  02120.    But when n is larger than 1, we need to look at two separate cases:  when the 2’s are separated by more than one 0/1, so that we are looking at two blocks of 021 or 120.  When the 2’s are separated by exactly one 0/1, we only have the options 02120 or 12021.  We need to count each case separately.

Let’s look at the first case.  We have two blocks of either 021 or 120.  This uses up the two 1’s but there are n – 2 1’s left over.  So we have n things to arrange:  two blocks, and n – 2 1’s.  This may done in

4\displaystyle{n \choose 2}

ways, since we first choose the 2 places for the blocks, but then multiply by 4 since each block has two possibilities:  021 or 120.

In the second case, if the 2’s are only separated by one number, we may have a block of 02120 and n – 1 1’s to place, giving n possibilities. With a block of 12021, we have the block, one 0, and n – 2’s to place, which can be done in

\displaystyle2{n\choose2}

ways (since the order of the block and the one 0 matters). Adding these three cases together results in

\displaystyle4{n\choose2}+n+2{n\choose2}=3n^2-2n

possible lineups for the Knights and Rogues.

Interestingly, these are the octagonal numbers (A000567 in the OEIS).  I have no idea why, though….

What I like about this problem is that parameterizing p, q, and r in different ways produces seemingly very different results.  One interesting parameterization is p = qrn.  It turns out that this sequence — at least the first several values, which I used the computer to generate and didn’t work out by hand — is also in the OEIS (A141147), and the description is the

number of linear arrangements of n blue, n red and n green items such that the first item is blue and there are no adjacent items of the same color (first and last elements considered as adjacent).

I find this particularly intriguing since in Knights and Rogues, 0’s and 1’s can be adjacent — but even though 2’s are not adjacent, it is not possible to have any block be 020 or 121, although these are counted in A141147.  Finding a bijection between the two linear arrangements would be a very interesting problem.

I hope you enjoyed reading about Knights and Rogues!  Again, this is another example of mathematics as it happens — I came up with this problem within the past few weeks, and I’ve just scratched the surface of this interesting puzzle.  I hope it’s actually a new problem, but I won’t be surprised if I get a comment like, “Oh, I saw that problem in…..”  Generating new, novel mathematics problems is not an easy task…..

And incidentally, the answer to the initial problem is 80,096.  Did you get it?

On Coding XIII: Retrospective.

I published the first installment of On Coding on September 11, 2016.  It seems a bit surreal that this thread is over a year old — but all good things must come to an end.  I really enjoyed writing these posts; they helped me organize my thoughts about my own personal coding history.

But there are some loose ends I’d like to tie up.  I’ve had brief forays into other languages — too brief to devote an entire post to any one of them.  I’ve mentioned a few of them here and there, but I’d like to take the opportunity to include them all in one post.

Before doing so, I should mention that Processing is my most recent programming adventure.  But I have written so much about using Processing in the context of my digital art course, I don’t feel the need to devote a separate post to it.  And I feel I might bore you, dear reader….

The first is PASCAL, which I first learned while taking an undergraduate programming class.  Other than the course, I only did a few other things with PASCAL.  I did write a routine that printed out 4 x 4 magic squares — I was really into magic squares back in college.  I also dabbled with computer graphics and geometrical inversion — I recall giving a talk where I discussed geometrical inversion, and I split the screen so on one side you saw lines tangent to a conic section, while on the other side, you saw inverse circles tangent to the inverse limaçon.

While in graduate school, I had a one-year stint filling in for a faculty member at a nearby college, and I taught a data structures course using PASCAL.  Now, I would never think of PASCAL as a go-to language for any particular purpose.  It’s still around, but not nearly as popular as it was then.

The next is LISP*, which I used while teaching at a summer program during graduate school.  This was a parallel version of LISP written for the Connection Machine, a state-of-the-art supercomputer in its day.  It had literally thousands of different processors, each very simple.  But because of the sheer number of processors, the speed of the Connection Machine merited it the designation “supercomputer.”

The language was quite similar to LISP, except that many functions had parallel versions which could be executed on each processor.  I can’t recall much of what I did on the Connection Machine, but I do remember programming Conway’s Game of Life on a 1000 x 1000 torus.  Of course I can do that on my laptop right now in Mathematica, but at the time, it was a real feat!  Remember, that was back in the day when Mandelbrot sets were calculated pixel by pixel and computers were so slow you could actually see the pixels march right on by….

Chronologically, Maple — a direct competitor of Mathematica — comes next, sort of…I used Maple around the same time as LISP*.  I seem to recall the only reason I played around with it was that I had a house-sitting job for a few summers, and there was a computer I could use which had Maple on it.

I recall finding Maple really useful, but there was a bit more syntax than with Mathematica.  I really like Mathematica‘s fundamental data type — the list, just like LISP.  But I think part of the reason I’ve stuck with Mathematica through the years is that most places I’ve been have supported it — and being free is a big advantage.  I know Maple has changed a lot since I last used it, so I don’t feel I’m able to say more about a comparison with Mathematica than what I’ve already said.

Jump ahead a few years to C++.  I can’t remember exactly when I started learning it, but I was teaching at a small liberal arts college, and a colleague who usually taught an algorithms course was going on sabbatical.  I was really the only other faculty member at the university qualified to teach it, and so there it was!  The students in the course knew C++, so I needed to learn it, too….

Well, I should say I learned enough to write code for an introductory algorithms course, which means I didn’t have to dive too deeply in.  I can’t say I used C++ for much after I taught the course, except I remember writing some routines to do financial planning.  You know, like if you have different investments at different interest rates for different numbers of years, etc., how much will you have when you retire?  (Being a mathematician, I thought it insane that I should pay someone else to do my financial planning, so I read everything I could on the topic and did it myself.)  But I haven’t used C++ since.

Last — and perhaps least — there’s Java.  I learned Java was when I was applying for a job teaching mathematics and computer science, and the language taught was Java.  I had never written a line in Java before, and there was some concern that I wasn’t qualified.

So I wrote a little interactive game based on some puzzles I created, which was really quite nice, if I must say.  The only way to show you know how to code in a language is to code, so I did it.

It was rather unpleasant, though.  What I needed to do was really just algorithmic, and the object-orientedness of Java and the need to precisely define data structures really got in the way.  I hope never to write another line of Java again.  (Incidentally — long story — I was offered the job but turned it down.  Saved me from teaching Java….)

And I think that’s about it!  If I can leave you with anything after this series, it’s GO CODE!  Learn as many different types of languages as you can.  The best way to learn is to find something you really want to do, and then go for it.

Remember, my first programming language was Fortran — using punch cards.  Running batch jobs.  Today, you’ve got laptops and the internet.  The only limit is your imagination….

 

 

Bay Area Mathematical Artists, III

Another successful meeting of the Bay Area Mathematical Artists took place yesterday at the University of San Francisco!  It was our largest group yet — seventeen participants, include three new faces.  We’re gathering momentum….

Like last time, we began with a social half hour from 3:00–3:30.  This gave people plenty of time to make their way to campus.  I didn’t have the pleasure of participating, since the campus buildings require a card swipe on the weekends; I waited by the front door to let people in.  But I did get to chat with everyone as they arrived.

We had a full agenda — four presenters took us right up to 5:00.  The first speaker was Frank A. Farris of Santa Clara University, who gave a talk entitled Fibonacci Wallpaper Spirals.

p4IrisLoRes.jpg

He took inspiration from John Edmark’s talk on spirals at Bridges 2017 in Waterloo, which I wrote about in my blog last August (click here to read more).  But Frank’s approach is rather different, since he works with functions in the complex plane.

He didn’t dive deeply into the mathematics in his talk, but he did want to let us know that he worked with students at Bowdoin College to create open-source software which will allow anyone to create amazing wallpaper patterns.  You can download the software here.

Where do the Fibonacci numbers come in?  Frank used the usual definition for the Fibonacci numbers, but used initial values which involved complex numbers instead of integers.  This allowed him to create some unusually striking images.  For more details, feel free to contact him at ffarris@scu.edu.

Next was our first student talk of the series, My Experience of Learning Math & Digital Art, given by Sepid Ebrahimi.  Sepid is a student in my Mathematics and Digital Art course; she is a computer science major and is really enjoying learning to code in Processing.
Sepid
First, Sepid mentioned wanting to incorporate elements into her work beyond simple points, circles, and rectangles.  Her first project was to recreate an image of Rick and Morty, the two main characters in the eponymous cartoon series.  She talked about moving from simple blocks to bezier curves in order to create smooth outlines.
Sepid then discussed her second project, which she is using for her Final Project in Mathematics and Digital Art.  In order to incorporate sound into her work, she learned to program in Java to take advantage of already-existing libraries.  She is creating a “live audio” program which takes sound input in real time, and based on the frequencies of the sound, changes the features of various geometrical objects in the video.  Her demo was very fascinating, and all the more remarkable since she just started learning Processing a few months ago.  For more information, you can contact Sepid at sepiiid.ebra@gmail.com.
The third talk, Conics from Polygons: the Chord Ratio Construction, was given by Scott Vorthmann.  He is spreading the word about vZome, an open-source virtual environment where you can play with Zometools.
The basis of Scott’s talk was a simple chord ratio construction, which he is working on with David Hall.  (Here is the GeoGebra worksheet if you would like to play with it.)  The essential idea is illustrated below.
chordratio
Begin with two segments, the red and green ones along the coordinate axes.  Choose a ratio r.  Now add a chord parallel to the second segment and r times as long — this gives the thick green segment at y = 1.  Connect the dots to create the third segment, the thin green segment sloping up to the right at x = 1.  Now iterate — take the second and third segments, draw a chord parallel to the second segment and r times as long (which is not shown in the figure), and connect the dots to form the fourth segment (the thin green segment sloping to the left).
Scott then proceeded to show us how this very simple construction, when iterated over and over with multiple starting segments, can produce some remarkable images.
scott
Even though this is created using a two-dimensional algorithm, it really does look three-dimensional!  Conic sections play a fundamental role in the geometry of the points generated at various iterations.  Quadric surfaces in three dimensions also come into play as the two-dimensional images look like projections of quadric surfaces on the plane.  Here is the GeoGebra worksheet which produced the graphic above.  For more information, you can contact Scott at scott@vorthmann.org.
 The final presenter was Stacy Speyer, who is currently an artist-in-residence at Planet Labs.  (Click here to read more about art at Planet Labs.)  She didn’t give a slideshow presentation, but rather brought with her several models she was working on as examples of Infinite Polyhedra Experiments with Planet’s Satellite Imagery.
Planet-1stTryInfinte4_6.jpg
One ongoing project at Planet Labs is planetary imaging.  So Stacy is taking high-resolution topographical images and using them to create nets for polyhedra.  She is particularly interested in “infinite polyhedra” (just google it!).  As you can see in the image above, six squares meet at each vertex, and the polyhedron can be extended arbitrarily far in all directions.
One interesting feature of infinite polyhedra (as you will notice above) is that since you cannot actually create the entire polyhedron, you’ve got to stop somewhere.  This means that you can actually see both sides of all the faces in this particular model.  This adds a further dimension to artistic creativity.  Feel free to contact Stacy at cubesandthings@gmail.com for more information!
We’ll have one more meeting this year.  I am excited to see that we’re making so much progress in relatively little time.  Presentations next time will include talks being prepared for the Joint Mathematics Meetings in San Diego this coming January, so stay tuned!

 

Beguiling Games III: Splotch!

In this installment of Beguiling Games, we’ll learn how to play Splotch!

Day119Splotch1

But first, I’ll start off by giving you the solution to the last puzzle I presented in the last installment.  The statement of the puzzle is too long to repeat, so you can refresh your memory at Beguiling Games II.

First, it is important to note that Lucas’s statement actually provides no information!   Suppose Ophelia’s card was Truthteller.  Then she would have told the truth in Round 1, passed her card to Lucas, and he would truthfully have stated that she told the truth in Round 1.

But what if Ophelia’s card was Liar?  Then her statement “I am a Truthteller” in Round 1 would in fact have been a lie.  Now she passes her card to Lucas.  He lies and says she told the truth in Round 1!  What this means is Lucas could have made his statement in Round 2 regardless of what card Ophelia passed him.

Note that the same logic applies to Mordecai’s statement.  He could have said “Lucas also told the truth in the first round” regardless of whether Lucas passed him a Truthteller or a Liar card.

Now let’s examine Nancy’s statement in some detail.  She said that there is at least one liar at the table.  Could she have lied?

Well, if the fact that the there is at least one liar at the table is false, that means everyone is a Truthteller.  But there is no way Nancy could have known this, since the only two cards she saw were hers and the card passed to her by Mordecai.

That means Nancy must have told the truth in Round 2, and Mordecai must have passed her a Truthteller card.  But in order for her to have sufficient information to say there is at least one Liar at the table, she must have been holding a Liar card in Round 1.

Now this information could be deduced by anyone at the table.  In other words, anyone would know that Nancy held a Liar card in Round 1, and Mordecai held a Truthteller card.  That leaves Lucas’s and Ophelia’s cards in Round 1.

The only person who could know both these cards would be Lucas — he knew his own card in Round 1, and he knew Ophelia’s card because she passed it to him in Round 2.  So he had enough information to declare after Nancy’s statement.

It is important to point out that there is no way to know what Lucas’s and Ophelia’s cards actually were.  All we need to know is that Lucas knew what both of them were.

Did you figure it out?  It takes a little bit of reasoning, but all the facts were there.

Now as I mentioned in the last installment, this time I’d give you a geometrical two-player game to work out.  I call it Splotch!

In the game of Splotch!, players alternate coloring in squares on a 4 x 4 grid.  The goal is to create a target shape, called a splotch.  A player wins when he or she colors in a square which completes a splotch, and then announces the win.

So if a player completes a splotch but doesn’t notice it and doesn’t announce the win, then play continues until someone completes another splotch.  You can only call Splotch! on your turn, so you cannot win by calling it if your opponent fails to.  It is also important to remember that the square you color in on your turn must be part of a splotch you announce.

In the version of Splotch! I’m sharing with you this week, the target splotch is:

Day119Splotch1

Just so you know how it works, let’s look at a sample game, shown below.

Day119Splotch2

There are two players, A and B.  A goes first, and plays in the lower left corner (labelled with A1).  B colors in a square in the top row (B1).  Then A’s second move is in the second row.  B wins on the next play by completing — and announcing! — a splotch.  The splotch may be rotated (as in this example), reflected, or even both!  So you’ve got to watch carefully.

Now admittedly, A was not a very clever player in this round of Splotch!  In fact, B could also have won by playing as follows:

Day119Splotch3

But here is the question:  In this version of Splotch!, which player can force a win every time?  Remember:  you must be able to provide a response to every move by your opponent!  I’ll reveal which player can force a win in my next installment of Beguiling Games, and I’ll share my particular strategy for winning.

One final remark — a bit of a tangent, but related to puzzles and games.  If you’ve been following my blog for a long while, you might remember my (fiendishly diabolical) number searches.  (These were posted well over a year ago.)

Day031Fig1

Here, the numbers in the right are in base 10, but you have to convert them to another base to find them in the grid!  You can read more about these puzzles here and here.

I submitted these puzzles to MAA Focus, the newsmagazine of the Mathematical Association of America.  I am happy to report that they will be featured on the Puzzle Page in the December 2017/January 2018 issue!

Now I will admit that this doesn’t exactly make me famous, given the number of people who subscribe to MAA Focus.  But I composed these puzzles specifically for my blog — so if I hadn’t decided to write a blog, these puzzles might never have been created.  Perhaps another reason to write a blog!

Stay tuned for the next round of Beguiling Games, where you’ll learn (if you didn’t already figure it out for yourself) who has a winning strategy in the game of Splotch!

Geometrical Dissections III: Octagons and Dodecagons

It has been quite a while since I’ve written about geometrical dissections.  For a brief refresher, you might want to look at my first post on dissections.

But recently my interest has been rekindled — to the point that I started writing a paper a few weeks ago!  I often like to share mathematics I’m working on as it’s happening to give you some idea of the process of doing mathematics.  The paper has quite a bit more mathematics in it than I’ll include in this post, but I’ll try to give you the gist of what’s involved.

Recall (again, see my first post for a more thorough discussion) that I’m interested in finding dissections that you can draw on graph paper — I find these more enjoyable as well as being accessible to a wider audience.  So all the dissections I’ll talk about will be based on a grid.

The first example is a dissection of two octagons to one, such as shown below.

Day118Dissection2

In other words, you can take the pieces from the two smaller octagons, move them around, and build the larger octagon.  If you look carefully, you’ll notice that the larger octagon is rotated 45° relative to the smaller octagons.  Geometrically, this is because to get an octagon twice the area of a given octagon, you scale the side lengths by \sqrt2.  Imagine a square — a square with side length S has area S^2, while a square with side length \sqrt2S has area (\sqrt2S)^2=2S^2  — which is double the area.

Now think of a segment of unit length.  To get a segment of length \sqrt2, you need to take a diagonal of a unit square, which rotates the segment by 45° as well as scales it by a factor of \sqrt2.  This is why the larger octagon is rotated with respect to the smaller ones.

But what makes this dissection interesting is that there is an infinite family of very similar dissections.  By slightly varying the parameters, you get  a dissection which looks like this:

Day118Dissection3

Here, you can clearly see the 45° rotation of the larger octagon.  I always enjoy finding infinite families of dissections — it is very satisfying to discover that once you’ve found one dissection, you get infinitely many more for free!

The proof that this always works (which I will omit here!) involves using a geometrical argument — using arbitrary parameters — to show that the green triangles always have to be right isosceles triangles.  This is the essential feature of the dissection which makes it “work” all the time.

The second example I’m including in the paper is a dissection on a triangular grid, like the one below.

Day118Dissection4

Note that the figure on the left is an irregular dodecagon; that is, it has twelve sides.  Recall that the interior angles of a regular dodecagon have measure 150° — but so do the angles of this irregular dodecagon as it is drawn on a triangular grid.

If you look carefully, you’ll see how the sides in the pieces of the dissection on the right match up with sides of the same length from the other pieces.  Also, looking at the dissection on the right, you’ll see that around all the interior vertices, there are two angles with measure 150° and one with measure 60°, adding up to 360° — as we would expect if the pieces fit exactly together.

And — as you might have guessed from the first example — this is also one of an infinite family of dissections.  As long as the sides of the irregular dodecagon alternate and the vertices stay on the triangular lattice, there is a dissection to a rhombus.  Below is another example, and there are infinitely many more….

Day118Dissection5

My third and final example involves irregular dodecagons, but this time on a square grid.  And while I found the previous two dissections several years ago, I found this example just last week!  What inspired me was one of my favorite dissections — from an irregular dodecagon to a square — also found many years ago.

Day118Dissection1

In the spirit of the first two examples, I asked myself if this dissection could be one of an infinite family.  The difficulty here was that there were three parameters determining an irregular dodecagon, as shown below.

Day118Dodecagon

We do need b>c so that the dodecagon is convex and actually has 12 sides; if b=c, four pairs of sides are in perfect alignment and the figure becomes an octagon.

There is an additional constraint, however, which complicates things a bit.  The area of this dodecagon must also be the area of some tilted square with vertices on the grid, as illustrated below.  Note that the area of this square is just d^2+e^2.

Day118Square

It is not a difficult geometry exercise to show that the area of the dodecagon is a^2+4(a+b)(c+b).  So in order to create a dissection, we must find a solution to the equation

a^2+4(a+b)(c+b)=d^2+e^2.

Again, here is not the place to go into details.  But it is possible to find an infinite family of solutions when a=e.  You get a dissection which looks like this:

Day118Dissection6

I was particularly pleased to have found this eight-piece dissection since most of my attempts until this point had ten pieces or more.  And to give you a sense of this family of dissections, here is an example with different parameters within this family.

Day118Dissection7

You can definitely see the resemblance, but it is also clear that the dodecagon and square are not the same shape as those in the previous dissection.

So these are the three families of geometrical dissections I’ll be including in my paper.  I hope these examples might inspire you to pick up a pencil and graph paper and try to find some infinite families of your own!

 

On Coding XII: Python

It has been some time since I wrote an installment of On Coding.  It’s time to address one of my more recent programming adventures:  Python.  I started learning Python about two-and-a-half years ago when I began teaching at the University of San Francisco.

One of my colleagues introduced me to the Sage environment (now going by “CoCalc”) as a place to do Mathematica-like calculations, albeit at a smaller scale.  Four features were worthy of note to me:  1)  you could do graphics;  2)  you could write code (in Python);  3)  you could run the environment in your browser without downloading anything;  and 4)  it was open source.

For me, this was (at the time) the perfect environment to develop tools for creating digital art which I could freely share.  Yes, I had thousands of lines of Mathematica code, but Mathematica is fairly expensive.  I wanted an environment which would be easily accessible to students (and my blog followers!), and Sage fit the bill.

So that’s why I started learning Python — it was the language I needed to learn in order to use Sage.

For me, two things were a challenge.  The first was how heavily typed Python is.  In Mathematica, the essential data structure is a list, just like in LISP.  For example,

{1, 2, 3}

is a list.  But that list may also represent a vector in three-dimensional space — even though it would look exactly the same.  It may also represent a set of numbers, so you could calculate

Intersection[{1, 2, 3}, {3, 4, 5}].

In Python you can create a list, tuple, or set, as follows:

list([1, 2, 3]),  tuple([1, 2, 3]), set([1, 2, 3]).

And in Python, these are three different objects, none equal to any other.  I don’t necessarily want to start a discussion of typed vs. untyped languages, but when you’re so used to using an untyped language, like Mathematica, you are constantly wondering if the argument to some random Python function is a list, tuple, or….

Second, Python has a “return” statement.  In languages like LISP and Mathematica, the value of the last statement executed is automatically returned.  In Python, you have to specify that you want a value returned by using a return statement.  I forget this all the time.

And while not a huge obstacle, it does take a little while to get used to integer division.  In Python, 3/4 = 0, since when you divide integers, the value of the fraction is the quotient when considered as integer division.  But 3/4. = 0.75, since adding the decimal point after the 4 indicates the number is a floating point number, and so floating-point arithmetic is performed.

Of course, if you’ve been reading recent posts, you know I’ve moved from Sage entirely to Processing in my Mathematics and Digital Art course.  You can read more about that decision here — but one key feature of Processing is that there’s a Python mode, so I was able to take work already done in Sage and adapt it for Processing.

It turns out that this was not as easy as I had hoped.  The essential difficulty is that in Sage, the bounding box of your image is computed for you, and your image is appropriately scaled and displayed on the screen.  In Processing, you’ve got to do that on your own, as well as work in a space where x– and y-coordinates are in units of pixels, which is definitely not how I am used to thinking about geometry.

I am finding out, however — much to my delight and surprise — that there are quite a few functional programming aspects built into Python.  I suspect there are many more than I’m familiar with, but I’m learning them a little at a time.

For example, I am very fond of using maps and function application in Mathematica to do some calculations efficiently.  Rather than use a loop to, say, add the squares of the numbers 1– 10, in Mathematica, you would say

Plus @@ (#^2& /@ Range[10])

The “#^2&” is a pure function, and the “/@” applies the function to the numbers 1–10 and puts them in a list.  Then the function “Plus” is applied, which adds the numbers together.

There is a similar construct in Python.  The same sum of 385 can be computed by using

sum([(n + 1)**2 for n in range(10)])

OK, this looks a little different, but it’s just the syntax.  Rather than the “#” character for the variable in the pure function, you provide the variable name.  The “for” here is called list comprehension in Python, though it is just a map.  Of course you need “(n + 1),” since Python always starts at 0, so that “range(10)” actually refers to the numbers 0–9.  And the “sum” function can take a list of numbers as well.  But from a conceptual level, the same thing is going on.

The inherent “return” in any Mathematica function does find its way into Python as well. Let’s take a look at a simple example:  we’ll write a function which computes the maximum of two numbers.

Now you’d probably think to write:

Day117python1

This is the usual way of defining “max.”  But there’s another way do to this in Python.

If you ask Python to

print 3 > 2,

you’ll see “True.”  But you can also tell Python to

print (3 > 2) + 7

and get “8.”  What’s going on here is that depending on the context, “3 > 2” can take on the value “True” or “1.”  Likewise, “3 < 2” can take on either the value “False” or the value “0.”

This allows you to completely sidestep making Boolean checks.  Consider the following definition.

Day117python2

This also works!  If in fact a >= b, you return the value 1 * a + 0 * b, which gives you a — the maximum value when a >= b.  And when a < b, you return b.  Note that when a = b, both are the maximum, so we could just as well have written

Day117python3

I think this is a neat feature of Python, which does not have a direct analogue in Mathematica.  I am hoping to learn many other intriguing features like this as I dive deeper into Python.

Python is my newest language, and I have yet to become “fluent.”  I still sometimes ask the internet how to do simple things which would be at my fingertips in Mathematica.  But I do love learning new languages!  Maybe in a year or so I’ll update my On Coding entry on Python with a flurry of new and interesting things I’ve learned….