From 6768f1f1e626c2bc753b1bacfc3400affdf0c621 Mon Sep 17 00:00:00 2001 From: Shoofle Munroe Date: Tue, 3 Sep 2013 11:39:11 -0400 Subject: [PATCH] Fixed up Tamari a bit and also moved it to use supplementary content. --- articles/__init__.py | 15 ++- articles/language_for_games.template.html | 15 +++ articles/something_or_other.article.html | 14 +-- articles/something_or_other/soo.js | 11 +++ articles/tamari.article.html | 106 +++++++++++----------- {static => articles}/tamari/tamari.py | 0 {static => articles}/tamari/tamari_2.dot | 0 {static => articles}/tamari/tamari_2.png | Bin {static => articles}/tamari/tamari_3.dot | 0 {static => articles}/tamari/tamari_3.png | Bin {static => articles}/tamari/tamari_4.dot | 0 {static => articles}/tamari/tamari_4.png | Bin {static => articles}/tamari/tamari_5.dot | 0 {static => articles}/tamari/tamari_5.png | Bin {static => articles}/tamari/tamari_6.dot | 0 {static => articles}/tamari/tamari_6.png | Bin {static => articles}/tamari/tamari_7.dot | 0 {static => articles}/tamari/tamari_7.png | Bin {static => articles}/tamari/tamari_8.dot | 0 19 files changed, 92 insertions(+), 69 deletions(-) create mode 100644 articles/language_for_games.template.html create mode 100644 articles/something_or_other/soo.js rename {static => articles}/tamari/tamari.py (100%) rename {static => articles}/tamari/tamari_2.dot (100%) rename {static => articles}/tamari/tamari_2.png (100%) rename {static => articles}/tamari/tamari_3.dot (100%) rename {static => articles}/tamari/tamari_3.png (100%) rename {static => articles}/tamari/tamari_4.dot (100%) rename {static => articles}/tamari/tamari_4.png (100%) rename {static => articles}/tamari/tamari_5.dot (100%) rename {static => articles}/tamari/tamari_5.png (100%) rename {static => articles}/tamari/tamari_6.dot (100%) rename {static => articles}/tamari/tamari_6.png (100%) rename {static => articles}/tamari/tamari_7.dot (100%) rename {static => articles}/tamari/tamari_7.png (100%) rename {static => articles}/tamari/tamari_8.dot (100%) diff --git a/articles/__init__.py b/articles/__init__.py index 95390ce..02d6160 100644 --- a/articles/__init__.py +++ b/articles/__init__.py @@ -6,7 +6,7 @@ to the `bloop` object. It's a blueprint which describes how to route requests fo `render_article`; Go team!""" import os -from flask import Blueprint, render_template, abort +from flask import Blueprint, render_template, send_from_directory, abort folder = "articles" article_base_template = os.path.join(folder, "article.template.html") @@ -78,17 +78,22 @@ def supplementary(article_name, file_path): necessary to make a blueprint for it. Then, it's necessary to include the blueprint in this file. Oh well. """ # Put the article name into the standard form, and concatenate them together. - article_name = page_name.replace("-", "_").lower() + article_name = article_name.replace("-", "_").lower() # You could make a strong argument that this is unnecessary, and we could just shove in a static file handler. # But I like this solution more. It better separates out the supplementary content from the article itself. # Things that don't fit into this framework might not belong as articles, anyway! - path = os.path.join(article_name, file_path) - print("trying to render supplementary stuff at /{an}/{p}/".format(article_name, file_path)) + + # Important! This didn't work right for a long time until I finally made it join `folder` to the beginning. + # Without that, it tries to load the file relative to wherever the server's running - which is /not/ the + # right thing. The server's running somewhere, but this needs to be in the articles folder, yadda yadda, + # you can figure it out. + path = os.path.join(folder, article_name, file_path) # If the path exists and is a file, then we should send it. if os.path.isfile(path): directory, file_name = os.path.split(path) - abort(420) + print("sending %(fn)s from directory %(d)s" % {"fn": file_name, "d": directory}) + return send_from_directory(directory, file_name) # If that file wasn't found, then, well, whoops. diff --git a/articles/language_for_games.template.html b/articles/language_for_games.template.html new file mode 100644 index 0000000..9a12a25 --- /dev/null +++ b/articles/language_for_games.template.html @@ -0,0 +1,15 @@ +{% extends "articles/article.template.html" %} + +{% block title -%} +Features for a game-focused programming language or library +{%- endblock %} + +{% block body -%} +

I like making games but sometimes I spend a lot of time doing stuff that is just annoying. What if a language or environment were designed to make those things easy?

+
+{%- include "articles/snorlax_evaluation.article.html" -%} +
+{%- include "articles/time_integration.article.html" -%} +
+{%- include "articles/easy_peasy_state_machinesy.article.html" -%} +{%- endblock %} \ No newline at end of file diff --git a/articles/something_or_other.article.html b/articles/something_or_other.article.html index 53bea68..156fb4c 100644 --- a/articles/something_or_other.article.html +++ b/articles/something_or_other.article.html @@ -1,19 +1,7 @@
- +

Oh look a graph

That's the graph

diff --git a/articles/something_or_other/soo.js b/articles/something_or_other/soo.js new file mode 100644 index 0000000..7141d4a --- /dev/null +++ b/articles/something_or_other/soo.js @@ -0,0 +1,11 @@ +var data, config; +$(document).ready(function() { + data = []; + for (var i=0; i<10; i++) { + data.push([i, i*i/10]); + } + config = {}; + config.yaxis = {max: 10}; + config.xaxis = {min: 0, max: 10}; + $.plot($('#the_graph'), [data], config); + }); diff --git a/articles/tamari.article.html b/articles/tamari.article.html index 6d97300..1442d02 100644 --- a/articles/tamari.article.html +++ b/articles/tamari.article.html @@ -1,66 +1,70 @@
-

Tamari Lattices!

-

Tamari lattices are graphs (in the mathematical sense - a set of nodes with connections between them) describing a particular set of operations. I like them because they're pretty!

-
- The (trivial) Tamari lattice for a three-element tree. -
A (trivial) Tamari lattice, generated by the associations of three elements. Source file.
-
-

Oh - oh dear. How'd that get there? Okay, that's not a very good example.

-

There are many ways to generate and think of a Tamari lattice. The way I prefer to think of it is this: Consider some binary operation - you take two elements to produce a new one. You want to combine several of these elements. So long as you have three or more elements, there are multiple ways to combine them.

-

The game we play is this: You're allowed to step from one way of combining the elements to another, but only by left-association: turning (a, (b, c)) into ((a, b), c).

-

The only remaining rule is that if you can step from one combination to another, the second one has to appear below the first one when you draw it.

-
- A Tamari lattice for a four-element tree. -
As above, but generated by a four-element tree. Source file.
-
-

You can also think about it in terms of tree rotations - but remember that that's a different tree than the one we're building as the Tamari lattice. Tree rotations are just another way to think of left-association and right-association.

-

If you look at the wikipedia article on Tamari lattices, you'll see a very pretty image:

+

Tamari Lattices!

+

Tamari lattices are graphs (in the mathematical sense - a set of nodes with connections between them) describing a particular set of operations. I like them because they're pretty!

+
+The (trivial) Tamari lattice for a three-element tree. +
A (trivial) Tamari lattice, generated by the associations of three elements. Source file.
+
+

Oh - oh dear. How'd that get there? Okay, that's not a very good example.

+

There are many ways to generate and think of a Tamari lattice. The way I prefer to think of it is this: Consider some binary operation - a way to use two things to make a new one. You want to combine a bunch. So long as you have three or more elements, there's more than one way to combine them - if you've got a, b, and c, you could combine b and c, and then combine the product of that with a, or you could combine a and b, and then combine that with c. We're going to pretend you can't combine a and c (although maybe that would produce more pictures...). The way we write combining two elements is like this: (a, b). So that means that the first way of combing a, b, and c is written like so: (a, (b, c)). The second way would be ((a, b), c).

+

Okay, got it? Good.

+

The game we play is this: You're allowed to step from one way of combining the elements to another, but only by left-association: turning (a, (b, c)) into ((a, b), c).

+

The only other rule is that if you can step from one combination to another, the second one has to be drawn below the first one when you list them all out.

+
+ A Tamari lattice for a four-element tree. +
As above, but generated by a four-element tree. Source file.
+
+You can also think about it in terms of tree rotations - but remember that that's a different tree than the one we're building as the Tamari lattice. Tree rotations are just another way to think of left-association and right-association. +

If you look at the wikipedia article on Tamari lattices, you'll see a very pretty image:

+
-

There are a lot of ways to reorganize a Tamari lattice, and it takes some artistic work to make one that really looks good. You can even visualize the same graph as a 3D shape called an "associahedron", but I like it in the simple gridded lattice form above. It reminds me how much beauty there can be in regularity - you can see the grid, but it doesn't look constrained by it. I might get a tattoo of the five-element Tamari lattice someday.

-
- Tamari lattice for a five-element tree. -
Also the five-element lattice! Compare to the example above, on wikipedia.. Source file.
-
-

All these graphs with the ovals and the curvy lines were generated by yours truly! I made some python that would take a string representation of an association of a number of elements and convert it into an easily-manipulated memory representation. Then, a few tree rotations spit out all the possible results of left-associating on it, and it was relatively simple to print out a .dot file, parseable by graphviz, that described the graph. It even labeled the nodes!

-

dot happily converted them into the png files you're looking at. Of course, they don't have the human touch, so they're not organized into beautiful grid lines and 45° angles - but it can be fun to try to mentally reorganize them into a nicer shape. If you want, you can download the .dot source files for any of these, and play around with them in a graph-editing program (such as XDot)

-
- Tamari lattice for a six-element tree. -
It's starting to get out of hand, I think.Source file.
-
-

Unfortunately, at a certain point I think it's going to get difficult to make these pretty. It turns out there are a lot of ways to associate a larger number of elements! Starting with a six-element tree or string, there are 42 elements (above). With seven, there are 132! Wowie!

-
- Tamari lattice for a seven-element tree. -
Oh dear. Source file.
-
-

My server was chugging along trying to generate tamari_8.dot but I started getting messages from linode about going over my CPU quotas, so I canceled it - after it ran for an hour or so, without finishing. I think the seven-element one is messy-looking enough!

-

You can look at the python script I used to make this, but it's not particularly pretty - I was bored one day and decided I was going to figure out how to generate these... It's not exactly meant to be extensible. It's got a basic binary tree node class I threw together for working the association rules and a handful of (really ugly) helper functions. I just went through and rewrote it a bit to be nicer - the final output loop may please you if you enjoy sets and list comprehensions:

-
+	
http://en.wikipedia.org/wiki/File:Tamari_lattice.svg
+
+

There are a lot of ways to reorganize a Tamari lattice, and it takes some artistic work to make one that really looks good. You can even visualize the same graph as a 3D shape called an "associahedron", but I like it in the simple gridded lattice form above. It reminds me how much beauty there can be in regularity - you can see the grid, but it doesn't look constrained by it. I might get a tattoo of the five-element Tamari lattice someday.

+
+Tamari lattice for a five-element tree. +
Also the five-element lattice! Compare to the example above, on wikipedia.. Source file.
+
+

All these graphs with the ovals and the curvy lines were generated by yours truly! I made some python that would take a string representation of an association of a number of elements and convert it into an easily-manipulated memory representation. Then, a few tree rotations spit out all the possible results of left-associating on it, and it was relatively simple to print out a .dot file, parseable by graphviz, that described the graph. It even labeled the nodes!

+

dot happily converted them into the png files you're looking at. Of course, they don't have the human touch, so they're not organized into beautiful grid lines and 45° angles - but it can be fun to try to mentally reorganize them into a nicer shape. If you want, you can download the .dot source files for any of these, and play around with them in a graph-editing program (such as XDot)

+
+Tamari lattice for a six-element tree. +
It's starting to get out of hand, I think. Source file.
+
+

Unfortunately, at a certain point I think it's going to get difficult to make these pretty. It turns out there are a lot of ways to associate a larger number of elements! Starting with a six-element tree or string, there are 42 elements (above). With seven, there are 132! Wowie!

+
+Tamari lattice for a seven-element tree. +
Oh dear. Source file.
+
+

My server was chugging along trying to generate tamari_8.dot but I started getting messages from linode about going over my CPU quotas, so I canceled it - after it ran for an hour or so, without finishing. I think the seven-element one is messy-looking enough!

+

You can look at the python script I used to make this, but it's not particularly pretty - I was bored one day and decided I was going to figure out how to generate these... It's not exactly meant to be extensible. It's got a basic binary tree node class I threw together for working the association rules and a handful of (really ugly) helper functions. I just went through and rewrote it a bit to be nicer - the final output loop may please you if you enjoy sets and list comprehensions:

+
 current_generation = set()
 next_generation = {RootOfAllEvil}
-edges = set()
+	edges = set()
 labels = set()
 
-while next_generation: # While there are trees to examine.
-	# Move to look at the next generation.
+	while next_generation: # While there are trees to examine.
+# Move to look at the next generation.
 	current_generation = next_generation
 
-	# Clear out the next gen to fill it with the children of this generation.
-	next_generation = set()
+# Clear out the next gen to fill it with the children of this generation.
+next_generation = set()
 
-	# Ensure there are labels for this generation.
-	labels = labels | set(label_from_node(parent) for parent in current_generation)
+# Ensure there are labels for this generation.
+labels = labels | set(label_from_node(parent) for parent in current_generation)
 
 	for parent in current_generation:
-		children = generate_children(parent)
+children = generate_children(parent)
 
-		labels = labels | set(label_from_node(child) for child in children)
-		edges = edges | set(str(parent) + " -> " + str(child) + ";" for child in children)
-		next_generation = next_generation | children
+labels = labels | set(label_from_node(child) for child in children)
+	edges = edges | set(str(parent) + " -> " + str(child) + ";" for child in children)
+	next_generation = next_generation | children
 
 # Output a dot-formatted stream!
-args.output.write(u"digraph tamari {\n")
-args.output.write(u"\n".join(labels) + "\n")
-args.output.write(u"\n".join(edges))
-args.output.write(u"\n}\n")
+ args.output.write(u"digraph tamari {\n") + args.output.write(u"\n".join(labels) + "\n") + args.output.write(u"\n".join(edges)) + args.output.write(u"\n}\n")

The full script can be used by running python tamari.py --length 4 | dot -Tpng > output.png to produce a graph. tamari.py will print out to a specified file if you also include a filename: python tamari.py --length 5 output.dot

-
\ No newline at end of file +
diff --git a/static/tamari/tamari.py b/articles/tamari/tamari.py similarity index 100% rename from static/tamari/tamari.py rename to articles/tamari/tamari.py diff --git a/static/tamari/tamari_2.dot b/articles/tamari/tamari_2.dot similarity index 100% rename from static/tamari/tamari_2.dot rename to articles/tamari/tamari_2.dot diff --git a/static/tamari/tamari_2.png b/articles/tamari/tamari_2.png similarity index 100% rename from static/tamari/tamari_2.png rename to articles/tamari/tamari_2.png diff --git a/static/tamari/tamari_3.dot b/articles/tamari/tamari_3.dot similarity index 100% rename from static/tamari/tamari_3.dot rename to articles/tamari/tamari_3.dot diff --git a/static/tamari/tamari_3.png b/articles/tamari/tamari_3.png similarity index 100% rename from static/tamari/tamari_3.png rename to articles/tamari/tamari_3.png diff --git a/static/tamari/tamari_4.dot b/articles/tamari/tamari_4.dot similarity index 100% rename from static/tamari/tamari_4.dot rename to articles/tamari/tamari_4.dot diff --git a/static/tamari/tamari_4.png b/articles/tamari/tamari_4.png similarity index 100% rename from static/tamari/tamari_4.png rename to articles/tamari/tamari_4.png diff --git a/static/tamari/tamari_5.dot b/articles/tamari/tamari_5.dot similarity index 100% rename from static/tamari/tamari_5.dot rename to articles/tamari/tamari_5.dot diff --git a/static/tamari/tamari_5.png b/articles/tamari/tamari_5.png similarity index 100% rename from static/tamari/tamari_5.png rename to articles/tamari/tamari_5.png diff --git a/static/tamari/tamari_6.dot b/articles/tamari/tamari_6.dot similarity index 100% rename from static/tamari/tamari_6.dot rename to articles/tamari/tamari_6.dot diff --git a/static/tamari/tamari_6.png b/articles/tamari/tamari_6.png similarity index 100% rename from static/tamari/tamari_6.png rename to articles/tamari/tamari_6.png diff --git a/static/tamari/tamari_7.dot b/articles/tamari/tamari_7.dot similarity index 100% rename from static/tamari/tamari_7.dot rename to articles/tamari/tamari_7.dot diff --git a/static/tamari/tamari_7.png b/articles/tamari/tamari_7.png similarity index 100% rename from static/tamari/tamari_7.png rename to articles/tamari/tamari_7.png diff --git a/static/tamari/tamari_8.dot b/articles/tamari/tamari_8.dot similarity index 100% rename from static/tamari/tamari_8.dot rename to articles/tamari/tamari_8.dot