# How to find the norm of a quaternion?

EDIT︠ED: (never start with the code, always put the wanted question also in the posted question, not only in the title.)

N.<a1,a2,a3,a4,b1,b2,b3,b4,a,b> = QQ[]
H.<i,j,k> = QuaternionAlgebra(Frac(N),-1,-1)
p = a1 + a2 * i + a3 * j + a4 * k
q = b1 + b2 * i + b3 * j + b4 * k
r=(1-a-2*b)*(1-p*q+a*p)
r.norm()

edit retag close merge delete

Sort by » oldest newest most voted

[ Please, take the time to format your code properly, using the "101010 butten orf the damn' editor...]

(Sort-of) WorksForMe ... *provided * that you take the pain to use Sage's syntax (which requires the use of * to denote multiplication...).

sage: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:N.<a1,a2,a3,a4,b1,b2,b3,b4,a,b> = QQ[]
:H.<i,j,k> = QuaternionAlgebra(Frac(N),-1,-1)
:p = a1 + a2 * i + a3 * j + a4 * k
:q = b1 + b2 * i + b3 * j + b4 * k
:r=(1-a-2*b)*(1-p*q+a*p)
:
:--


Indeed, r parent's category, which is:

sage: r.parent()
Quaternion Algebra (-1, -1) with base ring Fraction Field of Multivariate Polynomial Ring in a1, a2, a3, a4, b1, b2, b3, b4, a, b over Rational Field


, by the way), has no norm, method. But it has ûreduced_norm:

sage: r.reduced_norm().factor()
(a + 2*b - 1)^2 * (a1^2*b1^2 + a2^2*b1^2 + a3^2*b1^2 + a4^2*b1^2 + a1^2*b2^2 + a2^2*b2^2 + a3^2*b2^2 + a4^2*b2^2 + a1^2*b3^2 + a2^2*b3^2 + a3^2*b3^2 + a4^2*b3^2 + a1^2*b4^2 + a2^2*b4^2 + a3^2*b4^2 + a4^2*b4^2 - 2*a1^2*b1*a - 2*a2^2*b1*a - 2*a3^2*b1*a - 2*a4^2*b1*a + a1^2*a^2 + a2^2*a^2 + a3^2*a^2 + a4^2*a^2 - 2*a1*b1 + 2*a2*b2 + 2*a3*b3 + 2*a4*b4 + 2*a1*a + 1)
`

HTH,

more