Thursday, February 28, 2008

Zeit Sudoku Bookmarklet

As you know, I am a Sudoku addict. For a nice ten minute break I often download the daily sudoku from Die Zeit. Until recently, from this bookmarked page, I had to change the level from "leicht" to "schwer" and then press the button for the PDF version to print out.

But now, they introduced even another page before that (where you have to choose between the Flash version and the puzzle from the printed (only weekly) newspaper or the oldstyle version that allows the download. You could no longer bookmark the next page as there the URL already contained some sort of session ID.

Of course, they want me to go through all these pages to make sure I do not miss any of the ads they want to present me. But I think that this new version requires a few mouse clicks too much and so I decided to have a look at the page's source code.

It turns out that the URL for the PDF no longer contains a session ID but instead contains today's date, slightly more than you can do with a static bookmark. But that got me thinking that one might be able to solve this problem with a bookmarklet, a bookmark that makes use of the fact you can have JavaScript in a URL and in a bookmark.

Last time I looked into JavaScript was roughly ten years ago and at that time it seemed like a very stupid idea to have some crippled language where you have to transmit all of the source code to the browser which then slowly interprets it if you can do much much more powerful things on the server side with CGI scripts.

Since then, a lot of time has passed and I have heard many interesting things (let me mention only AJAX) suggesting I should maybe reconsider my old dismissal of JavaScript. I had a look though a number of reference sheets and here it is: My first own JavaScript sniplet: A sudoku download bookmarklet. Clicking on this link (or bookmarking it and retrieving the bookmark) brings you directly to the PDF version on the latest "schweres" sudoku! Here is the source:


javascript:var d=new Date();
var m=d.getMonth()+1;
if(m<10){m="0"+m};
var t=d.getDate();
if(t<10){t="0"+t};
open('http://sudoku.zeit.de/sudoku/kunden/die_zeit/pdf/sudoku_' +
d.getFullYear()+'-'+m+'-'+t+'_schwer.pdf')

Thursday, February 07, 2008

Geometric Hamilton Jacobi

Today, over lunch, togther with Christian Römmelsberger, we tried to understand Hamilton-Jacobi theory from a more geometric point of view.

The way this is usually presented (in the very end of a course on classical mechanics) is in terms of generating functions for canonical transformations such that in the new coordinates the Hamiltonian vanishes. Here I will rewrite this in the laguage of symplectic geometry.

As always, let us start with a 2N dimensional symplectic space M with symplectic form \omega. In addition, pick N functions q^i such that the submanifolds L(x^i)=\{m\in M|q^i(m)=x^i\} are Lagrangian, that is T_mL(x^i) is a Lagrangian subspace of T_mM (meaning that the symplectic form of any two tangent vectors of L(x^i) vanishes). If this holds, the q^i can be regarded as position coordinates.

Starting from these Lagrangian submanifolds, we can locally find a family of 1-forms in the normal bundle \theta\in N^*L(x^i) such that \omega=d\theta. You should think that \theta=p_idq^i for appropriate momentum coordinates p_i on the Lagrangian leaves of constant q^i. But here, these are just coefficient funtions to make \theta a potential for \omega.

Now we repeat this for another set of position coordinates Q^i which we assume to be "sufficiently independent" of the q^i meaning that TM=TL(q^i)\oplus TL(Q^i). This implies that locally (q^i, Q^j) are coordinates on M. With the Q^i comes another 1-form \Theta and since d\Theta=\omega=d\theta are locally related by a "gauge transformation". We have \theta = \Theta + dF for a function F.

Let's look at \theta a little bit closer. A general normal 1-form would look like f_i(q^j,Q^k)dq^q. But since we started from Lagrangian leaves, there is no dq^i\wedge dq^j in \omega and thus \theta=p_i(Q^j)dq^i. But expressing this in coordinates yields

p_i(Q^j)dq^i=\theta=\Theta + dF= P_idQ^i + \frac{\partial F}{\partial q^i}dq^i + \frac{\partial F}{\partial Q^i}dQ^i

Comparing coefficients we find p_i = \frac{\partial F}{\partial q^i} and P_i = -\frac{\partial F}{\partial Q^i}. You will recognize the expressions for momenta in terms of a "generating function".

What we have done was to take two Lagrangian foliations given in terms of q^i and Q^i and compute a function F from them. The trick is now to turn this procedure around: Given only the q^i and a function F(q^i,X^j) of these q^i and some N other variables X^j, one can compute the Q^i as functions on M: Take a point m=(q,p)\in M and define Q^i(m) by inverting p_i = \frac{\partial F(q,X=Q)}{\partial q^i}. For this remember that p_i was defined implicitly above: It is the coefficient of dq^i in \theta.

Up to here, we have only played symplectic games independent of any dynamics. Now specify this in addition in terms of a Hamilton function h. Then the Hamilton-Jacobi equations are nothing but the requirement to find a generating function F such that the Q^i are constants of motion.

Even better, by making everything (that is h and Q and F) explicitly time dependent, by the requirement that the action 1-form is invariant: \theta- hdt = \Theta - Hdt giving H = h +\frac Ft we get a transforming Hamilonian and we can require this to vanish:

0= H = h +\frac Ft

If we think of the Hamiltonian h given in terms of the coordinates (q^i,p_i) this is now a PDE for F which has to hold for all m\in m. That is, writing F as a function of q^i and X^i it has to hold for all (fixed) X^i as a PDE in the q^i and t.