ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 28 Mar 2023 19:51:53 +0200How can i get n linearly independent vector ?https://ask.sagemath.org/question/67131/how-can-i-get-n-linearly-independent-vector/how can i get (n) linearly independent vector for a given space ?
for example ;
v=VectorSpace(GF(11),8)
can i get 6 "RANDOM" linearly independent vector ?aliosman9522Tue, 28 Mar 2023 19:51:53 +0200https://ask.sagemath.org/question/67131/Using javascript to interact with sagecellhttps://ask.sagemath.org/question/67108/using-javascript-to-interact-with-sagecell/I am wondering if there's sample code that allows javascript to interact with the sagecell where it can display an output from the sagecell after evaluation. I want javascript to be able to send code to the sagecell and ask the sagecell to evaluate the code. Then I want javascript to be able to alert the evaluated code.ginnMon, 27 Mar 2023 21:31:30 +0200https://ask.sagemath.org/question/67108/Problems with the new way to load Sagemathhttps://ask.sagemath.org/question/67104/problems-with-the-new-way-to-load-sagemath/One more question in form of a suggeestion. Since the new way to install Sagemath inside a container, the mechanism consisting in modifiying `custom.css` to change the display of the output cell is not accessible (at least for me since I do not know how to enter in the container and I have enough work not to use my time to try to understand how to do that. It's also the case when one want to change the MathJax behavior.
It the same problem when you try to use `view()` since Sagemath cannot find LaTeX.
My first problem is that if a computation could be left displayed without any problem, it seems taht for a plot it would be more suitable to have the output centered.
Could a ticket be open to ask that `show` had an option `centered`, `left`, 'right`.
Could a docker image be proposed which include a Latex version.
I have the same problem with `Mathplotlib` which cannot find the fonts.
Last of all I would like to use Mathics and for the same reason I can't.CyrilleMon, 27 Mar 2023 11:42:55 +0200https://ask.sagemath.org/question/67104/Rendering 3D Objects error in Sage with WSL/VSCode/Jupyter Notebookhttps://ask.sagemath.org/question/67099/rendering-3d-objects-error-in-sage-with-wslvscodejupyter-notebook/As the title suggests, whenever I try to render anything in 3D (a polygon, for example) in a Jupyter notebook in VSCode using the Sagemath kernal with WSL, the output is just a blank space that is approximately the size of what the output graph is suppose to look like.
If I try to switch from the text/html to text/plain, the original render would change to one line of "Graphics3d Object."
Is there a fix to this?
Thanks! SW_kMon, 27 Mar 2023 03:09:00 +0200https://ask.sagemath.org/question/67099/How to solve for coefficients in a Quotient ring?https://ask.sagemath.org/question/67094/how-to-solve-for-coefficients-in-a-quotient-ring/
I'm finding that the solve function doesn't take into account the quotients or even the coefficient ring while solving. Is there a way to do so?
For context: I am trying to solve the equation (a+bS+cS^2+dS^3+eS^4+fS^5)^6 = 1 for the variables a, b, c, d, e, f, where a, b, c, d, e, f are elements of the ring of Integers adjoined a 3^6-1 root of unity, and the variable S has the relation S^6 = 3.
The following are three attempts to do so, and the errors they bring.
var('a,b,c,d,e,f,w,s,W,S')
Rw.<w> = PolynomialRing(ZZ)
R0 = Rw.quotient(w^288 + w^284 - w^260 - w^256 - w^236 + w^228 + w^208 - w^200 + w^184 + w^172 - w^156 - w^144 - w^132 + w^116 + w^104 - w^88 + w^80 + w^60 - w^52 - w^32 - w^28 + w^4 + 1)
R1.<a,b,c,d,e,f> = PolynomialRing(R0)
R2.<s> = PolynomialRing(R1)
R = R2.quotient(s^6 - 1)
S = R(s)
W = R(w)
poly = (a+b*S+c*S^2+d*S^3+e*S^4+f*S^5)^6
solve([poly==R(1)], a,b,c,d,e,f)
It freaks out at the poly stage, giving us the following error (the same error that it gives if I run a*S):
TypeError: unsupported operand parent(s) for *: 'Symbolic Ring' and 'Univariate Quotient Polynomial Ring in sbar over Univariate Quotient Polynomial Ring in wbar over Integer Ring with modulus w^288 + w^284 - w^260 - w^256 - w^236 + w^228 + w^208 - w^200 + w^184 + w^172 - w^156 - w^144 - w^132 + w^116 + w^104 - w^88 + w^80 + w^60 - w^52 - w^32 - w^28 + w^4 + 1 with modulus s^6 - 1'
But if we change it to another order, the "poly" line runs but not the "solve" line:
sage: var('w,s,a,b,c,d,e,f')
....: Rw.<w> = PolynomialRing(ZZ)
....: R0 = Rw.quotient(w^288 + w^284 - w^260 - w^256 - w^236 + w^228 + w^208 - w^200 + w^184 + w^172 - w^156 - w^144 - w^132 + w^116 + w^104 - w^88 + w^80 + w^60 - w^52 - w^32 - w^28 + w^4 + 1)
....: R2.<s> = PolynomialRing(R0)
....: R3 = R2.quotient(s^6 - 1)
....: R.<a,b,c,d,e,f> = PolynomialRing(R3)
....: S = R(s)
....: W = R(w)
....: poly = (a+b*S+c*S^2+d*S^3+e*S^4+f*S^5)^6
....: solve([poly==R(1)], a,b,c,d,e,f)
(a, b, c, d, e, f)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[60], line 10
8 W = R(w)
9 poly = (a+b*S+c*S**Integer(2)+d*S**Integer(3)+e*S**Integer(4)+f*S**Integer(5))**Integer(6)
---> 10 solve([poly==R(Integer(1))], a,b,c,d,e,f)
And lastly, my first and most naive approach, which has the same errors as the "solve" stage above.
sage: var('a,b,c,d,e,f,w,s,W,S')
sage: Rw.<w> = PolynomialRing(ZZ)
sage: R0 = Rw.quotient(w^288 + w^284 - w^260 - w^256 - w^236 + w^228 + w^208 - w^200 + w^184 + w^172 - w^156 - w^144 - w^132 + w^116 + w^104 - w^88 + w^80 + w^60 - w^52 - w^32 - w^28 + w^4 + 1)
sage: R1.<a,b,c,d,e,f> = PolynomialRing(R0)
sage: R2.<s> = PolynomialRing(R1)
sage: R = R2.quotient(s^6 - 1)
sage: S = R(s)
....: W = R(w)
sage: poly = (a+b*S+c*S^2+d*S^3+e*S^4+f*S^5)^6
sage: solve([poly==R(1)], a,b,c,d,e,f)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[54], line 1
----> 1 solve([poly==R(Integer(1))], a,b,c,d,e,f)
File /usr/lib/python3.10/site-packages/sage/symbolic/relation.py:1049, in solve(f, *args, **kwds)
1047 for i in x:
1048 if not isinstance(i, Expression):
-> 1049 raise TypeError("%s is not a valid variable." % repr(i))
1050 elif x is None:
1051 vars = f.variables()
TypeError: a is not a valid variable.tzeentchSun, 26 Mar 2023 22:09:33 +0200https://ask.sagemath.org/question/67094/How to convince Sage that integer^(positive integer) is an integer?https://ask.sagemath.org/question/67093/how-to-convince-sage-that-integerpositive-integer-is-an-integer/As title. If p and k are integers, and k is positive, then p^k should be an integer. Why is Sage telling me otherwise, and how can I convince it of the truth?
----------
`sage: var('p,k')`
`(p, k)`
`sage: assume(p,'integer')`
`sage: assume(k,'integer')`
`sage: assume(k>0)`
`sage: alpha = p^k`
`sage: alpha.is_integer()`
`False`
rebeccarohrlichSun, 26 Mar 2023 21:25:46 +0200https://ask.sagemath.org/question/67093/Scientific notation matrixhttps://ask.sagemath.org/question/67052/scientific-notation-matrix/ Given a certain matrix, how do you remove scientific notation on the entries? For example, for 10000000000.0 show the full number instead of 1e10scc12Fri, 24 Mar 2023 05:05:34 +0100https://ask.sagemath.org/question/67052/How to find the intercept between curve and linehttps://ask.sagemath.org/question/67046/how-to-find-the-intercept-between-curve-and-line/ I need to find the point where the curve f(x) = 4-x^6 and the line g(x) = x interceptDelld300Thu, 23 Mar 2023 17:37:19 +0100https://ask.sagemath.org/question/67046/Geometric multiplicitieshttps://ask.sagemath.org/question/67044/geometric-multiplicities/ Is there any function to find the geometric multiplicities of an eigenvalue of a matrix?bobby.mirThu, 23 Mar 2023 16:00:31 +0100https://ask.sagemath.org/question/67044/Some questions on plothttps://ask.sagemath.org/question/67029/some-questions-on-plot/This is a multi-form question. After this question `https://ask.sagemath.org/question/67023/error-in-listing-a-zip/` my code works anew. Do not ask me why ?
But I encounter some new problems. I have had problem to make docker works properly on my computer. But now I would like to enlight the following code (look at 3) for the docker problem)
billes=[ZZ.random_element(0, 4) for i in range(50)]
billes+=[ZZ.random_element(5, 10) for i in range(80)]
billes+=[ZZ.random_element(10, 25) for i in range(21)]
billes+=[ZZ.random_element(25, 50) for i in range(28)]
billes+=[ZZ.random_element(50, 100) for i in range(28)]
shuffle(billes)#no necessary here only to confirm
billes1=sorted(billes)
binbilles1=[[x for x in billes1 if 0 <= x < 4],[x for x in billes1 if 5 <= x < 10],[x for x in billes1 if 10 <= x < 25],[x for x in billes1 if 25 <= x < 50],[x for x in billes1 if 50 <= x < 100]]
avbinbilles1=[len(x)^(-1)*sum(x) for x in binbilles1]
number=[len(x) for x in binbilles1]
cumsumpop=[sum(number[:i]) for i in range(1, len(number)+1)]
percumsumpop=[0]+[sum(number[:i])/sum(number) for i in range(1, len(number)+1)]
cumsumavbinbilles1=[sum(avbinbilles1[:i]) for i in range(1, len(avbinbilles1)+1)]
percumsumavbinbilles1=[0]+[sum(avbinbilles1[:i])/sum(avbinbilles1) for i in range(1, len(avbinbilles1)+1)]
#percumbilles1=[0]+[sum(binbilles1[:i])/sum(number) for i in range(1, len(binbilles1)+1)]
show(percumsumpop)
show(percumsumavbinbilles1)
A=zip(percumsumpop,percumsumavbinbilles1)
p=line([(0,1),(1,1),(1,0)],color='black')
p+=list_plot(list(A),color='red',plotjoined=true,aspect_ratio=1)
p+=line([(0,0),(1,1)])
p+=text(r"$Courbe\,\, de\,\, Lorenz$",(0.2,0.95), color='green')
p+=text(r"$Pourcentages\,\, Cumulés\,\, de \,\, la \,\, Population$",(-0.1,0.5), color='green', rotation=90)
p+=text(r"$Pourcentages\,\, Cumulés\,\, de \,\, la \,\, richesse$",(0.5,-0.1), color='green', rotation=0)
show(p)
1. I would like to fill the space between the red and the blue line but I do not find how
2. I would like to change the font of the ticks and label if I use them but I do not find how
3. I use Docker but I do not know how to gives access to Latex (We need a container with bot Sagemath and latex)
4. Incidently, I do notknow how to make docker remanent. Each time I shut down my computer , I loose all my notebooksCyrilleThu, 23 Mar 2023 00:10:44 +0100https://ask.sagemath.org/question/67029/Error in listing a Ziphttps://ask.sagemath.org/question/67023/error-in-listing-a-zip/
Until the end of this code all is fine
billes=[ZZ.random_element(0, 4) for i in range(50)]
billes+=[ZZ.random_element(5, 10) for i in range(80)]
billes+=[ZZ.random_element(10, 25) for i in range(21)]
billes+=[ZZ.random_element(25, 50) for i in range(28)]
billes+=[ZZ.random_element(50, 100) for i in range(28)]
shuffle(billes)#no necessary here only to confirm
billes1=sorted(billes)
binbilles1=[[x for x in billes1 if 0 <= x < 4],[x for x in billes1 if 5 <= x < 10],[x for x in billes1 if 10 <= x < 25],[x for x in
billes1 if 25 <= x < 50],[x for x in billes1 if 50 <= x < 100]]
avbinbilles1=[len(x)^(-1)*sum(x) for x in binbilles1]
number=[len(x) for x in binbilles1]
cumsumpop=[sum(number[:i]) for i in range(1, len(number)+1)]
percumsumpop=[0]+[sum(number[:i])/sum(number) for i in range(1, len(number)+1)]
cumsumavbinbilles1=[sum(avbinbilles1[:i]) for i in range(1, len(avbinbilles1)+1)]
percumsumavbinbilles1=[0]+[sum(avbinbilles1[:i])/sum(avbinbilles1) for i in range(1, len(avbinbilles1)+1)]
#percumbilles1=[0]+[sum(binbilles1[:i])/sum(number) for i in range(1, len(binbilles1)+1)]
bool(len(percumsumavbinbilles1)==len(percumsumpop))
To plot a Lorenz curve I add
A=list(zip(percumsumavbinbilles1,percumsumpop))
as show by `If you meant to plot two lists 'x' and 'y' against each other, use 'list_plot(list(zip(x,y)))'` in `https://doc.sagemath.org/html/en/reference/plotting/sage/plot/plot.html`
But this generate an error `'list' object is not callable`. Could somebody explain my mistake?
CyrilleWed, 22 Mar 2023 16:22:41 +0100https://ask.sagemath.org/question/67023/Checking whether a poset is thin with Sagehttps://ask.sagemath.org/question/66987/checking-whether-a-poset-is-thin-with-sage/Following the definition in https://arxiv.org/pdf/1508.05446.pdf after theorem 7.7 a finite graded poset (we can assume it is connected) is called thin if each interval [x,y] of rank 2 has cardinality 4.
Is there a quick way to check with Sage whether a given graded poset is thin?
edit: Thanks to John Palmieri, who suggests to look at the code for is_slender() and modify it.
Here is the code:
def is_slender(self, certificate=False):
for x in self:
d = {}
for y in self.upper_covers(x):
for c in self.upper_covers(y):
d[c] = d.get(c, 0) + 1
for c, y in d.items():
if y >= 3:
if certificate:
return (False, (x, c))
return False
if certificate:
return (True, None)
return True
I do not fully understand it yet as Im not experienced with programming in SAGE but I will try to modify it a bit and see if Im succesful.klaaaSun, 19 Mar 2023 14:56:30 +0100https://ask.sagemath.org/question/66987/Parallel computation of roots and loopshttps://ask.sagemath.org/question/66992/parallel-computation-of-roots-and-loops/ Hello!
I am dealing with fairly complicated polynomials which need to be recalculated many times ~5000. I am looking for a way to optimize my code as the whole procedure took 11h for one of the cases meanwhile Mathematica was able to do it in 20 minutes.
I would like to use parallel computing, but I am not sure how to implement it. For now, letting SageMath run with many CPUs did not change the result.
sage.parallel.ncpus.ncpus()
Parallelism().set('tensor', nproc=16)
Parallelism().set(nproc=16)
Parallelism()
#Parameters
e1 = 1/3
e2 = 1/3
l1 = 1/4
l2 = 1
fi = pi/2
z = var('z')
x,y = var('x,y',domain='complex')
xs,ys = var('x,y',domain='real')
mu = var('mu',domain='complex')
zeta = x + I*y
zeta_bar = x - I*y
z_bar(z) = zeta_bar + e1/(z-l1*exp(I*fi)) + e2/(z+l1*exp(I*fi)) + (1-e1-e2)/(z-l2)
L(z) = zeta -z + e1/(z_bar(z)-l1*exp(-I*fi)) + e2/(z_bar(z)+l1*exp(-I*fi)) + (1-e1-e2)/(z_bar(z)-l2)
exp1 = L(z).numerator(normalize=true)
derivative_z(z) = e1/(z_bar(z)-l1*exp(-I*fi))^2 + e2/(z_bar(z)+l1*exp(-I*fi))^2 + (1-e1-e2)/(z_bar(z)-l2)^2
derivative_z_bar(z) = e1/(z-l1*exp(I*fi))^2 + e2/(z+l1*exp(I*fi))^2 + (1-e1-e2)/(z-l2)^2
magnification(z) = mu*(1-derivative_z(z)*derivative_z_bar(z))-1
exp2 = magnification(z).numerator(normalize=true)
def resultant(xs,ys):
temp1 = exp1.subs({x:xs,y:ys})
temp2 = exp2.subs({x:xs,y:ys})
QQI.<I> = QQ[i]
R.<mu> = QQI[]
S.<z> = R[]
poly1 = temp1.polynomial(None,ring=S)
poly2 = temp2.polynomial(None,ring=S)
poly3 = poly1.resultant(poly2)
return poly3
def magn(xs,ys):
roots = resultant(xs,ys).roots(ring=CDF)
mag = sum([abs(roots[k][0].n(50)) for k in range(len(roots))])
return log(mag)
x_list = []
y_list = []
for u in range(36):
x_list.append(u/35)
for u in range(1,36):
x_list.append(-u/35)
x_list.sort()
y_list = x_list
A = np.zeros([71,71])
for u in range(71):
for v in range(71):
A[u,v] = magn(x_list[u],y_list[v])
To get through the last loop it took 11,5 hours. Is there any way to make it run parallel? Or maybe another way to speed up the code?
Thank you for any insights!
NiversSun, 19 Mar 2023 19:03:28 +0100https://ask.sagemath.org/question/66992/numerial_integral for a function having two variableshttps://ask.sagemath.org/question/66988/numerial_integral-for-a-function-having-two-variables/Why the following code does not work with SageMath version9, though it works with SageMath version8?
f(x,y)=sin(x+2*y)
numerical_integral(f,0,pi,params=[5])
SageMath version8.6 gives (-1.6781430581529053, 2.2206773047754592e-14).
SageMath version9.7 gives (0.0, 0.0).
Execution of numerical_integral(f(x,5), 0, pi) in SageMath version9.7 also gives (-1.6781430581529053, 2.2206773047754592e-14).
hiros1Sun, 19 Mar 2023 15:52:31 +0100https://ask.sagemath.org/question/66988/How to determine expression size before printing?https://ask.sagemath.org/question/66982/how-to-determine-expression-size-before-printing/Hello,
doing:
> expression = 10^10^7*x
takes less than a second
but doing:
> len(str(expression))
takes a lot of time.
I would like to quickly check the size of the output expression and if too large, then throw some exception. Is there a fast way to do it?
If
> expression = 10^10^7
I could use
> expression.ndigits()
but if it contains pi, x etc I cannot come up with any other solution than len(str(..)) which is time consuming.
Thanks :)vesolovskiSat, 18 Mar 2023 19:52:26 +0100https://ask.sagemath.org/question/66982/Which algorithm is used for computing the gcd of sparse polynomialhttps://ask.sagemath.org/question/66980/which-algorithm-is-used-for-computing-the-gcd-of-sparse-polynomial/ There are lot of algorithms that compute the gcd of the polynomial for handling different cases
Is there any fast algorithm that computes the gcd of polynomial faster, also wants to know which algorithm does sage math used for computing the gcd of sparse polynomialjaySat, 18 Mar 2023 11:08:52 +0100https://ask.sagemath.org/question/66980/How to get multiplication of square roots to simplify?https://ask.sagemath.org/question/66973/how-to-get-multiplication-of-square-roots-to-simplify/ All I want is for Sage to take the sqrt(3)*sqrt(2) and show me it is sqrt(6). I have looked through the forums and found a few solutions but they are all from 5+ years ago and don't seem to do anything any more. Here is an example:
from sage.manifolds.utilities import simplify_chain_real
a = var("a")
assume(a>0)
a = sqrt(2)*sqrt(3)+6
show(a)
show(simplify_chain_real(a))
show(a.simplify_real())
show(a.canonicalize_radical())
My output is the following for all of these:
sqrt(3)*sqrt(2)+6
What do I need to do to get the output to display sqrt(6)+6? I am sure there is some really advanced mathematical reason for this not to work, but I just dealing with fairly standard stuff.
I am using the following version of Sage:
SageMath version 9.8, Release Date: 2023-02-11ZakEspleyFri, 17 Mar 2023 19:54:15 +0100https://ask.sagemath.org/question/66973/Kernel for maps into iterated PolynomialRingshttps://ask.sagemath.org/question/66870/kernel-for-maps-into-iterated-polynomialrings/It's often convenient to construct quotient rings in an iterated fashion, e.g. when localizing a polynomial ring:
B.<x>=QQ[]
C.<y>=B[]
However, Sage complains when I am trying to calculate a kernel of a homomorphism into such an iteratively constructed ring:
A.<a,b>=QQ[]
f=A.hom([x,y],C)
f.kernel()
Here, Sage treats B as the base ring for C and QQ as the base ring for A and kernel() is not implemented for different base rings. I know, that I could simply construct C as
C.<x,y>=QQ[]
to overcome the problem, but in practice B might be the argument of a method and it would be convenient to extend the ring B instead of having to unpick its construction and create a new ring from scratch.
Is there a way to make this work? E.g. by "flattening" such an iterated construction in an automated fashion?hendrikSFri, 10 Mar 2023 16:35:15 +0100https://ask.sagemath.org/question/66870/TypeError: 'sage.rings.integer.Integer' object is not subscriptablehttps://ask.sagemath.org/question/66969/typeerror-sageringsintegerinteger-object-is-not-subscriptable/ def undamped(x, t):
return [x[1], x[0]-x[0]^3]
from scipy.integrate import odeint
from scipy import linspace
coordinates=0
nbpts = 1000 # number of points
endtime = 20 # end of time span
tspan = linspace(0.0, endtime, nbpts)
ics1 = [0.09, 0.0] # first initial conditions
sol1 = odeint(undamped, ics1, tspan)
solx1 = [(tspan[k], sol[m]) for k in range(nbpts)]
xplot1 = list_plot(sol, axes_labels=['t','x'], size=1)
coordinates1 = [(s[0], s[1]) for s in sol1]
phaseportrait1 = list_plot(coordinates,axes_labels=['x','y'], size=1)
a = graphics_array([xplot1, phaseportrait1])
a.show()Adwait1602Fri, 17 Mar 2023 12:05:03 +0100https://ask.sagemath.org/question/66969/solving 2 non-linear functions (max degree of 3) failshttps://ask.sagemath.org/question/66925/solving-2-non-linear-functions-max-degree-of-3-fails/I'm having trouble solving the following:
![image description](/upfiles/16787597533661572.png)
It's a simple system that uses the functions and their respective derivatives to find values fo x and k.
Mathematica has no problem with this. My machine and the cocalc machine become compute bound. My machine runs out of memory. How do I redo this to get sage to solve it ? Should I try a numeric solve ?PatBTue, 14 Mar 2023 03:04:25 +0100https://ask.sagemath.org/question/66925/Grouping Variables in SageMathhttps://ask.sagemath.org/question/66940/grouping-variables-in-sagemath/I have a multivariate polynomial of the form (type `sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular`)
a_1*x^2 + a_2*x*y + a_3*y^2 + a_4*x + a_5*y + a_6 + b_1*x^2 + b_2*x*y + b_3*y^2 + b_4*x + b_5*y + b_6
in the ring where all of the `a_i, b_j, x, y` are variables. Is there a way to group the variables `x,y` such that I can treat the equation as
(a_1+b_1)*x^2 + (a_2+b_2)*x*y + (a_3+b_3)*y^2 + (a_4+b_4)*x + (a_5+b_5)*y + (a_6+b_6)
in particular, I want to extract the coefficients of monomials in `x,y` say for example to get the coefficient of `x^2` I want to get `a_1+b_1`.
Thanks in advance.wgabrielongTue, 14 Mar 2023 21:26:10 +0100https://ask.sagemath.org/question/66940/Graph polynomial constructionhttps://ask.sagemath.org/question/66932/graph-polynomial-construction/I wish to construct the graph polynomial (as given [here](https://carma.newcastle.edu.au/pdf/combinatorial_nullstellensatz.pdf)) of any given graph. To do so, I wrote the following code. But, the output was null. What needs to be modified in the following code to get the appropriate graph polynomial (the product of binomials corresponding each edge):
def grappoly(G):
R=PolynomialRing(ZZ,['x_'+str(k) for k in G.vertices()])
R.inject_variables()
for i in G.vertices():
for j in G.vertices():
P=1
if set((i,j)).intersection(set(G.edges()))==(i,j):
P=('x_'+str(i)-'x_'+str(j))*P
return P
X=graphs.CompleteBipartiteGraph(5,5)
grappoly(X)
Thanks beforehand.vidyarthiTue, 14 Mar 2023 11:59:36 +0100https://ask.sagemath.org/question/66932/How to define function with indexed variables and sumhttps://ask.sagemath.org/question/66868/how-to-define-function-with-indexed-variables-and-sum/ I would like to define a function f(n)=sum(x[k]*x[k+1], k= 1..n) so that it produces expressions like this:
f(1)= x[1]*x[2],
f(2)=x[1]*x[2]+x[2]*x[3]
f(3)=x[1]*x[2]+x[2]*x[3]+x[3]*x[4]
How to do this in sage? I tried to generate indexed variable with the following:
class VariableGenerator(object):
def __init__(self, prefix):
self.__prefix = prefix
@cached_method
def __getitem__(self, key):
return SR.var("%s%s"%(self.__prefix,key))
x=VariableGenerator('x')
k, n = var('k,n')
f(n)=sum(x[k], k, 1, n)
Unfortunately this does not work. Any ideas?
AedifexFri, 10 Mar 2023 15:56:02 +0100https://ask.sagemath.org/question/66868/Launch Automatization for Sagemath through Dockerhttps://ask.sagemath.org/question/66909/launch-automatization-for-sagemath-through-docker/In connection with this question `https://ask.sagemath.org/question/66844/new-ways-to-install-sage-failed-need-help/`
is there a way to make a little Windows program with
1) open docker
2) docker run -p8888:8888 sagemath/sagemath:latest sage-jupyter
3) open a browser on the url ` http://127.0.0.1:8888/?token=eed147f951986331190b56607dd0d01c8e6acbde92870fd8`
as consecutive commands.
With this in hand working with SageMath would by highly simplified for dummies like I.CyrilleSun, 12 Mar 2023 21:40:45 +0100https://ask.sagemath.org/question/66909/Regarding remove() functionhttps://ask.sagemath.org/question/66881/regarding-remove-function/ I want to remove all symmetric matrices from the list of all possible 0,1 matrices of (say) 2nd order.
When I run this code, not all symmetric matrices are removed. Where am I wrong?`
>
T=Tuples((0,1),4)
W=[matrix(2,2,v) for v in T]
[W.remove(s) for s in W if s.is_symmetric() is true]
show(W)
mak3521Sat, 11 Mar 2023 13:11:21 +0100https://ask.sagemath.org/question/66881/New ways to install Sage failed ; Need helphttps://ask.sagemath.org/question/66844/new-ways-to-install-sage-failed-need-help/I am sorry to be obliged to ask this question. Until now, I was using the old Sagemath version with an automatic installation on Windows 10. But I would like to be update. Secondly, I use Sagemath in courses, and I need student to install it. Of course they can use Sagecell but I prefer to use Jupiter notebooks to interact with them. So if I understand correctly, there is two ways now to install Sagemath on my computer :
1) Docker Sagemath. So Docker has been installed on my computer (for two days it was installed but the start was non stopping so I supposed that a correction has been applied). Now I went in the site `https://hub.docker.com/r/sagemath/sagemath`, copy `docker pull sagemath/sagemath` and run it in PowerShell. Then inside Powershell running `docker run -it sagemath/sagemath:latest` I have a perfect version of a command line Sagemath.
Here comes my problem : running ` docker run -p8888:8888 sagemath/sagemath:latest sage-jupyter` returns the following error `docker: Error response from daemon: driver failed programming external connectivity on endpoint kind_kirch (58408cd6ac6e671d23cf5f9875de73bd013477b6ebb526ba499cc00d9e68c78f): Bind for 0.0.0.0:8888 failed: port is already allocated.`
Inside Docker I have closed all the containers and even if I worked from Docker, I could not have a jupiter notebooks. I have tried to search on internet to find what went wrong but I hav not founded any usefull information. Could some one help me.
2) the second way is to use wsl2 and install Ubuntu and then Sagemath in Ubuntu. But in that case, when installing sagemath inside Ubuntu I have always errors some comming from mathplot-lib.
I have constructed all my Operation Research on Sagemath and I need to have a simple way to install it. Not only for me but mainly for my students who are not computer scientists.CyrilleWed, 08 Mar 2023 19:20:47 +0100https://ask.sagemath.org/question/66844/Expanding a bivariate exponential generating functionhttps://ask.sagemath.org/question/66860/expanding-a-bivariate-exponential-generating-function/Expanding an univariate exponential generating function can be done like this:
def egfExpand1(f, size):
x = var('x')
return taylor(f(x), x, 0, size).power_series(SR).egf_to_ogf().list()
For example egfExpand1(sec, 10) returns [1, 0, 1, 0, 5, 0, 61, 0, 1385, 0, 50521].
But how can I expand a bivariate exponential generating function? Say
def f(x, y): return exp(x * y) * sec(x)
def egfExpand2(f, size):
return ...
The expected output is an integer triangle (i.e. a list of integer lists).
The example would return an unsigned version of A119879, which starts:
1
0, 1
1, 0, 1
0, 3, 0, 1
5, 0, 6, 0, 1
**Edit:**
Frédéric suggested the following solution, slightly rewritten here.
def egfExpand2(f, size):
y = polygen(QQ, "y")
x = LazyPowerSeriesRing(y.parent(), "x").gen()
return [list(f(x, y)[n] * factorial(n)) for n in range(size)]
f = lambda x, y: exp(x * y) * sec(x)
egfExpand2(f, 10)
The univariate case can also be written more elegantly with this method:
def egfExpand1(f, size: int):
x = LazyPowerSeriesRing(QQ, "x").gen()
return [f(x)[n] * factorial(n) for n in range(size)]
egfExpand1(sec, 11)Peter LuschnyThu, 09 Mar 2023 22:38:21 +0100https://ask.sagemath.org/question/66860/How to solve differential equation series solutionhttps://ask.sagemath.org/question/66849/how-to-solve-differential-equation-series-solution/How can I solve differential equation series in general solution in sage?
Also, how can I adjust the default center x0=0 to another value(for example, x0=2)?posstThu, 09 Mar 2023 02:00:34 +0100https://ask.sagemath.org/question/66849/Switching coordinate charts mid-integration with solve_across_chartshttps://ask.sagemath.org/question/66826/switching-coordinate-charts-mid-integration-with-solve_across_charts/ I am trying to utilize `solve_across_charts` to avoid coordinate singularities by switching from spherical to cartesian coordinates when integrating geodesics in the Kerr spacetime. However the code just keeps infinitely running. Following the documentation, my code is (9.3 version),
M = Manifold(4, 'M', latex_name=r'\mathcal{M}', structure='Lorentzian')
X.<t,r,th,ph>=M.chart(r"t r:(2.011,+infinity) th:(0,pi):\theta ph:(0,2*pi):periodic\phi")
C.<T,x,y,z>=M.chart()
C.add_restrictions(sqrt(x**2+y**2+z**2) > 2.011)
X_to_C=X.transition_map(C,[t,r*sin(th)*cos(ph),r*sin(th)*sin(ph), r*cos(th)])
C_to_X=C.transition_map(X,[T,sqrt(x**2+y**2+z**2),atan(sqrt(x**2+y**2)/z),atan(y/x)])
var('m,b,a', domain='real')
m=1
g = M.metric()
rho2 = r^2 + (a*cos(th))^2
Delta = r^2 -2*m*r + a^2
g[0,0] = -(1-2*m*r/rho2)
g[0,3] = -2*a*m*r*sin(th)^2/rho2
g[1,1], g[2,2] = rho2/Delta, rho2
g[3,3] = (r^2+a^2+2*m*r*(a*sin(th))^2/rho2)*sin(th)^2
def g00(m,r,th,a):return g[0,0](m,r,th,a)
def g03(m,r,th,a):return g[0,3](m,r,th,a)
def g11(m,r,th,a):return g[1,1](m,r,th,a)
def g22(m,r,th,a):return g[2,2](m,r,th,a)
def g33(m,r,th,a):return g[3,3](m,r,th,a)
def D(m,r,th,a): return (g03(m,r,th,a))^2-g00(m,r,th,a)*g33(m,r,th,a)
def initial_vector(r0, b,al,ph0=0, E=1, inward=False):
print(b)
t0,th0=0,pi/2
L = -b*E
vth0 = al/(r0*r0)
vt0=(E*g33(m,r0,th0,a)+L*g03(m,r0,th0,a))/(D(m,r0,th0,a))
vr0=sqrt((((1/D(m,r0,th0,a))*((L^2)*g00(m,r0,th0,a)+2*E*L*g03(m,r0,th0,a)+(E^2)*g33(m,r0,th0,a)))
-((vth0)^2)*g22(m,r0,th0,a))/g11(m,r0,th0,a))
if inward:
vr0 = - vr0
vph0 = -(1/D(m,r0,th0,a))*(E*g03(m,r0,th0,a)+L*(g00(m,r0,th0,a)))
p0 = M((t0, r0, th0, ph0), name='p_0')
return M.tangent_space(p0)((vt0, vr0, vth0, vph0), name='v_0')
r0 = 100
th0=pi/2
s = var('s')
ph0=0
v0 = initial_vector(r0, b=0,al=0, ph0=ph0, inward=True)
geod = M.integrated_geodesic(g, (s, 0, 150), v0, across_charts=True)
sol = geod.solve_across_charts(step=0.1, method='odeint', parameters_values={a:0.5},
verbose='False')
interp = geod.interpolate()
I think the issue is on the declaration of the transition maps, however I've tried everything I could think of with no luck. Any help would be much appreciated. BubbzTue, 07 Mar 2023 11:49:36 +0100https://ask.sagemath.org/question/66826/Compile/run individual Cython file from Sage's source?https://ask.sagemath.org/question/66831/compilerun-individual-cython-file-from-sages-source/ I have been trying to understand how the 'generate_children' function works in the "binary_code.pyx" file, and so I would like to be able to edit and compile/run this file on its own without having to build the entirety of Sage each time. My attempts to try to do this with a "setup.py" file or using the command-line 'cythonize' command have led to a lot of complications, so I was wondering if there was a more straightforward way to do so. Do you have any advice on how to be able to compile/run an individual Cython file from the Sage source code? I guess this would also include compiling whatever dependencies would be required for it to run.tomgadronTue, 07 Mar 2023 17:09:26 +0100https://ask.sagemath.org/question/66831/