Logo, Fractals, and Recursion; Programming, and Removing Repetition
Last summer while volunteering for OWL I spent several weeks working with a fifth grader we'll call Sam who'd already blown through all of OWL's exercises. Logo is a dialect of lisp and I was particularly interested in teaching Sam some different ways to use lists and functions. I searched the net a bit hoping to find something short and interesting, but with some repetition in its implementation that would help me teach how to remove repetition.
When learning literacy, one begins with reading before writing. Then the two skills grow together, one complementing the other. Working with someone else's code was an important dimension of this lesson.
I found an example logo program in the Dictionary of Programming Languages which turned out to be even better than I expected. I've copied the code from that example below making minor changes to run it in MicroWorlds Logo. In addition to all of my own criteria, this example introduces recursion and fractals.
; Recursive procedure to line, fractalized
to DrawFractalLine :level :length
ifelse :level < 1 [
forward :length] [
DrawFractalLine (sum -1 :level) (quotient :length 3.00)
left 60
DrawFractalLine (sum -1 :level) (quotient :length 3.00)
right 120
DrawFractalLine (sum -1 :level) (quotient :length 3.00)
left 60
DrawFractalLine (sum -1 :level) (quotient :length 3.00)
]
end
; procedure to clear screen and position turtle
to SetupTurtle
cg setpensize 1 setpos [-160 -10] right 60 clean pd
end
; setup turtle then draw Koch's snowflake(5)
SetupTurtle
repeat 3 [DrawFractalLine 5 330 right 120]

Having seen the above, we typed in the following:
cg pu setpos [-160 250] right 90 pd DrawFractalLine 0 330 pu setpos [-160 150] pd DrawFractalLine 1 330 pu setpos [-160 50] pd DrawFractalLine 2 330

Sam pretty quickly understood that we can compare level=0 with level=1 to understand the basic transformation that happens at each additional level of recursion. At each level we divide the previous level's line segments into three pieces and replace the middle one with two sides of an equilateral triangle.
pu setpos [-160 -50] pd DrawFractalLine 3 330 pu setpos [-160 -150] pd DrawFractalLine 4 330 pu setpos [-160 -250] pd DrawFractalLine 5 330

My first surprise was how quickly Sam began developing an intuitive grasp of recursion. Watching the turtle draw each shape in real-time helped make clear what was happening. A simple set of rules created a fairly complex shape. What a concrete and compelling introduction to recursion compared to computer science tradition in the Fibonacci series!
Although I didn't go there while working with Sam, I realize while writing this there's an opportunity to plant seeds of understanding for "significant digits." We can only barely see a difference between a curves drawn with level=6 and level=7. The differences are smaller than the pixels on our screen -- visually their insignificant. In other words, there's no extra value to be gained by setting the level any more than 6, and it's obviously not worth the significant extra time.

Having worked with Rob "Once and only once" Nagler for five years now, I cannot look at a routine like DrawFractalLine without seeing the repetition. DrawFractalLine DrawFractalLine DrawFractalLine. Let's clean that up a bit. (By the way, Logo really shines here. It would be considerably more difficult and verbose to do this in Java or C#.)
to DrawFractalLine :level :length
ifelse :level < 1 [
forward :length
] [
dolist [command [
[left 60]
[right 120]
[left 60]
[]
]] [
DrawFractalLine (sum -1 :level) (quotient :length 3.00)
if not empty? :command [run :command]
]
]
end
This is a small enough bit of code that one might reasonably ask "why bother?" However one additional change lets us reuse DrawFractalLine for another classic fractal: the Peano curve.
to DrawFractalLine :commands :level :length
ifelse :level < 1 [
forward :length
] [
dolist [command :commands] [
DrawFractalLine :commands (sum -1 :level) (quotient :length 3.00)
if not empty? :command [run :command]
]
]
end
to VonKoch :level :length
DrawFractalLine [
[left 60]
[right 120]
[left 60]
[]
] :level :length
end
to Peano :level :length
DrawFractalLine [
[left 90]
[right 90]
[right 90]
[right 90]
[left 90]
[left 90]
[left 90]
[right 90]
[]
] :level :length
end

In shape, the Von Koch snowflake and the Peano curve are markedly different. But with the code in front of us the similarity of construction is quite concrete. Both involve replacing the middle of one segment with the same basic shape. That's exactly what DrawFractalLine now does. As another point of comparison between these two fractals, the Peano curve is space-filling: the higher the more deeply we recurse, the more completely the space is colored in (see figure N, for an example using level=4)

By the time we'd made these changes to the code and talked about a these two classic fractals, Sam started suggesting different base shapes to try. Here was one where he suggested doing things a little differently with the peano curve.
to sam-curve :level :length DrawFractalLine [ [left 90] [right 90] [right 90] [] [right 90] [right 90] [right 90] [forward (2 * :length / 3)] ] :level :length end




And next is a variation on the Von Koch curve. Why does this one grow in size with the depth of recursion?
to vkzig :level :length
DrawFractalLine [
[left 30]
[right 120]
[left 120]
[right 30]
[]
] :level :length
end



Sam's attention was really captured thinking of new base shapes and trying to understand why they behave the way they do.
There's also a really important lesson about programming and automation in general. With a couple fairly simple refinements to the original program, we have created our own power tool for exploring this class of fractal. We created our own power tool. As programs go, this one is incredibly simple and small, yet has some amazing reach instructionally. What if we started kids in elementary school building up their own collection of computational tools? What if they shared tools? Computers are more than just fancy typewriters, or televisions. They're more than excellent gaming systems. Used thoughtfully, software offers leverage unlike anything that's come before. The problem we solved today can become a tool that lets us solve more complex problems tomorrow.
Reenacting Galileo's experiments with Gravity
Alan Kay and computational thinking part 4.
Alan Kay suggests we have kids reenact Galileo's experiments with Gravity. [The Real Computer Revolution Hasn't Happened Yet p.15]
A nice "real science" example for 11 year olds is to investigate what happens when we drop objects of different weights.
The children think that the heavier weight will fall faster. And they think that a stopwatch will tell them what is going on. But it is hard to tell when the weight is released, and just when it hits.
In every class, you'll usually find one "Galileo child". In this class it was a little girl who realized: well, you don't really need the stop watches, just drop the heavy one and the light one and listen to see if they hit at the same time.
These are powerful experiences: the frustration of measuring with a stopwatch, the excitement of solving that problem with essentially a race to the ground, and the unexpected result that the heavy and light balls always tie. But the real excitement for me is in his examples of how to use computers to enhance the experiment.
It starts with the use of a digital video camera to record the fall of a ball. In the software we pull out several frames from the video and have the students use computer graphics to measure the difference in position from one frame to the next. We can remind the students of their experience in measuring the tire -- this technique gives us a measurement tolerance of one pixel, so we won't get exact results.
Through these measurements the students discover constant acceleration. Remember, they have seen velocity and acceleration when they programmed their digital car earlier. Now they can connect those lessons to their own direct measurements of gravity. In other words, we've begun teaching elementary aged children physics and Newtonian mechanics.
Even better, they can repurpose the earlier exercises with car to create a model of gravity that matches their experimental data. This is an example of the kind of work real scientists are doing all over Boulder -- creating elaborate software models and verifying and adjusting the models against experimental data.
Kay goes on to suggest the kids use their new knowledge about modeling gravity to create a Lunar Lander video game.
Measure a tire: math vs. measurement
Alan Kay and computational thinking part 3.
Here I'll summarize another excellent and accessible activity from Allan Kay. [The Real Computer Revolution Hasn't Happened Yet pp. 13-14] This also doesn't require a computer. On its own, it doesn't excite me as much as some of his other examples, but it does set up some important experience for other exercises.
Students are asked to measure the circumference of a bicycle tire and are surprised to get different answers from different materials. Most math activities set children up to expect exact answers (true for most teachers for that matter). This math exercise is really a science experiment in disguise. The students get real answers instead of ideal mathematical answers. In this case the teacher was also mislead to expect an exact answer by the measurements stamped on the tires by the manufacturer. Measuring the tire uninflated gave a different measurement than measuring when inflated. This stirred up questions about measuring under different pressures. The measurements will likely differ at different temperatures too. One of Kay's team contacted the manufacturer and eventually discovered that the engineers don't even know the exact circumference and diameter. "We extrude them and cut them to a length that is 159.6 cm ± 1 millimeter tolerance!"
Kay mentioned Mandelbrot and fractals almost in passing with this example, but that connection is worth describing in more detail, particularly for those who may be unfamiliar with Mandelbrot's work. Mandelbrot published a paper in Science in 1967 entitled "How long is the Coast of Britain?" Wikipedia's entry on Mandelbrot's article has a nice series of images which illustrate what's happening in this measurement exercise. If you measure the coast of Britain with a long ruler, you will get a shorter measurement than if you use a short ruler. Hopefully it's obvious that there's a connection between Mandelbrot's article and this exercise of measuring a bicycle tire. We'll come back to fractals in another post.
Despite CSAP, Columbine is succeeding
I attended meetings about Columbine every night last week except Friday. This is an archive of my guest opinion published in the Daily Camera on Saturday
On Tuesday night, I witnessed a profound civics lesson. Despite CSAP and other data, Columbine Elementary School is doing something right.
Recently BVSD announced Columbine will get a new building. Two weeks ago, the principal announced her retirement. Last week the superintendent appointed a new principal, promised a redesigned program, and told teachers and staff they must re-apply for their jobs.
CSAP data report a gloomy academic performance. For two years Columbine have not made Adequate Yearly Progress. The Colorado Department of Education (CDE) recently conducted a thorough audit of the school. Though the district have reviewed the results, they cannot present them until CDE releases them in early January. The school itself will review the report next week.
Several weeks ago, exhausted with years of Columbine rumors, a group of neighbors arranged to meet with Superintendent Chris King on Monday to look at data -- no hidden agendas, just the facts. Our conversation focused on CSAP growth data first made available this year. These data show student improvement, not absolute scores.
Most disappointing, the median growth rates for English language learners (ELL) at Columbine is below the median for ELL students both district- and state-wide. Most surprising, the median growth rates for Anglo children at the school is higher than district and state medians. Consistent with BVSD achievement gap but exactly opposite the rumor mill, ELL students are scoring better at schools other than Columbine and Anglo students at Columbine are outscoring those at other schools.
I believe the superintendent sincerely feels a moral obligation here, and also that his recent decisions were based not only on test scores, but other data as well, including the school climate data and the CDE audit. However, he made at least four mistakes.
1) Last week's announcements implied blame on the teachers and staff. The issues impacting Columbine are far too complex to affix blame on one group. Teachers at Columbine are committed to their students and would welcome any effort to improve the school. They deserved better.
2) Effectively firing the entire school stifled communication. Who would be willing to challenge the decisions of their future employer before the job interview? Moreover, educators throughout BVSD now fear similar treatment.
3) He should have discovered the restrictions on publishing the CDE audit before taking action. In haste to answer his moral obligation, he took actions that could not be defended convincingly.
4) The teachers and staff participated in the CDE audit with great candor about their strengths and weaknesses. The superintendent violated their trust and candor by firing the school in part for weaknesses disclosed in the audit. The teachers deserve to be involved in whatever changes are demanded by the audit.
On Tuesday night the community responded. What the data could not show was on wide display as hundreds of people, about eighty percent Hispanic, packed into Columbine's cafeteria. Clearly, Columbine have forged deep and strong bonds with the families they serve. The air was thick with indignation at the threat to the staff and teachers.
Although the superintendent had prepared a statement, his agenda was quickly overwhelmed by angry questions.
For three hours he endured our moral indignation in English and Spanish. About half-way through, a number of children joined the line for the microphone. Children, including one fifth grader who translated his own speech, asked eloquently, why the teachers who had taught them English wouldn't be at Columbine to teach their younger siblings.
It was a microcosm of our great nation: citizens, immigrants, and children assembled peacefully to petition the government for redress of their grievances. Late in the evening, to his great credit, Chris King agreed to reconsider his decision in the face of this unexpected opposition. He also agreed to first personally review the CDE audit with the teachers. He was visibly affected by each of the students.
He confessed "I get no points for style on how I handled this" and publicly and sincerely apologized for the pain he'd caused.
We now face an extraordinary opportunity. Dramatic changes are necessary and we all -- board of education, administration, staff and teachers, parents, and the community at large -- have a responsibility to be involved in that change. Let us strengthen the powerful social fabric on display Tuesday night. There's work to be done here and we are obviously up to the task.
I can think of no better lesson in civic duty than what happened Tuesday night: through peaceful if angry assembly, the government heard the will of the people and responded accordingly. In particular, the government bowed to the courageous children who, even in elementary school, have already begun to assume their responsibility as our future leaders. Whatever the CSAP and other data show, there can be no greater evidence that Columbine is succeeding.
I'm reminded of something my mother-law wrote after Wellstone died in 2002
We have the great privilege, we think, of living in a democracy, but we are training our students to act in ways that may undermine that democracy....I think that helping our students develop into effective citizens lies straight in our laps as teachers of reading, writing, speaking, and listening. We need to help them to be discerning as they take in information about the world and to speak their own conscience as they act upon the world.
Alan Kay, Etoys, Drive a Car, and math education
Alan Kay and computational thinking part 2.
In most demos, Alan Kay shows off a sequence of tutorials from Etoys. These are lessons in powerful ideas specifically designed for children, but I think they're equally powerful for adults too.
Drive a Car
If you want to play along, download a copy of etoys.
In this lesson children use a built-in paint program in Etoys to paint their own car. In the next tutorial, they write instructions to make the car drive around the screen in various ways. These become lessons in turtle graphics from logo. To an uninformed adult, it just looks like a funny way to draw geometric shapes. But closer examination of turtle graphics reveals something profound. They are a beautiful existence proof that powerful software tools enable elementary aged children to learn very high level mathematics, in this case, differential geometry of vectors. As with the example of geometric growth, there are also experiential lessons in functions and infinity. Students can learn how different combinations of very simple concepts (e.g. repeat, move forward a little, turn a little) can lead to larger forms. Moreover, they get direct and concrete experience with variables (a key ingredient of algebra), a powerful idea that can otherwise seem quite abstract and confusing.
In an exercise on Speed and Acceleration, students compare constant velocity, constant acceleration, and random acceleration in a fairly direct way.
There's another fun lesson in these activities that I haven't heard Alan Kay mention directly. When these lessons call for the car to leave a trail of dots behind, students are subtly introduced to the fundamental concept of graphing and visualizing mathematical behavior. Although the exercises in these examples don't go there, turtle graphics can reinforce lessons about the number line and introduce Cartesian coordinates.
Lesson in geometry, growth, and foundations of calculus
Alan Kay and computational thinking part 1.
This first exercise is fantastic and notably does NOT need a computer. Although my focus here is definitely about computation, computers are too often used just for the sake of the technology. Let's not use computers in the classroom unless they're adding something vital to the lesson. Dr. Kay credits Julia Nishijima with this lesson.
"The children pick a shape that they liked, and the idea was to, using just those shapes, make the next larger forms that had the same shape." [The Real Computer Revolution Hasn't Happened Yet p. 7]

They're asked to write down two numbers with each new size: how many tiles were added, and the total number of tiles. Later in the exercise they're asked to share their results with the class at which point they're stunned to learn that they all have the same table of numbers:
| shape | how many added? | how many total? |
| 1 | 1 | 1 |
| 2 | 3 | 4 |
| 3 | 5 | 9 |
| 4 | 7 | 16 |
| 5 | 9 | 25 |
| 6 | 11 | 36 |
| 7 | 13 | 49 |
| 8 | 15 | 64 |
| 9 | 17 | 81 |
| 10 | 19 | 100 |
Children generally notice the pattern in these series of numbers. The odd natural numbers on the left and the series of squares on the right. Kay points out that these are first and second order differential equations. I note specifically these equations:
f(x) = x2
f'(x) = 2x - 1,
With this exercise we have laid a foundation for calculus. We've revealed a little number theory: that the sum of the first n odd numbers is n2. We're only a few steps from describing infinite series of numbers. We could talk to the kids about why square numbers are called "square" and similarly with "square roots" -- these strange names betray geometric origins and we have the geometry right in front of us with this exercise. With a little creativity, we can also introduce functions. "I have a magic box. I put a number in on one side and the number that comes out the other side is the first number multiplied by two. I have another box which always subtracts one. What happens if I put these boxes together in a line? Let's try putting some different numbers in and see if there's a pattern." Given f(x) = 2x and g(x) = x - 1, g(f(x)) = 2x - 1. With elementary age kids we can maybe skip the formal notation until we've introduced them to the notion of a variable.
Alan Kay and computational thinking
Alan Kay is an inspiration for much of my recent thinking about educational technology. If you have any interest in educational technology or the history of modern computers and don't know who he is, go learn about Alan Kay
I'm going to be summarizing a few of his ideas for educational technology here. Briefly, here are some highlights to set up future topics. Alan Kay has been working on educational technology since 1968 when he first visited Seymour Papert. If you're interested in educational technology and don't already know him, go learn about Seymour Papert. And if you don't already know about it, also go learn about Logo.
Alan Kay generally uses Squeak (a Smalltalk implementation) and in particular Etoys when he gives a demo. The combination of these tools have undergone continual refinement since the origins of Smalltalk at Xerox PARC in the 1970s. Some of the original developers of Smalltalk are still actively maintaining them. They're freely available to anyone and run on almost any computer you might care about: Windows, Mac OS, Linux, and even, notably, the XO laptop of the One Laptop Per Child project.