CoCalc Public Filessupport / 2018-09-14-091151-quat.sagews
Author: William A. Stein
Description: Jupyter notebook support/2015-06-04-141749-bokeh.ipynb
%time
R.<x> = QQ[]
K = R.fraction_field()
H.<i,j,k> = QuaternionAlgebra(K, -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].numerator().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] [7] [64, 448, 336, -280, -280, -42, 7, 1] [8] [-128, 512, 1792, 896, -560, -448, -56, 8, 1] [9] [-512, -1152, 2304, 5376, 2016, -1008, -672, -72, 9, 1] [10] [-512, -5120, -5760, 7680, 13440, 4032, -1680, -960, -90, 10, 1] [11] [1024, -5632, -28160, -21120, 21120, 29568, 7392, -2640, -1320, -110, 11, 1] [12] [4096, 12288, -33792, -112640, -63360, 50688, 59136, 12672, -3960, -1760, -132, 12, 1] [13] [4096, 53248, 79872, -146432, -366080, -164736, 109824, 109824, 20592, -5720, -2288, -156, 13, 1] [14] [-8192, 57344, 372736, 372736, -512512, -1025024, -384384, 219648, 192192, 32032, -8008, -2912, -182, 14, 1] [15] [-32768, -122880, 430080, 1863680, 1397760, -1537536, -2562560, -823680, 411840, 320320, 48048, -10920, -3640, -210, 15, 1] [16] [-32768, -524288, -983040, 2293760, 7454720, 4472832, -4100096, -5857280, -1647360, 732160, 512512, 69888, -14560, -4480, -240, 16, 1] [17] [65536, -557056, -4456448, -5570560, 9748480, 25346048, 12673024, -9957376, -12446720, -3111680, 1244672, 792064, 99008, -19040, -5440, -272, 17, 1] [18] [262144, 1179648, -5013504, -26738688, -25067520, 35094528, 76038144, 32587776, -22404096, -24893440, -5601024, 2036736, 1188096, 137088, -24480, -6528, -306, 18, 1] [19] [262144, 4980736, 11206656, -31752192, -127008768, -95256576, 111132672, 206389248, 77395968, -47297536, -47297536, -9674496, 3224832, 1736448, 186048, -31008, -7752, -342, 19, 1] [20] [-524288, 5242880, 49807360, 74711040, -158760960, -508035072, -317521920, 317521920, 515973120, 171991040, -94595072, -85995520, -16124160, 4961280, 2480640, 248064, -38760, -9120, -380, 20, 1] CPU time: 0.05 s, Wall time: 0.05 s

%time
R.<x> = QQ[]
K = R.fraction_field()
H.<i,j,k> = QuaternionAlgebra(K, -1, -1)
def Q(a, b, c, d): return H(a + b*i + c*j + d*k)
@cached_function
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].numerator().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] [7] [64, 448, 336, -280, -280, -42, 7, 1] [8] [-128, 512, 1792, 896, -560, -448, -56, 8, 1] [9] [-512, -1152, 2304, 5376, 2016, -1008, -672, -72, 9, 1] [10] [-512, -5120, -5760, 7680, 13440, 4032, -1680, -960, -90, 10, 1] [11] [1024, -5632, -28160, -21120, 21120, 29568, 7392, -2640, -1320, -110, 11, 1] [12] [4096, 12288, -33792, -112640, -63360, 50688, 59136, 12672, -3960, -1760, -132, 12, 1] [13] [4096, 53248, 79872, -146432, -366080, -164736, 109824, 109824, 20592, -5720, -2288, -156, 13, 1] [14] [-8192, 57344, 372736, 372736, -512512, -1025024, -384384, 219648, 192192, 32032, -8008, -2912, -182, 14, 1] [15] [-32768, -122880, 430080, 1863680, 1397760, -1537536, -2562560, -823680, 411840, 320320, 48048, -10920, -3640, -210, 15, 1] [16] [-32768, -524288, -983040, 2293760, 7454720, 4472832, -4100096, -5857280, -1647360, 732160, 512512, 69888, -14560, -4480, -240, 16, 1] [17] [65536, -557056, -4456448, -5570560, 9748480, 25346048, 12673024, -9957376, -12446720, -3111680, 1244672, 792064, 99008, -19040, -5440, -272, 17, 1] [18] [262144, 1179648, -5013504, -26738688, -25067520, 35094528, 76038144, 32587776, -22404096, -24893440, -5601024, 2036736, 1188096, 137088, -24480, -6528, -306, 18, 1] [19] [262144, 4980736, 11206656, -31752192, -127008768, -95256576, 111132672, 206389248, 77395968, -47297536, -47297536, -9674496, 3224832, 1736448, 186048, -31008, -7752, -342, 19, 1] [20] [-524288, 5242880, 49807360, 74711040, -158760960, -508035072, -317521920, 317521920, 515973120, 171991040, -94595072, -85995520, -16124160, 4961280, 2480640, 248064, -38760, -9120, -380, 20, 1] CPU time: 0.01 s, Wall time: 0.01 s