# slelievre's profile - activity

2020-05-28 22:18:38 -0500 commented question email to sage-support was returned

Sorry about that. Not sure what went wrong with emaling sage-support, it's supposed to work. Try joining the sage-support mailing list first:

2020-05-27 09:01:14 -0500 commented question Why could not I install sage-9.1-OSX on Catalina?
2020-05-21 14:00:25 -0500 edited question Strange behaviour in simplifying a function

I am developping a long notebook to master Sage. But each time I fall on a problem. This time

p, D, w_0, x, I = var('p, D, w_0, x, I')
β = var('beta')
π = var('pi')
w00=8
D1=6
p1=0.5
A = matrix(SR, 2, 2, [[w_0, 1],[w_0-π,1]])
y = vector([w_0-D, w_0-D-π+I])
sol=A.solve_right(y)
sola=sol[0].full_simplify().function(D, π, w_0)
solb=sol[1].full_simplify().function(D, π, I, w_0)
f=(sola*x + solb).function(x, D, π, I, w_0)
g=f(x, D, β*I*(1-p), I, w_0).factor().collect(x).simplify().function(x, D, β, p, w_0)
h(x, D, p, w0)=g(x, D, 1, p, I, w_0).collect(D).collect(x).simplify()
show(f)
show(g)
show(h)


1) this is the main question : You can observe that g is independanr of I. But h is g with $\beta = 1$. So why I does reappear in h ?

2) How could we explain SM to write the slope of the 3 curves as I would write them in a sheet of paper ?

2020-05-21 13:56:18 -0500 answered a question how to generate a random 10 digit integer with 1 at last place?

There are many ways.

Here is a simple one using randint:

sage: 10 * randint(10^8, 10^9 - 1) + 1

2020-05-21 13:54:27 -0500 commented question how to generate a random 10 digit integer with 1 at last place?
2020-05-17 12:40:23 -0500 commented question Elliptic Curve over Tower of Finite Field

Please provide minimal complete code that can be copy-pasted in a fresh Sage session.

Providing concrete values helps immensely by saving others the trouble of making lots of decisions.

This allows others to help even if they are not experts in that field of mathematics.

2020-05-17 12:37:43 -0500 edited answer order finite field

You can get the source code of the order method by typing:

sage: E.order??


As you can see, this is basically a handler that decides which algorithm fits best since you did not specify one. In your case, it will use pari, so you have to look at the pari source code.

You can also have a look at

sage: E.cardinality_bsgs??


which implements "Mestre's trick", or

sage: E.cardinality_exhaustive??


which counts vertically over each x-value.

2020-05-16 21:37:12 -0500 answered a question PARI Group Labelling

The names (for degrees up to 15) are from the paper:

Basically they describe the particular permutation action, not just the abstract isomorphism type. The group in the question is abstractly a C(10) (cyclic), but the [x] (brackets indicate permutational actions) indicates that it is the product action of C(5) with C(2) on 10 points (not the intransitive action on 7 points).

[Related notes.]

The Sage documentation page:

points to the PARI documentation page:

Note that it is after a previous similar question here:

There is an open ticket to make it easier to extract information about a PARI group:

2020-05-16 21:25:53 -0500 edited question PARI Group Labelling

I have a Galois group that I'm tying to determine:

f = x^5 - 792*x^4 + 71280*x^3 + 39517632*x^2 - 7519640832*x + 314605513728
d = 3
A = -9504*d^2
B = 365904*d^3
K.<a> = NumberField(f)
R.<y> = K[]
g = y^2 - a^3 - A*a - B
L.<z> = NumberField(y^2 - a^3-A*a-B)
G = L.galois_group()


I have a couple of issues: When I type G[1], it says

GaloisGroup_v1 is not subscriptable


The second is the output for G says

[10,-1,1,'C(10)=5[x]2']


I know this is the PARI label and the last entry is the GAP 4 label. But for the life of me I cannot find anywhere where it explicitly tells me what C(10)=5[x]2 means.

2020-05-14 18:07:17 -0500 edited question How can I get an image in 3D using the axial symmetry of the graph in polar coordinates.

I have equations and the 2D curve drawing in polar coordinates.

Equations and 2D curve drawing in polar coordinates.

var('beta, phi, R, d')

# Transformation function
a(phi, beta) = (cos(phi) + beta)/(1 + beta*cos(phi))

# Two equations in polar coordinates
r1(phi, beta, R, d) = d*a + sqrt(d^2*(a^2 - 1) + R^2)
r2(phi, beta, R, d) = d*a - sqrt(d^2*(a^2 - 1) + R^2)


Plot both charts for parameters beta=0.8, R=1, d=2.

p = polar_plot(r1(phi, 0.8, 1, 2), (-pi/2 + 0.16, -0.16 + pi/2), color='red')
p += polar_plot(r2(phi, 0.8, 1, 2), (-pi/2 + 0.18, pi/2 - 0.18))
p

2020-05-12 16:30:46 -0500 commented question Traveling Salesman Problem

Can you provide the graph?

2020-05-12 13:14:38 -0500 answered a question Latex and SageMath

Here is a function to convert the LaTeX string of a matrix into a Sage matrix.

The function includes a bit of documentation with an example.

def matrix_from_latex(mat):
r"""
Return a Sage matrix corresponding to this LaTeX matrix.

Convert the LaTeX string for a matrix with integer entries
into a Sage matrix.

EXAMPLE:

Convert a Sage matrix to LaTeX and back::

sage: a = matrix([[0, 1, 2], [1, 0, 3], [4, -3, 8]])
sage: a
[ 0  1  2]
[ 1  0  3]
[ 4 -3  8]
sage: b = latex(a)
sage: print(b)
\left(\begin{array}{rrr}
0 & 1 & 2 \\
1 & 0 & 3 \\
4 & -3 & 8
\end{array}\right)
sage: c = matrix_from_latex(b)
sage: c
[ 0  1  2]
[ 1  0  3]
[ 4 -3  8]
"""
bits = [r'\left(\begin{array}', r'\end{array}\right)', 'r', '{}']
for b in bits:
mat = mat.replace(b, '')
row = mat.split(r'\\')
return matrix([[ZZ(a) for a in row.split('&')] for row in rows])


To start directly from a string such as in a comment to the question:

sage: z = r'\left(\begin{array}{rrr}0 & 1 & 2 \\ 1 & 0 & 3 \\ 4 & -3 & 8 \end{array}\right)'
sage: matrix_from_latex(z)
[ 0  1  2]
[ 1  0  3]
[ 4 -3  8]


Note that the function provided above works for matrices with integer entries.

It could be adapted to more general entries.

2020-05-12 12:35:23 -0500 edited answer Substitution in implicit function

I am not completely sure about your question, but i guess that what you call "procedure" is actually a Python function, which you can define using the def statement (check for Python introductions, there are very good tutorials online):

var("w1, w2, a, p")
EU(w1, w2, a, p)= p*w1^a+ (1-p)*w2^a

def my_procedure(V):
var("dw1, dw2")
V_w1 = diff(V, w1)
V_w2 = diff(V, w2)
# Differential
dV = V_w1 * dw1 + V_w2 * dw2
show("dV ="+latex(dV))
# Dérivée du premier ordre
sol = solve(dV == 0, dw2)
show(sol[0]/dw1)


Then, calling:

my_procedure(EU)


$dV = \left( w_{1}, w_{2}, a, p \right) \ {\mapsto} \ a \mathit{dw}_{1} p w_{1}^{a - 1} - a \mathit{dw}_{2} {\left(p - 1\right)} w_{2}^{a - 1}$

$\frac{\mathit{dw}_{2}}{\mathit{dw}_{1}} = \frac{p w_{1}^{a - 1} w_{2}^{-a + 1}}{p - 1}$

and

V=function('V')(w1, w2)
my_procedure(V)


$dV = \mathit{dw}_{1} \frac{\partial}{\partial w_{1}}V\left(w_{1}, w_{2}\right) + \mathit{dw}_{2} \frac{\partial}{\partial w_{2}}V\left(w_{1}, w_{2}\right)$

$\frac{\mathit{dw}_{2}}{\mathit{dw}_{1}} = -\frac{\frac{\partial}{\partial w_{1}}V\left(w_{1}, w_{2}\right)}{\frac{\partial}{\partial w_{2}}V\left(w_{1}, w_{2}\right)}$

2020-05-11 16:36:56 -0500 edited question 𝙸𝙿𝚢𝚝𝚑𝚘𝚗.𝚌𝚘𝚛𝚎.𝚍𝚒𝚜𝚙𝚕𝚊𝚢.𝙷𝚃𝙼𝙻𝚘𝚋𝚓𝚎𝚌𝚝

What means

<𝙸𝙿𝚢𝚝𝚑𝚘𝚗.𝚌𝚘𝚛𝚎.𝚍𝚒𝚜𝚙𝚕𝚊𝚢.𝙷𝚃𝙼𝙻𝚘𝚋𝚓𝚎𝚌𝚝>

It seems to be a complaint since nothing happens when this warning is displayed but it's not always the case? I found no documentation on this.

2020-05-11 16:36:02 -0500 commented question 𝙸𝙿𝚢𝚝𝚑𝚘𝚗.𝚌𝚘𝚛𝚎.𝚍𝚒𝚜𝚙𝚕𝚊𝚢.𝙷𝚃𝙼𝙻𝚘𝚋𝚓𝚎𝚌𝚝

Please include a way to reproduce: what input will cause this output?

2020-05-11 16:34:39 -0500 edited question How can I find the points on the hyperelliptic curve?

How can I find points on a hyperelliptic curve?

For example, consider the curve defined by the equation $$y^2 =2000 x^6 + 8000 x^5 + 27625 x^4 + 70500 x^3 + 345750 x^2 + 62500 x + 1968750$$

How can I find points on that curve?

2020-05-10 04:56:37 -0500 commented question Automatic substitution of unicode characters

Short code block to illustrate the problem please.

Something we can copy and paste in a fresh Sage session.

Would save time for anyone interested in exploring.

2020-05-10 04:52:05 -0500 commented question jupyter_contrib_nbextensions

What command did you run. What error message did you get.

The booleans True and False are Python built-ins. I doubt there is a way to change how they display.

A workaround is to build a class Bool to mimic bool in French:

class Bool(int):
r"""
Booléens francisés.

EXAMPLES:

sage: v = Bool(1)
sage: v
Vrai
sage: bool(v)
True

sage: f = Bool(0)
sage: f
Faux
sage: bool(f)
False
"""

def __init__(self, b):
self.bool = bool(b)

def __repr__(self):
return "Vrai" if self.bool else "Faux"

def __str__(self):
return "Vrai" if self.bool else "Faux"

def __bool__(self):
return self.bool


Note that we make Bool a subclass of int to better mimic Python's bool class (which itself cannot be subclassed).

Use Bool instead of bool in your code and the results should behave much the same as bool would, except they display as Vrai and Faux instead of True and False.

To go further, you might even decide to call this class bool instead of Bool, thus overriding the builtin class bool, and then you would not need to change your other code.

I wonder if that might have unexpected side-effects.

To be more cautious, call the class Bool and then run

bool = Bool


Revert to the usual booleans if needed by running

from builtins import bool


or

import builtins
bool = builtins.bool


If you really like having booleans display in French and don't mind the unusual setup, you could put the definition of Bool and the bool = Bool in the file ~/.sage/init.sage so it is run each time Sage starts (first create that file if it does not already exist).

Other ideas of how to name this class:

• FrenchBool for a more descriptive name
• fool for these French booleans that some might find a little crazy
2020-05-09 09:09:19 -0500 commented question Sagemath on Chromebook with Linux (Beta)

Not quite answering your question, but somewhat related: William Stein wrote notes on turning a Pixelbook into a development environment with ChromeOS + Crostini + a local installation of CoCalc.

2020-05-09 09:08:36 -0500 answered a question Sagemath on Chromebook with Linux (Beta)

William Stein wrote notes on turning a Pixelbook into a development environment with ChromeOS + Crostini + a local installation of CoCalc.

2020-05-09 08:57:37 -0500 answered a question Run a notebook from console

Some options are discussed at

The following tool could also be useful:

2020-05-09 08:51:58 -0500 answered a question Code and markdown cell

To display code in a Markdown cell in Jupyter, use single backticks for inline code, triple backticks for code blocks.

For example:

In the next cell we will define square by


def square(x):
return x * x



will render as

In the next cell we will define square by

def square(x):
return x * x


Some Jupyter Notebook and JupyterLab extensions allow to evaluate code in a Mardown cell in Jupyter. See:

2020-05-09 08:40:54 -0500 commented question Code and markdown cell

Do you mean code to be displayed, or code to be evaluated?

2020-05-08 16:06:27 -0500 edited question Polynomial ring over the ring of integers modulo 3

I am using SageMath and I want to use a polynomial ring in this form: (Z/3)[x]/(x^p - x - 1) , with Z as polynomial ring over integer Ring. How can I build that? Until now I only could declare Z[x]/x^p - x - 1

2020-05-08 16:03:08 -0500 commented question Issues with numpy.linspace()

The way the code appeared while the code portions of the question were not properly formatted as code, the asterisks for multiplication (*) were interpreted as markdown for "italics" and thus not displayed, which could give the impression of syntax errors.

@nooniensoong97 -- if you managed to solve the problem, please post the solution as an answer here, and accept the answer so that the question is marked as solved.

2020-05-08 02:57:30 -0500 edited question SageTeX: formatting matrices

Hello all,

I would like to have sagetex producing matrices with the columns centered. If was writing this by hand, I would do \begin{bmatrix*}[c] ... \end{bmatrix*}

From my XXX.sout file, I see the result \begin{array}{rrr} ... \end{array}. Is there a way to control this? Either playing at the sage level directly or by controlling sagetex?

Thanks!

2020-05-08 02:56:26 -0500 edited question Issues with numpy.linspace()

The following code:

# Restricted Three Body Problem
# Plotting x,y,dx,dy

# Import
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

# Variables
a,x,y,u,v,xdot,ydot,udot,vdot = var('a,x,y,u,v,xdot,ydot,udot,vdot')

# Sun-Jupiter Ratio
Em = 317.83
Ms = 5.9736*10^24
Sm = Em/Ms
b = Sm/(1+Sm)

# Restricted Three Body Problem
def r3bp(a,x,y,t):
a = b
x = x[0]
y = y[0]
u = u[0]
v = v[0]
xdot = u
ydot = v
udot = -(1-a)*((x-a)/(sqrt((x-a)^2 + y^2))^3)-a*((x+1-a)/(sqrt((x+1-a)^2 + y^2))^3)+x+2*v
vdot = -(1-a)*(y/(sqrt((x-a)^2 + y^2))^3)-a*(y/(sqrt((x+1-a)^2 + y^2))^3)+y-2*u
return[xdot,ydot,udot,vdot]

# Initial conditions
x0 = -0.509
y0 = 0.883
u0 = 0.0259
v0 = 0.0149
t = np.linspace(0,100,num=1000)
x,y,u,v = odeint(r3bp,x0,y0,u0,v0,t)

# Data
x = x[:,0]
y = y[:,0]
u = u[:,0]
v = v[:,0]

# Plot functions
px = plt.plot(t,x)
py = plt.plot(t,y)
pu = plt.plot(t,u)
pv = plt.plot(t,v)
plot.show(px)
plot.show(py)
plot.show(pu)
plot.show(pv)


produces the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-37-2a6a37bd25e9> in <module>()
34 u0 = RealNumber('0.0259')
35 v0 = RealNumber('0.0149')
---> 36 t = np.linspace(Integer(0),Integer(100),num=Integer(1000))
37 x,y,u,v = odeint(r3bp,x0,y0,u0,v0,t)
38

/opt/sagemath-9.0/local/lib/python3.7/site-packages/numpy/core/function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
136     stop  = asanyarray(stop)  * 1.0
137
--> 138     dt = result_type(start, stop, float(num))
139     if dtype is None:
140         dtype = dt

TypeError: data type not understood

2020-05-07 21:18:19 -0500 answered a question SageTeX: formatting matrices

Sage allows changing the delimiters and the column alignment that are used for creating the LaTeX form of a matrix.

Define a matrix:

sage: a = diagonal_matrix([1, -1])
sage: a
[ 1  0]
[ 0 -1]


Default LaTeX form:

sage: latex(a)
\left(\begin{array}{rr}
1 & 0 \\
0 & -1
\end{array}\right)


Modify settings:

sage: latex.matrix_delimiters('[', ']')
sage: latex.matrix_column_alignment('c')


New LaTeX form:

sage: latex(a)
sage: latex(a)
\left[\begin{array}{cc}
1 & 0 \\
0 & -1
\end{array}\right]


How to find such things by oneself?

The LaTeX form of a is given by latex(a) which in turns calls a._latex_().

Inspect the documentation and the source code with

sage: a._latex_?
sage: a._latex_??

2020-05-06 16:13:51 -0500 commented answer “python3.7” cannot be opened because the developer cannot be verified.

Glad this helped, and thanks for explaining which particular link and command helped.

@Szabolcs. Good point. I edited my answer, adding a warning as you suggest.

Sorry for the frustration. Note that @Sébastien's answer did have such a warning.

Please ask about other pain points, here or on sage-support or on sage-devel, or open tickets on Sage Trac.

While Sage is building, hopefully one of Binder, SageCell or CoCalc can provide a way to get work done.

(Or install a second version of Sage if you have enough disk space.)

## Installing extra Python packages for Sage on macOS

To "pip install" extra packages, pip needs to be able to establish secure connections. This requires the underlying Python to have its SSL module available.

On most Linux distributions, people normally have OpenSSL installed as part of their distribution, so we ship Sage binaries whose Python is compiled with its SSL module, and it will generally work.

On macOS, Apple uses another way to deal with secure connection, and does not provide the openssl package as part of the operating system.

The binaries we ship for macOS don't have OpenSSL because it was up to now licensed under "the OpenSSL license" which did not allow to distribute it along with GPL-licensed software such as Sage.

This is about to change since OpenSSL 3 will be licensed under the Apache 2.0 license. which will allow distributing OpenSSL with binaries of GPL-licensed software such as Sage. So far (2020-04), only a preliminary version of OpenSSL 3 is out. Maybe by the end of 2020 this will be solved for good.

In the meantime, macOS users who want to expand their Sage with extra Python packages have a few choices, including:

b. modify one's Sage installation to give its Python the SSL module

c. use a version of Sage whose Python has the SSL module

Below some more details about each of these options.

In terminal commands below, the initial $ represents the shell prompt, it should not be typed, so if you copy-paste the commands don't include that initial $.

First note that running sage --pip install packagename relies on packagename being available on PyPI (the Python Package Index).

The PyPI page for packagename is likely:

https://pypi.org/project/packagename


Visit that page in a web browser and find an option there to download packagename as a zip file, or maybe some other compressed format, but let's say zip. Download it, and get a file packagename.zip on your computer, at some location, let's say in the Downloads folder in your home.

Then run the following (adapt path and filename if needed):

$sage --pip install ~/Downloads/packagename.zip  This whole "go visit some webpage, download a zip, and run sage --pip install /path/to/packagename.zip" is a little less convenient than the simple sage --pip install packagename, but at least it gets the job done and doesn't require any change to your Sage installation. In particular, no risk of damaging your Sage installation and getting it to a non-working state. ### b. Install OpenSSL on an existing Sage installation There are two ways to do that: b.1 is the easiest, and b.2 is a little more involved. #### b.1. Ready-made The easy way is provided by the developers of computational topology software packages (for studying the topology of three-manifolds). That software can be made to work with Sage and they found a way to provide just the right pieces to fix a Sage installation. Download "fix_mac_sage8.tgz" or "mac_sage9.tgz" (respectively for Sage 8.x and Sage 9.x) from the page: Then unpack and follow the instructions in the README file found in the unpacked folder. #### b.2. Rebuilding a lot of things This is a different way of obtaining the same result one would get by following b.1. Warning: it takes a lot longer. It leaves you without a working Sage installation while it is running. In addition, if it fails, it could break your Sage installation, in which case you have to reinstall Sage. (In that case you might want to use option c). There is a preliminary, which is to have Apple's "command-line tools for developers" installed. To install those, run this command in a terminal: $ xcode-select --install


This will either tell you that the command-line tools are already installed, or open a dialog to let you install them.

Once this is done, it might be a good idea to restart your computer. Not sure it's needed but it can't hurt.

Now we are almost at the crucial step. This step will take a long time (up to hours) as it forces the rebuild of Sage's python3 module, which in turn forces to rebuild all packages that depend on python3 (in particular Numpy, Scipy, etc.).

To mitigate that, optionally, set the number of jobs that make should run in parallel.

To check how many processors can be used, run this:

$sysctl -n hw.ncpu  Then, to set make to run say 4 jobs in parallel, run: $ export MAKE='make -j4


Now these two commands should work (but to warn again, it's happened to me that it did not work and left me with a broken Sage which I did not know how to repair):

$sage -i openssl$ sage -f python3  # can take hours


If that worked, you should be able to run

\$ sage --pip install packagename


to install any Python package packagename from PyPI.

### c. Installing Sage with SSL support

We now mention ways to perform a complete installation of Sage with OpenSSL support.

There are several choices including:

1. install Sage via Conda, see

2. build Sage from source

• in a Conda environment which has OpenSSL installed
• or with OpenSSL installed via Homebrew
• or without any of Conda or Homebrew

### On several computers

If you have several computers with the same version of macOS, you might be able to transfer Sage installations from one to the other, as long as you put them at the exact same location, for example /Applications/SageMath.

Use your favourite way to transfer files:

• (compress then copy then uncompress)
• rsync
• ...

Careful, a Sage installation can be quite big, so it might not fit on a USB drive especially if it is formatted as "FAT" (which does not allow files over 4 GB).

If needed, after compressing to zip or tar-gz or other, split the file into several parts, put the parts on a usb drive, and reassemble the parts on the other side.

See this for details:

2020-05-06 13:50:30 -0500 answered a question Can't plot a function

The command plot samples 200 points in the specified interval.

For the combinatorial function in the question, only integer values matter.

The corresponding plotting function is list_plot.

sage: g = lambda x: binomial(3, x) * binomial(3, 2 - x) / binomial(6, 2)
sage: glist = [g(x) for x in range(3)]
sage: gplot = list_plot(glist, ymin=0, size=30)
sage: gplot.show()
Launched png viewer for Graphics object consisting of 1 graphics primitive


2020-05-05 18:09:52 -0500 commented question Boolean conditional function

Could you please edit the question to make it more consistent:

• decide between Vrai/Faux vs Accepté/Rejeté
• "a function with" -> "a function which"
• selon que ... ou ... -> according to whether ... or ...
• decide whether it's "x > y" or "x < y" that should be "accepted"
2020-05-05 18:05:23 -0500 answered a question Boolean conditional function

In some cases a lambda function is also okay.

It takes up less lines than a def function.

sage: cond = lambda x, y: "Accepté" if bool(x<y) else "Rejeté"


Then:

sage: a, b, c, d, e, f = [1 .. 6]
sage: essay = [[cond(a, b)], [cond(c, d)], [cond(e, f)]]
sage: hc = ['test', r'A', r'B', r'C']
`