Archive for July, 2005

Python keylogger

Sunday, July 31st, 2005

Going through my backlog of unread entries from the Python General mailing list, I found out that it is very easy to make a Python-based keylogger (<40 lines!). Not that I’d want to do a thing like that, but for future reference, it requires the Win32 module and PyHook, and the particular technique can be found by searching the mailing list. Also, I (re?)discovered that Qt has an open source development kit for Windows, finally, so I can use Qt under both Linux and Windows if I ever feel the need to learn it.

PyPI package basicCAS

Sunday, July 24th, 2005

I spent this morning figuring out how to use Distutils to 1)compile python extensions/non-pure modules, 2) install modules/packages. Then I packaged up basicCAS, version 1.0, and made my first submission to the PyPI library.

Although it is certainly usable— e.g. Didier is using it in a polynomial class he’s writing—, the first version of basicCAS is not all that wonderful. The eventual goal is full compatibility with Mathematica’s text mode parser, but I have a ways to go on that— even after reading the Mathematica Book, and appendices, it isn’t clear to me exactly what’s going on sometimes. So it looks like I’m going to have to play around with Mathematica for a while to get a feel before I start rewriting the parser. The things that will be– need to be– different in the next version of basicCAS are are: 1) precedence and associativity are respected, 2)all forms of character input taken by Mathematica are accepted, 3) the Fullform constructions returned are identical to Mathematica’s, and 4) the error reporting system as much as possible, reflects Mathematica’s. All of these are tall orders.

Applied Mathematicians write the best books

Thursday, July 21st, 2005

I started thinking that applied mathematicians write the best books at some point in the past. Not numerical mathematics books, which I wouldn’t touch with a ten-foot pole, but the good ‘ol analysis books. I guess this is only to be expected: I’m one of those who think math is much more interesting when it has a purpose. Especially when the purpose is more of an abstraction, because then you cover the theoretical material, and just mention the optimizations and heuristics that algorithms which apply the theory might use. I have avoided reading about FFTs, for instance, because I could care less about how they’re implemented: the equivalence to the DFT is all I care about.

All of this was motivated by a book I just saw in my advisor’s office, that I could have sworn wasn’t there before this week: Mathematics of Medical Imaging. It looks like a relatively light read, compared to what say a Springer book with the same name would be like (viz., an encyclopedic tome). Unfortunately, our library doesn’t carry it: I’ve noticed our imaging books tend to be old and hoary; maybe there was some disillusionment about that discipline that affected the acquisitors? So, I ordered it via interlibrary loan. I hope I’ll still be as excited about it when it finally arrives.

Gimp and Scheme in One Defun

Tuesday, July 19th, 2005

I’ve been attempting to script Guile for the past two days, to do what I consider an unlikely task. My problem: I finally got some more CAT scan data for use in my research project, but Matlab can’t read the DICOM files. In fact, of several dedicated DICOM readers that I tried, only DicomWorks in windows could read all of them, and even loading them in there and exporting them back out didn’t solve the compatibility problem with Matlab. So, I realized that the Gimp can load and save DICOM files, and found that Matlab could read the output Gimp produced. I even found a way to get around the fact that Gimp erases all the patient’s tags.

Since I have a whole collection of these files, and I recalled Gimp was scriptable, I looked it up, and was pleasantly surprised to discover how easy it is to script Gimp using, of all languages, Scheme! I wrote up a simple modification of the sample script that just loads all the files in a dir and saves them back out as dicom files, and wrote a python script that applies the script to every subdirectory of my data directory. In ten minutes, I had solved my problem, or so I thought.

Here’s the problem: since I have so much data, and I was doing this on my personal computer, and have a separate repository on my math department account, I thought I could transport my script over to that account, and repeat the same process. That’s when I discovered how horrid and broken Gimp’s script-fu scripting system is. It turns out that the plugin I used to do the file globbing is not available in Gimp 2.0, which is the version the math department provides, so I figured that I could just write an equivalent in Scheme. Since I couldn’t find what scheme implementation Gimp was using, I assumed that it was Guile— one would think this is the obvious choice? But, as I discovered after my script kept crashing, Scheme actually uses the Scheme in One Defun implementation of scheme, which despite its glowing description:

SIOD is a small-footprint implementation of the Scheme programming language that is provided with some database, unix programming and cgi scripting extensions.

is in fact, almost amusingly broken. Here are some of the functions that are not available: getcwd, fread, fseek,fopen!, exec, exit, opendir, strcat. What’s up with that: it looks like each of these could be implemented in a couple of lines of C. Anyhow, since the file/dir handling of SIOD is so gutted, my script was doomed, and I had to refigure it.

To make a boring story shorter, I ended up using a python wrap around ImageMagick to convert the DICOM files to Tiff files— it turned out that besides being poorly scriptable and poorly documented, Gimp also reduces the number of gray levels in its DICOM output to 255, which makes them useless for anything but decorative purposes— and loaded those into Matlab.

Oh, here’s another annoying undocumented Gimp scripting quirk: each gimp function call, when specified at the command line, must be in a separate string, so

gimp -i -b '(gimp-scripting-sucks) (gimp-quit 0)'

will execute the first instruction, then hang, while

gimp -i -b '(gimp-scripting-is-weird)' '(gimp-quit 0)'

will execute the appropriate script, then exit as wanted.

Despite all this, I still admire the fact that you can command Gimp from the SIOD prompt by entering
gimp -i -b -. What would be excellent would be if Gimp switched/completed switching to Guile as the scripting engine. Then we’d have a real language as the backend, and the wonderful guile prompt as the front-end.

The sequence of all finite sequences

Monday, July 18th, 2005

An interesting question arose today– posed by a student– in the Hilbert space class. Can you construct a sequence of sequences, such that this sequence contains every finite sequence of positive integers as a term? I would guess that the sequence wouldn’t contain any other terms.

Ordinarily a problem like this would give me an hour of pleasurable cogitation :), but I’ve seen the answer to this before, in Dick Grune’s Parsing book. In fact, it seems like the author of the question, a senior comp. sci. major, has probably seen a proof of this in one of his automata classes, and forgot it.

Given a finite sequence \{a_n\}_{n \in \Z_j} where \Z_j = \{1, 2, \ldots, j\}, let f(\{a_n\}) = \sum_{i=1}^j 10^{a_n} . f^{-1} is well-defined, assuming a unique decimal expansion for every positive integer. Let the sequence T = \{t_i = f^{-1}(i) \}; then T has the property that y is in T only in case y is a finite sequence of positive integers.

Fateman online CA lecture notes

Sunday, July 17th, 2005

I ran into this site maybe a year ago, but lost the link. It is a collection of materials from a class on Computer Algebra that Fateman taught at UCB. I looked through the additional material, but not yet the powerpoint presentations that make up the course– judging from the quality of those, the syllabus, and Fateman’s reputation as one of the prominent figures in CA, this material should provide a good foundation in CA.

Back up!

Thursday, July 14th, 2005

I found the problem with LatexRender: somehow, when I was attempting to uninstall unused packages from the server, I deleted gs and imagemagick; my guess is that ‘apt-get prune’ is a lot more powerful than I thought it’d be. So now I have equations back, I’m back!

Going down for a while

Friday, July 8th, 2005

The site is going to be down for the next week or so, for three reasons: I’m finally doing all those things I was to do this summer, but didn’t; a strange error is occuring with the LaTeXRender system that has rendered all the equations unreadable, and what can I post about, if it doesn’t include equations?; finally, the MySQL server keeps going down, yet again, this time I suspect because I’m running MlDonkey on the server also, and it’s eating up memory.

Later.

Hilbert space class

Thursday, July 7th, 2005

The Hilbert space class started this week. We’ve already gotten one problem at least that I’ve never seen in any of Dr. Johnson’s other classes, so it looks like I might have an interesting time in here. The grad students seem rather weak though: how could you be two years into a math grad degree and not know what it means for a set to be dense in a linear space?

Here’s the latest (greatest :)) problem. It was couched in terms of the Hilbert space l^2(\R), since that’s what the course is on, but it seems like a good question to ask in any Hilbert space H:

Is there a proper linear subspace M of H that is dense in H?

I think the answer is no, but I’m still working on a proof. My general idea (in l^2(\R)) is to show that for each element e_j = \{\delta_{nj}]}_\Nin the standard basis for l^2, there is at least one element in the basis for M that is a linear combination involving e_j– this is clear, because if not, there is no way to get an arbitrarily close approximation in M to that e_j. But now, I’m trying to show that means that e_j must be in M, but I can’t think of how to do so yet, or even see why that must be so. But intuitively, I don’t think it is possible to have a dense proper linear subspace, because it seems like any holes in \overline{M} would be filled in by the convexity of the subspace so M = \overline{M}.

Update This problem can be easily resolved by considering the definition of an o.n.b. of a Hilbert space.