Ask Your Question

Revision history [back]

Give a name to the generator of your quadratic field as follows.

sage: K.<a> = QuadraticField(5)

Taking square roots of elements in the field sometimes leaves the field, sometimes stays in it.

sage: K(2) + sqrt(K(3))
sqrt(3) + 2
sage: K(2) + sqrt(K(5))
a + 2

You can test membership in the field as follows.

sage: K(2) + sqrt(K(3)) in K
False
sage: K(2) + sqrt(K(5)) in K
True