terça-feira, 26 de outubro de 2010

Python class for quaternions


Last August in Dublin (at DCU) I presented a tutorial about Python in Scientific Computing.

While there I thought it was appropriate to give a native example (in Rome be Roman) and so I choose the Quaternions. This is a good excuse as any other to present the multiple features of python for science. :-)

The picture above is carved in the Broom Bridge, over the Royal Canal, and where supposedly Hamilton had the inspiration to come with such beasts :-) . I had described before (in Portuguese) my hazard quest to find the place. An yearly event, at 16th of October, gets people together to visit the place and probably for a couple of drinks. :-)

While preparing the course I searched for python implementations of the quaternions and I have only found code related with graphics transforms (where the quaternions can be useful).
In the same spirit of Free/Open Source Software, to scratch a itch, I make available my implementation of  a python class that implements the quaternions and that deals transparently with the complex numbers.

The code can be found at my homepage.

Here it is a sample:

    a = Quaternion(1, -2)
    b = Quaternion(1, 2, -3, 4)
    c = 1 - 2j

    print "a =", a
    print "b =", b
    print "c =", c

    print a + b
    print a - c

    print a*b
    print a*c

    print 2*a

    print b*b.conjugate()
    print abs(b)**2

And the resulting output:

a = +1-2*i+0*j+0*k
b = +1+2*i-3*j+4*k
c = (1-2j)
+2+0*i-3*j+4*k
+0+0*i+0*j+0*k
+5+0*i+5*j+10*k
-3-4*i+0*j+0*k
+2-4*i+0*j+0*k
+30+0*i+0*j+0*k
30.0

I hope this helps others who have the same problem I had. :-)

segunda-feira, 25 de outubro de 2010

Fedora: an auspicious name

I have stated several times before that Fedora is strange name in Portuguese. Imagine my surprise when walking in Lisbon at "Rua Aurea" I got the following view. "Bijuterias" the name after Fedora means costume jewelry.

For what is worth this post has been delayed one year since the last time I was there I only had my mobile phone camera (not terribly accurate). Now with a real camera the result is worth to show.

Equally interesting is that "Rua Áurea" can be translated as "Golden Street". The street that follows it is "Rua do Ouro", Gold Street.
The streets at that area of Lisbon were rebuilt after the 1755 major earthquake, and the resulting tsunami that followed it, that totally destroyed that area. The streets at that area were named after the particular trade practiced there (a common practice in medieval Europe).

A posteriori (as opposed to "a priori") the relevance of this poster can be attributed to the next release of Fedora. Fedora 14 release will happen (we hope) next Tuesday, 2nd of November the day next  to the anniversary of Lisbon earthquake. Let us hope for this to be a (benign) earthquake in OS landscape.