I saw the blog for your group a few times when I was doing a google blog
search for Sage. It looks really cool. Seattle isn't so far from
Portland, so I
hope some of you will consider coming to the next Sage days when we have
one up here (none are currently planned).
> compute with octonions in Sage, and discussed at our meeting last
> night possibly implementing such an algebra.
>
> As I understand it, multiplication of octonions can be implemented on
> top of the quaternions in a simple way using the Cayley-Dickson
> construction http://en.wikipedia.org/wiki/Octonion#Cayley-Dickson_construction
> .
> The difficulty then would seem to be to do it correctly so that it
> works with the rest of sage. I'm willing to do it once badly just for
> fun and then later maybe help with doing it correctly, but I'd like to
> at least get off to a respectable start. Any help would be greatly
> appreciated.
It's very helpful to take something already in Sage, e.g., the ring
of integers, or quaternions, or real double-precision numbers, and
copy that implementation. Note that most of the basic rings
are now implemented using Cython for speed purposes.
Of course, working in the framework of the upcoming coercion model
could also be very nice.
In any case, you're plan to just play around and do something that
works is a good one.
-- William
>
> Oh also in searching for existing implementations I saw that boost has
> this:
> http://www.boost.org/doc/html/boost_math/octonions.html
> but since sage already implements quaternions it seems unnecessary to
> look at boost except perhaps for inspiration.
>
> Regards,
> Eric Drechsel
>
> >
>
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org
> We want to compute with octonions in Sage, and discussed at our
> meeting last night possibly implementing such an algebra.
>
> As I understand it, multiplication of octonions can be implemented on
> top of the quaternions in a simple way using the Cayley-Dickson
> construction http://en.wikipedia.org/wiki/Octonion#Cayley-Dickson_construction
> .
If you define A_0 to be the reals and A_n to be the Cayley-Dickson
construction applied to A_{n-1}, then A_3 is the octonions. More
generally, write A_n(F) for the Cayley-Dickson construction applied
to A_{n-1}(F), where A_0 = F.
I've done lots of computations with A_4(float), A_5(float) and
A_6(float) in python, but not using Sage. I think the cleanest approach
is to define a function CayleyDickson that takes a class representing a
*-algebra and produces a new class representing the result of applying
the Cayley-Dickson construction. This allows you to change the base
"field" from float to int, Z, Z[x], high-precision floats, or whatever
you need for a particular application.
Potential problems:
- If I call CayleyDickson(float) twice, do I get a new class each time?
- How to handle coercions between A_n(F) and A_m(F)? And between A_n(F)
and A_n(F')? (F and F' are ground rings with *.)
- Efficiency. In my application, I was multiplying elements of
A_n(float) zillions of times, and this was *way* to slow using
the obvious recursive method in python. (If I recall correctly,
the time scales like 4**n.)
I instead worked with a class that directly implemented A_n(float)
using numpy arrays, and used weave to compile some inline C code for
the multiplication operation. (Cython/Pyrex might be just as good for
this, but I'm not sure if they can directly access numpy arrays as C
arrays.) It falls back to using python for the multiplication for
"object" arrays, which allows for changing float to other classes,
but is awkward.
I'm not sure how to get the best of both worlds. Maybe the first
way, with some clever Cython/Pyrex, could be made both flexible
and efficient? Or maybe the first way, with some special casing
to speed up common cases?
Dan
> I instead worked with a class that directly implemented A_n(float)
> using numpy arrays, and used weave to compile some inline C code for
> the multiplication operation. (Cython/Pyrex might be just as good for
> this, but I'm not sure if they can directly access numpy arrays as C
> arrays.)
Quick remark -- yes, Cython most certainly can directly access numpy
arrays as C arrays. There's an extension to Cython called PEX "in
the works" that is designed partly for doing exactly this really
cleanly, but it can be done
in a messy way too.
William