P/NP for Into CS: A Work in Progress

So after finally figuring out a way to get things appropriately transcoded, I had videos of me using Prezi to talk about P/NP.

Overall, I’m not sure that the zoomable interface really worked for me. What I wanted was for my discussion to be embedded in a concrete document you could take with you after the presentation was through.

I still think the idea of linking the presentation to the document is a good one. Here is the pdf that goes with the presentation.

But trying to layout everything in a small space made the visuals very busy. I don’t like that.

Having this terse version of your presentation in your field of view also I think encouraged me to be be terse and formal. As a result I feel like this presentation was a lot less fun, which is a particularly bad thing for this whole P/NP business.

When I have slides by contrast, many of them reference prepared jokes and force me to keep re-engaging the audience. Things like jokes won’t ever really be able to appear on the “one page” version of a talk.

But then again, things are always different on the other side of the podium. Anyone else willing to watch a hour long talk to tell me what you think?

P/NP Practice Talk Part 1 from Michael Hewner on Vimeo.

P/NP Practice Talk Part 2 from Michael Hewner on Vimeo.

P/NP Practice Talk Part 3 from Michael Hewner on Vimeo.

TACrypt – A JavaScript Hack for Webpages With Multiple Reveals

So the TAs in the class I’m observing have a problem. They’ve got some material they want to present about (briefly), but because students have a lab assignment the presentations tend to get drowned out. Students are busily trying to get started and get out as quickly as they can.

Of course, one solution is to just not post the assignment until the presentation is complete. But in an assignment with multiple parts, this tends to make for long boring lecturing. And who remembers how problem 5 was presented after doing problems 1-4 anyways?

I’ve also been encouraging the TAs to stop work every now and again and have students pair up or something to check their answers. An hour practicing the wrong technique is not gonna help anybody. But as long as the students are just trying to get done at max speed, they’re not going to be particularly reflective as they compare answers.

OK, solution-time. I wanted a way to post a static page with encrypted sections. That way the TAs can just write the password on the board – they don’t have to have multiple files, or login anyplace to “enable” stuff.

So I built a library using jQuery and Gibberish-AES to do that. The main thing was trying to make it easy to write these homework pages. Here’s my instructions:

  1. Write your webpage with the various sections you want to hide
    surrounded by div tags with a password attribute. Like so:

    <div password="foo">
    This is a question.  But I don't want it revealed till
    you enter 'foo' in the password box.
    </div>
    

    Of course the password should be whatever you want the password for that section to be.

    The webpage can be just about as fancy as you need it to be. But you must have a <head></head> and <body></body>tag pairs. Certian kinds of tricky javascript may also have some problems.

  2. 2. Include my javascript library in your page, by adding this to the head:
    <script type="text/javascript" src="http://home.cc.gatech.edu/hewner/uploads/1/tacrypt.js"></script>
    

    or, you know, copy that javascript to wherever you want to and point the page there.

  3. When you load your page now, every div that you marked with a password should now be invisible. For double checking purposes a label should be there pointing it out and indicating what the password is. To make sure everything is working properly, type your passwords into the box at the upper left and be sure everything is appearing like you think it should be.
  4. Click the link on the bottom of the page to show code. You should see all the div contents has been replaced with encrypted strings. Sanity check to make sure the HTML looks fine…the replace mechanisms aren’t 100% bulletproof.
  5. Cut and paste that code into a new HTML file you distribute. That’s all you need to do!

You can see a page in action as well as the student view.

What do you think? Is this the easiest way? For the curious, here is the source code.

A Real Example Of Exponential Runtime

With the help of the textbook associated with the graph library I was using, I was able to build some graphs that require exponential runtime. Actually, factorial runtime which is slow, as my laptop’s second processor can attest to at this moment. The key to defeating the algorithm was to come up with a graph that was Biconnected but had no Hamiltonian Cycle. Once I had that, it was easy enough to to attach it to arbitrary-size complete graphs. The algorithm always checks the edges in order, so having this “unhamiltonianable” appendage stuck onto the end forced it to try every permutation of the first n – 7 vertices.

This may not be the most elegant solution ever, but it is a bit gratifying to know I haven’t completely lost everything I learned in algorithms class.

An for those who are curious, here, is an honest-to-goodness graph of an exponential algorithm sucking for real. Not quite as smooth as I would like, but then again I don’t think I’ll be able to get n = 20 even if I let this thing run overnight.

An Example of Exponential Runtime

This is a question any theory-oriented friends of mine should feel free to jump in on.

So I wanted to make some graphs for explaining Big O. And I wanted to include exponential functions on that graph. But unlike my previous examples of such things, I didn’t want to say “oh wow, look at this graph of 2^n….see how terrible it is” because I know that real exponential functions in practice are often much happier than 2^n. I wanted real run-time data, ideally using source code from some trustworthy seeming source (i.e. not me).

“So heck,” said I, “surely Mathematica has implementations of some of these famous NP-Complete problems. I’ll run some of those and I think that that’s at least plausibly trustworthy.” So I poked around and found some graph algorithms – specifically traveling salesman and Hamiltonian cycle.

Then came the difficulty of generating good problem examples. I initially thought I’d just use random graphs but the runtime varied so much it just wasn’t reasonable. Then I noticed that if I passed in complete graph to Hamiltonian Cycle with one completely disconnected vertex, the Hamiltonian Cycle algorithm would be pretty dang slow:

But was it really exponential? This is where I’m stuck. I don’t really understand the algorithm that’s generating these solutions – for all I know it might be detecting the disconnected vertex (albeit somewhat late) and might be evidencing merely some (bad) polynomial time.

HamiltonianCycle[g_Graph,flag_:One] :=
	Module[{s={1},all={},done,adj=Edges[g],
                e=ToAdjacencyLists[g],x,v,ind,n=V[g]},
		ind=Table[1,{n}];
		While[ Length[s] > 0,
			v = Last[s];
			done = False;
			While[ ind[[v]] < = Length[e[[v]]] && !done,
                               x = e[[v,ind[[v]]++]];
                               done = !MemberQ[s, x] &&
                                       (Length[s] == 1 ||
                                        BiconnectedQ[DeleteVertices[AddEdges[g, {{1, x}}], Rest[s]]])
			];
			If[done, AppendTo[s,x], s=Drop[s,-1]; ind[[v]] = 1];
			If[(Length[s] == n),
				If [MemberQ[adj, Sort[{x, 1}]],
                                    AppendTo[all,Append[s,First[s]]];
                                    If [SameQ[flag,All],
                                        s=Drop[s,-1],
					all = Flatten[all]; s={}
			            ],
			            s = Drop[s,-1]
				]
			]
		];
		all
	]

Does that look familiar to anyone? Any guesses to Big-O for this kind of input?

OR – say you wanted to provide an example of real running exponential function. What would you use instead of my Hamiltonian Cycle hack?

Thoughts on Lecture, Slides, and What We Take Away

Most of you have seen a presentation of mine. My usual presentation style involves big pictures and titles, the occasional joke, and every now and then a diagram to illustrate a point. I certainly like this style, and I know that I can at least be entertaining when I try. But I’ve come to believe it is not a style that really works for teaching.

The main problem as I see it is that you have nothing to take away. The slides are just props to the performance happening up front; they’re useless by themselves. And even if things have been video-taped and are available after the fact, all that detailed motivation and funny stories is just fluff the second time through. That said, your average “regular style” slide deck is pure torture to see live and only marginally better after the fact.

A good set of notes is one alternative and I have no beef with that form. But I’ve been thinking about an alternative, riffing on Tufte’s idea that a good visualization can convey plenty and also be the sort of thing you can take home with you. But the difficulty with these information-dense formats is that they are hard for novices.

I’ve been thinking about a presentation centered around a sheet of graphical notes (pdf). You could use something like prezi to zoom around the sheet, adding digressions and details and explaining. And the sheet acts as “cheat sheet” as well, providing a physical source for definitions and other details that may not have been internalized when they were presented. And then, when the presentation is done the physical artifact acts as a trigger – not only containing its raw summary text but also potentially the memories of the jokes and digressions and examples that came along with the presentation itself.

My first attempt at uploaded video

There are still quite a few problems here.

Also, I’m not sure that allowing me to do re-takes on my introductions is a good thing. I just never feel like I’ve done it properly.

Putting your best foot forward

So I’m going to introduce myself to the class I am observing.

Did it make anybody chuckle? Trying too hard?

Those who want the complete presentation (yes, with even more jokes) can see my slides including notes.

My First Android App: 10K Hours

Ok, for people who haven’t read Malcolm Gladwell’s book Outliers, it includes the idea that to be really good at something you must practice. It’s not exactly revolutionary, but what is interesting is that he puts a number to the amount of practice you ought to do: about 10000 hours to be world-class. Gladwell goes through a lot of examples – Beethoven, The Beatles, Bill Gates. Some people might argue with some of Gladwell’s specifics, but what really is clear is that these people did practice quite a lot before they did any of their really cool stuff.

Gladwell makes a somewhat provocative claim: that what we normally think of as “talent” is basically the opportunity and willingness to practice. Some have disagreed with him on this point, saying basically that he is engaging in wishful thinking.

But when you look at 10000 hours, I’m not sure wishful thinking is really the way I would describe it. Having the opportunity to get that much time to work on a particular skill – well it definitely speaks to a certain amount of freedom from life’s usual responsibilities. It may simply be that 10,000 hours is correlated with great talent because if you are less than supremely talented, around hour 5000 or so somebody is going to insist that you stop practicing and get a real job.

Anyways, this has all got me thinking of my own life and how little time there really is for reflective practice. I may be here at Georgia Tech “training” to become a teacher, but even with practice considered quite broadly I’m not getting many hours in on a daily basis. You don’t have to buy much of Gladwell’s thesis to imagine that maybe 1000 hours of practice on a valued skill would be worthwhile. I am not on track, in that regard.

So this is all to say that I built an Android App to help motivate myself. It’s pretty simple: you tell it what skills you want to practice, how many hours your goal is, and then it logs how many hours you put in.

10k-hours.png

The most motivating line is the one that says how many years it will take to reach your goal at your current speed. It’s surprisingly how easily that can exceed a lifetime.

Anyways, if you have an android phone and would like to try my app, go here. You can also get the source here: hours10src.zip.

Given some motivation, I could probably test this on a couple more emulated systems and drop it in the android marketplace. Would anybody out there in internet land like me to go through the trouble?

The Llamas of Computing: A P/NP Fairytale

As part of my continuing obsession, I had the thought that it might help things if I had a story that people could related to. One of the tricky things about P/NP is everything has non-obvious names and the relationships (i.e. problem reducibility, problem runtime) are not something non-CS people think about. I played around with a couple of metaphors and this one was the one I liked the most. My only regret is that there’s really no llama equivalent of a verifier.

My original thought was that I would use this story as an introduction, and then have it structure the rest of the lesson. Now that’s it’s fully written out I wonder if it’s a bit long and involved for that. A homework assignment beforehand? With a few questions at the end to make sure you’ve thought through all the details? Or is it just too patronizing to make people do homework with made up fairy stories?

Once upon a time, there was a giant mountain range. And in this giant mountain range there was city. And in this city was a tribe of people. And this tribe of people was called the Llama Scientists.

The Llama Scientists were a hearty people, and they loved nothing better than to travel out from their city and explore the mountains. The mountains were filled with treasures: gold, platnum, jewels, DVD players and boulders that were shaped like various celebrites – everything was out there in the mountians if you knew where to look.

But the treasures were all very heavy, and the Llama Scientists moderately lazy, and so all the treasure would have remained in the mountains if not for the Llamas. The Llamas could carry the treasures back to the city. But Llamas, not being very smart, had to have a path. And it was important that the path not be too long – otherwise there was no way for a Llama overburdened with treasure to make the trip back to the city.

So the Llama Scientists soon became great experts at finding short paths for the Llamas to take. And the city soon was overflowing with treasure. The city became as rich as a kingdom, and being like a kingdom, needed to have borders. And so the Mayor set forth a Mayorial Decree:

Let all the land to which a llama may traverse in a reasonable amount of time be called P (“P” being short for “Polynomial”, which means “short” in the Llama Scientists simple but beautiful language). P will be the kingdom of the Llama Scientists, this I decree.


So now the Llama Scientists had a kingdom called P. But the kingdom borders infurated the royal cartographers. Clearly, all the land that Llama scientists had found a short path to, that was in the kingdom P. And it might be reasonable to think that Llamas could not fly off to the clouds or cross over an ocean. But that still left a great big chunk of land that still might be in P, just no one had ever found a path yet.
Having nothing better to do, the called this mysterious land NP. They had names for the clouds and the oceans too, but those are not important for this story.

Let all the land to which a llama might traverse, but no path has yet been found, be called NP. NP is the mysterious land of possibility, because at any moment a path may be found that makes something that was in NP part of P.


As Llama Scientists scouted more and more, there were certain rich mountian treasures they longed to find a short route for. But as years of Llama Scientists searched for the paths and found nothing, the more pragmatic Llama Scientists started to believe there was no short path at all. But everyone was infuriated that there was no way to prove that no short path existed, not even for one mountian in the realm of NP.

It might have remained that way forever, were it not for one smart Llama scientist called Cook.

Cook was climbing a mountian in NP called “Satisfiablity” that had been climed many times before. But when he got to the top, he noticed something no one had ever noticed before. Coming down from Mt. Satisfiablity were llama paths: one-way llama paths that led from Satisfiability to the top of every other mountian in NP.

If a short path could be found for Satisfiability, a llama could travel from there to every other mountian in NP. So Satisfiability was “NP-Complete” in that a path for Satisfiability was a path for every other mountian in NP. If Satisfiability had a short path, then the kingdom of P encompassed all of NP.


Cook’s discovery was big news. But then other Llama Scientists noticed something interesting: certain mountians had short paths to the top of Satisfiability. A llama reaching the top of those mountians could quickly travel to Satifiability – and then to any mountian in NP. All these mountains were NP-complete as well.

Any mountian that has a path to a NP-Complete mountian is itself NP-Complete.


Many of the mountains that turned out to be NP-Compelete were mountains that people had been trying to find a path to for a long time. These were the hardest mountains in all of NP.

Most Llama Scientists believe that there is no pratical point in trying to find paths to NP-Compelete mountains, because so many have tried and failed before. So showing that a mountian is NP-Complete is almost like saying “there is no short path”.

But no one is really happy with this. If no short path exists to the NP-Complete mountains, it would be nice to prove that for sure. If there is a short path to one of the NP-Compelete mountains, it would revolutionize Llama science: all the treasures in all the NP-Complete mountains would be open to the Llama Scientists.

Llama scientists often say “Does P = NP?”. What they mean is “is there a short path to every mountian in NP?” If P does not equal NP, it must be the case that there is no short path to any of the NP-Compelete mountains.

Attaching files to your PDFs

One of the things that I don’t like about LaTeX is that the thing you distribute – usually a PDF – is not the same thing you edit. This means that if you ever lose the source files, you can’t rely on just redownloading the version you posted on your website or emailed to your friend or whatever. I keep my LaTeX files in a backed-up source control system, but still I worry.

But I was pleased to discover that PDF files actually supports attachments, so there’s really no reason for me to ever distribute PDFs without the accompanying source ever again. With pdftk, attaching a files is as simple as:


pdftk source.pdf attach_files source.tex source.bbl output output.pdf

I really wish that pdflatex had a flag to do this for me, especially since that way all my weird styles and other auxiliary files could come along for the ride easily. But a quick shell script should suffice for my use case easily enough.