Geomlab crib sheet

From Spivey's Corner
Jump to: navigation, search

Show each of the various main tiles (man, woman, tree, star, blank) Illustrate the various operations and what some basic ones look like:

man $ tree (man beside tree)
star & tree (star above a tree)
rot(man) (rotate man 90 degrees anti-clockwise)

From here, this is the basic script I use:

Welcome to the University of Oxford Department of Computer Science! My name is Jim Whitehead and I'm one of the teaching assistants here in the department and a DPhil student, along with Ed, who is also a Dphil student in Computer Science. Today we're going to introduce you to some of the concepts used in computer science through a tool called 'Geomlab'. To start, please click on the painting in the center of the web page and then click on the large green arrow to launch the program.

[Once everyone has a Geomlab session lanched] Geomlab is a kind of calculator, but it is much more powerful. Why don't you try a simple maths expression like "two plus three times four". Once you've typed it into the command window, you can click 'Go' or hold 'Control' and press 'Enter' in order to run the command. What's the answer?

[wait for the answer, show how to type this on the screen] Absolutely, 14! Did anyone get a different answer? Alright, good, now we know we have working calculators, we can move into the more interesting stuff. Numeric calculators are interesting, but what sets Geomlab aside is that it can also calculate pictures. Just like we use numbers in arithmetic, we can combine small pictures together to make more complicated ones. We have a few pictures we can use. The first is called man. So type 'man' into the command window and click Go.

[Demo this] You should see a picture of a man show up in the output window. We also have a woman <do it>, a tree <same>, a star <same>, and a blank picture that is just white with no other image. Just like we can add numbers together, using plus, divide, multiply and subtract, we have some operators we can use to combine pictures. If you type man $ woman, you get a picture of a man next to a woman. The dollar sign is the 'beside' operator, putting the thing on the left next to the thing on the right. We can also put pictures on top of each other using the ampersand (shift-7). So to put a star above a tree, we can use star & tree. Let's try a simple example. Can you draw me a man beside a woman with a star above her head?

[show them the picture window without the solution; students will normally just type man $ woman & star or man $ star & woman>] Did anyone end up with the right picture? What did you notice as you were trying to construct it? It seems like the order we type things is important. Just like in maths when you type 2 + 3 * 4. Did you mean (2 + 3) * 4 or did you mean 2 + (3 * 4)? The calculator is able to make a best guess, but you can also group things explicitly using brackets. So what you really want to do here is:

[type this into a notepad window with a large font so they can see]

man $ (star & woman)

When you do this, you tell the program that you want star & woman be one composite picture, and that you want to place that whole thing next to the man. Now onto a more difficult challenge. Please create the following picture: <type family> this is the following formula:

((blank & star & blank) & tree) $
(blank & man) $
(blank & woman) &
(blank & blank & man)

[We normally run into the following issues;

  • The star over the tree is created without blanks next to the star, which makes the tree smaller and the star way too large.
  • The man and woman don't have blanks above them, so they are too large.
  • Some students do (blank & (man $ woman)) which is better than the huge people, but still not correct (the size is different).
  • Once students figure out how to make the man and woman smaller, they seem to be unable to translate this to making the star smaller. They think that they need to put it above, and can't quite see that you can put them to the side. We can point this out in the picture.]

[Once this exercise is done, we introduce the concept of rotation. We demonstrate a man being rotated once, then rotated twice using rot(rot(man)). This shows that we have functions or procedures, and that our procedures can take in a picture. There are also some helper functions calls rot2() and rot3() that perform multiple 90 degree rotations.]

Your next challenge is to make this picture: <type four(man)>

[This one seems to go a bit quicker. Once most of the room has it:] This picture can be split up into either rows or columns. If we work through this as rows, we have the following:

(blank $ man $ blank) &
(rot(man) $ blank $ rot3(man)) &
(blank $ rot2(man) $ blank)

Doing it with columns just changes the solution, but the picture looks the same.

[Depending on speed, we introduce functions now.] What if I asked you to make the same pattern of pictures, but with a woman instead? What would you do? You'd probably just copy/paste your last command and then substitute each place we've used 'man' for 'woman' instead. Of course, there are easier ways to do this. We can define a function which takes a picture as an argument and then creates this picture. Let's start bu typing:

define four(p) =

This tells Geomlab that we are making a new formula called 'four' and that this formula is going to take a single parameter, just like the rot() function does. On the right-hand side of the equation we can simply paste your working formula, but we can subtitute p for every place thatn 'man' was written before. If you click 'Go', you'll get a message that says:

four = <function>

Now we can call this by typing:


More interestingly, since the parameter is just a picture, we can make them more complicated, such as :


This gives us a nice pattern of stars!

[Now we're going to introduce recursion] Okay. If I asked you to create me a row of four men, what would you type? <prompt them for man $ man $ man $ man> Certainly! You'll type a man, beside a man, beside a man, beside a man. Now what if I asked you to make me 12 men? You could copy and paste it four times, but what about 73 men in a row? Do you trust yourself to copy and paste the correct number of times? These are computers! Surely we have to have a better way to do this. Does anyone have any ideas?

<90% of the time, someone will suggest a loop>

Sure, you could write some kind of loop that says 'do this 12 times', but that's not really how Geomlab works. But there is a nice solution we can use, if we think about the program in a different When I asked you how to fraw this picture, what was the first thing you said? Man, exactly right. And what's next to that man?

<90% of the time someone will say 'a man'>

Yes, he's next to a man, but that's only part of the picture. What is he actually next to?

<someone says three men>

Yes! Three men. Is there another way we can say that? Isn't three men in a row just a row of three men? So what does this look like as a formula?

define row(p, n) =

<prompt students for help>

define row(p, n) = p $ row(p, n-1)

Great! We have a function here which should draw us rows. Why don't you try it with row(man, 4) and see if it works?

<Let them type it in and try>

What does it say? "Argh, it took to many steps!" Why might that have happened? Well, let's see what our formula has done. row(man, 4) could be rewritten using the formula:

man $ row(man, 3)
man $ man  $ row(man, 2)
man $ man $ man $ row(man, 1)
row $ row $ row $ row $ row(man, 0)
row $ row $ row $ row $ man $ row(man, -1)

It seems our formula doesn't quite match the English definition we gave before. In our description, we said that a row of 1 men was what? Just the man itself! So our formula doesn't quite reflect what we said. We can rewrite it like this instead:

define row(p, 1) = p
  | row(p, n) = p $ row(p, n-1) when n > 1

Now try creating a row of five men! Great! What happens if you create a row of -1 men? You get the same too many steps error. This might make some kind of sense, since we don't know what a rot of -1 men would look like. Can you create a row of 12 trees?

row(tree, 12)

Is there another way to do that? What about something like:

row(row(tree, 3), 4)

Why does this work? It's because our functions just take a picture, and a row of three men is a picture, and we can make a rot of four of those, which gives us 12 trees!

This is normally about the end of the session. If things go on further, we can show them the M.C. Escher painting make with Geomlab, showing how it looks and uses the same techniques as the row() function. Alternatively, we can show them crowd(man, 8, 5), which uses the same recursive pattern.

I hope that all makes sense. Mostly, you'll just be typing the things on I say into either Geomlab or Notepad (so they can see the code). Then when they're solving our challenges, we walk around and try to help them out. If you run through the first few worksheets on the Geomlab website, you'll be an expert.

Personal tools