# slelievre's profile - activity

2020-09-26 10:07:44 -0500 commented answer Splitting a list into sub-list

@Cyrille, my username in any of my answers is clickable and points to my Ask Sage profile.

My profile in turn links to various pages including my professional webpage.

That should have all information needed to refer to me or contact me.

2020-09-26 05:40:57 -0500 answered a question log(e) won't convert to 1

Below: - result when e is as when Sage starts - result when e is a symbolic variable - how to restore the initial value of e

With e as when Sage starts, no unsimplified log(e):

sage: log(e)
1

sage: f(x) = e^x*cos(x)
sage: f_int(x) = integrate(f, x)
sage: f_int(x)
1/2*(cos(x) + sin(x))*e^x


With e redefined as a symbolic variable, log(e) stays log(e):

sage: e = SR.var('e')
sage: log(e)
log(e)

sage: f(x) = e^x*cos(x)
sage: f_int(x) = integrate(f,x)
sage: f_int(x)
(e^x*cos(x)*log(e) + e^x*sin(x))/(log(e)^2 + 1)


To reset e to its default value, use either:

sage: reset('e')


or

sage: e = sage.symbolic.constants.e


or

sage: from sage.symbolic.constants import e


To figure out what import statement to use above, run this in a fresh Sage session:

sage: import_statements(e)
from sage.symbolic.constants import e

2020-09-26 05:31:04 -0500 answered a question Splitting a list into sub-list

Define a function split_into_k which takes a list l of length n and an integer k and splits the list l into a list of k sublists of length n // k.

def split_into_k(l, k):
n = len(l)
m = n // k
return [l[i*m:(i+1)*m] for i in range(k)]


Examples with a list of length 12 split into 3 or 4:

sage: split_into_k(A, 3)
[[1, 2, 3, 4], [6, 8, 2, 7], [9, 0, -1, -2]]
sage: split_into_k(A, 4)
[[1, 2, 3], [4, 6, 8], [2, 7, 9], [0, -1, -2]]


If k does not divide len(l), the trailing part is removed.

sage: split_into_k(A, 5)
[[1, 2], [3, 4], [6, 8], [2, 7], [9, 0]]


Other options would be to raise an exception or to have a shorter last part.

2020-09-25 06:38:56 -0500 commented answer Get the error "NameError: name '_interact_' is not defined" when run sagenb.

Do you get errors at the time of starting the sagenb notebook?

Or does it start without error, and do you get an error when executing some code?

2020-09-25 06:37:56 -0500 commented answer Get the error "NameError: name '_interact_' is not defined" when run sagenb.

This computer no longer had a Python2-based Sage.

I installed it again when writing my answer, and tested it.

2020-09-25 06:34:11 -0500 commented question How do I uninstall SageMath 9.1 from MacBook OS 10.14.5

Happy to help you uninstall, but also happy to help you solve any installation problems. Don't hesitate if you want to try again.

2020-09-25 06:32:40 -0500 commented question How do I uninstall SageMath 9.1 from MacBook OS 10.14.5

As far as I understand, if you take care of removing Anaconda from your PATH the first time you start Sage after installing it, everything is fine and you can then restore the PATH and not get interference.

2020-09-25 06:32:33 -0500 commented question How do I uninstall SageMath 9.1 from MacBook OS 10.14.5

2020-09-24 16:14:39 -0500 edited question How do I uninstall SageMath 9.1 from MacBook OS 10.14.5

How do I uninstall SageMath 9.1 from MacBook running macOS 10.14.5 Mojave? It never installed properly and I want to get rid of it. I can do my computations on Cocalc. I do have Anaconda installed and I heard that it can interfer with the installation of SageMath.

2020-09-24 16:10:51 -0500 edited question An algorithm on root systems' vectors "ValueError: too many values to unpack "

While finishing a math project, I need to run the following code, and get an error message which seems related to Sage calculation capacity, could anyone help me through this? (I am quite new to Sage.) If there is no way to handle that in Sage, could anyone recommend me another software with similar language where this code could be run properly?

e = RootSystem(['E', 6]).ambient_space()
Roots = e.roots()
a1 = vector((1/2, -1/2, -1/2, -1/2, -1/2, -1/2, -1/2, 1/2))
a2 = vector((1, 1, 0, 0, 0, 0, 0, 0))
a3 = vector((-1, 1, 0, 0, 0, 0, 0, 0))
a4 = vector((0, -1, 1, 0, 0, 0, 0, 0))
a5 = vector((0, 0, -1, 1, 0, 0, 0, 0))
a6 = vector((0, 0, 0, -1, 1, 0, 0, 0))
Lini = [a1, a2, a3, a4, a5]

def proj(t, ai):
myLone = vector(ai)
result= t - myLone.dot_product(t) / (ai.dot_product(ai))*myLone
return result

myP = [proj(x, a6) for x in Lini]
[proja1, proja2, proja3, proja4, proja5] = myP
myR = [vector(v) for v in Roots]
myL = [proj(x, a6) for x in myR]

len(myL)

myPlist1= Combinations(myP, 3).list()
myLlist1= Combinations(myL, 2).list()

# alternatively: produce all combinaisons in myL of five vectors
# (all to be used in a function where these combinaisons are variables:
# this does not work either

# myLlist = Combinations(myL, 5).list()

def letsapply(listg, alist):
for listel in listg:
myPset1= set(tuple(v) for v in listel)
print(myPset1)
for listel2 in alist:
myLset1 = set(tuple(v) for v in listel2)
print(myLset1)
myLset1 = myLset1.union(myPset1)

if len(myLset1) >= 5:
print(myLset1, "myLset1")

if len(myLset1) >= 5:
for myLel in myLset1:
[proja1, proja2, proja3, proja4, proja5] = myLel
print(myLel)

print(letsapply(myPlist1, myLlist1))

2020-09-24 15:59:31 -0500 edited question Root systems algorithm: "TypeError: 'str' object is not callable"

I am rather new to Sage and formal language.

I am running the following code which works fine with a slighty simpler version (where the variables p1, p2, ..., p5 in the function letsapply are fixed).

Here is the original function that works fine:

def letsapply(listg, alist):
mylistg = listg
mylistg.reverse()
for si in mylistg:
if si == 's1':
alist = map(s1, alist)
elif si == 's2':
alist = map(s2, alist)
elif si == 's3':
alist = map(s3, alist)
elif si == 's4':
alist = map(s4, alist)
elif si == 's5':
alist = map(s5, alist)
elif si == 's6':
alist = map(s6, alist)
else:
print("Wrong input in letsapply!!")
alistt = [tuple(v) for v in alist]
alistts = set(alistt)
return alistts


Below, I am getting the following

TypeError: 'str' object is not callable


Could anyone help me fix this? Thanks a lot!

e = RootSystem(['E',6]).ambient_space()
Roots = e.roots()

a1 = vector((1/2, -1/2, -1/2, -1/2, -1/2, -1/2, -1/2, 1/2))
a2 = vector((1, 1, 0, 0, 0, 0, 0, 0))
a3 = vector((-1, 1, 0, 0, 0, 0, 0, 0))
a4 = vector((0, -1, 1, 0, 0, 0, 0, 0))
a5 = vector((0, 0, -1, 1, 0, 0, 0, 0))
a6 = vector((0, 0, 0, -1, 1, 0, 0, 0))

Lini = [a1, a2, a3, a4, a5]

# alist is the set of all projections of roots in E6

myR = [vector(v) for v in Roots]

def proj(t, ai):
myLone = vector(ai)
result= t - myLone.dot_product(t) / (ai.dot_product(ai))*myLone
return result

myL = [proj(x, a6) for x in myR]

def si(t, projai):
myLone = projai
result = t- 2*myLone.dot_product(t)/(projai.dot_product(projai))*myLone
return result

def decompose(g, mylength):
# g is a str(aa) where aa belongs to list(WeylGroup ...)
listg = [g[3*i]+ g[3*i+1] for i in range(0, mylength)]
return listg

def letsapply(listg, alist, p1, p2, p3, p4, p5):
mylistg = listg
mylistg.reverse()
for si in mylistg:
if si == 's1':
alist = map(lambda w: si(w, p1), alist)
elif si == 's2':
alist = map(lambda w: si(w, p2), alist)
elif si == 's3':
alist = map(lambda w: si(w, p3), alist)
elif si == 's4':
alist = map(lambda w: si(w, p4), alist)
elif si == 's5':
alist = map(lambda w: si(w, p5), alist)
else:
print("Wrong input in letsapply!!")
alistt = [tuple(v) for v in alist]
alistts = set(alistt)
return alistts

def main():
W = WeylGroup(["A", 5], prefix="s")
listW = list(W)
# We remove the first element which is 1:
listW.pop(0)
listWdecomposed = [decompose(str(g), g.length()) for g in listW]

e = RootSystem(['E',6]).ambient_space()
Roots = e.roots()
## get all projections of roots in E6
myR = [vector(v) for v in Roots]
myL = [proj(x, a6) for x in myR]
print("myL =", myL)

# produce all combinaisons in myL of five vectors,
# and apply the procedure to them: the procedure consists first in writing
# the Weyl group associated to any five elements in myL (call any : myLel),
# then applying these elements si to myLel

myLlist= Combinations(myL, 5).list()
for myLel in myLlist:
[proja1, proja2, proja3, proja4, proja5] = myLel
res = set(tuple(v) for v in myLel)
for listg in listWdecomposed:
res = res.union(letsapply(listg, myLel, proja1, proja2, proja3, proja4, proja5))
# Reconvert
res = [vector(v) for v in res]
res.sort()
if len(res)< 30:
return(len(res), res)
else:
print("too many vectors in this subspace")
return 0
main()

2020-09-24 15:28:32 -0500 commented question Hi Friends, How can I uninstall SageMath on MacBook?
2020-09-24 15:27:47 -0500 answered a question How do I uninstall SageMath 9.1 from MacBook OS 10.14.5

If you have Anaconda installed you could install Sage via Conda using the conda-forge channel. That way there won't be a danger of Anaconda interfering in bad ways with Sage. That might works better for you than installing Sage another way.

If you installed the app and want to uninstall it, put it in the trash and empty the trash.

If you installed the non-app version, put the SageMath folder in the trash and empty the trash.

To get rid of the last bits of Sage, remove the .sage folder in your home folder.

That's all.

2020-09-24 05:35:28 -0500 commented question Sage very slow until restarting the session

If possible, say more on the calculations you were running. That might help uncover a memory leak in Sage.

2020-09-23 19:45:39 -0500 edited question metric to christoffel symbols yielding overflow

In a Sage 9.1 Jupyter notebook I tried the following SageManifolds commands

M = Manifold(4, 'M', structure='Lorentzian')

Mani.<t,X,rh,ph> = M.chart(r"t X:(-oo,+oo) rh:(0,+oo):\rho ph:(0,2*pi):\phi")

B = function('B')(X,rh,ph)
d_Ph_X = function('d_Ph_X')(X,rh,ph)
d_Ph_rh = function('d_Ph_rh')(X,rh,ph)
d_Ph_ph = function('d_Ph_ph')(X,rh,ph)

g = M.metric()

g[0,0] = (-1+B**2*  ((d_Ph_X/B**2)**2 +(d_Ph_rh/B**2)**2 +((1/rh*d_Ph_ph/B**2)**2     )))

g[1,1] = B**2
g[2,2] = B**2
g[3,3] = rh**2*B**2

g[0,1] = B**2*(d_Ph_X/B**2)
g[0,2] = B**2*( d_Ph_rh/B**2)
g[0,3] = B**2*( d_Ph_ph/B**2)

g.christoffel_symbols_display()


The last line makes the notebook overflow... i really don't understand why.

the computation, even if it is rather tedious, seems straightforward to me...

Any idea? Any help would be greatly appreciated.

2020-09-23 18:38:14 -0500 answered a question defining a translation surface

Install surface_dynamics and sage-flatsurf following instructions on the

Then launch Sage and follow the

Start by importing flatsurf:

sage: import flatsurf


Say we wish to define a flat surface from a two by one rectangle with opposite sides glued together.

Start by constructing the rectangle with one of these commands:

sage: p = flatsurf.polygons((2, 0), (0, 1), (-2, 0), (0, -1))
sage: p = flatsurf.polygons(vertices=[(0, 0), (2, 0), (2, 1), (0, 1)])


Observe the result:

sage: p
Polygon: (0, 0), (2, 0), (2, 1), (0, 1)


Construct a surface dictionary:

sage: from flatsurf import Surface_dict
sage: s = Surface_dict(base_ring=p.base_ring())
'A'
sage: s.change_polygon_gluings("A", [("A", (e + 2) % 4) for e in range(4)])
sage: s.change_base_label("A")
sage: s.set_immutable()
sage: s


Construct a translation surface:

sage: from flatsurf import TranslationSurface
sage: t = TranslationSurface(s)
sage: t
TranslationSurface built from 1 polygon
sage: t.plot()
Launched png viewer for Graphics object consisting of 10 graphics primitives


Check that we got a genus one surface:

sage: t.genus()
1


If we constructed a similarity surface by using a different side pairing for the gluings, we might get a genus zero surface.

For reference here are the versions that were used in this answer:

sage: print(version())
SageMath version 9.2.beta12, Release Date: 2020-09-06
sage: import surface_dynamics
sage: print(surface_dynamics.version.version)
0.4.4
sage: import flatsurf
sage: print(flatsurf.version.version)
0.3

2020-09-23 12:23:17 -0500 edited question Asymptotics of Multivariate Generating Series

I am new to Sage and I need to find the asymptotic form of the series coefficients of the following generating function:

F(t,x,z) = (1 + t*x - t*x*z)/(1 - t - t^2*x - t*x*z + t^2*x*z)


In other words, in the Taylor expansion of the function in terms of the variable $t$, I am interested in the asymptotic form of the coefficient of the term $t^L\ x^N\ z^B$ in the limit of large $L$, $N$, and $B$.

2020-09-23 12:21:44 -0500 commented question translation surface
2020-09-21 15:50:43 -0500 answered a question Sagemath 9.1 For

2020-09-21 04:27:51 -0500 commented question Sagemath 9.1 For

Also posted on sage-support:

2020-09-21 03:56:12 -0500 commented question Sagemath 9.1 For

What operating system? How did you install Sage? What instructions did you follow so far?

2020-09-21 03:56:05 -0500 commented question Sagemath 9.1 For

2020-09-21 03:12:45 -0500 commented question can't append to graphics object

If possible, please provide a minimal example to reproduce the problem.

2020-09-20 04:12:31 -0500 commented question Get the error "NameError: name '_interact_' is not defined" when run sagenb.

One way to get SageNB to build is to use --enable-sagenb=yes at the ./configure step.

In the situation where Sage is already built,

• either run the configure step again with --enable-sagenb and run make again
• or, without re-running the configure, step, build SageNb with make sagenb

Then run sage -n sagenb to launch the SageNB notebook server.

2020-09-20 03:35:25 -0500 answered a question Get the error "NameError: name '_interact_' is not defined" when run sagenb.

## Building Sage 9.1 and SageNB from source

Here are the steps to build Sage and SageNB from source, and to launch the SageNB notebook.

## Build Sage and SageNB

Here are the steps I would suggest.

Note that the ./configure output might end with a list of recommendations of additional system packages to install. Following those recommendations can speed up the make step.

If you know you already have all the possible recommended software and you want the ./configure step to be less verbose, add -q (for "quiet") to the ./configure line, after --enable-sagenb=yes.

### Linux

Configure

$V=0$ MAKE='make -j1'
$make configure$ ./configure --with-python=2 --enable-sagenb=yes


Make

$brew install autoconf automake bdw-gc boost cairo ccache \ cmake coreutils cryptominisat curl curl-openssl docutils \ ffmpeg fontconfig freetype gambit gcc@9 gd gettext glib \ glpk gmp gnutls gsl imagemagick isl jpeg libffi libmpc \ libogg libomp libpng libtiff libtool mpfi mpfr mpir nauty \ ncurses ninja numpy octave open-mpi openblas openjdk \ openjpeg openssl@1.1 pandoc pari pkg-config ppl python@3.7 \ r readline scipy scons sip sphinx-doc sqlite suite-sparse \ wget xz yasm zeromq  #### Configure $ V=0
$MAKE='make -j1'$ source .homebrew-build-env
$make configure$ FC=gfortran-9 ./configure --with-python=2 --enable-sagenb=yes


#### Make

$make -s V=0 openssl$ make -s V=0


Add a symbolic link to your Sage installation somewhere in your PATH.

For example by running this from the sage root folder:

$ln -sf pwd/sage /usr/local/bin  of if that complains about a permission problem, $ sudo ln -sf pwd/sage /usr/local/bin


which might require entering the password for your user account on the computer on which you are installing.

Check that this worked by running

$which sage$ sage --version


## Launch the SageNB notebook

Launch the Sage notebook by running this in the terminal:

\$ sage -n sagenb

2020-09-19 12:23:55 -0500 answered a question Sage very slow until restarting the session

Bugs in Sage and in the programs it uses may include memory leaks.

The slowdown you reported might have been caused by such a bug, known or new.

Hard to say without more detail on what calculations were running.

2020-09-19 12:21:22 -0500 answered a question Functions in polynomials rings

One can produce strings and have the polynomial ring eat them.

String formatting is easy thanks to Python.

Define a polynomial ring as in the question:

R.<x1, x3, x5> = PolynomialRing(QQ)


Define a "generator power" function as follows:

def f(i, j):
r"""
Return the polynomial variable xi raised to the j-th power.
"""
return R('x{}^{}'.format(i, j))


Example:

sage: f(3, 2)
x3^2


It could help someone who runs into the same question in the future.

2020-09-18 12:11:59 -0500 commented answer how to move from notebook() to jupyter

Congratulations. Don't hesitate to accept your own answer as it can help other users who have the same question.

### Documentation

SageMathCell project is an easy-to-use web interface to a free open-source mathematics software system SageMath.

It allows embedding Sage computations into any webpage: check out short instructions or comprehensive description of capabilities.

That "comprehensive description of capabilities" page has a section dedicated to your question:

which says

When multiple input locations are given, this sets whether the code from these cells is to be executed from the same kernel, so that code executed in one will affect the execution of code from another cell:

{ ..
.. }


This option is false by default.

So try using linked: true.

### Examples

Many pages online use SageCell with linked cells.

PreTeXt is an authoring system allowing, in addition to (or instead of) a pdf version of documents, to produce an html version with executable code cells, using SageCell.

which has a page about using Sage via SageCell:

See in particular

which conveniently has several cells.

Try typing a = 2 in the first one, executing (by hitting Shift+Enter or by clicking the "Execute" button) and then typing a^2 in the second one and executing.

Check the source code of that page and search the word "linked" there (e.g. using cmd-F or ctrl-F).

For many more example, see the PreTeXt gallery or the PreTeXt catalog.

2020-09-17 19:08:57 -0500 answered a question Imaginary result for cube root of -1

The power operator has higher priority than the unary negation.

So in the first case you are really doing "minus (1 to the 1/3)", and not "(minus 1) to the 1/3".

For the real n-th root, use real_nth_root.

sage: real_nth_root(-1, 3)
-1


Regarding cubing the cube root:

sage: a = (-1)^(1/3)
sage: a
(-1)^(1/3)
sage: a^3
-1


Using the numerical approximation of the cube root:

sage: aa = a.n()
sage: aa
0.500000000000000 + 0.866025403784439*I
sage: aa^3
-1.00000000000000 + 3.88578058618805e-16*I


So, very close to -1, with tiny imaginary part from rounding errors.