ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 21 Jan 2019 02:58:09 -0600- Extended Sage exampleshttp://ask.sagemath.org/question/45091/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"?)Thu, 17 Jan 2019 20:33:43 -0600http://ask.sagemath.org/question/45091/extended-sage-examples/
- Answer by slelievre for <p>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"?)</p>
http://ask.sagemath.org/question/45091/extended-sage-examples/?answer=45116#post-id-45116The book [Calcul mathÃ©matique avec Sage](http://sagebook.gforge.inria.fr/)
was translated into German as
[Rechnen mit Sage](https://members.loria.fr/PZimmermann/sagebook/CalculDeutsch.pdf)
and into English as
[Computational mathematics with SageMath](http://sagebook.gforge.inria.fr/english.html).
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](http://dl.lateralis.org/public/sagebook/sagebook-ba6596d.pdf#page=141&zoom=100,0,65)
> and [9](http://dl.lateralis.org/public/sagebook/sagebook-ba6596d.pdf#page=193&zoom=100,0,65).
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.)Mon, 21 Jan 2019 02:58:09 -0600http://ask.sagemath.org/question/45091/extended-sage-examples/?answer=45116#post-id-45116
- Answer by rburing for <p>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"?)</p>
http://ask.sagemath.org/question/45091/extended-sage-examples/?answer=45098#post-id-45098Firstly there is the [reference manual section on Algebraic Numbers and Number Fields](http://doc.sagemath.org/html/en/reference/number_fields/index.html). As you mentioned, there is the [Bordeaux lecture](http://doc.sagemath.org/html/en/thematic_tutorials/explicit_methods_in_number_theory/number_fields.html) (thematic tutorial) on number fields. There is also an [introductory worksheet](https://sage.math.leidenuniv.nl/home/pub/37/) for the Mastermath course taught in Leiden, the Netherlands. It would also make sense to go through a book or [lecture notes](http://websites.math.leidenuniv.nl/algebra/ant.pdf) 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](https://wstein.org/books/ant/ant.pdf).
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)]]Fri, 18 Jan 2019 05:59:18 -0600http://ask.sagemath.org/question/45091/extended-sage-examples/?answer=45098#post-id-45098