Matrix Wars (1.01)

Tags

, , ,

Continuing in our exploration of gamified higher math, Leo and I programmed up a version of space invaders in HopScotch that depends on matrix multiplication. I took only a few hours to create a pretty interesting game. Below are some screenshots from the game. It’s a bit hard to explain the game play; I recommend playing it yourself here!

img_0995


The matrix (Vmn) is constantly being multiplied by the current target (Txy) to create the new values (Nxy):

Nxy=Txy*Vmn

You click on the V(mn) entries to roll them through -1, 0, 1, and then when you have an Nxy result you like, click “Fire” to load the new (Nxy) to the target (Txy). Since the matrix multiplication is being continuously, as soon as you load the Nxy into the Txy, the new Nxy are re-computed. It’s easy to create matrices that move the target around in more-or-less any way you like.

img_0987


Meanwhile, the invader is getting closer and closer. If you hit the invader before it hits earth, you win.

img_0996



 

PythonCraft: Chasing the Sort Front

Tags

, ,

Leo watched an extremely good TedEd about sorting algorithms, and wanted to try it out himself, so we wrote a simple bubble sort in Python, and we deployed it through the PythonCraft API to run in MineCraft. This turned out to be more fun and educational than I thought it was going to be.

To begin with, here’s the code (slightly cleaned up for display here; you’ll have to add the right imports, for example):

pythoncraftbubblesort

Unsurprisingly, we had the longest discussion about why you need the “Hold” variable in the swap step(s). There are two errors in this code, that I’ll reveal below. (The highly motivated reader can try to figure these out; Actually, any semi-competent programmer can probably guess what the errors are without even looking at the code!) Regardless, it does the basic job.

So, it’s actually extremely cool when it runs, because you can watch the sort in action, and actually chase down the sort front! Here are a couple of videos of us doing that:

(Note the sheep on the blocks!)

You can see (and I mention) one of the bugs in the video: The “Obi wan” (Off by One) error, which leaves on of the blocks unsorted at the far end of the array.

The other bug is more subtle, until I point it out: We actually intended to sort by rainbow order (ROYGBIV), but that would have required another dereference, and when I tried to explain that, it went right over Leo’s head, him already being well snowed by the Hold/Swap problem, so I simply let it go. As a result, it’s actually sorting by whatever the color codes happen to be in MineCraft, which seem to be random (or at least I can’t tell what the logic is that relates MC color IDs to rainbow order).



 

NewtonCraft: Rocket Engine Blocks

Tags

, , , , , ,

This year I’ve been making a concerted effort to “climb the mountain of algebra” with Leo through physics (like some sort of Newtonian Julie Andrews*). One way into this that works extremely well in motivational terms is (unfortunately) via MineCraft. Here’s an early example of using MineCraft to motivate some algebra. This week we did an interesting problem on Newton’s second law. (That’s the F=MA one, in case you don’t remember the order!) The pages are reproduced below, and if you click any of them, they link to a downloadable powerpoint which contains a bunch of “fun” math worksheets, including these (although, of course, “fun” is in the eye of the student).


img_2159img_2161
img_2165

By the way, although there really is a MineCraft Mod called “Mekanism”, which has a lot of cool stuff, like lasers and a fusion reactor, it doesn’t actually have an REB … I made that up!


(*) This is an oblique reference to the wonderful movie “In The Loop”. Search for “Climb the mountain of conflict”, and watch the youtube video. I won’t link to it because it’s slightly NSFW (“strong language”, as they say), and definitely NSFK! But if you’re an adult, it’ll make you truly lol!



 

Fun (and Educational) Fluid Physics

Tags

, , ,

Off of quantum mechanics for a moment, and back to the world of macroscopic (newtonian) fluid physics. We’ve been playing a lot with fluid (particle-based) simulations lately, looking at lift, drag, and turbulence, the bernoulli effect, eddies, and other such-like chaotic phenomena.  (“Macroscopic” would be putting it a bit too strongly; Maybe “mesoscopic” is the right word?)

I had in mind actually making a Navier-Stokes game, but it turns out that there are already a bunch of great apps out there that simulate these phenomena perfectly well, and are also very fun! I’ve tried out at least a dozen — I only bother with the free ones! — and two are of special note.

The first is Wind Tunnel (Free), by Algorizk (which I assume is either a name or a pun). This is a simple but extremely nice app with all the right capabilities. You can draw arbitrary shapes, view in particle, smoke, pressure, or speed modes, and calculate overall lift and drag. Here are some examples:

 

There are a bunch of pre-drawn objects (although not many), and you can draw your own objects. My only complaint about this app is that you can’t rotate solid bodies, like the wing above, in order to experiment with angle-of-attach (that is, the position of the object with respect to the flow).

The other great example of a fluid sim is Powder Game. The free version is ad-supported, but the ads are along the bottom, and not too annoying. In addition to being an newtonian fluid simulator, Powder Game has tons of special types of particles:

img_0976

This lets you do a ton of very fun experiments, like exploding things and watching the chaotic dynamics on Nitro!

img_0978img_0980

You can spend hours with either of these apps in the perfect paradigm of learning-by-playing.

In another post I’ll talk more about some great newtonian sims that are a truly macroscopic, which is fun (and educational) of a very different sort, at a very different level.



 

HopScotching towards Quantum Computing

Tags

, , , , ,

Leo’s FLG (Focused Learning Goal) for this year is to build a real quantum computing mod in MineCraft. (Note that the kids set these goals for themselves at the beginning of the year, and although I might have slightly influenced his choice of project, the “in MinceCraft” setting was all Leo!) This came from several sources, aside from just the obvious entanglement of his interest in quantum computers with MineCraft. The main one is that there are two quite cool MineCraft mods, one, called qCraft, that adds a sort of quasi-quantum mechanics, and another, called Mekanism, that adds all sorts of advanced devices, esp. lasers. The qCraft mod actually has quantum computer components, but they are not very elegantly done; We wanted to make it a little more like a real quantum computer by using the Mekanism lasers as the qubit sources, and then add optical components for the gates.

(If you don’t know what the heck I’m talking about, there are innumerable videos on quantum computation on youtube, but if you REALLY want to understand it, I strongly recommend this excellent set of short lectures by Michael Nielsen, which not only nicely demystifies quantum computers, but at the same time demystifies quantum mechanics!)

Anyway, so we needed to get our feet a tiny bit wet toward this pretty massively complex FLG. Unfortunately, direct MineCraft modding is done either in Java or Python. (There are a few little experiments in modding in scratch-like languages, but, much as they are nice tries, they have issues, so I decided not to bother with them, at least for the moment.)

To get our feet wet using a programming paradigm that Leo already knows, we chose HopScotch. Together we created a highly simplified quantum computer game in HopScotch. We only have one gate, a Hadamard gate, and the quantum state is highly simplified, having only the possibilities of being 1 or 0 or 50/50, no complex numbers nor normalizations.

But it’s kinda cool, none-the-less:

img_0958

The circle represents a qubit that might be a photon, for example, and its color represents its quantum state: green is definite 1, and red is definite 0. It travels a continuous loop from left to right, and then re-appears on the left again, as though it’s on a quantum wire that’s looped around from the end to the start.

When the program starts, the photon’s quantum state is definite 1 (1.0|1>+0.0|0>), and so the photon is green. The M box on the right measures the quantum state, “collapsing” it to 1 or 0. If you just let the program run from the start without doing anything (as above), the measurement gate will just keep reading 1, and incrementing the 1 count. The photon will just stay green.

The hex is a Hadamard gate (H gate), which splits the quantum state in half: 0.5|1>+0.5|0>. (Remember that we’re simplifying here, so there are no complex values or normalizations, and I’m using probabilities instead of amplitudes; I did say “simplified” and “baby steps”, right?!) If you drag the hex into the photon’s path (pic below), the state becomes a mixture of 1 and 0, and the color becomes a (ugly) mixture of red and green:

img_0960

When the qubit in this 50/50 state gets measured (that is, when it hits the M gate), there’s a 50/50 chance of “collapsing” into a 1 or a 0. It’ll change to either red or green, start again at the left, hit the H gate again, and so on. If you let it run like that for a while, the counts of 1 and 0 will come out the same, statistically speaking.

You can try it out yourself on HopScotch on your iPad. (I’m told that HopScotch now allows you to run code in your browser, so you don’t need to actually have HopScotch on an iPad, although I highly recommend HopScotch on an iPad!)



 

Some pointless Pi/factorial numerology

Tags

, , ,

As I’ve previously mentioned, Leo loves large numbers. While we were looking at factorials with huge numbers of digits in the result — a favorite puzzle being predicting the number of trailing zeros — he noticed that there were a few digits of Pi embedded in one of them. So we wrote a program to find the largest run of Pi embedded in a factorial…or at least as far as we felt like letting the program run, which was up to 26000!

Here’s the log:

Pi digs  n(!)
1          8
2         32
3         35
4        116
5        147
6        380
7       3057
8       5599
9      14192

That’s it under 26000! I’ll spare you the 52765 digits of 14192! Suffice it to say that the sequence “314159265″ shows up at the 48996-th digit!

(Before you complain, of course there are many occurrences of shorter sequences all over the place. This is just the location of the first occurrence of each next longest subsequence, so, for example, there are 3, and 31, and 314’s all over the place, but the first 314 occurs in 35!)

I’m not going to bother showing you the couple of line of simple Lisp code that it took to program this up. …Exercise for the reader!   🙂



An Exploration of Molecular Rigidity

Tags

, ,

As I mentioned a few posts ago, Leo and I have started receiving Science Magazine, and each week, in addition to paging through the issue looking at interesting pictures, I try to find something that we can actually do together that is related to one of the papers (even if the relationship is tenuous).

This week Leo became interested in this paper:

IMG_7923

Okay, so I’ll admit that, not only didn’t we actually read the paper, but I can only vaguely understand the abstract! However, what attracted our attention was this cool figure:

IMG_7914

Leo has always liked complex molecular structures; since he was three, or so, he’s had a molecular construction kit, so these looked like fun!

What seemed most interesting about these molecules is that some of the structures appear to be rigid, while others appear to be floppy. Molecule 2.2, for example, seems to be floppy, whereas the 4.x structures (and 2.1) appear to be rigid.

Whether or not this ends up being really true (recall that we didn’t actually read the paper — see “tenuous” above! :-)), it’s a great excuse to explore rigid v. floppy structures, which we did!

It turns out to be surprising, and surprisingly simple to build structures that can be easily transformed from a rigid to a floppy structure, and back. This is a little hard to explain without seeing it, so here’s a video showing off these interesting structures, built out of Knex . All you need to do to transform it from the rigid form:

IMG_7901

To the floppy form:

IMG_7906

You’ll have to watch the video to see how the conversion works.

These are actually amazingly fun to manipulate, and it’s quite surprising when you discover that just by changing one link you completely change the flexibility of the structure!

It appears that if you add even one additional link to this particular structure, you convert it into one that only has a floppy conformation, although I can’t prove that. Here’s Leo manipulating a slightly larger structure:

IMG_7885



 

A Quantum Mechanical Maze Game

Tags

, , , ,

Leo designed a maze game (roughly) based on quantum mechanics and entanglement.

Here’s the board (the player tokens are the dime and quarter):

IMG_7744

Each square represents a quantum state, so the maze is a state space.There are six paths out of each state, to some other state (or back to itself). (Well, there are supposed to be six paths out of each state, but Leo was being highly disorganized in drawing the maze, so we ended up with a few less in the latter states, but anyway…)

Both players start out in the start state, entangled together. Rounds are collective, that is, players play together. A round begins by rolling two die: First the count die (the green one, in this case) is rolled, and then the path die (yellow) is rolled the number of times shown by the count die. So, for example, if the count die rolls 3, we would then roll the path die three times. Let’s say that the path results are: 4,2,4. Each player then chooses one of the paths to take from their current state to a new state, trying to reach the end state. BUT, there is an “exclusion” constraint(*) that requires that only one player choose each value. So, in the example above (4,2,4), if one player wants to move on path 4, and the other on path 2, there is no problem. Similarly, if both want to move on path 4, there’s no problem because there are two 4s. However, if both want to move on path 2, you have to roll against one another for priority, and the player with the highest roll gets to choose his or her path first, and the other player is left with whatever paths are left.

Simple, but fun!

We had ideas for a bunch of enhancements, esp. re-entanglement if we ended up on the same state, and I had this fantasy of using <bra|OP|ket> notation to record the paths, but we never got around to these. It would have been  a bit better with a more state space maze.

(*) It occurred to me that it would have made more physical sense for the exclusion constraint to keep the players out of the same state, but that would have required redesigning the board from scratch, with two starts next to one another, or something. We’ll have to think about this for a redesign.



 

HopScotch Turing Machine

Tags

, ,

(Unlike most of the work described on this blog, the work described in this post is mostly my own; Leo only participated as a willing player of the resulting game, and in a tiny bit of programming at the end.)

I’ve been trying for some time to get Leo to understand Turing Machines. I had high hopes for MineCraft Turing Machines that Leo found utterly fascinating … as did I! (There are some amazing videos of MineCraft Turing Machines out on YouTube!)  And we’ve had a couple of iPad apps that are slightly helpful,  but they aren’t really engaging enough for a seven year old. I had the idea of creating a Turing Machine mystery game, where you have to figure out what the program is doing, and I finally got around to programming it.

Because we’ve mostly been doing our collaborative programming in HopScotch, which Leo really like, I figured I’d try to make the game I’d imagined there. Unfortunately,  There are many issues — such as timing problems, lack of local variables, and non-independence of cloned objects — that made HopScotch is a little too simple to make anything very complex. (Although some HopScotchers have done amazing things! Sort of like the MineCrafters building computers (and Turing Machines!) out of RedStone!)  However, with a tiny bit of clever design, and a great deal of trial-and-error mucking about, I finally managed to get a simple version of the game I’d envisioned to work, and Leo actually liked it and played it!

You can play it here, if you have HopScotch.

Here are a couple of screencaps from the game in progress. By tapping on the circles, you toggle them center/up/down, and then you can start the machine, which pushes the robot on the left one cell to the right, which starts it executing The Rule. The lower picture, below, shows the state after the machine has stopped from some starting point that I don’t remember.

IMG_0920
IMG_0926

And here’s the rule, which is coded inside the custom function: “Execute the Rule”(Y Nil means that the circles are centered — poor choice of names!):

IMG_0923

Leo got the idea of the game right away, and actually mostly figured out the rule by the intended game play. Then we tried to modify the rule, and although he knew what he wanted to do, which means that he got the concept (Success!), actually making the right changes to the rule case took a little collaborative programming. (My poorly chosen names, like Nil, didn’t help things!)



 

Playdough Science

Tags

, , , , , , , ,

I decided, somewhat insanely, to get Leo a subscription to Science magazine, the lead publication of the AAAS, and one of the two top international scientific periodicals (the other being Nature). My concept here was that we might find at least one interesting science thing to talk about each week, and the pictures in Science are way cool!

(I had gotten him a subscription to Scientific American a while back, but, to be honest, the articles are too long and too wordy, and frankly dumbed-down and pretty boring, so Leo really never got into them. I think what’s going on, in part, is that the graphics/word count is too low in SciAm, whereas in Science it’s way higher, so Science is more like a graphic novel than SciAm.)

The first issue arrived this week, and it turned out that there’s a very high density of articles that were quite interesting, both graphically and in terms of content. Leo was especially interested in this one:

ScreenShot2016070274550

I can hear you yawning, even over the internet!

But wait! I turns out that this is a really cool paper about making very interesting nan0-alloys by combining a bunch of different molecules. It has great graphics, for example:

ScreenShot2016070274520

Notice the interesting seemingly-3-Dimensional egg-like thing in the middle of the picture. The reason that it seems 3D is that is is 3D! We got hold of some PlayDough and made a bunch of model of the various nano-alloys depicted in the paper. Here’s another:

ScreenShot2016070274540

I’m not actually sure which one this was supposed to be…possibly the AuCuCo that it’s sitting on top of.

Anyway, this devolved…or perhaps I should say “evolved” into our creating a complete Clay Science Museum!

Here’s the whole museum:

IMG_7131

In the center we have the anatomically correct insides of a person. Here’s a close up:

IMG_7018

It’s a male, in case it isn’t obvious; I’ll spare you the details! 🙂

This is a ciliate protozoa that we saw in the microscope the other day from a sample of pond water:

ScreenShot2016070273830

This is the LHC (the rings at the bottom are the smaller injection rings, and the ATLAS is the blue thing at the top):

ScreenShot2016070274020

This is quantum tunneling. (Too hard to explain!)

IMG_7115

Here’s the galaxy (supermassive black hole in the center, of course), and the solar system:

ScreenShot2016070274200

Later on Leo stuck his finger in the middle of the black hole to create a singularity.

[Aren’t you relieved that MineCraft isn’t mentioned ANYWHERE in this post! Ummmm … Oops!]