Sage and PyQt4

I wanted to use Qt4 as a backend for Sage’s matplotlib.  This wasn’t as hard as I thought it was going to be.  This “all done for you” systems always leave me stymied when I want to do something.  Sage had some really nice surprises (dare I say gifts) in this regard.

The basic steps for installing your favorite Python package into Sage seems to be:

  1. Pull down the package
  2. Unextract it (e.g. tar -xzf <package.tgz>
  3. Create an spkg (sage pkg) by writing a spkg-install and tarring it up with a spkg extension.
  4. Installing the spkg by running `sage -i <package>.spkg`
  5. Dropping into sage sh to fix whatever goes wrong (following the instruction spit out by sage when the installation fails).

To get started, I installed the latest Sage.  I unpacked this into a local directory and made a soft link to the sage executable.

I then pulled down PyQt and sip from Riverbank.  I unpacked these in a local directory.  For both packages, I did the following:


mv packagedir src
mkdir packagedir
mv src packagedir/
cd packagedir
cat > spkg-install
#!/bin/sh
cd src
# Now build and install.
python configure.py
make
make install
if [ $? -ne 0 ]; then
echo "Error building PyQt4."
exit 1
fi
^D
cd ..
tar -cvf package.spkg packagedir

Then I ran sage -i for the sip package and this went perfectly.  The PyQt had issues because I have both Qt3 and Qt4 installed on my system.  Following the cool sage install output I dropped into the sage -sh shell and manually ran the steps in the PyQt’s spkg-install script.  Specifically, I had to run the pythong configure.py with the -q <path to Qt4 qmake> and the -g option (something to do about libraries).

sage -pylab works for normal plotting.  However, it barfs for function plotting e.g plot([sin,cos]).  Sigh.  Guess that is why they don’t use it.

Maxwell’s Demon

There is a box that contains two chambers each containing gas molecules at the same temperature.  A demon controls a door between the two chambers.  He opens it if in the right chamber he sees a particle moving fast right to left or if he sees a particle in the left chamber moving slow left to right.  Over time, the left chamber is hot and the right chamber is cold.

The problem is the entropy of the system supposedly didn’t increase — it decreased!

Maxwell presented this scenario in the 1800’s and it took physicists like a hundred years to figure it out.  Supposedly, the amount of entropy in the system increased when the demon “forgets” about each particle that he is tracking.  There is this whole theory of reversible computing where the computation takes no energy but the clearing of registers takes energy and produces entropy.  The demon acts as a irreversible state machine consuming energy and increasing the entropy of the system.  (Not that all this makes sense to me as I have forgotten almost everything I ever knew about thermodynamics).

Complex Numbers I

[latexpage]

I have been trying to read Penrose’s

    Road to Reality

. He spends a lot of time talking about complex numbers.

Nature uses numbers that contain the square root of -1.

$$
i=\sqrt{-1}
$$

Any number can be expressed as:

$$ x=\Re(x)+i\Im(x) = a+ib $$

In a limited way, complex numbers are 2 dimensional. Some guy defined the “Complex Plane” where the y-axis is the imaginary part and the x-axis is the real number line. Numbers can be plotted on this plane. The numbers can be expressed in polar coordinates:

$$ x = |x| e^{i\theta} $$

where:

$$ |x| = \sqrt{a^2 + b^2} $$
$$ \theta = \tan^{-1} \left( \frac{b}{a} \right) $$

I learned about these numbers in circuit and electromagnetics courses at A&M. A signal that varies with the sine of the frequency time the time can be expressed as the real part of a point in the Complex Plane with a fixed value (distance from the origin) rotating about the origin at the signal’s frequency.

Math Wiki

I have been working on a tiddly wiki that is available off this site. I do capacity, reliability and performance modeling where I work so its kind of starting to lean that way. I am also trying to slowly (re)read Strogatz’s
Nonlinear Dynamics and Chaos.

Equation Test Blog Entry


Here’s an example equation:

\int \sin x\ dx= -\cos\ x + C

To get this to work I used the jsMath stuff that I pulled down for tiddlywiki and followed the directions at http://www.squarecirclez.com/blog/jsmath-in-wordpress-blogs/967.

\int \sin x\ dx= -\cos\ x + C

The Button Test

In front of you is a button that is the culmination of millennia of human knowledge and effort.  Using amazing complex mathmatics, mathematicians and physicists, who you know personally, have proven that there are only two outcomes of pushing the button: total knowledge and bliss for all humans living and dead or the total and instantaneous annihilation of the universe.

Your friends have left you alone with the button.  What do you do?

Benford’s Law Part 1

“You are full of sh**.”

I looked up from my lunch in surprise. I had been telling the table at the burrito place about this weird statistical thing called “Benford’s Law” that I had read about.

“You are saying that if I look at the first digit of any number it is 20% likely to be a 1”.

I said yes for most collection of numbers.

“Addresses?”

Yes.

“File sizes?”

Absolutely, I responded. Then I told them that this holds true if you change the numbers into hexadecimal.

“You’re a moron.”