ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 12 Sep 2019 04:20:58 -0500Memory leak with matroid is_connected methodhttp://ask.sagemath.org/question/47839/memory-leak-with-matroid-is_connected-method/Hello.
I've been using Graphic Matroids to deal with some enumeration problems, where I filter a list of graphs based on their flats. Even without really undestanding what happens at low level, I could verify that the computation is faster when I build the equivalent representation of each graphic matroid using the Incidence matrix of the graph over GF(2).
One big issue that I am facing is that some memory leak is ocurring. As the size of my list of graphs grows, the ram memory got consumed until a point that my computer breaks down and restarts. My way out has been to use a bash script to keep calling the main program until I reach the end of an external text file (the input).
To force the `gc.collect()` seems to not be an option, because the program becomes really slow.
EDIT 1:
The memory leak seems to be related with the `is_connected` method. Here is a piece of my code showing two different situations:
With the use of `is_connected`:
sage: G = [g for g in graphs.nauty_geng("12 16:16 -Ct")]
sage: len(G)
11771
sage: print(get_memory_usage())
....:
....: for g in G:
....: A = g.incidence_matrix()
....: M = Matroid(A, ring = GF(2))
....: if M.is_connected():
....: pass
....: print(get_memory_usage())
....:
3396.38671875
3418.06640625
and without:
sage: print(get_memory_usage())
....: for g in G:
....: A = g.incidence_matrix()
....: M = Matroid(A, ring = GF(2))
....: for r in range(M.corank()):
....: for F in M.coflats(r):
....: pass
....:
....: print(get_memory_usage())
....:
3490.53515625
3490.53515625
EDIT 2:
Ok, I solved my problem by just explicitly declaring the function `is_connected` in the body of my code, instead of using the method present in the abstract matroid class. I'm not sure about why it really worked, I tried this approach because I thought it had something to do with the lists that are created by the `components` method, however I stopped investigating when I notice the memory leak vanished just by using the function. To be honest, I changed the script to not return any output (there was an option to input a certificate flag and return the components).
I'm letting the code below for the case someone faces a similar problem or has any better solution or clue about why it happened:
cpdef components(self):
B = self.basis()
components = [frozenset([e]) for e in self.groundset()]
for e in self.groundset() - B:
C = self.circuit(B | set([e]))
components2 = []
for comp in components:
if len(C & comp) != 0:
C = C | comp
else:
components2.append(comp)
components2.append(C)
components = components2
return components
cpdef is_connected(self):
comp = components(self)
if len(comp) == 1:
return True
else:
return FalsefmorlinThu, 12 Sep 2019 04:20:58 -0500http://ask.sagemath.org/question/47839/Error computing curvature of graph submanifoldhttp://ask.sagemath.org/question/47786/error-computing-curvature-of-graph-submanifold/The following appears to be a bug in sagemanifolds curvature. I see the error running it in cocalc.com. Other things like computing the induced_metric() and normal() and fine. Am I doing something wrong?
sage: P = Manifold(3, 'P', structure='Riemannian', metric_name='g', start_index=0)
sage: Q = Manifold(2, 'Q', ambient=P, structure='Riemannian', metric_name='k', start_index=1)
sage: CP.<x,y,z> = P.chart()
sage: CQ.<u,v> = Q.chart()
sage: g = P.metric()
sage: c = 2/(sum(y^2 for y in CP[1:]) + 1)
sage: g[0,0], g[1,1], g[2,2] = 1, c^2, c^2
sage: f = sum(CQ[:])
sage: f = u + v
sage: phi = Q.diff_map(P,{(CQ, CP):[f] + list(CQ[:])})
sage: phi_inv = P.diff_map(Q, {(CP, CQ) : list(CQ[:])})
sage: Q.set_embedding(phi, inverse=phi_inv)
sage: K = Q.extrinsic_curvature()
> Error in lines 13-13
>
> Traceback (most recent call last):
>
> File
> "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py",
> line 1188, in execute
> flags=compile_flags), namespace, locals)
>
> File "", line 1, in <module>
>
> File
> "/ext/sage/sage-8.8_1804/local/lib/python2.7/site-packages/sage/manifolds/differentiable/pseudo_riemannian_submanifold.py",
> line 1067, in second_fundamental_form
> range(self._dim + 1))
>
> File "sage/matrix/matrix0.pyx", line
> 1424, in
> sage.matrix.matrix0.Matrix.__setitem__
> (build/cythonized/sage/matrix/matrix0.c:8796)
> self.set_unsafe(row, col, self._coerce_element(value))
>
> File "sage/matrix/matrix0.pyx", line
> 1529, in
> sage.matrix.matrix0.Matrix._coerce_element
> (build/cythonized/sage/matrix/matrix0.c:10273)
> return self._base_ring(x)
>
> File "sage/structure/parent.pyx",
> line 900, in
> sage.structure.parent.Parent.__call__
> (build/cythonized/sage/structure/parent.c:9197)
> return mor._call_(x)
>
> File
> "sage/structure/coerce_maps.pyx", line
> 288, in
> sage.structure.coerce_maps.NamedConvertMap._call_
> (build/cythonized/sage/structure/coerce_maps.c:5942)
> cdef Element e = method(C)
>
> File "sage/symbolic/expression.pyx",
> line 1087, in
> sage.symbolic.expression.Expression._integer_
> (build/cythonized/sage/symbolic/expression.cpp:8689)
> raise TypeError("unable to convert %r to an integer" % self)
>
> TypeError: unable to convert
> 1/2*sqrt(2)*(u^4 + v^4 + 2*(u^2 +
> 1)*v^2 + 2*u^2 + 1)*y/(sqrt(u^4 + v^4
> + 2*(u^2 + 1)*v^2 + 2*u^2 + 3)*(y^2 + z^2 + 1)) + 1/2*sqrt(2)*(u^4 + v^4 +
> 2*(u^2 + 1)*v^2 + 2*u^2 +
> 1)*z/(sqrt(u^4 + v^4 + 2*(u^2 + 1)*v^2
> + 2*u^2 + 3)*(y^2 + z^2 + 1)) to an integer
Paul BryanSat, 07 Sep 2019 23:15:18 -0500http://ask.sagemath.org/question/47786/StopIteration raised during G.eulerian_circuit()http://ask.sagemath.org/question/47620/stopiteration-raised-during-geulerian_circuit/Hello, I just ran into a raised error during an overnight computation. I found the function and line on the git hub but I feel I don't know enough python/sagemath to figure out why this error occurred.
The error in question:
if G.eulerian_circuit() is False:
File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/sage/graphs/generic_graph.py", line 3935, in eulerian_circuit
next_edge = next(g_edge_iter(v))
StopIteration
EDIT:
Here is the code that creates the error. I am using sagemath 8.6 on windows 10.
from sage.all import Polyhedron
from sage.all import polytopes
from sage.all import Combinations
from sage.combinat.gray_codes import combinations
from sage.all import Graph
from sage.all import factorial
from sage.graphs.connectivity import is_connected
import numpy as np
from progress.bar import Bar
import pprint
def gray(flatten, all_vertex_pairs):
r"""
Uses gray code to solve the problem without memory storage. Calculate the
next combination of edges using gray code then test s. If true the return
the planar representation and the graph else continue. If all combinations
were found and there does not exist a solution then the function will
return an empty dict and None.
SEE:
test_edges
INPUT:
flatten {list} A list of faces of some polytope P.
all_vertex_pairs {list} A list of every pair of vertices possible in P.
OUTPUT: A planar representation of a polytope P as a dictionary and the
undirected graph.
"""
n = len(all_vertex_pairs)
t = len(flatten) - 1
s = set([i for i in range(t)])
num_combos = factorial(n) / (factorial(t)*factorial(n-t))
with Bar('Processing', max=num_combos) as bar:
for i, j in combinations(n, t):
s.remove(i)
s.add(j)
flag, planar, G = test_edges(all_vertex_pairs, s, flatten)
if flag:
return planar, G
else:
bar.next()
return {}, None
def combo(vertices, length):
r"""
Creates a list of every combination of a certain length from the set of
possible vertices.
INPUT:
vertices {integer} The number of vertices for a polytope.
length {integer} The length of the noninversion set.
OUTPUT:
A list of every combination of a set.
"""
set_of_vertices = [i for i in range(0, vertices)]
return Combinations(set_of_vertices, length).list()
def convert(data):
r"""
Converts a polyhedron object to array.
There has to be a way to convert a polyhedron face into a list.
"""
s_data = str(data)
s_data = s_data.replace('<', '')
s_data = s_data.replace('>', '')
s_data = s_data.split(",")
for i in range(len(s_data)):
s_data[i] = float(s_data[i])
return np.array(s_data)
def poly2list(face):
r"""
Converts a polygon into an array and finds all combinations of length 2, ie
given any face, create a list of every edge possible from the vertices that
create that face. Return that list as a numpy integer array.
SEE:
convert
INPUT:
face {sagemath polygon} A face of some polygon P represented as a
sagemath polygon object.
OUTPUT: A numpy integer array of every edge possible inside a face.
"""
converted_face = convert(face)
edges = np.array(Combinations(converted_face, 2).list()).astype(int)
return edges
def assign_edges(values, keys):
r"""
Each potential unfolding is represented in a new vertex space so for this
set to be in a correct format each vertex in the potential unfolding will
need to be assigned the correct edge from the old vertex space. Each edge
is stored in a list then returned as a numpy array.
INPUT:
values {list} A list of values to be used.
keys {list} A list of keys associated with each value.
OUTPUT: A numpy array of all the edges in a potentail unfolding.
"""
edges = []
for key in keys:
edges.append(values[key])
return np.array(edges)
def planar_representation(planar, flatten, test_case):
r"""
A planar representation of a polytope P is a dictionary of faces and edges.
The keys are the faces and the values are the edges. This loops each face
in flatten and converts each face into a list of vertices. Each list of
vertices from each face is looped and tested against the test_case.
SEE:
poly2list
INPUT:
planar {dict} A dictionary to store planar information.
flatten {list} A list of faces of a polytope P.
test_case {list} A list of edges that will unfold P.
OUTPUT: A dictionary of a potentially flattened polytope.
"""
for i in range(len(flatten)):
key = flatten[i]
cycle = poly2list(key)
to_delete = []
for j in range(len(cycle)):
_flag = True
for k in range(len(test_case)):
check_test_case = np.array_equal(cycle[j], test_case[k])
if check_test_case:
_flag = True
break
else:
_flag = False
if not _flag:
to_delete.append(j)
cycle = np.delete(cycle, to_delete, axis=0)
cycles = [str(cycle[i]) for i in range(len(cycle))]
value = dict(zip(cycles, [1 for num in cycle]))
planar[key] = value
return planar
def test_edges(all_v_pairs, possible_unfolding, flatten):
r"""
Create a test case by assigning a potential unfolding the correct edges
from the list of all possible vertex pairs. The test case will be attempted
to be represented as dictionary by matching faces with edges. If the planar
representation can be made into a sagemath Graph then a series of tests are
performed on the test graph. A solution will be a graph without a cycle
basis, is void of Eulerian circuits, and is connected. A boolean flag, the
planar representation, and the graph will be returned.
SEE:
assign_edges
planar_representation
INPUT:
all_v_pairs {list} A list of all possible edges from a set of vertex.
possible_unfolding {list} A list of possible edges that may unfold P.
flatten {list} A list of the faces of P.
OUTPUT: A boolean flag, a planar representation, and a sagemath Graph.
"""
if all_v_pairs == []:
return False, {}, None
test = assign_edges(all_v_pairs, possible_unfolding)
planar = planar_representation({}, flatten, test)
if planar == {}:
return False, {}, None
G = Graph(planar)
basis = G.cycle_basis()
if len(basis) == 0:
flag = False
if G.eulerian_circuit() is False:
if is_connected(G) is True:
flag = True
return flag, planar, G
else:
flag = False
return False, {}, None
else:
flag = False
return False, {}, None
else:
flag = False
return False, {}, None
def create_vertices(dimensions, length, vertices):
r"""
Creates a randomly generated list of length dimensions then stores
each list as a tuple inside another list.
INPUT:
dimensions {integer} The number of dimensions the polytope exists in.
length {integer} The length of each dimension.
vertices {integer} The number of vertices of a polytope.
OUTPUT:
A list of tuples of vertices.
"""
polyhedron_vertices = []
for i in range(vertices):
vertex = []
for j in range(dimensions):
vertex.append(np.random.randint(-length, length + 1))
polyhedron_vertices.append(tuple(vertex))
return polyhedron_vertices
def create_polyhedron(dimensions, length, vertices):
r"""
Creates a randomly generated polyhedron with a given dimension, length,
and vertices. With the polyhedron, p, the number of faces is calculated.
The polyhedron and the list of faces are returned.
SEE:
create_vertices
INPUT:
dimensions {integer} The number of dimensions the polytope exists in.
length {integer} The length of each dimension.
vertices {integer} The number of vertices of a polytope.
OUTPUT:
A sagemath polytope object and a list of the faces.
"""
polyhedron_vertices = create_vertices(dimensions, length, vertices)
polyhedron = Polyhedron(vertices=polyhedron_vertices)
# polyhedron = polytopes.octahedron()
# polyhedron = polytopes.cube()
# polyhedron = polytopes.cuboctahedron()
# polyhedron = polytopes.great_rhombicuboctahedron()
return polyhedron
if __name__ == "__main__":
# Initial Conditions
np.random.seed(12345)
dimensions = 3
length = 10
vertices = 8
# Create Polyhedron to unfold
polyhedron = create_polyhedron(dimensions, length, vertices)
flatten = np.array(list(polyhedron.faces(2)))
p = polyhedron.plot()
p.save('full.png')
print('\n{}\nUnfold: {} faces\n{}'.format(
polyhedron, len(flatten), flatten))
vertices = len(polyhedron.vertices())
# Combinations of length 2
print('\nFind all length 2 sets from {} vertices'.format(vertices))
all_vertex_pairs = combo(vertices, 2)
# Combinations of length flatten - 1
print('\nFind all length {} sets from {} edges\n'.format(
len(flatten) - 1, len(all_vertex_pairs)))
# Unfold
planar, G = gray(flatten, all_vertex_pairs)
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(planar)
# Plot
print('\nSaving Graph')
P = G.plot()
P.save('graph.png')
print('\nDone!\n')
I hope this kind of helps.
The code is creating a graph G and checking if there exists a Eulerian circuit but just millions of times. Is this error something that indicates the limitation of Hierholzer's algorithm or was this a random computer error?
I can post more information if needed. This is my first post and there seems to be no other threads on this topic.
EDIT 2:
Using the code sninppet from David Coudert
Traceback (most recent call last):
File "fold.sage.py", line 327, in <module>
planar, G = gray(flatten, all_vertex_pairs)
File "fold.sage.py", line 65, in gray
flag, planar, G = test_edges(all_vertex_pairs, s, flatten)
File "fold.sage.py", line 215, in test_edges
raise ValueError(G.edges())
ValueError: []
The error seems to be from an graph created without edges which means that the planar representation is a dict of only keys without values. I going to run it again in an attempt to get more information.mqpsfTue, 27 Aug 2019 07:51:20 -0500http://ask.sagemath.org/question/47620/weighted univariate polynomialshttp://ask.sagemath.org/question/47628/weighted-univariate-polynomials/I have a polynomial algebra in n variables k[x_1,...,x_n]. I know how assign different degrees to each of the generators as in
sage: P = PolynomialRing(QQ, 'x,y,z', order = TermOrder('wdegrevlex', (2,3,4)))
sage: P.inject_variables()
Defining x, y, z
sage: z.degree()
sage:
4
However if I want to do this with only one variable this does not work
sage: P = PolynomialRing(QQ, 'x', order = TermOrder('wdegrevlex', (2)))
sage: P.inject_variables()
Defining x
sage: x.degree()
1
I wander if I can do this in an uniform way cause I need to use a class that takes an arbitrary number of variables.
heluaniTue, 27 Aug 2019 13:55:48 -0500http://ask.sagemath.org/question/47628/Sage not detecting integers in Boolean Polynomial Ring?http://ask.sagemath.org/question/44880/sage-not-detecting-integers-in-boolean-polynomial-ring/Hi all,
I'm trying to do a detecting system for terms in the equations used in a polynomial. I'm using Boolean Polynomials here.
Here's is my code. This prints all the terms of the equations.
P.<x,y,z> = BooleanPolynomialRing(3, order = 'lex')
equations = [x+y+z-1, y*z, x+z]
for i in range(len(equations)):
for j in equations[i]:
print j
Output:
x
y
z
1
y*z
x
z
As you can see, 1 appears in the output. However, when I implement this logic onto it, the output is empty.
for i in range(len(equations)):
for j in equations[i]:
if j == 1:
print 'true'
It's not like the logic doesn't work, if I change '1' to 'x', my logic works.
for i in range(len(equations)):
for j in equations[i]:
if j == x:
print 'true'
Output:
true
true
What am I doing wrong here?Stockfish3709Thu, 03 Jan 2019 22:54:41 -0600http://ask.sagemath.org/question/44880/Inverse of real sparse matrixhttp://ask.sagemath.org/question/47587/inverse-of-real-sparse-matrix/Dear sagemath community,
I'm a bit surprised in the result that I obtain when I compute the inverse of a real, sparse matrix. The problem occurs in Sagemath 8.7, (on windows).
In my case the matrix is
B=matrix(RR, [[1/6, -1/24, -1/30, 1/120,1/12, 0, 0, 0, 0],
[-1/24,1/60,1/60, 1/420, -1/24, 0, 0, 0, 0],
[-1/30,1/60, 2/105, 1/140, -1/20, 0, 0, 0, 0],
[1/120, 1/420, 1/140, 13/1260, -1/40, 0, 0, 0, 0],
[1/12, -1/24, -1/20, -1/40, 1/3, -1/24, -1/30, 1/120,1/12],
[0, 0, 0, 0, -1/24,1/60,1/60, 1/420, -1/24],
[0, 0, 0, 0, -1/30,1/60, 2/105, 1/140, -1/20],
[0, 0, 0, 0, 1/120, 1/420, 1/140, 13/1260, -1/40],
[0, 0, 0, 0,1/12, -1/24, -1/20, -1/40, 1/6]],sparse=true)
(B.inverse()*B).norm(1)
The result is 138.4999999999923, which is very far from the expected value: 1. If one replaces sparse=true by sparse=false, the result becomes reasonable.The problem also does not occur when I replace RR by QQ.
I suspect that this will not happen in all versions of Sagemath, since I stumbled upon this strange behaviour when I was executing a code that used to work fine years ago. Sadly I do not recall which version I used to have back then. I wanted to ask: what is currently the right way to compute the inverse of a sparse real matrix?
cheers,
IVIVSun, 25 Aug 2019 13:39:38 -0500http://ask.sagemath.org/question/47587/asking real part of a function crash the kernelhttp://ask.sagemath.org/question/47488/asking-real-part-of-a-function-crash-the-kernel/Hi
SageMath 8.8 notebook OS=W10
asking the real part of this function systematically crash the kernel
with the message :
**The kernel appears to have died. It will restart automatically.**
n=var('n')
assume(n>=0)
assume(n,'integer')
a_n=1/20*(1/2*sqrt(5) + 1/2)^n*(11*sqrt(5) + 25) - 1/20*(-1/2*sqrt(5) + 1/2)^n*(11*sqrt(5) - 25) - 1/12*(1/2*I*sqrt(3) + 1/2)^n*(I*sqrt(3) + 3) - 1/12*(-1/2*I*sqrt(3) + 1/2)^n*(-I*sqrt(3) + 3)
show(a_n)
a_n.real_part()
#real_part(a_n)ortolljThu, 15 Aug 2019 02:22:32 -0500http://ask.sagemath.org/question/47488/var list with only one variable errorhttp://ask.sagemath.org/question/47470/var-list-with-only-one-variable-error/Hi
SageMath 8.8 notebook OS=W10
why does it fail if L has only one variable ? :
L=['sd_1']
#L=['sd_1','sd_2']
varL=var(L)
show(varL)ortolljWed, 14 Aug 2019 02:00:37 -0500http://ask.sagemath.org/question/47470/How to change the unreadable dark blue colour in the SageMath command line window under Windows-10?http://ask.sagemath.org/question/47136/how-to-change-the-unreadable-dark-blue-colour-in-the-sagemath-command-line-window-under-windows-10/ I have just installed SageMath 8.7 on my Windows-10 laptop and want to learn it. The font colour of the prompt and of the typed numbers is dark blue on the black background, totally unreadable. Google search delivers tons of such complaints about bash/pythin/mintty/cygwin command lines. All suggest to edit some configuration files, which are hardly possible to locate in SageMath, neither in the SageMath installation directory, nor in my user home directory. There is a file ".sage\profile_default\ipython_config.py" in my Windows home, containing the line
c.TerminalInteractiveShell.colors = 'Linux'
Changing this line has no effect.SevasFri, 12 Jul 2019 05:59:10 -0500http://ask.sagemath.org/question/47136/Interact layout in Jupyter-Notebookhttp://ask.sagemath.org/question/47120/interact-layout-in-jupyter-notebook/When I run this code
@interact(layout=dict(top=[['f', 'color']],
left=[['axes'],['fill']],
bottom=[['zoom']]))
def _(f=input_box(x^2,width=20),
color=color_selector(widget='colorpicker', label=""),
axes=True,
fill=True,
zoom=range_slider(-3,3, default=(-3,3))):
show(plot(f,(x,zoom[0], zoom[1]), color=color, axes=axes,fill=fill))
in Jupyter notebook, the controls are not organised as specified. But this is not so with the old SageNB notebook. How can I make the controls specified in the `layout` parameter to appear in the output as originally specified? Please advise.eocanseyWed, 10 Jul 2019 16:49:30 -0500http://ask.sagemath.org/question/47120/Possible bug in CC needs confirmationhttp://ask.sagemath.org/question/47068/possible-bug-in-cc-needs-confirmation/Hello, Sage community. I just noticed what I believe is a bug in the implementation of `CC`, but I would like to receive confirmation.
When I try the following:
'hello' in RR
I get the natural answer: `False`. However, if I try the same with `CC`:
'hello' in CC
I get the following error message:
NameError: name 'hello' is not defined
Just in case, I am using SageMath v8.8, specifically, the binary version downloaded from the mirrors.
Can somebody confirm this is a bug? Thanks in advance!dsejasThu, 04 Jul 2019 21:05:28 -0500http://ask.sagemath.org/question/47068/solve equation with two variables over RRhttp://ask.sagemath.org/question/46915/solve-equation-with-two-variables-over-rr/Hi,
I have a problem with the following code (minimal example) in SageMath 8.7 notebook:
x, y = var('x,y', domain=RR)
solve(x == 0, x, y)
when executed, I get the following error:
/opt/sagemath-8.7/local/lib/python2.7/site-packages/sage/symbolic/relation.pyc in _solve_expression(f, x, explicit_solutions, multiplicities, to_poly_solve, solution_dict, algorithm, domain)
1357 if to_check:
1358 for ix, soln in reversed(list(enumerate(X))):
-> 1359 if soln.lhs().is_symbol():
1360 if any(a.contradicts(soln) for a in to_check):
1361 del X[ix]
AttributeError: 'list' object has no attribute 'lhs'
both
x, y = var('x,y')
solve(x == 0, x, y)
and
x, y = var('x,y', domain=RR)
solve(x == 0, x)
work as expected.
I am sorry if that question a already been posted, I don't know which keyword to use.
Pierre MacherlFri, 14 Jun 2019 09:48:56 -0500http://ask.sagemath.org/question/46915/chromatic polynomial graph with loopshttp://ask.sagemath.org/question/46808/chromatic-polynomial-graph-with-loops/Since there are no proper colorings of graphs with loops,
their chromatic polynomial should be zero.
SageMath 8.6 however seems to ignore the loops
and returns a nonzero chromatic polynomial for the
graph on one vertex with one loop edge.
sage: Graph([[1, 1]], multiedges=True, loops=True).chromatic_polynomial()
xluisWed, 05 Jun 2019 07:16:04 -0500http://ask.sagemath.org/question/46808/Sagemath not evaluating complicated expressionhttp://ask.sagemath.org/question/46698/sagemath-not-evaluating-complicated-expression/I'm working with Sagemath for an in-depth project for the first time. I'm experiencing what I perceive to be some very strange behavior and I'm totally stumped on resolving it. I have a class that is encoding some geometric objects.
It works perfectly fine for relatively simple inputs. The strange thing is that when self.center and/or C get sufficiently complicated, I get an error:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-11-4e5b3134f826> in <module>()
1 c1 = circle(I+Integer(1),Integer(4))
2 m1 = c1.mobToRealLine()
----> 3 c2 = m1.imageCircle(c1)
4 print(c2)
<ipython-input-8-5610dc2742b9> in imageCircle(self, circle)
70 print("new A, B, C = {}, {}, {}".format(newA, newB, newC))
71
---> 72 return Circle(newA, newB, newC)
73
74 def circle(center, radius):
<ipython-input-8-5610dc2742b9> in __init__(self, A, B, C)
9 if A != Integer(0):
10 self.center = -conjugate(B)
---> 11 self.radius = abs(sqrt(abs(self.center)**Integer(2) - C))
12 elif A == Integer(0):
13 self.center = None
/Applications/SageMath/local/lib/python2.7/site-packages/sage/functions/other.pyc in sqrt(x, *args, **kwds)
869 return sqrt(x)
870 try:
--> 871 return x.sqrt(*args, **kwds)
872 # The following includes TypeError to catch cases where sqrt
873 # is called with a "prec" keyword, for example, but the sqrt
/Applications/SageMath/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.sqrt (build/cythonized/sage/symbolic/expression.cpp:44675)()
8075 """
8076 return new_Expression_from_GEx(self._parent,
-> 8077 g_hold2_wrapper(g_power_construct, self._gobj, g_ex1_2, hold))
8078
8079 def sin(self, hold=False):
RuntimeError: unsupported type in numeric::lcm
The error occurs when it's trying to initialize a the class with
A, B, C, = 1/2*abs(sqrt(16) - I - 1)^2/sqrt(16) + (1/2*I + 1/2)*(sqrt(16) + I - 1)/sqrt(16) - (1/2*I - 1/2)*(sqrt(16) - I - 1)/sqrt(16) - 7/sqrt(16),1/2*I*(sqrt(16) - I + 1)*(sqrt(16) - I - 1)/sqrt(16) + (1/2*I - 1/2)*(sqrt(16) - I + 1)/sqrt(16) - (1/2*I + 1/2)*(sqrt(16) - I - 1)/sqrt(16) + 7*I/sqrt(16),1/2*abs(sqrt(16) + I + 1)^2/sqrt(16) + (1/2*I - 1/2)*(sqrt(16) + I + 1)/sqrt(16) - (1/2*I + 1/2)*(sqrt(16) - I + 1)/sqrt(16) - 7/sqrt(16)
If I (by hand) initialize the class with these values of A, B, and C, it works just fine. If, on the other hand, I use the "imagecircle" method that I've written (which is implemented as follows. prints are there for debugging), it fails, despite the fact that the A, B, and C given by the imagecircle method are exactly as above. Here is code that if run, gives the error:
class Circle:
"""Unified line and circle class. If A=0,
then this represents a line."""
def __init__(self, A, B, C):
self.A = A
self.B = B
self.C = C
if A != 0:
self.center = -conjugate(B)
self.radius = abs(sqrt(abs(self.center)^2 - C))
elif A == 0:
self.center = None
self.radius = None
def isCircle(self):
"""Am I a geometric circle in the complex plane?"""
return self.A != 0
def isLine(self):
"""Am I a geometric line in the complex plane?"""
return self.A == 0
def mobToRealLine(self):
if self.isCircle():
"""return the Mobius that takes self to the real line. It takes z0+r to 0, and z0 +- Ir to +-1"""
z0 = self.center
r = self.radius
a = 1/sqrt(r) * (1/2 - I/2)
b = -1/sqrt(r) * (1/2 - I/2) * (r+z0)
c = 1/sqrt(r) * (1/2 + I/2)
d = 1/sqrt(r) * (1/2 + I/2) * (r-z0)
return Mobius(a,b,c,d)
if self.isLine() and imag(self.B) != 0: #This takes iC/2Im(B), 1/2 +- I(ReB + ImC)/(2ImB) to 0, +-1
B, C = self.B, self.C
a = (1-I) / sqrt( conjugate(B)/imag(B) )
b = -( (1/2+I/2)*C*sqrt( conjugate(B)/imag(B) ) ) / ( conjugate(B) )
c = 0
d = (1/2+I/2)*sqrt( conjugate(B)/imag(B) )
return Mobius(a,b,c,d)
else:#Vertical line case x=x0
B, C = self.B, self.C
x0 = -C/(2*B)
a = -sqrt(2)/2 + I*sqrt(2)/2
b = (sqrt(2)/2 - I*sqrt(2)/2)*x0
c = 0
d = -sqrt(2)/2 - I*sqrt(2)/2
return Mobius(a,b,c,d)
class Mobius:
"""Mobius transformation class"""
def __init__(self, a, b, c, d):
self.a = a
self.b = b
self.c = c
self.d = d
self.matrix = Matrix([[a,b],[c,d]])
def imageCircle(self, circle):#This seems broken for a vertical line...
"""Return the image of circle under self."""
A, B, C = circle.A, circle.B, circle.C
cA, cB, cC = conjugate(A), conjugate(B), conjugate(C)
a, b, c, d = self.a, self.b, self.c, self.d
ca, cb, cc, cd = conjugate(a), conjugate(b), conjugate(c), conjugate(d)
newA = A*abs(d)^2 - cc*d*B - c*cd*cB + C*abs(c)^2
newB = -A*cb*d + ca*d*B + cb*c*cB - ca*c*C
newC = A*abs(b)^2 - ca*b*B - a*cb*cB + abs(a)^2*C
print("new A, B, C = {}, {}, {}".format(newA, newB, newC))
return Circle(newA, newB, newC)
def circle(center, radius):
"""returns Circle(A,B,C) with appropriate A, B, C (for simplicity of use)"""
A = 1
B = -conjugate(center)
C = abs(center)^2 - radius^2
return Circle(A,B,C)
c1 = circle(I+1,4)
m1 = c1.mobToRealLine()
c2 = m1.imageCircle(c1)
print(c2)ckaWed, 29 May 2019 10:06:30 -0500http://ask.sagemath.org/question/46698/Strange matrix producthttp://ask.sagemath.org/question/45547/strange-matrix-product/When I enter
A = matrix([[1, 2], [-1, 0], [1, 1]])
B = matrix([[0, 4], [1, -1], [1, 2]])
A*B
I get an error message, as expected.
But when I enter
A = matrix(QQ, [[1, 2], [-1, 0], [1, 1]])
B = matrix(QQ, [[0, 4], [1, -1], [1, 2]])
A*B
I get the output
[ 1 0]
[ 1 -2]
[ 1 3]
However, if I try
A = matrix(QQ, [[1, 2], [-1, 0], [1, 1]])
B = matrix(QQ, [[0, 4], [1, -1], [1, 2], [2, 2]])
A*B
I get an error message.
In all of the examples I try, Sage will give some output for a matrix product of two matrices of the same size as long as the field QQ is specified for at least one of the matrices. I’ve searched online and haven’t found anything to help me understand this. This will be problematic for my students who might draw the conclusion that the standard matrix product is defined when it really isn't. Can anyone help me understand this?SteveSMon, 25 Feb 2019 07:50:00 -0600http://ask.sagemath.org/question/45547/How to increase maxterms for hypergeometric?http://ask.sagemath.org/question/46337/how-to-increase-maxterms-for-hypergeometric/I'm trying to compute a (bunch of) hypergeometric functions for which I get a NoConvergence error
e.g.
hypergeometric([4.14 + 15*I, -3.14 + 15*I],[1. - 1.12e7*I], -500000)
The suggestion of the error message is to try increasing 'maxterms'. However, I don't seem to find a way to do this as e.g.` hypergeometric([4.14 + 15*I, -3.14 + 15*I],[1. - 1.12e7*I], -500000,maxterms=10^6)` does not work.
(I could be missing something very basic, I'm rather new to sage)virtual_neutrinoWed, 24 Apr 2019 09:19:34 -0500http://ask.sagemath.org/question/46337/Sage Notebook crashes immediatelyhttp://ask.sagemath.org/question/46075/sage-notebook-crashes-immediately/New installation of Windows binaries, version 8.6 (Windows installer 0.4.2), on 64-bit Windows 8.1 system with 8GB of RAM. Clicking on the "SageMath 8.6 Notebook" desktop icon opens a terminal window and displays the message "Please wait while the Sage Jupyter Notebook server starts", but the window closes within 2 or 3 seconds.
Would appreciate any guidance on troubleshooting - happy to study any relevant documentation if someone can point me in the right direction.
When running `sage --notebook=jupyter` in the shell I get:
[I 17:51:21.659 NotebookApp] Using MathJax: nbextensions/mathjax/MathJax.js Traceback (most recent call last):
File "/opt/sagemath-8.6/src/bin/sage-notebook", line 268, in <module> launcher(unknown)
File "/opt/sagemath-8.6/src/bin/sage-notebook", line 100, in __init__ main(argv)
File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/jupyter_core/application.py", line 266, in launch_instance return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/traitlets/config/application.py", line 657, in launch_instance app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/traitlets/config/application.py", line 87, in catch_config_error return method(app, args, *kwargs)
File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/notebook/notebookapp.py", line 1629, in initialize self.init_webapp()
File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/notebook/notebookapp.py", line 1408, in init_webapp self.http_server.listen(port, self.ip)
File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/tornado/tcpserver.py", line 142, in listen sockets = bind_sockets(port, address=address)
File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/tornado/netutil.py", line 197, in bind_sockets sock.bind(sockaddr)
File "/opt/sagemath-8.6/local/lib/python2.7/socket.py", line 230, in meth return getattr(self._sock,name)(*args)
socket.error: [Errno 1] Operation not permittedrixensoTue, 09 Apr 2019 23:57:42 -0500http://ask.sagemath.org/question/46075/Memory usage strictly increasing on Sage interactive shellhttp://ask.sagemath.org/question/45863/memory-usage-strictly-increasing-on-sage-interactive-shell/
Hello,
I executed the following script on the Sage interactive shell on Ubuntu 18.04 (on SageMath version 8.7.beta5):
sage: import gc
sage: t = 100000
sage: l = [n for n in xrange(t,t+100)]
sage: ll = []
sage: for x in l:
....: s = 0
....: for n in xrange(0,x):
....: s += cos(RDF(2)*RDF(pi)*RDF(n)/RDF(x))
....: ll.append([x, s])
....: del(s)
....: print "memory usage: " + str(get_memory_usage()) + ", gc: " + str(gc.collect())
....:
memory usage: 5824.5546875, gc: 277
memory usage: 5828.3046875, gc: 0
memory usage: 5832.0546875, gc: 0
memory usage: 5836.0546875, gc: 0
:
memory usage: 6203.5546875, gc: 0
memory usage: 6207.5546875, gc: 0
As we can see the memory usages, it increases by about 4 MB per each step. Thus, after completed, it increased around 400 MB in total. It is frustrating since it eventually eats up all memories in my system as the size of the input list grows and gc.collect() does not seem to help.
I suspect that there were memory leaks or Sage(or Python) stored all the values of cos() and never freed them for some reasons while the shell not killed.
Can someone please explain what was going on and suggest how to avoid this unwanted memory consumption? Thank you in advance.jbThu, 21 Mar 2019 16:57:45 -0500http://ask.sagemath.org/question/45863/Free nilpotent Lie algebra of step 3 with 11 generatorshttp://ask.sagemath.org/question/44619/free-nilpotent-lie-algebra-of-step-3-with-11-generators/ This works:
S = LieAlgebra(QQ, 10, step=3, names='X', naming='linear')
and this works:
S = LieAlgebra(QQ, 11, step=2, names='X', naming='linear')
but this doesn't work:
S = LieAlgebra(QQ, 11, step=3, names='X', naming='linear')
though it should?
Traceback:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-79-8672234ea66b> in <module>()
----> 1 S = LieAlgebra(QQ, Integer(11), step=Integer(3), names='X', naming='linear')
/opt/sagemath-8.4/local/lib/python2.7/site-packages/sage/misc/classcall_metaclass.pyx in sage.misc.classcall_metaclass.ClasscallMetaclass.__call__ (build/cythonized/sage/misc/classcall_metaclass.c:1640)()
327 """
328 if cls.classcall is not None:
--> 329 return cls.classcall(cls, *args, **kwds)
330 else:
331 # Fast version of type.__call__(cls, *args, **kwds)
/opt/sagemath-8.4/local/lib/python2.7/site-packages/sage/algebras/lie_algebras/lie_algebra.pyc in __classcall_private__(cls, R, arg0, arg1, names, index_set, abelian, nilpotent, category, **kwds)
439 from sage.algebras.lie_algebras.nilpotent_lie_algebra import FreeNilpotentLieAlgebra
440 del kwds["step"]
--> 441 return FreeNilpotentLieAlgebra(R, arg1, step, names=names, **kwds)
442 elif nilpotent:
443 raise ValueError("free nilpotent Lie algebras must have a"
/opt/sagemath-8.4/local/lib/python2.7/site-packages/sage/misc/classcall_metaclass.pyx in sage.misc.classcall_metaclass.ClasscallMetaclass.__call__ (build/cythonized/sage/misc/classcall_metaclass.c:1640)()
327 """
328 if cls.classcall is not None:
--> 329 return cls.classcall(cls, *args, **kwds)
330 else:
331 # Fast version of type.__call__(cls, *args, **kwds)
/opt/sagemath-8.4/local/lib/python2.7/site-packages/sage/algebras/lie_algebras/nilpotent_lie_algebra.pyc in __classcall_private__(cls, R, r, s, names, naming, category, **kwds)
325 return super(FreeNilpotentLieAlgebra, cls).__classcall__(
326 cls, R,r, s, names=tuple(names), naming=naming,
--> 327 category=category, **kwds)
328
329 def __init__(self, R, r, s, names, naming, category, **kwds):
/opt/sagemath-8.4/local/lib/python2.7/site-packages/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedFunction.__call__ (build/cythonized/sage/misc/cachefunc.c:6301)()
1003 return self.cache[k]
1004 except KeyError:
-> 1005 w = self.f(*args, **kwds)
1006 self.cache[k] = w
1007 return w
/opt/sagemath-8.4/local/lib/python2.7/site-packages/sage/structure/unique_representation.py in __classcall__(cls, *args, **options)
1025 True
1026 """
-> 1027 instance = typecall(cls, *args, **options)
1028 assert isinstance( instance, cls )
1029 if instance.__class__.__reduce__ == CachedRepresentation.__reduce__:
/opt/sagemath-8.4/local/lib/python2.7/site-packages/sage/misc/classcall_metaclass.pyx in sage.misc.classcall_metaclass.typecall (build/cythonized/sage/misc/classcall_metaclass.c:2090)()
494 TypeError: Argument 'cls' has incorrect type (expected type, got classobj)
495 """
--> 496 return (<PyTypeObject*>type).tp_call(cls, args, kwds)
497
498 # Class for timing::
/opt/sagemath-8.4/local/lib/python2.7/site-packages/sage/algebras/lie_algebras/nilpotent_lie_algebra.pyc in __init__(self, R, r, s, names, naming, category, **kwds)
398 for X_ind, X in basis_by_deg[dx]:
399 for Y_ind, Y in basis_by_deg[dy]:
--> 400 Z = L[X, Y]
401 if not Z.is_zero():
402 s_coeff[(X_ind, Y_ind)] = {W_ind: Z[W.leading_support()]
/opt/sagemath-8.4/local/lib/python2.7/site-packages/sage/algebras/lie_algebras/lie_algebra.pyc in __getitem__(self, x)
573 return x[1].ideal(x[0])
574 # Otherwise it is the bracket of two elements
--> 575 return self(x[0])._bracket_(self(x[1]))
576 return super(LieAlgebra, self).__getitem__(x)
577
/opt/sagemath-8.4/local/lib/python2.7/site-packages/sage/algebras/lie_algebras/lie_algebra_element.pyx in sage.algebras.lie_algebras.lie_algebra_element.FreeLieAlgebraElement._bracket_ (build/cythonized/sage/algebras/lie_algebras/lie_algebra_element.c:19132)()
1452 a, b = mr, ml
1453 cr = -cr
-> 1454 for b_elt, coeff in self.parent()._rewrite_bracket(a, b).iteritems():
1455 d[b_elt] = d.get(b_elt, zero) + cl * cr * coeff
1456 if d[b_elt] == zero:
/opt/sagemath-8.4/local/lib/python2.7/site-packages/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedMethodCaller.__call__ (build/cythonized/sage/misc/cachefunc.c:10824)()
1951 return cache[k]
1952 except KeyError:
-> 1953 w = self._instance_call(*args, **kwds)
1954 cache[k] = w
1955 return w
/opt/sagemath-8.4/local/lib/python2.7/site-packages/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedMethodCaller._instance_call (build/cythonized/sage/misc/cachefunc.c:10280)()
1827 True
1828 """
-> 1829 return self.f(self._instance, *args, **kwds)
1830
1831 cdef fix_args_kwds(self, tuple args, dict kwds):
/opt/sagemath-8.4/local/lib/python2.7/site-packages/sage/algebras/lie_algebras/free_lie_algebra.pyc in _rewrite_bracket(self, l, r)
690 # For a similar reason, we have b >= c.
691 # Compute the left summand
--> 692 for m, inner_coeff in iteritems(self._rewrite_bracket(l._right, r)):
693 if l._left == m:
694 continue
AttributeError: 'sage.algebras.lie_algebras.lie_algebra_element.Lie' object has no attribute '_right'
rburingSun, 09 Dec 2018 16:51:13 -0600http://ask.sagemath.org/question/44619/multiplicity of a point in a schemehttp://ask.sagemath.org/question/45777/multiplicity-of-a-point-in-a-scheme/ The commands
`A1.<x>=AffineSpace(1, QQ)
X=A1.subscheme([x^1789+x])
Q=X([0])
Q.multiplicity() `
result in 1789.
There seems to be a bug in the multiplicity command for subschemes of the line.
costeWed, 13 Mar 2019 11:13:41 -0500http://ask.sagemath.org/question/45777/Jupyter-Python3 notebooks.http://ask.sagemath.org/question/45366/jupyter-python3-notebooks/ Jupyter interface creates and works with Python2 notebooks. It is possible configure it to work also with Python3? (If present in the system obviously) GGuaspFri, 08 Feb 2019 03:55:38 -0600http://ask.sagemath.org/question/45366/solve(x) does not fully isolate x. Can Sympy use assume()tions?http://ask.sagemath.org/question/45463/solvex-does-not-fully-isolate-x-can-sympy-use-assumetions/This is my worksheet.
https://cocalc.com/share/f7766c5e-2f4d-4916-bb0d-74a7182e5fd5/2019-02-09-203517.sagews?viewer=share
In line 50 i solve the equation describing my physical model for d_k:
d = solve(p_ges == p_ges_rhs, d_k)
But it turns out, that this does not fully isolate d_k at all. Many occurances of d_k remain. How can I help sage along? I really would like to get this fully solved for d_k.
Update: I tried to
assume(d_e >0, d_k > d_m > 0, e_m > e_s > 0)
things about the equation, but to no avail. In Mathematica `assume()` is just for simplifying quations, is it the same in sage, with no effect on `solve()`?
Update2:
I did this:
sage: import sympy
sage: x,d_e, d_m, e_m, e_s, v_ges, d_k =var('x d_e d_m e_m e_s v_ges d_k')
sage: sympy.solve(-1/((d_e - x)*e_m) + 1/(e_m*x) + 1/(sqrt((d_e - x)^2 + 4*d_k^2)*d_k*(e_m/d_m + e_s/(d_k - d
....: _m))) - 1/(sqrt(4*d_k^2 + x^2)*d_k*(e_m/d_m + e_s/(d_k - d_m)))-v_ges ,d_k)
[]
sage:
which I found mention of here:
https://ask.sagemath.org/question/23967/solve-for-variable-but-variable-is-still-in-answer/
I guess that means there is no solution for that problem. On IRC I was told that it is highly likely true, if sympy says so. doh.stockh0lmThu, 14 Feb 2019 10:56:35 -0600http://ask.sagemath.org/question/45463/long traceback when calling solve()http://ask.sagemath.org/question/45473/long-traceback-when-calling-solve/After https://ask.sagemath.org/question/45463/solvex-does-not-fully-isolate-x-how-can-i-help-along/ I substituted variables with numbers (in RIF format) so that sage might have an easier time solving for d_k. I got this:
0 == -v_ges + 1/(sqrt(4*d_k^2 + 0.57?)*d_k*((3.?e-11)/(d_k - 0.1?) + 1.?e-8)) - 1/(sqrt(4*d_k^2 + 0.0625000000000000)*d_k*((3.?e-11)/(d_k - 0.1?) + 1.?e-8)) + 3.7?e9
But now, when I try to solve the above for d_k, I get this long traceback, which is above my sage skills. How can I solve this? The worksheet is https://cocalc.com/share/f7766c5e-2f4d-4916-bb0d-74a7182e5fd5/2019-02-09-203517.sagews?viewer=share
*** WARNING: Code contains possible implicit multiplication ***
*** Check if any of [ 5e, 5e ] need a "*" sign for multiplication, e.g. 5x should be 5*x ! ***
Error in lines 42-42
Traceback (most recent call last):
File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1188, in execute
flags=compile_flags) in namespace, locals
File "", line 1, in <module>
File "sage/symbolic/expression.pyx", line 11568, in sage.symbolic.expression.Expression.solve (build/cythonized/sage/symbolic/expression.cpp:59905)
return solve(self, x, multiplicities=multiplicities,
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 1044, in solve
return _solve_expression(f, x, explicit_solutions, multiplicities, to_poly_solve, solution_dict, algorithm, domain)
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 1282, in _solve_expression
m = ex._maxima_()
File "sage/symbolic/expression.pyx", line 817, in sage.symbolic.expression.Expression._maxima_ (build/cythonized/sage/symbolic/expression.cpp:7898)
return super(Expression, self)._interface_(maxima)
File "sage/structure/sage_object.pyx", line 663, in sage.structure.sage_object.SageObject._interface_ (build/cythonized/sage/structure/sage_object.c:5290)
s = init_func()
File "sage/structure/sage_object.pyx", line 769, in sage.structure.sage_object.SageObject._maxima_lib_init_ (build/cythonized/sage/structure/sage_object.c:7971)
return self._maxima_init_()
File "sage/structure/sage_object.pyx", line 762, in sage.structure.sage_object.SageObject._maxima_init_ (build/cythonized/sage/structure/sage_object.c:7742)
return self._interface_init_(I)
File "sage/symbolic/expression.pyx", line 854, in sage.symbolic.expression.Expression._interface_init_ (build/cythonized/sage/symbolic/expression.cpp:8069)
return InterfaceInit(I)(self)
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 219, in __call__
return self.relation(ex, operator)
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 471, in relation
self(ex.rhs()))
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 217, in __call__
return self.arithmetic(ex, operator)
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 624, in arithmetic
args = ["(%s)"%self(op) for op in ex.operands()]
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 217, in __call__
return self.arithmetic(ex, operator)
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 624, in arithmetic
args = ["(%s)"%self(op) for op in ex.operands()]
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 217, in __call__
return self.arithmetic(ex, operator)
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 624, in arithmetic
args = ["(%s)"%self(op) for op in ex.operands()]
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 217, in __call__
return self.arithmetic(ex, operator)
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 624, in arithmetic
args = ["(%s)"%self(op) for op in ex.operands()]
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 207, in __call__
raise err
TypeError
stockh0lmFri, 15 Feb 2019 16:30:38 -0600http://ask.sagemath.org/question/45473/Wrong factorization of expressions containing exponentials ?http://ask.sagemath.org/question/45469/wrong-factorization-of-expressions-containing-exponentials/Is there something wrong with the factorization of expressions containing exponentials ?
I obtain the following strange results (Sagemath 8.6):
`factor(exp(-x)+2*exp(x))` ---> `3*e^x`,
`factor(exp(-x)+x*exp(-x))` ---> `(x + 1)*e^x`
Any suggestions welcomed.irizosFri, 15 Feb 2019 06:40:40 -0600http://ask.sagemath.org/question/45469/Norm in UniversalCyclotomicFieldhttp://ask.sagemath.org/question/44623/norm-in-universalcyclotomicfield/ Hi,
I'm trying to work with vectors in the `UniversalCyclotomicField`, But I can't find a way to make the norm work. I'm writing the following code :
sage: a = vector([E(8)])
sage: a.norm()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-5b5ddb3f4c99> in <module>()
----> 1 a.norm()
/home/[name]/SageMath/local/lib/python2.7/site-packages/sage/modules/free_module_element.pyx in sage.modules.free_module_element.FreeModuleElement.norm (build/cythonized/sage/modules/free_module_element.c:12840)()
1671 sqrt(5)
1672 """
-> 1673 abs_self = [abs(x) for x in self]
1674 if p == Infinity:
1675 return max(abs_self)
TypeError: bad operand type for abs(): 'UniversalCyclotomicField_with_category.element_class'
And having no luck with it. Does any of you know a workaround allowing me to stay in exact calculations ?
Thanks in advanceAssombranceMon, 10 Dec 2018 10:22:04 -0600http://ask.sagemath.org/question/44623/Bug in computing sum (of binomials)http://ask.sagemath.org/question/45136/bug-in-computing-sum-of-binomials/One gets a wrong output when running the following command:
sage: sum(binomial(1,n),n,0,oo)
3
The output should be $2$ instead of $3$. Compare:
sage: sum(binomial(1,n),n,0,oo,algorithm="sympy")
2
ThrashTue, 22 Jan 2019 11:38:13 -0600http://ask.sagemath.org/question/45136/Cannot install SageMath on Ubuntu 16.04: "Maximum recursion depth exceeded"http://ask.sagemath.org/question/44785/cannot-install-sagemath-on-ubuntu-1604-maximum-recursion-depth-exceeded/I have Ubuntu 16.04.
I downloaded the binary file "sage-8.4-Ubuntu_16.04-x86_64.tar.bz2",
extracted it with:
tar jxf sage-8.4-Ubuntu_16.04-x86_64.tar.bz2
then went into the folder and ran sage:
cd SageMath
./sage
I got the following error:
RecursionError: maximum recursion depth exceeded during compilation
************************************************************************
It seems that you are attempting to run Sage from an unpacked source
tarball, but you have not compiled it yet (or maybe the build has not
finished). You should run `make` in the Sage root directory first.
If you did not intend to build Sage from source, you should download
a binary tarball instead. Read README.txt for more information.
************************************************************************
I don't think I should run make, since I downloaded a binary version, but I tried anyway and got a similar error:
RecursionError: maximum recursion depth exceeded during compilation
Makefile:31: recipe for target 'base-toolchain' failed
make: *** [base-toolchain] Error 1
I found some notes saying that it might be related to the Python version. I have both 3.7 and 2.7. Should I somehow tell SageMath to use 2.7? How?
Alternatively, is there another possible source for this error?Erel Segal-HaleviWed, 26 Dec 2018 11:56:46 -0600http://ask.sagemath.org/question/44785/Is it possible to remove the latex parentheses from exponential functions?http://ask.sagemath.org/question/44777/is-it-possible-to-remove-the-latex-parentheses-from-exponential-functions/Consider the block of code
sage: f = exp(x**2)
sage: latex(f)
e^{\left(x^{2}\right)}
It looks like sage is configured to include parentheses in the latex of an exponential function. Is it possible to configure sage to exclude these parentheses? done_with_fishTue, 25 Dec 2018 04:28:00 -0600http://ask.sagemath.org/question/44777/LaurentPolynomial can't factor constantshttp://ask.sagemath.org/question/44764/laurentpolynomial-cant-factor-constants/Hi all,
Many `LaurentPolynomials` throw errors when I try to factor them. For example:
sage: R.<x,y> = LaurentPolynomialRing(QQ)
sage: R.one().factor()
AttributeError: ...
sage: (x^-1).factor()
AttributeError: ...
This seems to come from the unit part of `Polynomial.factor()` sometimes (incorrectly) living in `Integer Ring`, and sometimes (correctly) living in whatever `self.parent()` is.
Is this intentional or a bug?
Thanks,
Henryliu.henry.hlSun, 23 Dec 2018 15:28:33 -0600http://ask.sagemath.org/question/44764/Why doesn't f(alpha) act like a function?http://ask.sagemath.org/question/44757/why-doesnt-falpha-act-like-a-function/
var('t,alpha,beta,gamma')
sage: i
[ 0 -I]
[-I 0]
sage: f(alpha) = cos(alpha)*i
sage: f(alpha)
[ 0 -I*cos(alpha)]
[-I*cos(alpha) 0]
sage: f(0)
[ 0 -I*cos(alpha)]
[-I*cos(alpha) 0]deburgess7Sun, 23 Dec 2018 09:58:12 -0600http://ask.sagemath.org/question/44757/