How can I speed up this computation?

    H.<i,j,k> = QuaternionAlgebra(SR, -1, -1)
    def Q(a, b, c, d): return H(a + b*i + c*j + d*k)
    def P(n): return Q(x+1,1,1,1)*P(n-1) if n > 0 else Q(1,0,0,0)
    def p(n): return P(n)[0].list()
    for n in (0..20): print [n], p(n)

    [0] [1]
    [1] [1, 1]
    [2] [-2, 2, 1]
    [3] [-8, -6, 3, 1]
    [4] [-8, -32, -12, 4, 1]
    [5] [16, -40, -80, -20, 5, 1]
    [6] [64, 96, -120, -160, -30, 6, 1]
    ...

With Mathematica this takes 6 sec, with Sage it takes 
hours, (in fact I interrupted after n=15). 

Thanks, Peter


-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to