Archive for June, 2005

Koder search engine

Wednesday, June 22nd, 2005

While reading about Google’s history of acquisitions, as well as likely future acquisitions, I discovered a search engine just for code! I tried running a few queries, and was pleased by the fact that I even got results; I wonder what metric they’re using for matching: it seems like they’re just searching for direct matches. The only problem I’ve noticed is that they don’t index small, out of the way projects; of course, this may be due to three plausible considerations: that they don’t want to accidentally index someone’s private code and get into legal issues (although, one could argue this is a non-issue: if someone posted code that could be spidered, they must not have wanted it kept private), it might be hard to distinguish code from general web content (e.g. short code excerpts on a web-page probably aren’t worth the bother of identifying), and … maybe the metric they’re using relegates small projects to the back of the list, were I didn’t look.

Uniform convergence of power series

Wednesday, June 22nd, 2005

Proposition 25
Suppose a_0,a_1,\ldots is a bounded sequence. We’ve seen that if z is a point, |z|<1, then the sequence s_0(z), s_1(z), \ldots converges, where

 \displaystyle s_0(z) = a_0, s_1(z) = a_0 + a_1z, s_2(z) = a_0 + a_1 z + a_2 z^2, \ldots.

Suppose now that f is a function with initial set that contains all points z, |z|<1, and for each z, |z|<1, s_0(z), s_1(z), \ldots converges to f(z). Show that if 0<r<1 and c>0, there is a positive integer N such that if n>N and |z|\leq r,

 \displaystyle |f(z) - s_n(z)| < c .

Soln
For each z, |z|<r let N_z be the least integer satisfying  n > N \Rightarrow |s_n(z) - f(z)| < c . Let  U be the collection of all N_z.

Claim: U is finite. Assume U is not finite, then for every n \in \N, there is a non-empty set V_n = \{z \,:\, |z|\leq r \text{ and } N_z > n \}. Notice  V_{n+1} \subseteq V_n , and each V_n contains infinitely many elements. From here we can use the same ‘boxing in’ process that we used to show power series converge: namely, since V_n is infinite, we can find a rectangle of definite size (which we get to choose) which contains infinitely many of V_n , and then a rectangle of even smaller size which contains infinitely many of  V_n \cap V_{n+1} . Since we get to choose the size of the rectangles, we can make them converge to a point  z as  n \rightarrow \infty. This point is in  \big\cap_\N V_n , and therefore has the property that  \forall n \in N \,:\, N_z > n , which is not possible. Therefore U is finite.

Since U is finite, it contains its maximum M which satisfies: if n>M and |z|\leq r,

 \displaystyle |f(z) - s_n(z)| < c .

The fact that  |z| \leq r <1 is used in making the rectangles to ensure that the z converged to satisfies |z| < 1; otherwise you couldn’t claim a contradiction.

Math parser update

Wednesday, June 22nd, 2005

I found a massive error in the parsing of factors: as soon as implied multiplication occurred, any explicit multiplication and division (using * or /) caused an error. That was silly, and easily fixed. I also fixed the problem with unary minuses and pluses. I think I’m going to reimplement the whole thing anyhow, to fit much more closely to the Mathematica grammar (which I can’t seem to find anywhere; even MockMMA doesn’t come with an explicit grammar), so that it could be used for the same purpose MockMMA has in LISP: to allow the implementation of a free system which can use code written for Mathematica. I tried looking at the MockMMA code, but Common LISP is alien to me. I haven’t uploaded the update yet; I’m at school right now.

Mathematica-style parser

Monday, June 20th, 2005

I spent this weekend writing a parser for a Mathematica-style grammar. I posted the files (scanner, parser, and grammar). They should be pretty interesting for anyone who is interested in implementing a non-trivial parser from scratch. I based them on the example calculator parser in Programming Python, but the complexity of the grammar I used, compounded with the fact that it doesn’t evaluate anything, makes it different enough to be interesting as is. The only big problem I have is that I haven’t been able to figure out how to implement unary minuses; everything else is licked, but that’s getting me. I’m going to implement the equivalent of Mathematica’s FullForm command for printing out the trees returned by the parser; currently, I’m using a crude tree dump that’s pretty hard to read (and extremely long! for even short expressions), but contains every last detail. Also, I’m going to gut the current error handling system, based on the rather inadequate system in Programming Python, and put in a more informative one; currently, half the time when an expression is ill-formed, the parser crashes instead of signaling the location of the error as it should, and it never makes any suggestions about what the error could be. Another caveat is that, for some reason, when the parser crashes on one expression, it sometime crashes on everything else after it, so you have to create a new parser for each expression to be safe. Oh, and the parser (this is minor, I’m just too tired to fix right now) expects each expression to be on separate lines.

Example of parsing f[{x_,y_}] = {0-1*y, x} / Norm[{x,y}] ( the weird 0-1*y is because of the incapability of dealing with unary minuses).

BasicCAS Mathematica FullForm

Type: factor
Value: None
Children:
   Type: term
   Value: None
   Children:
      Type: ImmediateAssign
      Value: Type: factor
      Value: None
      Children:
         Type: term
         Value: None
         Children:
            Type: list
            Value: None
            Children:
               Type: sum
               Value: None
               Children:
                  Type: factor
                  Value: None
                  Children:
                     Type: term
                     Value: None
                     Children:
                        Type: integer
                        Value: 0
                        Children:

                     *

                  +
                  Type: factor
                  Value: None
                  Children:
                     Type: term
                     Value: None
                     Children:
                        Type: integer
                        Value: 1
                        Children:

                     *
                     Type: term
                     Value: None
                     Children:
                        Type: identifier
                        Value: y
                        Children:

                     *

                  -

               Type: factor
               Value: None
               Children:
                  Type: term
                  Value: None
                  Children:
                     Type: identifier
                     Value: x
                     Children:

                  *

         *
         Type: term
         Value: None
         Children:
            Type: funccall
            Value: None
            Children:
               Norm
               Type: factor
               Value: None
               Children:
                  Type: term
                  Value: None
                  Children:
                     Type: list
                     Value: None
                     Children:
                        Type: factor
                        Value: None
                        Children:
                           Type: term
                           Value: None
                           Children:
                              Type: identifier
                              Value: x
                              Children:

                           *

                        Type: factor
                        Value: None
                        Children:
                           Type: term
                           Value: None
                           Children:
                              Type: identifier
                              Value: y
                              Children:

                           *

                  *

         /

      Children:
         Type: funccall
         Value: None
         Children:
            f
            Type: factor
            Value: None
            Children:
               Type: term
               Value: None
               Children:
                  Type: list
                  Value: None
                  Children:
                     Type: factor
                     Value: None
                     Children:
                        Type: term
                        Value: None
                        Children:
                           Type: identifier
                           Value: x_
                           Children:

                        *

                     Type: factor
                     Value: None
                     Children:
                        Type: term
                        Value: None
                        Children:
                           Type: identifier
                           Value: y_
                           Children:

                        *

               *

   *
List[Times[-1, y, Power[Norm[List[x,y]], -1]], Times[x, Power[Norm[List[x, y]], -1]]]

Note that Mathematica performs some pre-processing before displaying the output (the zero disappears, for one, and the list takes the division inside). I plan on implementing this also, because among other things, I’m going to use GMP or a similar library for the numbers, and I want to keep rationals, reals, and integers distinct.

The next step is to implement a pattern based function definition system, like the one Mathematica uses. I love being able to say f[{x_, y_}] := {-y, x} /Norm[{x, y}] in Mathematica, so I want to be able to define functions in the same way. Or specify the value for a particular class of inputs, e.g. f[x_Integer] := Factorial[x] . Before starting the parser, this seemed like a difficult task, but now it seems like cakewalk. To implement this system, all I have to do is store the expression tree used to define the parameters to the function, and then match that tree against the parameters used to call the function. In the first example, the tree would be something like List[x, y] , so I’d match up the passed in parameters to this tree, binding x and y to the value of the expressions in the corresponding space, and running any tests on them (like _Integer); if the tree fit and the parameters passed the test, then I’d know what definition of the function to use.

After that, I need to make a namespace system. Then it should be a simple task to code in the simple interpretive programming utilities like For, Do, While, etc. Then I can think about the real hard stuff– the symbolic stuff– at leisure.

Comments and suggestions are more than welcome.

Page parsing quandry

Friday, June 17th, 2005

I’m working on a Python script that helps you to manage XBEL files. I’ve done the hard part: parsing the XBEL file into a Python structure. But now I’m trying to write code to fill in, as much as possible, the missing descriptions in the bookmark lists. My first idea was to use the < meta name="description" > tag, but it looks like none of the sites (666, exactly) I have on my bookmark list use that– or at least the hefty subset I attempted to pull it from over my dial-up connection. What else is there, besides resorting to the title tag?

I’m too lazy to bother posting it, especially considering there are probably tons of scripts out there that will do the same job, perhaps better, but anyone who’d like a copy of the code, just let me know. Here are the list of features I plan on implementing in the future that might distinguish it from its competition:


#  -- add IDs automatically to facilitate handling by programs
#  -- delete/add/edit/move (up and down, in and out in hierarchy) bookmarks and folders
#  -- add description to bookmarks when possible, using META tags
#  -- merge multiple XBEL files, preserving as much structure as possible (especially ID uniqueness)
#  -- make diffs between XBEL files
#  -- output XBEL files nicely formatted
#  -- search by regexp title and/or desc of a bookmark or folder
#  -- list all bookmarks in a given folder
#  -- find and optionally eliminate redundant bookmarks (bookmarks on same site in same folder)
#  -- verify existence of bookmarked sites
#  -- update bookmarked sites URLs by detecting redirects
#  -- opening a browser at a bookmark to get desc info or browse

The purpose is three-fold: to provide a user interface to manipulating data stored in the XBEL files, to provide a programmatic interface for the same purpose, and to reformat, extend (in the sense of adding IDs, descriptions, and maybe meta data) and error-check (in the sense of spidering) XBEL files. Eventually, I plan on using it to power a web app for organizing and displaying my bookmarks in several formats (I tried XSLT and found it wasn’t very flexible— for instance, you can’t easily add dynamic content as the bookmark list is being displayed— plus it is an ugly paradigm IMO; the two are probably related).

But first, I have these hurdles to clear…

Dr. Singh’s Take on the Fourier Unicity Theorem (via Invariant Subspaces)

Friday, June 17th, 2005

This is a truly beautiful (original to Dr. Singh?) result which is not in any textbook, if I understood him correctly. Having seen hard analytic proofs of this, I prefer his geometric method. When he started laying the background for the proof, I was a little skeptical: how interesting could the operator S: f\rightarrow e^{i\theta}f be? Let’s find out…

The ultimate goal, the Unicity Theorem, states that the fourier (series) coefficients of a function in L^1 are uniquely associated with it. Note, in this context, L^1 is an abbreviation of L^1[-\pi, \pi], and likewise for L^2.

Background (Invariant Subspaces and their Characterization)

Consider the aforementioned operator S: L^2 \rightarrow L^2: it is linear and continuous. Note also that p(S) = \alpha_0 I + \alpha_1 S + \ldots + \alpha_nS^n is also a linear, continuous operator from L^2 to L^2. Recall the essentially bounded functions L^\infty can also be characterized by  L^\infty = \{ \varphi \in L^2\, :\, \forall f \in L^2, \,\varphi f \in L^2 \}. If \varphi \in L^\infty, then M_\varphi : L^2 \rightarrow L^2 can be defined as M_\varphi : f \rightarrow \varphi f , and is a continuous linear transformation.

Consider the commutant of S, \{S\}^\prime = \{T: L^2 \rightarrow L^2\, : \, TS = ST\}, consisting of all the continuous linear transformations on L^2 which commute with S. For all p(S) as defined before, M_{p(S)} \in \{S\}^\prime. In fact, it is clear that \{M_\varphi \, :\, \varphi \in L^\infty \} \subseteq \{S\}^\prime.

Let T \in \{S\}^\prime, then T(1) = \varphi \in L^2 , and T(e^{i\theta}) = TS(1) = ST(1) = e^{i\theta} \varphi . Since  TS = ST \Rightarrow S^{-1}T = TS^{-1} , also T(e^{-i\theta}) = e^{-i\theta} \varphi. Let p(\theta) = \alpha_{-n} e^{-in\theta} + \alpha_{-n+1} e^{-i(n-1)\theta} + \cdots + \alpha_0 + \alpha_1 e^{i\theta} + \cdots + \alpha_n e^{in\theta} \in L^2 , then T(p(\theta)) = \varphi p(\theta).

Take  f \in L^2, then f = \sum_{-\infty}^\infty} \alpha_n e^{in\theta} in the sense that f_N = \sum_{-N}^N \alpha_n e^{in\theta} \rightarrow f in the L^2 norm. Since T is continuous, T(f_n) \rightarrow T(f) , so for some subsequence \{f_{n_k}\}, \varphi(\theta)f_{n_k}(\theta) \rightarrow (Tf)(\theta) almost everywhere. Since f_{n_k}(\theta) - f(\theta) \rightarrow 0 almost everywhere also, \varphi f_{n_k}(\theta) \rightarrow \varphi f(\theta) almost everywhere, so Tf(\theta) = \varphi f(\theta) almost everywhere.

What was shown is that if T \in \{S\}^\prime, then there is a  \varphi \in L^2 such that Tf = \varphi f for all f \in L^2. This since \varphi f \in L^2 for all f \in L^2, \varphi \in L^\infty. Together with the former inclusion, this shows  \{S\}^\prime = \{ M_\varphi \,:\, \varphi \in L^\infty\}.

Recall if H is a Hilbert space and M a closed subspace of H, then H = M \oplus M^\perp. If M is such that S(M)=M (or equivalently, S^{-1}(M) = M), M is called doubly invariant on S.

A theorem due to Wiener neatly characterizes all doubly invariant subspaces of S:

Theorem Let M \neq \{0\} be a doubly invariant subspace of S on L^2. Then there exists a set of positive Lebesgue measure, I, such that M = \chi_I L^2 = \{ \chi_I f \,:\, f \in L^2 \}.

Proof
Since M is doubly invariant, S^{-1}(M) = M. Let P: H \rightarrow M be the projection unto M; recall P is a continuous linear transformation, and acts as an identity on its image.

For all f \in L^2, SPf = PSf, since f = g +h where g \in M and h \in M^\perp, so SPf = SP(g+h) = Sg = PSg = P(Sg + Sh) = PSf since PSh = 0. Therefore  P \in \{S\}^\prime, so P = M_\varphi for some \varphi \in L^\infty. P^2 = P \Rightarrow M_{\varphi^2} = M_\varphi; specifically, taking f = 1, M_{\varphi^2} f = M_\varphi f \Rightarrow  \varphi^2 = \varphi \Rightarrow \varphi ( 1 - \varphi) = 0 .

Let I = \{\theta \,:\, \varphi(\theta) = 1 \} , so \varphi = \chi_I; then M = P(L^2) = M_{\chi_I} (L^2) = \chi_I L^2 . Note that M \neq \{0\} \Rightarrow \varphi \neq 0 guarantees I is of positive measure.

Unicity Theorem

Let  f\in L^1 and suppose  \int_{-\pi}^\pi f(\theta) e^{-in\theta} d\theta = 0 for all  n \in \Z . Then f = 0.

Proof

Let f = f_1 f_2 where f_1, f_2 \in L^2. Assume f \neq 0. Since

\displaystyle \frac{1}{2\pi} \int_{-\pi}^\pi f_1f_2 e^{-in\theta} d\theta = \langle f_1, \overline{f_2}e^{in\theta} \rangle = 0, \quad \forall n \in \Z,

 f_1 is orthogonal to the closure, M, of the linear span, N, of \{\overline{f_2}e^{in\theta}\}_{n \in \Z}.

Let  v = (\alpha_{-k} e^{-ik\theta} + \cdots + \alpha_0 + \cdots + \alpha_j e^{ij\theta}) \overline{f_2} \in N . Then Sv \in N and S^{-1}v \in N. Since S is continuous, S(M) \subseteq M and S^{-1}(M) \subseteq M, so M is doubly invariant.

For some set I of positive measure, M = \chi_I L^2, so  f_1 \perp \chi_I L^2 . Therefore  \int_{-\pi}^\pi f_1 \overline{\chi_I f_1} d\theta = 0 \Rightarrow \frac{1}{2\pi}  \int_I |f_1|^2 d\theta = 0 \Rightarrow f_1 \big|_I = 0 . Since \overline{f_2} \in M, f_2 = \chi_I g for some g \in L^2, so f_2 \big|_{I^\prime} = 0 .

Therefore f = f_1 f_2 = 0 a.e.

Mathematical Art

Thursday, June 16th, 2005

These are beautiful sculptures, even if they are expensive. This could be my hobby! Assuming I can ever afford it. Also, the surface evolver seems like an interesting toy (the sculptor used it to help in getting smoother models for the surface); I’d love to play around with it and POV-Ray.

Along the same lines:
KnotPlot, SolSurf, and The Scientific Graphics Project.

Fourier HW

Thursday, June 16th, 2005

This is the second hw assignment; looks like fun:

  1. Let f be a 2\pi periodic function with a continuous derivative f^\prime on [-\pi, \pi]. Let the Fourier series for f be \sum_{-\infty}^\infty \alpha_n e^{in\theta}. Without using the fact that  f \in L^2, show by directly estimating the coefficients \alpha_n that \sum_{-\infty}^\infty |\alpha_n|^2 < \infty.
  2. Let f and g be two continuous 2\pi-periodic functions with Fourier series \sum_{-\infty}^\infty \alpha_n e^{in\theta} and \sum_{-\infty}^\infty \beta_n e^{in\theta} in [-\pi, \pi]. Let
    \displaystyle h(\theta) = \frac{1}{2\pi} \int_{-\pi}^\pi f(t) g(\theta - t) dt, \quad \forall \theta \in [-\pi, \pi] .

    Show h is continuous and has F.S. \sum_{-\infty}^\infty \alpha_n \beta_n e^{in\theta} in [-\pi, \pi].

  3. Let T: L^2 \rightarrow L^2 be defined as Tf \sim \sum_{-\infty}^\infty \alpha_n r^n e^{in\theta} where f \sim \sum \lapha_n e^{in\theta} and 0<r<1 is a fixed number. Show T is a continuous linear transformation. Is T onto?

Note taking

Thursday, June 16th, 2005

If books carried STDs, everyone in the engineering department would have one. We share books there like crazy, and a lot of people sell their books as soon as they’re done with classes. It seems like in the math department, people rarely share books, and only sell them back if they are horrible. I wonder why that is; of course, my impression may be biased, as most of the people I talk to in the math department fall into the heading-for-graduate-school-and-actually-want-to-be-here-learning-this category, while just about everyone in the engineering department seems to fall into the oh-my-god-what-the-hell-was-I-thinking-when-I-signed-up-for-this-torture-I-want-to-graduate-and-get-a-job category, self included.

I tend to keep all my books from my technical courses— all my lit. books, history, etc. tend to disappear slowly. I’m paranoid about the math books, always checking to make sure I don’t misplace them, but pretty loose with the engineering books: I lend those out like clockwork candy: every semester, just about all the books (and notes) from engineering courses I’ve taken find my way into other peoples’ hands; mostly, I don’t care about making sure they come back to me. The only engineering books I care about are my circuits and electronics textbooks, because they might come in useful if I ever decide to build a gadget, my EM books, because I like EM, and my signals books, because they’re really math books without proofs :) .

I borrowed a guy’s notes from the Fourier course I’m auditing to catch up on the material for the first few lectures I missed— the prof was reviewing the first hw assignment, and I did not understand anything of what he was doing (Poisson kernel?)– and saw that they are written in pen. I found that weird, until I remembered he’s not a math major; I always find it weird when math people do their notes in pen. I know I must use pencil, because when the prof says something that I think I can prove or don’t quite understand, I go off on tangents and try to prove it, or figure it out in the margins. Since I’m usually not as clever as I think I am, my notes would be a lot nastier in pen. Not that the nastiness matters: I keep notes in my classes for very specific reasons, which usually have nothing to do with actually ever reading them again. Sometimes I take notes to stay awake when the prof is boring, or the material is boring; sometimes to force myself to follow important but tedious material; sometimes because I like to draw connections as the material is taught…

Mathematics students writing in pen is weird, I reiterate. IMO, that either signifies genius (but then, why take notes at all), arrogance, or that all their attention is focused on copying from the blackboard, instead of the content of the lecture. One of my friends contends that note taking at all is distracting. I can see his sentiment, and sometimes it is necessary to sit back and give up on note taking, or risk being left behind as the prof moves on. But, at base, note taking is a comfort mechanism: it makes me feel like I’m doing something concrete.