Ask Your Question

slelievre's profile - activity

2019-10-08 07:37:14 -0500 answered a question Creating a vector of indexed variables

The Python identifier can't have brackets so this fails:

sage: var('x[0]')
Traceback (most recent call last)
ValueError: The name "x[0]" is not a valid Python identifier.

but the LaTeX name can, so you can do:

sage: X = [SR.var('x_{}'.format(i), latex_name='x[{}]'.format(i)) for i in (0 .. 7)]

and then you would have in the Sage REPL:

sage: X
[x_0, x_1, x_2, x_3, x_4, x_5, x_6, x_7]
sage: show(X)
\newcommand{\Bold}[1]{\mathbf{#1}}\left[{x[0]}, {x[1]}, {x[2]}, {x[3]}, {x[4]}, {x[5]}, {x[6]}, {x[7]}\right]

but in a Jupyter notebook, show(X) would give a LaTeX-rendered $$[x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7]]$$

2019-10-08 05:45:12 -0500 answered a question Sagemath 8.8 crash on startup on windows 10

The SageMath installer works by installing a "Linux-like" layer for Windows called Cygwin. This operates at a rather low level, and various anti virus scanners tend to consider this low-level activity as "virus-like", and as a consequence they tend to get in the way of the SageMath installer, or of the Cygwin it installs. Depending on the antivirus software and how one configures it, it might just raise an alert, or block the software it thinks is virus-like, or try to destroy it.


  • download the SageMath installer for Windows
  • tell all antivirus software to ignore the SageMath installer for Windows
  • run the installer; this installs SageMath
  • tell the antivirus software to ignore SageMath
  • run SageMath

If one runs the installer, or SageMath, before having told antivirus software to ignore it, and if antivirus software considers some of the low-level activity by the installer or by SageMath as virus-like, then such antivirus software might decide not only to block the installer or SageMath, but to remove it, or parts of it, making it non-working later on, even if one later tells the antivirus software to ignore it.

This applies not only to "trend micro" but also to "windows defender", "kaspersky", etc.

2019-10-08 05:41:16 -0500 commented question Sagemath 8.8 crash on startup on windows 10

Trend Micro is a cyber security company, and Trend Micro office scan is likely an anti-virus scanner by that company.

2019-10-07 10:52:21 -0500 answered a question Factoring vs Prime identification

Yes, checking that a number is not prime can be very easy, without factoring it: you just check that it does not satisfy some condition that all primes satisfy.

For example, if $n$ is a prime, then for any integer $a$, we have $a^n$ is congruent to $a$ modulo $n$.

Another way to say that is that if $n$ is an integer, and if there is any integer $a$ such that $a^n$ is not congruent to $a$ modulo $n$, then $n$ is not prime. Finding such an $a$ can be very cheap but it would not give a way to factor $n$.

See the notion of probable prime and pseudo-prime.

2019-10-06 10:32:16 -0500 commented question Hypergeometric Bug?

To display blocks of code or error messages, skip a line above and below, and do one of the following (all give the same result):

  • indent all code lines with 4 spaces
  • select all code lines and click the "code" button (the icon with '101 010')
  • select all code lines and hit ctrl-K

For instance, typing

If we define `f` by

    def f(x, y, z):
        return x * y * z

then `f(2, 3, 5)` returns `30` but `f(2*3*5)` gives:

    TypeError: f() takes exactly 3 arguments (1 given)


If we define f by

def f(x, y, z):
    return x * y * z

then f(2, 3, 5) returns 30 but f(2*3*5) gives:

TypeError: f() takes exactly 3 arguments (1 given)

Please edit your question to do that.

2019-10-03 08:13:51 -0500 commented question expand large expressions made of complex functions and variables

To display blocks of code or error messages, skip a line above and below, and do one of the following (all give the same result):

  • indent all code lines with 4 spaces
  • select all code lines and click the "code" button (the icon with '101 010')
  • select all code lines and hit ctrl-K

For instance, typing

If we define `f` by

    def f(x, y, z):
        return x * y * z

then `f(2, 3, 5)` returns `30` but `f(2*3*5)` gives:

    TypeError: f() takes exactly 3 arguments (1 given)


If we define f by

def f(x, y, z):
    return x * y * z

then f(2, 3, 5) returns 30 but f(2*3*5) gives:

TypeError: f() takes exactly 3 arguments (1 given)

Please edit your question to do that.

2019-09-24 15:07:21 -0500 commented question Illustrate column picture of matrix multiplication between a 3 x 4 matrix and a 4 x 2 matrix?

Could you post code that can be copy-pasted into a fresh Sage session to illustrate your problem?

Please edit the question to do that.

2019-09-24 15:07:18 -0500 commented question Illustrate column picture of matrix multiplication between a 3 x 4 matrix and a 4 x 2 matrix?

Welcome to Ask Sage. Thank you for your question.

2019-09-04 06:23:21 -0500 received badge  Nice Answer (source)
2019-09-01 12:54:35 -0500 answered a question donation button on ?

Thanks for your appreciation of SageMath! I find a lot of happiness in it too!

There used to be a donation button for donating to "The Sage Foundation", a foundation supporting SageMath which was operated by the University of Washington; however this foundation has been discontinued.

SageMath applying to become a sponsored project of NumFOCUS (or of its European equivalent, which is in the process of being created) is regularly discussed; this has not happened yet but I am sure it will become a reality in the not so distant future.

In the meantime, you could make a donation to one or several of the NumFOCUS-sponsored projects that underly SageMath, for example NumPy, Matplotlib, Jupyter, IPython, SymPy, Conda-Forge, MathJax... Or to other NumFOCUS-affiliated projects, for example Cython... Or to the Python Software Foundation.

The "14 USD/month" you refer to is probably a CoCalc plan; note that you can subscribe to it once in a while for just a month or two, if that is the kind of amount you want to spend.

Another way to help is to get Google Cloud starting credits and to set up some GitLab runners to help with the continuous development / continuous integration of SageMath. See the GitLab-CI page on the SageMath wiki.

2019-08-28 05:49:43 -0500 commented question Sage not detecting integers in Boolean Polynomial Ring?

Note: instead of

for i in range(len(equations)):
    for j in equations[i]:
        if j == 1:
            print 'true'

you could use

for eq in equations:
    for j in eq:
        if j ==
2019-08-14 06:40:35 -0500 received badge  Good Answer (source)
2019-08-13 17:12:54 -0500 received badge  Nice Answer (source)
2019-08-13 04:42:42 -0500 answered a question Import sage in python3

As @Emmanuel_Charpentier hints at in his comment, this requires using Sage's Python.

If you built from source, you can call Sage's Python with sage --python.

Or you could change your path so that Sage's Python is found first. Use with caution, as other apps / scripts / uses may rely on python calling the system Python.

Note that you can install SageMath using Conda; it will install for Python 3. With the corresponding Conda environment activated, python will be the Python 3 which has SageMath installed on top of it. In that Python, from sage.all import * will work.

2019-08-09 17:10:35 -0500 commented question Obtain a particular solution for a system of inequalities whose variables can only take certain values

What is SRC?

2019-08-07 08:58:16 -0500 received badge  Nice Answer (source)
2019-08-06 08:17:44 -0500 marked best answer Install optional packages (eg extra Jupyter kernels) on top of conda-installed SageMath

Suppose one has installed SageMath using the conda package.

How does one then install optional packages? It seems sage -i is not active there.

For example, what would be the replacement for

$ sage -i gap_jupyter         # install Jupyter kernel for GAP 4.8
$ sage -i pari_jupyter        # install Jupyter kernel for PARI/GP
$ sage -i r_jupyter           # install Jupyter kernel for R
$ sage -i singular_jupyter    # install Jupyter kernel for Singular

if one is using a conda-installed Jupyter and SageMath?

2019-08-06 08:14:59 -0500 received badge  Popular Question (source)
2019-08-04 06:02:19 -0500 commented answer graphs of order n

The documentation can be accessed with ?:

sage: graphs?

and it says this generator produces one representative for each isomorphism class.

To get "all graphs", run through all subsets of the set of unordered pairs of integers among the first n integers and construct the corresponding graphs.

2019-08-04 03:48:15 -0500 answered a question Can someone explain this theorem from von Staudt on denominators of Bernoulli numbers.

There are several ways to write 74 as a product: $74 = 1 \times 74 = 2 \times 37 = 37 \times 2 = 74 \times 1$.

2019-08-03 16:11:01 -0500 answered a question How do I install opencv in SageMath 8.8 on Windows 10

OpenCV-Python provides Python bindings for OpenCV (free software for computer vision).

To install it you need OpenCV itself, as well as Python, to be installed.

Maybe try the following, in a Sage shell (which, if you installed Sage using the Sage-Windows installer, runs in Cygwin):

apt-cyg install libopencv-devel

Then install opencv-python with the command:

pip install opencv-python
2019-08-03 16:07:59 -0500 answered a question Add labels to x/y axes

Use point2d instead of list_plot in this case.

2019-08-03 16:05:56 -0500 edited question characteristics three field elliptic curve lliptic curve for characteristics three field

How to generate elliptic curve from the following code as B is in hexadecimal form. The elliptic curve generated from the following code is ... which is not showing B in irreducible polynomial form.

Elliptic Curve defined by $y^2 = x^3 + x^2 + 1$ over Finite Field in $a$ of size $3^{151}$

F1.<x> = GF(3)[]
F.<a> = GF(3^151, 'a', modulus=x^151 + 2*x^2 + 1)
A = 1
B = (0x1fc4865afe00a9216b0b5fd32c6300c4bed0707ae4072a03e55299f157b)
E = EllipticCurve(F, (0, A, 0, 0, B))
2019-08-03 16:02:18 -0500 commented question no module string in sage on Debian 10

Please edit your question to specify how Sage was installed:

2019-08-03 16:00:08 -0500 answered a question plot comment not working

Try using show to display the graph:
2019-08-03 15:56:02 -0500 answered a question graphs of order n

The documentation is at

and especially

In particular the following generators exist:

sage: graphs(5)
<generator object GraphGenerators.__call__ at 0x...>
sage: graphs.nauty_geng("5")
<generator object GraphGenerators.nauty_geng at 0x...>
sage: graphs.nauty_geng("5 -c")
<generator object GraphGenerators.nauty_geng at 0x...>

and there are many more options to nauty's geng.

2019-08-01 10:36:09 -0500 commented question Building Sage on legacy macos system 10.5.8

Congratulations on building SageMath on this legacy macOS!

2019-07-29 09:22:47 -0500 commented answer type error solving system of differential equations numerically

@werner1717 if that answers your question please mark the answer as accepted by clicking the "accept" button (the one with a tick mark) at the top left of the answer. This marks the question as answered in the list of questions on the home page of Ask Sage.

2019-07-28 11:36:48 -0500 edited question type error solving system of differential equations numerically

I tried to solve a differential system numerically as follows:

R = 5
g = 9.8
t = var('t')
x = function('x')(t)
y = function('y')(t)
de1 = diff(x,t) - y == 0
de2 = diff(y,t) + (g/R)*sin(x) == 0
desolve_system_rk4([de1,de2],[x,y],ics = [0,(20/180)*pi,0],ivar=t)

and got a type error:

Traceback (most recent call last)
TypeError: Error executing code in Maxima
    sage4 : rk(['diff('x(_SAGE_VAR_t),_SAGE_VAR_t,1)-'y(_SAGE_VAR_t)=0,'diff('y(_SAGE_VAR_t),_SAGE_VAR_t,1)+1.96*sin('x(_SAGE_VAR_t))=0],['x(_SAGE_VAR_t),'y(_SAGE_VAR_t)],[%pi/9,0],[_SAGE_VAR_t,0,10,0.1])        $
Maxima ERROR:

rk: variable name expected; found: 'x(_SAGE_VAR_t)
 -- an error. To debug this try: debugmode(true);
2019-07-21 09:47:21 -0500 edited question Generate all the monic polynomials up to degree n with coefficients in Zp(p prime number) field and find all the irriducible polynomials

My code.

    if n==1:
        for i in range(0,p):
    else :
        for i in range(0,p):

def MYSIEVE(n,All)
    for d in range(1,floor(n/2)+1):
        for j in range(d+1,n+1):
            for polinomio1 in All[j]:
                for polinomio2 in All[d]:
                    if polinomio1%polinomio2==0:

def project(p,n):
    if not(is_prime(p)):
        print('p is not prime',p)
2019-07-21 09:45:24 -0500 commented question conda sagetex
2019-07-12 10:16:39 -0500 received badge  Nice Answer (source)
2019-07-12 06:03:52 -0500 answered a question How to change the unreadable dark blue colour in the SageMath command line window under Windows-10?

This is because the default color scheme in Sage is adapted to a light background, while Sage-Windows starts on dark background.

There is an "ipython magic" that allows to choose the color scheme for syntax highlighting.

At the Sage prompt, type:

sage: %colors Linux

To make that permanent, add that line to your init.sage file, which is read each time Sage starts.

2019-07-12 05:42:51 -0500 answered a question Constructing a number field with complex embedding

Having defined:

sage: a = sqrt(-7)

This works:

sage: number_field_elements_from_algebraics([a])
(Number Field in a with defining polynomial y^2 - y + 2,
 [-2*a + 1],
 Ring morphism:
   From: Number Field in a with defining polynomial y^2 - y + 2
   To:   Algebraic Field
   Defn: a |--> 0.50000000000000000? - 1.322875655532296?*I)

This fails:

sage: number_field_elements_from_algebraics([a], embedded=True)
Traceback (most recent call last)

The reason for why only embeddings of real numbers are supported is that nobody has done it yet. If you can do it, your contribution will be appreciated.

Regarding your worry that there was a good reason: if so, the correct thing to do would have been to add as a comment about the reason, and to raise a ValueError rather than a NotImplementedError.

2019-07-12 02:20:59 -0500 commented question Is it possible to load a Maxima package into Sagemath?

The package you have in mind is probably Dirac3 by Ted Woollett, right?

2019-07-12 01:06:52 -0500 commented question Is it possible to load a maxima package into Sagemath ?
2019-07-08 13:07:09 -0500 commented question Factorization of multivariate polynomials over complex field

Please give an example of what you would like to input and what output you would hope to get.

2019-07-08 13:06:17 -0500 commented question How to turn the function into expression?

Instead of "I have some function f(x, y, z)", please paste the actual code you wrote, for example f(x, y, z) = x*y*z + x*x*y + 5*y*z^2 + 3*x*y^2.

Also, instead of "I want to use some commands like [...] on it, but it is no more possible if it's a function", you could give an example of input and output that works, and an example of input that does not work, and say what you were expecting to get, and what error message you got.

2019-07-08 12:57:37 -0500 commented answer absolute value for the ln function

@Sha -- since this answers your question, please accept the answer (by clicking on the button with a tick mark); this will mark the question as answered in the main list of question on the Ask Sage homepage.

2019-07-03 06:42:21 -0500 edited answer What is the best way to implement polynomials with fractional exponents with SageMath?

Polynomial with fractional exponents are also called Puiseux polynomials.

Implementing Puiseux polynomials and Puiseux series in Sage is tracked at:

See also this other Ask Sage question