# The Spectre of Math

## January 21, 2013

### The correct finite field does wonders

Filed under: Hacking,Mathematics,Technology — jlebl @ 5:26 pm

So the computation I was running since thanksgiving was getting nowhere (finding degree 19 polynomials which are equal to 1 on x+y=1, which have fewest possible terms (11) and which have only positive coefficients, we know that there are finitely many, the trick is to find them). My code didn’t really have good status updates. Well it does tell you exactly where it is, but it takes a bit of computation to really see how it’s progressing, so I didn’t do that until a few days ago since I thought it was going way too slow.

And low and behold, it was going way too slow. I computed that it should take another 3-7 years or so (different parts of the search space take different times so it’s a bit hard to estimate). That was a bummer. That was about 10 times longer than I thought it should be. At first I was a bit resigned to this reality, but the next day I started to look into it, and one thing I figured out after running a bunch of tests was that one shortcut I was using was never triggered. The idea is that we need to find when a certain matrix with integer coefficients has 1 dimensional nullspace. Doing the integer row reduction is done with gmp, and is reasonably fast. But since we do this many times over and most of these matrices are simply full rank (no null space), we don’t really need to do the whole computation. So what we can do (and this is a useful trick to know), is to first do all computation in some small finite field, e.g. do everything mod p for some small prime p. If a matrix is full rank mod p, it is full rank. The computation can be done rather quickly this way and you don’t even have to involve modulo computation, since all the possible computations you can just precompute first and just build up a big table, so instead of two multiplications, an addition, and finding the remainder, you just look up in a table. Anyway, that gets us quite a bit of a speed up.

Now the thing is that I was using mod 19, since that worked for lower degrees. One thing I forgot when I started the run (remember this was a few years since I looked at this code and ran it last time), is that the modulus cannot be the same as the degree. The matrices we need to work with have most terms divisible by the degree. So moding out by 19 essentially always made the matrix all 0 (except for a few 1s scattered around). So these matrices were essentially always singular and the shortcut never triggered. So after doing a useless mod 19 calculation we had to do the actual integer arithmetic. That’s why it was slow. Damnit!

Well the calculations were not wrong, I just did a lot more computation than needed. After a small amount of testing it seemed that mod 23 was a good finite field to proceed in, so I restarted the code. Suddenly 3-7 years turned into first estimating 90 days and after running things for a day, that turned into an estimate of 30 days.

Then I noticed one more thing (and Danny pointed this out too), that his code used symmetry and just threw out half of the nonsymmetric polynomials, since the computations are the same. I remembered that my code didn’t do it. It didn’t make much sense if the longest run we did was 5 days on one core (for code that is only ever run once or twice, small speedups are somewhat pointless). I implemented this idea and it seems to achieve 33% reduction in time (there’s still the checking for symmetry, and there are of course symemtric polynomials, so that’s probably close to where we can get). So anyway, I guess within 20 days we should have the answer.

After it finsihes, I still have one more speedup up my sleeve. It could be that I can do the row reduction really fast mod 2 by using binary operations (each row would be an unsigned int). Not sure what speedup I can achieve though, at best 90%, since that’s how many cases mod 2 catches. While mod 23 or so catches essentially everything. So the idea is to do mod 2, then mod 23, and only then if the matrix is still singular do the integer arithmetic. If the speedup is another 50%, and my most optimistic estimates hold, that would put degree 21 within the realm of possibility, though at least half a year on 4 cores. That’s is, within something I’d be willing to run.

So, the mood went from “I’ll probably give up n d=19 soon” to “maybe d=21 is possible”. All this just by using a different prime

## December 19, 2012

### Interesting calculation

Filed under: Mathematics,Teaching — jlebl @ 5:02 pm

An interesting back of the envelope calculation: UC Irvine is using the differential equations book as standard, that’s a couple of hundred students every quarter, and there are at least a few other places with large and small lectures using the book. A reasonable estimate at the current adoption, there are at least 1000 students every year who use the book. I recently checked on amazon how much does Boyce-DiPrima cost: the new edition is $184 (Yaikes!). It costs$110 just to rent for a semester (a used version was $165). That’s 110-184 thousand dollars a year saved by students, just because of one open book adopted in a couple of large lecture classes. Presumably, the adoption rate can only go up, so this number will go up, just from one of my books (savings from the real analysis book are going to be much smaller due to less students taking that kind of class). Now I have nothing against the publishers, but they have their incentives wrong. Boyce-DiPrima is a fine book, but … There is really no reason to print big bulky books on expensive paper for these classes. Locally printed coursepacks or cheaply printed paperbacks are much more efficient. And the students might actually keep their books and they might help them along in other classes. Currently most students return their books as soon as they can to recover most of the cost. So if you’re teaching say a PDE class as I did this semester, you can hardly tell them to brush up on their calculus from their calculus book. They don’t have it anymore! The incentive for me is to simply make the best book because I want to (makes me feel good, that’s I guess all I can expect). Since I make almost no money on it, I don’t really have to inflate page count just to make it more expensive, or add color and pretty pictures just for the hell of it (it would make the book quite a bit more expensive). Plus the book is more accessible. I already know students use the web version even from their phones. So anyway, I guess I’m providing at least 2 to almost 4 times my salary in free books. Anyway, if you do want to buy the books (and I make$2.50 on each, yay! I made almost $400 so far, it’s mostly for making me feel good rather than making money), here are the links to lulu: Real Analysis,$13.09 + shipping

Differential equations, $16.78 + shipping Yes, I’m a fan of arbitrary looking prices. Actually the reason for those prices is that I simply set the price so that I get$2.50 from the book, so it’s the (cost of printing)+2.50+(lulu’s cut).

## December 17, 2012

### New versions of books and new genius

Filed under: Hacking,Mathematics,Teaching — jlebl @ 11:47 pm

So in the last two days I’ve put up new versions of both the differential equations textbook (3 new sections, and of course some fixes) and the real analysis textbook (fixes, plus 4 new exercises). And also I’ve made a new release of genius. Actually two of those I just did today when my students were taking their final. The nice things about proctoring tests with small upper division classes is that you can get stuff done. There is no cheating going on. There’s only a few questions, so I had over two hours to burn. Next semester will be quite different. I’ll have two calculus lectures with 250+ students each. Proctoring an exam for that many students is not at all a relaxing exercise (and then there’s the grading … ugh!)

## December 9, 2012

### Yet another new section in DE book

Filed under: Hacking,Mathematics,Teaching — jlebl @ 7:31 am

In trying to avoid bad mood and keep stress level down, people turn to hobbies. One of my hobbies is working on my textbooks, so I have written a new section on the Dirichlet problem for the Laplace equation in the circle for the differential equations book. See the draft section. The previous section 4.9 is OK, but the solution is far more natural in the circle in polar coordinates than in a square, that is we obtain

$\displaystyle u(r,\theta) = \frac{a_0}{2} + \sum_{n=1}^\infty a_n r^n \cos(n\theta) + b_n r^n \sin(n\theta)$

And then we can derive the Poisson formula which is just cool. Also it’s a good example showing more complicated change of variables since we do it in polar, and also it shows a somewhat more complicated and different separation variables.

Part of the motivation was that I did this topic in my PDE class so I had lecture notes and it really felt right for that point in the book, even to leave it as reading to interested students. The other part is that I have been improving the graphing ability of genius so I can do polar coordinates for example:

That’s the graph of the solution $u(r,\theta) = r^{10} \cos(10\, \theta)$, showing that high frequency on the boundary means fast decay as you go closer to the center of your domain.

Though there is no UI for polar coordinates, there is just a function that allows you to plot arbitrary surface data now. Notice how it’s not graphed on a square grid, but above the disc. Also notice that internal rings have fewer points on them, that’s because I just compute fewer values at smaller radii, remember I am passing in arbitrary data, a list of tripples (x,y,z). This will be in version 1.0.16, which should come out end of next week sometime (have to let translators have a go at it). Actually the reason for doing this work on genius was not polar coordinates but showing numerical solutions in my PDE class. It’s just that one of my test cases was polar coordinates and so it just clicked and I thought: I have to write up this section, it’s just too cool to pass up and I can make the graphs now.

This brings the number of pages in the DE book to 315, and the number of exercises to 533. Yaikes! It’s become a beast. I’ll make the new version in a week or two so that it’s usuable for next semester (so if you have comments on the new section do let me know quickly).

I think now a two semester course could possibly be run out of the book. What’s going to be added in the new version is essentially about 5-6 lectures. At my speed the whole thing is now approximately 65 lectures, so a bit less than two semesters worth, but if you go just a tad slower (as many people do), do more examples, and if you factor in exams, reviews, quizzes, etc… it’s just right I think. You’ve got lots of room to spare if you want a two quarter course.

## December 7, 2012

Filed under: Hacking,Mathematics,Technology — jlebl @ 6:47 am

So I just remembered, it wasn’t that we thought the computation (see a previous post) would take half a year, it would take 450 days on 3ghz CPU. I guess my memory was being optimistic. I remembered “half a year” when it was really “one and a half a year”. OK, so the computation has now been running for a bit over 2 weeks now on 4 cores. I guess I’m at least 10% there (I hope). It looks a bit worse from the output. It doesn’t seem computers have gotten all that much faster (not at all it seems at least on the load I am trying to do) in the past few years. The only thing better is more cores.

## November 27, 2012

### Frobenius method and Bessel functions

Filed under: Hacking,LaTeX,Mathematics,Teaching — jlebl @ 6:57 pm

I had occasion to talk about Bessel functions and mention the Frobenius method in my PDE class and I realized that I do not have any mention of this in the book. This was the section I did not quite get to when teaching at UCSD, so it never got written. Well, worry no more. I’ve written up a draft version of the section. This will appear in the next version of the book whenever I make it, though if you do have comments, do let me know. It’s good to catch typos or make changes now.

This brings the number of pages to 307 together with new delta function section and the number of exercises to 521. Yay!

This also made me realize that Genius did not have Bessel functions implemented. They were actually easy to implement as MPFR has them done. At least for integer orders and real values anyway. Then as my current working directory of genius was such a mess with trying to include LAPACK, I decided to remove LAPACK for now from the genius git. I think what I will do is link to the fortran version at some later point. It seems like the fortran LAPACK is available almost everywhere, so it should not be a bad new dependency. Much easier than trying to make the beast compile cleanly inside genius. Anyway, so Bessel functions will be in Genius, which I think I ought to make a release of soon as there are a bunch of other small changes to set upon the world.

## November 25, 2012

### “Maxima is calculating”

Filed under: Hacking,Mathematics,Technology — jlebl @ 3:57 pm

So friday afternoon I wanted to test for existence of a certain mapping that takes one surface to another surface. Everything is algebraic so one might assume if a mapping exist it might actually be polynomial and since everything is of low degree, the mapping might be as well. So I just set up brute force equations and tried an arbitrary degree 2 mapping. After a second or two, maxima returned no solutions to the resulting system. OK, so how about plugging in degree 3. It turns out I don’t need to test the linear terms, and there are 3 variables so 16 variables per component so I get an algebraic system in 48 variables. Sounds bad, but lot of the equations become something of the form “x=0″. So I looked at a subset of the system. Already the generating of the equations took a few seconds. So I thought, this will take a few minutes. So I started “algsys” on the equations. Well, that was wednesday afternoon. It is Sunday and the thing is still running. Unfortunately it just says “Maxima is calculating” in the wxMaxima window, so one has no clue if it will take another day or so, another year or so, or if the sun will implode first. I sort of have the feeling it is doing something stupid. Once I get more time for math on monday, I’ll probably try to simplify the equations by hand first. I could also try for the solution (or lack thereof) numerically. In the meantime I’ll let it run. This is on my laptop which is surely not meant as a computation machine. It’s only running on one core so it’s not heating up too badly. When I was running some computations for days in the summer on all four cores you could almost cook eggs on the keyboard.

On a related front, I decided that my work computer is sitting too idly so I started the degree 19 calculation that we never did with Danny on our paper [1]. In 2008 we thought it would take at least half a year. Presumably the computers have gotten a tad quicker in the meantime (and since I’m running it on 4 cores), so perhaps the result will come in sooner. Still the progress seems slow from the output so far. It is a bit difficult to judge, I’ll try to estimate time left more precisely later on, but just as first guess from looking at the output I don’t think this will be done before christmas.

There is something magical about pressing ENTER to start the computation you know will take months to complete. It is one of the few places where you really use the fact that you have a fast computer. Most computer power is totally wasted. So for example in somewhat similar time frame Firefox managed to get 70 minutes of CPU time (maxima is up to 5208 now). Now that’s with only very occasional short browsing over the last few days. It seems mostly it’s the tabs being open that eat up time, run the CPU and heat our house. Come to think of that my office will be quite warm I bet once I get there on monday, I don’t think the heating runs on the room termostat, as the swich on that thing is in “off” position and it still heats the room. So with the added heating from 4 cores running at top speed and it being a small room, it should get toasty.

Update (monday morning): Actually my office was not much warmer. The computer case is actually quite cold and I don’t feel a huge difference in temperature of the air output. I don’t know why I never ran anything on this computer and always used my laptop so far for longer computations. I think I’ll abuse it more from now on.

[1] Jiří Lebl and Daniel Lichtblau, Uniqueness of certain polynomials constant on a line, Linear Algebra and its Applications, 433 (2010), no. 4, 824-837, arXiv:0808.0284.

## November 18, 2012

### News of Microsoft demise a bit premature and study habits of college students

Filed under: Teaching,Technology — jlebl @ 3:36 pm

There are apparently a number of people all excited about Microsoft now really destroying itself. Well it still remains to be seen. But I think a good indication of where things are headed are college students. Since I have google analytics now on the textbook pagess I can do some experiments. So for example essentially all the traffic from “Irvine” is from UCI students that look at the differential equations book. So I looked at the operating systems usage from Irvine. Here are the results (note that this is a small sample, very unscientific): 72.3% Windows, 10.6% Mac, 10.4% iOS (iPad + iPhone), 3.7% Linux, 3.1% Android. Now given if you watch what people use on campus it seems mostly Mac, I think that gut feeling might be a bit skewed. On the other hand there could be computer labs running that students use and have no choice over the OS. So what conclusions could one draw? Windows is still dominant, by far. Mac is doing better, but actually quite a bit worse than one would expect among college students. Linux is doing a bit better than I would expect, it’s where Mac was just a few years ago. The interesting thing is also the iOS vs Android. It seems from the news that Android phones have beat iPhones in terms of marketshare, but here it doesn’t look like it. So that would indicate tablets are being used and iPad still beats the android tablets. Interestingly 7.3% of visitors used 320×480 resolution, and that I guess means phone. I can’t figure out how to break that down in Google Analytics. By the way, this means 7.3% are reading their textbook on their phone. This number may spike during exams :). Let’s test this theory.

I don’t know how to draw this graph for Irvine only, so it could be other places as well. But look at this graph for the number of visits from phone-like resolution:

But let’s stop that cynical thinking about cheating: There were two exams at UBC (University of British Columbia) for two classes using the differential equations book, but they were on the 14th, and the spike is on the 13th, so the students were studying hard, not cheating. Well maybe studying from a pub so they needed to look at the textbook from a phone, but still.

## November 15, 2012

### New section in differential equations book

Filed under: LaTeX,Mathematics,Teaching — jlebl @ 7:44 pm

I have recently finally finished a new section on the Dirac delta function for the differential equations textbook. Take a look at the draft version. Note that this is a draft, so it could have typos and could still change. If you have any comments, let me know. Especially if you want to teach with it and would like to mention some detail I don’t mention right now. I will make a new version of the book including this section sometime in December, after semester ends.

In other news, the differential equations textbook is now apparently the standard book for Math 3D at University of California at Irvine. It’s nice if people pick the book to teach out of for their class, but it’s even nicer if a department decides to standardize on the book. The real analysis book is for example the standard book at University of Pittsburgh, and they even made their own changes (adding some extra material), which is a really nice example of what can be done with free textbooks.

I also added Google Analytics to the pages so I can see where the traffic is coming from. If someone uses the books by printing out a copy for students or putting a PDF on their site, I can’t quite see it, but if they simply link to my site it’s fun to watch the traffic. As the differential equations book has an HTML version, a lot of students seem to use that rather than the PDF. I assume the PDF is just downloaded and I don’t see traffic afterwards, but when they are using the HTML version, then of course they keep hitting my site. So currently there are several classes at Irvine and two classes at University of British Columbia that simply link to my site and I get lots of traffic on the HTML version of the book. These students using the HTML version takes up a large proportion of hits to my site. If you look on the map of which cities hits are coming from, there are two big circles, one over Irvine and one over Vancouver, and then lots of other smaller circles mostly distributed all over, mostly over english speaking coutries.

I am thinking I should make an HTML version of the real analysis textbook, but it’s quite a bit of work to set things up for tex4ht, and always quite a bit of work when making a new version so I have not yet gotten around to do it. Also I am more worried about formulas coming out correctly. It would be nice to get something like mathjax working with tex4ht. Or some other solution, but I don’t want to maintain two versions so it would have to take the LaTeX source and produce the HTML perhaps with a different style file. Anyway, for now it is images for equations, which do look bad when printed, but look OK on screen.

## November 9, 2012

### Numerical range

Filed under: Hacking,Mathematics — jlebl @ 12:06 am

I was fiddling with numerical range of two by two matrices so I modified my root testing python program to do this. The numerical range of $A$ is the set of all values

$\frac{v^* A v}{v^* v}$

for all nonzero vectors $v$. This set is a compact set (it can be seen as the image via the mapping $v \mapsto v^* A v$ of vectors on the unit sphere $v^* v = 1$ which is a compact set). It’s convex which is harder to show. For two by two it is an elliptic disc (could be degenerate).

See the result here, it plugs in random vectors and shows the result. Here’s an example plot for the matrix $A=\begin{bmatrix} 1 & i \\ 1 & -1 \end{bmatrix}$.

The code is really inefficient and eats up all your cpu. There’s no effort to optimize this.

« Previous PageNext Page »

The Rubric Theme. Blog at WordPress.com.