# Extended Sage examples

I'm trying to learn how to use Sage to do algebraic number theory. I've read the thematic tutorials that seem related, but they are pretty bare-bones. The documentation seems to be pretty much a list of methods; I haven't found a higher-level view of what concepts are implemented and how they can be used. Are there any meatier extended examples that are available? Or is there documentation that I'm missing? (So, for example, how would I go about finding in the documentation the answer to "is the square root of two in the field K that I just defined"?)

edit retag close merge delete

Sort by » oldest newest most voted

Firstly there is the reference manual section on Algebraic Numbers and Number Fields. As you mentioned, there is the Bordeaux lecture (thematic tutorial) on number fields. There is also an introductory worksheet for the Mastermath course taught in Leiden, the Netherlands. It would also make sense to go through a book or lecture notes and to do the computations that are suggested. In this spirit, you would probably appreciate:

The book by William Stein: Algebraic Number Theory, A Computational Approach.

Of course you are welcome to ask more specific questions here. Answering your example question: to find if your number field $K$ contains a square root of two, you can find the roots of $X^2 - 2$ in $K$:

sage: K.<a> = NumberField(x^4 - 6*x^2 + 7)
sage: R.<X> = PolynomialRing(K)
sage: rootsof2 = (X^2 - 2).roots(multiplicities=False); rootsof2
[a^2 - 3, -a^2 + 3]


Note that this $K$ is an abstract number field, with several different embeddings into $\mathbb{C}$, so the question of which one is "the" (positive) square root of two depends on the embedding you want to use:

sage: [map(phi, rootsof2) for phi in K.embeddings(CC)]
[[1.41421356237310, -1.41421356237310],
[-1.41421356237309, 1.41421356237309],
[-1.41421356237309, 1.41421356237309],
[1.41421356237310, -1.41421356237310]]


Or, with some more precision:

sage: [[phi(r).radical_expression() for r in rootsof2] for phi in K.embeddings(QQbar)]
[[sqrt(2), -sqrt(2)],
[-sqrt(2), sqrt(2)],
[-sqrt(2), sqrt(2)],
[sqrt(2), -sqrt(2)]]

more

The book Calcul mathématique avec Sage was translated into German as Rechnen mit Sage and into English as Computational mathematics with SageMath.

Section 5.3 of the English translation ends like this:

Algebraic Numbers. An algebraic number is defined as root of a polynomial. When the polynomial degree is 5 or more, in general it is not possible to explicitly write its roots in terms of the operations $+$, $−$, $\times$, $/$, $\sqrt{}$. However, many computations involving the roots can be performed successfully without any other information than the polynomial itself.

sage: k.<a> = NumberField(x^3 + x + 1); a^3; a^4+3*a
-a - 1
-a^2 + 2*a


This book does not describe in detail how to play with algebraic numbers in Sage, however several examples can be found in Chapters 7 and 9.

In general I would recommend this book as a very good introduction to computer algebra and numerical computation as well as to SageMath, with a lot of examples.

(Disclaimer: I know some of the authors.)

more