Ask Your Question
0

How can I define a function with quaternion argument, and other non-vector input

asked 2015-10-15 04:44:52 +0100

j0equ1nn gravatar image

updated 2015-10-19 20:45:22 +0100

I've been using Sage for 3 weeks so please bear with me if this is an ignorant question.

There are lots of great tools for studying properties of quaternion algebras http://doc.sagemath.org/html/en/refer... and also for doing computations in these algebras http://doc.sagemath.org/html/en/refer...

But I am interested in working with functions that move between quaternion algebras and other spaces. For instance let's say I write

K.<d> = NumberField(x^2 + 1)
A.<i,j,k> = QuaternionAlgebra(K,-1,-1)

And let's say I want a function $$f:A\rightarrow M_2(K), w+xi+yj+zij\mapsto (w,x,y,z).$$ How can define this function in such a way that I can enter something like

f(2*i+i*j)

and get as output

(0,2,0,1)

?

This particular function is not very useful or interesting, I'm just using this to keep it simple. I'd also be interested in defining functions that go from one quaternion algebra to another, or from a quaternion algebra to a matrix ring, in such a way that I can compose these things. It seems functions are generally expected to have vector input, but there is not always a straightforward way of turning elements of a domain into vectors (there is for matrices, but even this is tedious).

I feel there is probably a general principle addressing things like this but I'm not finding it.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2015-10-19 02:48:39 +0100

nbruin gravatar image

From your question and comments I understand you are interested in defining functions from the "quaternion algebra"

sage: K.<d> = NumberField(x^2 + 1)
sage: A.<i,j,k> = QuaternionAlgebra(K,-1,-1)

(note that -1 is a square in K, so this algebra is split: it's isomorphic to GL(2,K)) For instance, you might be interested in the function that sends the quaternion algebra element w+xi+yj+z*k to the 2x2 matrix with rows [w+x,y+z] and [y-z,w-x]. The following is a way of defining such a function.

sage: def C(u):
....:    w,x,y,z=list(u)
....:    return matrix(2,2,[w+x,y+z,y-z,w-x])

with the above commands you can do things like:

sage: C(2*i+i*j)
[ 2  1]
[-1 -2]
sage: C(3+5*i+d*j+11*k)
[     8 d + 11]
[d - 11     -2]

Note that w+x*i+y*j+z*k is not an element of A:

sage: w+x*i+y*j+z*k
NameError: name 'w' is not defined

You can't even construct the element, let alone apply C to it. If you want quaternions with w,x,y,z in the coefficients, you'll have to declare a quaternion algebra over a ring that contains these elements, e.g., a multivariate function field. The "function" C is really only a "function" in the python/programming language sense, not a mathematical construct. You may notice that the definition of C never referenced the fact that our original A is defined over K, or in fact A at all. It only depends on the fact that its parameter u can be taken apart by list into 4 coefficients that can be stuffed into a matrix. So we don't even have to change the definition of C.

sage: P.<w,x,y,z>=QQ[]
sage: L=P.fraction_field()
sage: A.<i,j,k> = QuaternionAlgebra(L,-1,-1)
sage: C(w+x*i+y*j+z*k)
[w + x y + z]
[y - z w - x]
edit flag offensive delete link more

Comments

Great, this is what I was looking for. I think I can get the various functions I want by fiddling with what you showed me. (I would upvote your answer but I am new here and need to have points before I can upvote.)

j0equ1nn gravatar imagej0equ1nn ( 2015-10-19 03:15:41 +0100 )edit
0

answered 2015-10-15 05:35:51 +0100

fidbc gravatar image

You can just use the list or vector functions

x=2*i+i*j
list(x)
# produces [0,2,0,1]
vector(x)
# produces (0,2,0,1)
edit flag offensive delete link more

Comments

Thanks but I think you're missing the fact that I'm interested in arbitrary functions that can take quaternion input, not just that example. What if I wanted for instance the (actually useful) function $$f(w+xi+yj+zij)=\begin{matrix}w+x & y+z \ y-z & w-x\end{matrix}$&? I guess I could define it like $f(w,x,y,z)$, then for quaternion $q$ I could evaluate it like

f(list(q)[0],list(q)[1],list(q)[2],list(q)[3])

but I quickly run into trouble when doing composition or evaluating algebraic expressions.

j0equ1nn gravatar imagej0equ1nn ( 2015-10-15 05:58:38 +0100 )edit

So is the problem convenience for writing the formula? The following may not be very readable, but it uses the parameter unpacking capabilities of python to give a concise way of writing the answer:

sage: C=lambda u: (lambda w,x,y,z:(w+x,y+z,y-z,w-x))(*list(u))
sage: C(2*i+i*j)
(2, 1, -1, -2)

perhaps a little more readable:

def C(u):
    w,x,y,z=list(u)
    return (w+x,y+z,y-z,w-x)
nbruin gravatar imagenbruin ( 2015-10-15 06:13:39 +0100 )edit

@nbuin: I'm not seeing how this would allow input/output of non-vectors. For instance, to get an output from this $C$ function, one needs to put it in the form

C((w,x,y,z))

I thought perhaps doing this would make

C(w+x*i+y*j+z*i*j)

work, or at least

C(list(w+x*i+y*j+z*i*j))

but no it seems I still cannot use quaternion input. Also, I really wanted that output to be a $2\times2$ matrix, not another vector. (My LaTeX code did not translate in the comment.)

j0equ1nn gravatar imagej0equ1nn ( 2015-10-19 02:10:41 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-10-15 04:44:52 +0100

Seen: 1,274 times

Last updated: Oct 19 '15