Monday, August 10, 2009

LaTeX-enabled Anonymous Message Boards

I find a lot of the time that I want to ask a stupid question online but don't want my name attached to it. Solution: LaTeX-enabled, optionally anonymous online message boards! To be fair they're really better for just asking quick questions in general. If I have a weird problem on a software project, I can often just pop over to IRC and ask some basic questions, but there's not really a good analogue for math.

I built these myself so they're liable to be a little shaky. I'd appreciate any feedback, and I'll also try to answer any questions you post there, assuming I know how to answer them. To post in LaTeX, just do something like:

How do I know that $\sup \left\{ \int f d\mu : f \leq \phi, \phi \text{ simple}\right\}$ exists?

And nobody will be able to make fun of you for not understanding integration, because they won't know who you are.

Friday, August 07, 2009

Microsoft Access VBA code to Convert Table Records to SQL

This isn't math per se, but today I found it useful to be able to convert some tables in Access to SQL statements that would insert said records into another database. This isn't densely commented and likely isn't bulletproof, but it gets the job done for me and I thought someone might want such a thing, so here it is:
Function SerializeRecords(table As String, criteria As String, filename As String)
Dim rs As DAO.Recordset

On Error Resume Next
Open filename For Append As 1
If Err.Number > 0 Then
MsgBox "Can't write to file " & filename & ".", vbCritical, "Output Error"
Exit Function
End If
qs = "SELECT * FROM " & table & " WHERE " & criteria

On Error Resume Next
Set rs = CurrentDb.OpenRecordset(qs)
If Err.Number > 0 Then
Close #1
MsgBox "Error executing query " & qs, vbCritical, "Output error"
Exit Function
End If

qds = "DELETE FROM " & table & " WHERE " & criteria & ";"
Print #1, qds

Do While Not rs.EOF
qis = "INSERT INTO " & table & "("
For Each f In rs.Fields
qis = qis & "[" & f.Name & "],"
Next f
qis = Mid(qis, 1, Len(qis) - 1) & ") VALUES("
For Each f In rs.Fields
If IsNull(f.Value) Then
qis = qis & "Null,"
ElseIf f.type = dbChar Or f.type = dbText Or f.type = dbMemo Then
qis = qis & EscapeString(f.Value) & ","
ElseIf f.type = dbDate Then
qis = qis & "'" & f.Value & "',"
Else
qis = qis & f.Value & ","
End If
Next f
qis = Mid(qis, 1, Len(qis) - 1) & ");"
Print #1, qis
rs.MoveNext
Loop

Close #1
rs.Close
End Function

Function EscapeString(s As String)
t = Replace(s, "'", "''")
t = Replace(t, Chr(13) & Chr(10), "' & chr(13) & chr(10) & '")
t = "'" & t & "'"
EscapeString = t
End Function

I'm currently working on a medium-scale software project *and* studying for quals, but I'll try to put up some more legit math content here soon.

Thursday, July 30, 2009

What comes next?

What comes next in the following sequences?
  1. ..., 4, 14, 23, 34, 42, 50, __, 72, 81, ...
  2. ..., a, f, p, n, __, m, ...
  3. ..., 1, 1, 1, 1, 1, __, ....

Monday, July 13, 2009

Dumb Stuff I Didn't Know, Volume I of Many

I was reading something the other day (context largely unimportant) and found myself completely unable to understand an argument that was being made. On further inspection, I was able to ascertain that the author had felt that the following was so obvious as not to merit any mention: that diagonalizable matrices commute if and only if they are simultaneously diagonalizable, i.e. if there is some basis which is an orthogonal basis of eigenvectors for both matrices.

Trying to prove this fact once you know what you're looking for isn't too hard -- playing around with formulas will show you quickly that if two linear maps commute then they must fix each others' eigenspaces; then just diagonalize the restriction of S to each of T's eigenspaces and stick the resulting mini-bases together.

We can do a little better here: Suppose that we have some commutative collection C of endomorphisms of a finite-dimensional complex vector space V; then they all share some eigenvector.
Proof: We know that C fixes V. Let W be a subspace of V of minimal positive order which is fixed by C. We claim that each vector in W is an eigenvector of each element of C. Suppose not; then there is some counterexample Mw≠λw. M fixes W though, so the restriction of M to W is a complex linear map in its own right; in particular, it has to have some eigenvector in W, say Mx=μx. Let's have Wμ denote the μ-eigenspace of M restricted to W. Then the previous two sentences in effect say that that 0 <>μ <>μ is fixed by C -- take any w in Wμ and any N in C and notice that M(Nw) = (MN)w = (NM)w = N(μw) = μ(Nw), i.e. Nw is a μ-eigenvector of M, and since N, being after all from C, fixes W, it's an element of Wμ. But wait! Before we said that W was as small as you could get and still be fixed by C, but we've just shown that Wμis both fixed by C and smaller than W. This can't be, so our assumption must have been wrong -- W must consist exclusively of eigenvectors for every element of C.
Quick question: how many different eigenvalues can be associated with the subspace W in this proof, for any given transformation? For all of them?

Less quick question: What happens when we pass to infinitely many dimensions?

Wednesday, July 01, 2009

Rings

Every time I read something that pertains to any kind of ring, there's always a necessary section at the beginning stipulating that such-and-such a ring has an identity, that the mappings under consideration must preserve that identity, and so forth. Can someone fill me in as to whether there's some area of study in which people use rings without 1 so extensively that it makes up for the extreme annoyance of dealing with such requirements everywhere else? As far as I can tell, rings without 1 occur basically as often as these things called "monoids" or "groupoids" -- more than never, but certainly not often enough to merit such a basic name, or take up space in textbooks and brains. Can someone set me straight here?

Tuesday, June 30, 2009

A Generalization of the Mean

First, some background:

Remember that the mean or expected value of a random variable is defined as the integral of that variable with respect to the associated probability measure. This works out great in some cases, e.g. when we're flipping coins, or rolling dice, or in general when we're thinking about random variables with finite variance. Of course, it's defined for a wider class of random variables -- not everything with a mean has a standard deviation -- but there are certainly random variables out there with no mean.

A famous example of a divergent mean is the St. Petersburg game, which goes something like this: I'll let you flip a coin and pay you for how many heads you can get in a row. If you get heads up the first time, but tails after that, I'll give you a dollar. Two heads in a row, $2. For n heads in general, n > 0, the payout will be $2n-1. Rather than giving you 50 cents for failing so spectacularly as to hit tails on your first try, let's say you just get nothing.

The probability of getting exactly n heads in a row is, of course, 1/2n, so the expected value is

(1/2)($1) + (1/4)($2) + (1/8)($4) + (1/16)($8) + ... = $.50 + $.50 + $.50 + ...

Uh oh. If we keep adding on $.50 forever, the right-hand side is going to infinity! Clearly, you should be willing to pay me any amount of money in order to play this game, since your measly $10k pales in comparison to the promised infinite reward. Any takers?

We're not done here, though; first, let's change up the game a little. We'll leave things the same if you flip 1 head, or three consecutively, or five, and so on, but let's say if you flip an even number of heads, you have to pay me. What was that expectation again?

(1/2)($1) - (1/4)($2) + (1/8)($4) - (1/16)($8) + ... = $.50 - $.50 + $.50 - $.50 + ...

Oh, dear. Depending on how we arrange that series, it can diverge up or down. You can see from here, if you didn't sleep through your calculus classes, that we can even produce a conditionally convergent expectation that can be rearranged to anything!

Okay, I've gotten away from myself here, but, long story short, means are weird. (I seem to be in an Italic mood today for some reason...) That said, consider the following, which has been bouncing around in my head for a year or better. I finally asked someone whether it was true and quickly received the following proof:
Let X1, X2, ... XN be i.i.d. random variables, and let YN = [ X1 + X2 + ... + XN ] / N. Put f(N) = Median(YN). If μ = Mean(Xi), i.e. if that mean exists, then as N → ∞ we have f(N) → μ.

Proof (thanks to Robert Israel): The Weak Law of Large Numbers states that, for ɛ>0, Pr{|YN - μ| < ɛ} → 1 as N → ∞. For N sufficiently large, then, Pr{|YN - μ| < ɛ} > 1/2, or in other words, more than half of the distribution for YN lies within the interval (μ - ɛ, μ + ɛ). In particular, at least half lies within (-∞, μ + ɛ), so there is no way that the median f(N) can exceed μ + ɛ; symmetrically, f(N) > μ - ɛ. Combining both sides, we see that |f(N) - μ| < ɛ, which is to say that f(N) → μ as N → ∞.
Note that this limit can converge in circumstances where there is no mean -- for instance, it clearly always gives the axis of symmetry for a symmetric distribution, and there exist symmetric distributions which have no mean, e.g. the Cauchy distributions. So in broad terms this is a generalization of the concept of the mean.

I'm really no expert on statistics or probability, so I don't really know how far the applications go or whether this is an elementary exercise in graduate textbooks in the field. I just thought it was interesting, and I'll probably poke around with it in the days to come.

Visualizing Groups of Symmetries

After realizing that I had some (now) bizarre misconceptions about the groups of symmetries of various graphs, I decided to write a small program to let me visualize the effects of a given permutation on a graph embedded in two or three dimensions:
Here we see a regular dodecahedron. (These don't look great as static images, I know, but the program allows you to rotate the figures which makes them a lot easier to discern.) Suppose we were to twist two of the opposite pentagonal faces; then we'd get something that looks a little like this:In case you couldn't tell from the shape, the background has turned light yellow to indicate that this permutation is not in fact an automorphism of the dodecahedron. This is a platform independent Java application, and I'll post a download as soon as my web hosting comes back up. If anyone would like to look over my Java code and tidy it up, and/or make it into a workable applet, that'd be great; I really don't know Java and this took me way longer to write than it should have.

Relevant math question: If we let S6 act on the vertices of the icosahedron, how many different graphs (up to isomorphism) do we get?

Update: now available for download. Extract the archive into a directory, then either double-click on the .jar file or use the provided shell script or batch file depending on platform. The graphs/ directory contains some different graphs you can load; if you peek at one of the files in a text editor it should be pretty clear how to make your own. Enter permutations in cycle notation, e.g. (1 2)(3 4), and beware the following caveats:
  • The vertices are numbered 0,1,...n-1 rather than 1,2,...n
  • You don't have to reduce your permutations, so you can enter e.g. (1 2)(1 3)(3 4 5) or somesuch. Be aware, though, that the program composites permutations backwards, so you'll have to flip things right to left with respect to normal mathematical notation.
I've had some annoying classpath issues on my computer so I'd be glad to hear whether this works on other people's computers or not.

Thursday, November 13, 2008

Help on an unusual LaTeX error

I ran into a somewhat unusual LaTeX error earlier today, for which I was unable to Google any relevant information, so I thought I'd put a quick description up here for the next person who runs into this and goes searching for help online. If you didn't get here by searching for help with this problem, you probably won't be interested in the rest of the article.



The relevant section of the error message reads:


! LaTeX Error: Missing \begin{document}.

...

1.1

\ d o c u m e n t c l a s s { a r t i c l e }

The problem turned out to be that I was that my LaTeX installation was expecting an ASCII input file, whereas I was feeding it something encoded with Unicode. I fixed this by opening the file in wordpad, using the "Save as..." option, and changing the dropdown box from Unicode text to regular text.

Apparently there are techniques for getting your LaTeX installation to handle Unicode input, but I'm not really sure how it's done. In the mean time, I guess I'll be writing all my math papers in English, rather than Japanese, Persian, or Tengwar.