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.Thu, 29 Feb 2024 23:16:51 +0100Implementing a new class on Sagehttps://ask.sagemath.org/question/76293/implementing-a-new-class-on-sage/I have developed a related to my PhD thesis that I believe could be a valuable addition to Sage, particularly for researchers in link homology. I have been reading the documentation and the contributing to Sage pages, but I'm unsure if I'm doing things right and I would like to check.
My work includes:
1. A 'Foam' class, an extension of SimplicialComplex with additional data and methods.
2. An algorithm to count colorings of a Foam by converting it into an Integer Linear Programming problem.
3. A module for (gln-) foam evaluation (see arXiv:1702.04140)
I forked the Sage repository's develop branch and created a 'foams' directory in sage/src. Should I simply develop my methods in the foams directory and submit a pull request, or is there a ticket system I should be aware of? Am I supposed to start a stream on zulip?
Thank you for your time!alvarolmartinezThu, 29 Feb 2024 23:16:51 +0100https://ask.sagemath.org/question/76293/How define a graph where edges are defined using a condition?https://ask.sagemath.org/question/76283/how-define-a-graph-where-edges-are-defined-using-a-condition/ I would like to define a graph where I want my vertices set to $\mathbb{F}_5^2$. I won't define there is an edge between $(A_0,B_0)$ and $(A,B)$ if $A\neq A_0$ and $F_{B-B_0}(A,B))=0$ Where $F_{A,B}(X)=X^3+AX+B$.
Any help or reference is appreciated.sunilpasupulatiThu, 29 Feb 2024 11:46:13 +0100https://ask.sagemath.org/question/76283/Generating prime graphshttps://ask.sagemath.org/question/76280/generating-prime-graphs/ I am trying to generate prime graphs on n vertices. Are there any inbuilt functions that might be useful? Also, what is the best method to check the minimum degree of a graph?
Thanks!MBelavadiThu, 29 Feb 2024 05:26:16 +0100https://ask.sagemath.org/question/76280/Combine sage plot with matplotlibhttps://ask.sagemath.org/question/76260/combine-sage-plot-with-matplotlib/I would like to combine the plots (canvases) of Sage and Matplotlib in one plot. The following is an example script. As you can see (if you run), that Sage is just putting another image on top of the canvas of Matplotlib... Any way to just update the canvas of matplotlib to combine two plots in one plot?
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
x = [1, 2, 3, 4, 5]
y = [1, 2, 3, 4, 5]
ax.plot(x, y)
c = circle((1,1),1)
c_matplotlib = c.matplotlib(figure=fig)
plt.show()
Rowing0914Tue, 27 Feb 2024 14:07:46 +0100https://ask.sagemath.org/question/76260/Confused about covariant derivatives and tensors in SageMathhttps://ask.sagemath.org/question/76265/confused-about-covariant-derivatives-and-tensors-in-sagemath/I'm trying to calculate covariant derivatives of tensor fields in SageMath, I established the metric connection using `g.connection()`. But I cannot find any specific method to calculate the covariant derivatives unlike Lie derivative which is an inbuilt method. I looked up documentations and I found that I have to apply the connection (which is just the christoffel symbol) to the tensor field to calculate its covariant derivative. Is that the correct way or is there an inbuilt method that I'm missing? I tried `diff()` to calculate partial derivative of a tensor defined on a chart on a manifold but it is not working.
So ultimately I want to know the correct method to calculate partial and covariant derivatives of vector fields and tensors on a manifold.
On a related note, I want to know how to save a tensor quantity which I transformed from one coord to another using `Tensor.display_comp(chart=differentOne)`. This method seems to take the original and just display the terms in a different coord system, how do I save the transformed one as a different tensor defined on the `differentOne `chart?
Please let me know. Thanks in advance for responding!AKGSageTue, 27 Feb 2024 17:37:56 +0100https://ask.sagemath.org/question/76265/Polynomial factorizationhttps://ask.sagemath.org/question/76264/polynomial-factorization/ I have a polynomial in x,y,z such that each term can factor out a certain power of x to get a polynomial with nonzero constant term. I want to simplify this polynomial, so I want to find the largest n such that each term can be divided by x^n and then divide the whole polynomial by x^n. How shall I do it?8moeb8Tue, 27 Feb 2024 17:32:48 +0100https://ask.sagemath.org/question/76264/Float-point precision in instantiation of point in Hyperbolic geometry modulehttps://ask.sagemath.org/question/76236/float-point-precision-in-instantiation-of-point-in-hyperbolic-geometry-module/I'm in the middle of debugging some other codebase (working in a Poincare Disk of hyperbolic-geometry) and I figured that the following specific point causing the issue.
Now, I would like to instantiate the point based on the that coordinate.
But the result of printing on console indicates that the last few digits have been rounded...
from sage.geometry.hyperbolic_space.hyperbolic_interface import HyperbolicPlane
# Instantiate HyperbolicPlane
PD = HyperbolicPlane().PD()
p = PD.get_point(CC(0.13816890584139213 + 0.4878012008585488*I))
print(p) # -> Point in PD 0.138168905841392 + 0.487801200858549*I
Could anyone help me instantiate the point on this particular coordinate?Rowing0914Mon, 26 Feb 2024 14:55:35 +0100https://ask.sagemath.org/question/76236/how display labels edges and color with dictionary? https://ask.sagemath.org/question/76231/how-display-labels-edges-and-color-with-dictionary/ Hi
How can I label edges style :edge (0,1) ='01' and give them a color like in the `simplex1ColorRevDic` dictionary ?
# functions
def strListToList(strL) :
Lstr=strL.replace('[','').replace(']','').split(',')
return [SR(e) for e in Lstr]
def addAxis(plt,textToPlt,xBound,yBound,zBound,wA,rA) :
# add axis for real part
plt += arrow3d((0, 0, 0), (xBound, 0, 0), color='red',width=wA,radius=rA)
plt += text3d("ex", (xBound, 0, 0), fontsize='200%', color='black')
plt += arrow3d((0, 0, 0), (0, yBound, 0), color='gray',width=wA,radius=rA)
plt += text3d("ey", (0, yBound, 0), fontsize='200%', color='gray')
plt += arrow3d((0, 0, 0), (0, 0, zBound), color='pink',width=wA,radius=rA)
plt += text3d("ez", (0,0, zBound), fontsize='200%', color='pink')
plt+=textToPlt
return plt
xBound=1.5 ;yBound=1.5 ;zBound=1.5
shiftV=vector([1/10,1/10,1/10])
widthA=0.2 ;radiusA=0.02
textToPlt = text3d("test",vector( (xBound, yBound, 1.5*zBound))+shiftV, fontsize='300%', fontweight=800)
g = DiGraph()
cubeDic={0: [0, 0, 0],1: [1, 0, 0], 2: [0, 1, 0], 3: [1, 1, 0] ,
4: [0, 0, 1], 5: [1, 0, 1], 6: [0, 1, 1], 7: [1, 1, 1]}
simplex0=[ 0, 1, 2, 3, 4, 5, 6, 7 ]
simplex1=[[0, 4], [0, 5], [0, 6], [4, 5], [4, 6],
[5, 6], [0, 1], [0, 3], [0, 7], [1, 3],
[1, 7], [3, 7], [1, 5], [5, 7], [0, 2],
[2, 3], [2, 6], [3, 6], [6, 7]]
colorPaletteSimplex1=rainbow(len(simplex1))
simplex1ColorDic={}
for v,c in zip(simplex1,colorPaletteSimplex1):
simplex1ColorDic[str(v)]=str(c)
keys=[simplex1ColorDic.get(k) for k in simplex1ColorDic.keys()]
values=[strListToList(s1)for s1 in simplex1ColorDic.keys()]
simplex1ColorRevDic=dict(zip(keys,values))
g.add_vertices( simplex0 )
g.add_edges(simplex1)
g.set_edge_label((0,1),'toto',(0,0.5,0))
g.set_pos(cubeDic,dim=3)
print('positions :',g.get_pos(dim=3))
#gPlt=g.plot3d(save_pos=True,edge_colors=simplex1ColorRevDic) #errors !
gPlt=g.plot3d(save_pos=True,edge_labels=True)
gPlt=addAxis(gPlt,textToPlt,xBound,yBound,zBound,widthA,radiusA)
gPlt.show()ortolljMon, 26 Feb 2024 13:08:37 +0100https://ask.sagemath.org/question/76231/rational canonical formhttps://ask.sagemath.org/question/76030/rational-canonical-form/ Please i want to compute the rational canonical form of a matrix also known as frobenius form in terms of the entries of the matrix
the matrix is a 2*2 matrix of the form A=[[a*b+1,b],[a,1]
Thank you in advancemiloulouFri, 16 Feb 2024 20:04:52 +0100https://ask.sagemath.org/question/76030/Defining new operators with specific ruleshttps://ask.sagemath.org/question/75929/defining-new-operators-with-specific-rules/I would like to define new derivative operators `dd1` and `dd2`. They should follow the following rules (`dd` being either `dd1` or `dd2` - They follow the same rules.):
dd(a+b)=dd(a)+dd(b);
dd(a*b)=b*dd(a)+a*dd(b);
dd(-a)=-dd(a);
dd(1/a)=-1/a^2*dd(a);
dd(c)=0;
dd(c*a)=c*dd(a);
dd(a**c)=c*a**(c-1)*dd(a);
where `c` is a symbolic variable or a number of any kind and, `a` and `b` are scalar field functions on a manifold.
If the code is something like the following:
# First operator
def dd1(x):
...
# Second operator
def dd2(x):
...
Man = Manifold(4, 'Man', r'\mathcal{Man}')
CO.<t,r,th,ph> = Man.chart(r't r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi')
a=Man.scalar_field(function('a')(*CO))
b=Man.scalar_field(function('b')(*CO))
c=var('c')
Then, it should produce these sample outputs for the following inputs:
Input> dd1(a)
Outpt> dd1(a)
Input> dd1(dd2(a))
Outpt> dd1(dd2(a))
Input> dd2(a*b)
Outpt> b*dd2(a)+a*dd2(b)
Input> dd1(c*a)
Outpt> c*dd1(a)
Input> dd2(dd1(c*a))
Outpt> c*dd2(dd1(a))
Input> dd1(-a)
Outpt> -dd1(a)
Input> dd2(c)
Outpt> 0
Input> dd1(7)
Outpt> 0tolgaSun, 11 Feb 2024 11:27:59 +0100https://ask.sagemath.org/question/75929/Applying RREF transformation of one matrix to anotherhttps://ask.sagemath.org/question/64691/applying-rref-transformation-of-one-matrix-to-another/Given a matrix `M`, let `M'` be the matrix created by `M.rref()`.
Let `E` be a matrix made from composing the elementary row operations which took `M` to `M.rref()`. In particular, E satisfies `M.rref() = EM`.
I now wish to compute `E` (actually, `EA`, for any matrix `A` of the right dimension). Does Sagemath offer anything which allows me to bypass manually computing `E`?yeetcodeSat, 29 Oct 2022 22:48:53 +0200https://ask.sagemath.org/question/64691/show() for equations is not workinghttps://ask.sagemath.org/question/76217/show-for-equations-is-not-working/ This might be a recurrent problem with Sagemath since I saw a previous question and its answer. That answer does not work in my case.
I just want to see equations rendered since it is easier to see if they are correct. The previous answer told us to add a
sys. stdout.flush() command line after each show
1. import sys
2. sys.stdout.flush()
3. var("x y z ")
4. show(x**2)
This does not work in my system.
> Linux mp74207-MS-7A34 6.5.0-21-generic
> 21~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Feb 9 13:32:52 UTC 2 x86_64
> x86_64 x86_64 GNU/Linux Ubuntu 22.04
I refreshed all packages containing Sagemath 9.5 (that is the current version available in the repository).
> apt search sagemath Sorting... Done
> Full Text Search... Done
> cantor-backend-sage/jammy
> 4:21.12.3-0ubuntu1 amd64 Sage
> backend for Cantor
>
> libpynac-dev/jammy 0.7.29-2 amd64
> Engine for symbolic geometric calculus
> for Python (development files)
>
> libpynac18py3/jammy 0.7.29-2 amd64
> Engine for symbolic geometric calculus
> for Python
>
> maxima-sage/jammy,now 5.45.1-2 amd64
> [installed,automatic] Computer
> algebra system -- base system
>
> maxima-sage-doc/jammy,jammy,now
> 5.45.1-2 all [installed,automatic] Computer algebra system --
> documentation
>
> maxima-sage-share/jammy,jammy,now
> 5.45.1-2 all [installed,automatic] Computer algebra system -- extra code
>
> python3-sage/jammy,now 9.5-4 amd64
> [installed,automatic] Open Source
> Mathematical Software - Python 3
> library
>
> python3-sagetex/jammy,jammy,now
> 3.6+ds-2 all [installed,automatic] Embed Sage code and plots into LaTeX
> -- Python 3
>
> rubiks/jammy 20070912-5build1 amd64
> Small collection of Rubik's cube
> solvers
>
> sagemath/jammy,jammy,now 9.5-4 all
> [installed] Open Source Mathematical
> Software
>
> sagemath-database-conway-polynomials/jammy,jammy,now
> 0.5-8 all [installed,automatic] Database of Conway polynomials
>
> sagemath-database-cremona-elliptic-curves/jammy,jammy
> 0~20191029-4 all Databases of
> elliptic curves over the rationals
>
> sagemath-database-elliptic-curves/jammy,jammy,now
> 0.8.1-5 all [installed,automatic] Databases for elliptic curves
>
> sagemath-database-graphs/jammy,jammy,now
> 20210214+dfsg-1 all
> [installed,automatic] Databases of
> graphs
>
> sagemath-database-mutually-combinatorial-designs/jammy,jammy,now 20140630-6 all [installed,automatic]
> Databases of combinatorial designs
>
> sagemath-database-polytopes/jammy,jammy,now
> 20170220-5 all [installed,automatic]
> Databases of polytopes
>
> sagemath-doc/jammy,jammy,now 9.5-4 all
> [installed,automatic] Open Source
> Mathematical Software - documentation
>
> sagemath-jupyter/jammy,jammy,now 9.5-4
> all [installed,automatic] Open
> Source Mathematical Software - Jupyter
> kernel
>
> sagetex/jammy,jammy,now 3.6+ds-2 all
> [installed,automatic] Embed Sage
> code and plots into LaTeX
>
> sagetex-doc/jammy,jammy 3.6+ds-2 all
> Embed Sage code and plots into LaTeX
> -- doc
Any help would be welcome.
Thanks
ny2292000Sat, 24 Feb 2024 14:31:52 +0100https://ask.sagemath.org/question/76217/How to write a differential equation with two enumerationhttps://ask.sagemath.org/question/76202/how-to-write-a-differential-equation-with-two-enumeration/How to write a differential equation with two enumeration like this P'_i,j (t) = beta * (i+1) * (j-1) * P_i+1,j-1 (t) - (beta * i * j + gamma * j) * P_i,j (t) + gamma * (j+1) * P_i,j+1 (t) in Sage Math. This is a stochastic SIR epidemic model where P_i,j (t) is the probability there are i susceptible, j infected and N-(i+j) recovered individuals at time t with 0<=i+j<=N.aqnora21Fri, 23 Feb 2024 16:10:44 +0100https://ask.sagemath.org/question/76202/Automate launching Sage notebook with mamba in WSLhttps://ask.sagemath.org/question/76206/automate-launching-sage-notebook-with-mamba-in-wsl/In WSL (Ubuntu), I have created a shell script `~/sage_nb.sh`:
mamba activate sageforge
cd /mnt/g/<somepath>
sage -n jupyter --NotebookApp.use_redirect_file=False
However, simply running the script via the command `~/sage_nb.sh` results in errors:
> Run 'mamba init' to be able to run mamba activate/deactivate and st art a new shell session. Or use conda to activate/deactivate.
I found out that running `source ~/sage_nb.sh` would work. However, this assumes that I manually launch ubuntu WSL and then run `source ~/sage_nb.sh`. I would like to automate this entire process.
Creating and running a Window batch script with the command `ubuntu run "source ~/sage_nb.sh"` results in error:
> mamba: command not found
I believe this is because mamba needs some preprocessing that is usually done by launching ubuntu manually.RoadFri, 23 Feb 2024 21:00:58 +0100https://ask.sagemath.org/question/76206/How to substitute the product of two variables in polynom?https://ask.sagemath.org/question/76197/how-to-substitute-the-product-of-two-variables-in-polynom/I want to replace all occurrences of the product of two or more variables in a polynomial with some expression.
If I call `subs` for expression, nothing happens:
x, y, z, w = var("x y z w")
P = 7*x^2*y^2 + 5*x^2*y + 6*x*y^2 + 4*x*y + x + 2*y + 3*z
P.subs({ x*y: w })
returns `7*x^2*y^2 + 5*x^2*y + 6*x*y^2 + 4*x*y + x + 2*y + 3*z`.
If I call `subs` for polynoms, it returns incorrect result.
R.<x, y, z, w> = QQ[]
P = 7*x^2*y^2 + 5*x^2*y + 6*x*y^2 + 4*x*y + x + 2*y + 3*z
P.subs({ x*y: w })
returns `7*y^2*w^2 + 6*y^2*w + 5*y*w^2 + 4*y*w + 2*y + 3*z + w`.
But in bots cases I expected `7*w^2 + 5*x*w + 6*w*y + 4*w + x + 2*y + 3*z`.Konstantin BatsFri, 23 Feb 2024 14:48:54 +0100https://ask.sagemath.org/question/76197/Possible bug with product of matrices over GF with modulushttps://ask.sagemath.org/question/76170/possible-bug-with-product-of-matrices-over-gf-with-modulus/Below is a minimal example, where the product of two matrices over a finite field (with a pre-described modulus) is not computed correctly. I am looking forward to explanations about this unexpected behavior:
# adjoing a 16th root of unity to GF(3) gives a field extension of degree 4, explicitly:
F.<xi> = GF(3^4,modulus=x^4-x^2-1)
# now xi is a primitive 16th root of unity
print(xi^8==1,xi^16==1)
# matrix multiplication over F doesn't seem to work with Sage Kernel 10.0
a1=2*xi^2+2
a2=xi^2
A1=matrix(F,[a1])
A2=matrix(F,[a2])
# Sage does not compute the product of the two 1x1-matrices correctly:
print(A1*A2)
# this does not agree with the product of the underlying elements
print(a1*a2)
The output produced by Sage (Kernel 10.0) is:
False True
[2*xi^3 + 2*xi^2 + 2]
xi^2 + 2
Update: The problem persists even after updating to SageMath 10.2 on my desktop computer. The error is also reproducible on CoCalc.JohannesThu, 22 Feb 2024 17:58:22 +0100https://ask.sagemath.org/question/76170/StandardAlgorithm returns rays that are not extremalhttps://ask.sagemath.org/question/76187/standardalgorithm-returns-rays-that-are-not-extremal/Hello,
I am currently trying to use sage's implementation of the double description algorithm to find all extremal rays of a given pointed cone $C={x: Ax \geq 0}$. My code looks as follows:
from sage.geometry.polyhedron.double_description import StandardAlgorithm, Problem
import numpy as np
def check_rays_extremal(res):
'''Check if all rays in res are actually extremal rays.'''
for i in range(len(res.R)):
if not res.is_extremal(res.R[i]):
print(f"ray{i} is not extremal")
return
def check_rays_projected_to_zero(res, A_bar):
'''Check if all extremal rays are actually projected onto 0 using A_bar.'''
for i in range(len(res.R)):
ray = res.R[i]
npar = np.array(ray)
mul = np.matmul(A_bar, npar)
max_entry = max(mul)
min_entry = min(mul)
if max_entry > 10**(-10) or min_entry < -10**(-10):
print(f"ray {it}: result is not zero: max value {max_entry}, min value {min_entry}")
return
def check_rays_geq_zero(res, A):
'''Check if all rays are in the pointed cone they are supposed to describe.'''
for i in range(len(res.R)):
ray = res.R[i]
npar = np.array(ray)
mul = np.matmul(A, npar)
min_entry = min(mul)
if min(mul) < -10**(-10):
print(f"ray {it}: result is not zero: min value {min(mul)}")
return
A = np.concatenate((A_bar, -A_bar, np.identity(A_bar.shape[1])))
A_sage = matrix(RR, A)
res = StandardAlgorithm(A_sage).run()
check_rays_extremal(res)
check_rays_projected_to_zero(res, A_bar)
check_rays_geq_zero(res, A):
Here, $\bar{A}$ is a numpy.matrix object with full rank and only integer entries (even though the datatype used is $A.dtype = float64$). To be precise, $A$ is an inequality description of a cone of shape $\{x \geq 0: \bar{A}x = 0\}$. The functions defined above are used to check the reasonability of $res.R$.
The results $res$ only have integer entries, but also have several properties that indicate wrong results:
- for some test matrices $A$,
$checkRaysExtremal(res)$ identifies
most of the rays in $res.R$ as being
non-extremal
- some entries of $res.R$ also neither
satisfy $\bar{A}x = 0$ nor $Ax\geq
0$, hence they seem to not even be in
the cone that is described by $A$
- some items in $res.R$ are identical,
i.e., some rays are generated
multiple times
I have tried several things to fix the problem, among others:
- define A_sage over the ring $QQ$
- explicitly convert $A$ to a
$np.matrix$ with $dtype=int64$
Nevertheless, I still can't fix the ascribed issues. Has one of you faced the same problem and managed to fix it? I am using SageMath 9.3 notebook on a Windows device.
If need be I can attach some more detailed information on inputs and outputs, but the matrices I am using usually have more than 200 rows and 100 columns.tun27Fri, 23 Feb 2024 12:06:38 +0100https://ask.sagemath.org/question/76187/Exporting pgf plots for latex from Sage environment using pandas and matplotlibhttps://ask.sagemath.org/question/76172/exporting-pgf-plots-for-latex-from-sage-environment-using-pandas-and-matplotlib/I've done some data analysis using Pandas in Sage, and would like to export plots to include in a paper. Unfortunately, exporting as a pdf means that titles etc. won't adjust to changes in the formatting of my Latex document, so I would like to export as a pgf (as explained, for example, [here](https://jwalton.info/Matplotlib-latex-PGF/)).
When I do this, however, I get the following error:
File ~/sage/sage/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/backends/backend_pgf.py:293, in LatexManager.__init__(self)
290 self._setup_latex_process(expect_reply=False)
291 except FileNotFoundError as err:
292 raise RuntimeError(
--> 293 f"{self.latex.args[0]!r} not found. Install it or change "
294 f"rcParams['pgf.texsystem'] to an available TeX "
295 f"implementation.") from err
296 except OSError as err:
297 raise RuntimeError(
298 f"Error starting process {self.latex.args[0]!r}") from err
AttributeError: 'LatexManager' object has no attribute 'latex'
It seems that somehow matplotlib is not able to find the correct latex implementation, but I'm not sure how to fix that. Does anyone do this regularly and know of a solution? If it's relevant, I am running Sage 10.0.beta6 on WSL. I also have a MWE below for reference. Thanks so much!
MWE:
sage: import matplotlib
sage: import matplotlib.pyplot as plt
sage: matplotlib.use('pgf')
sage: import pandas as pd
sage: df = pd.DataFrame({'length' : [float(x) for x in [1.5,0.5,1.2,0.9,3]],
....: 'width' : [float(x) for x in [0.7, 0.2, 0.15, 0.2, 1.1]]}, index = ['
....: pig', 'rabbit', 'duck', 'chicken', 'horse'])
sage: hist = df.hist(bins = 3)
sage: plt.savefig("test.pgf")
stillconfusedThu, 22 Feb 2024 19:08:10 +0100https://ask.sagemath.org/question/76172/Pythagorean triple counthttps://ask.sagemath.org/question/76159/pythagorean-triple-count/ I'm trying to calculate how many Pythagorean triples there are with all arguments under a given value and my program won't finish when I set my limit at 1000.
Here it calculates a number in about a second when I set the limit at 100:
sage: len([(a,b,c) for a in range(1,100) for b in range(1,100) for c in range(1,100) if a^2+b^2==c^2])
But when I switch 100 to 1000 it computes endlessly and I need to abort the program.
Is there a way to make this code more efficient so it doesn't get overloaded? For example I've been trying to find a way to condense the variable range declarations but I'm not getting answers. I'm also new to Sagemath.JwlmugThu, 22 Feb 2024 06:02:42 +0100https://ask.sagemath.org/question/76159/Bug: RSK Kills Kernelhttps://ask.sagemath.org/question/76164/bug-rsk-kills-kernel/I am using Sage 10.0 on an M2 Silicon chip Macbook Air 13'.
Method of replicating bug: I accidentally used RSK on an element of `SymmetricGroup(n)` instead of an object of `Permutation` class. I don't think it's intended to work on the former, but this always kills the kernel for some reason. The entire notebook needs rerunning after that.yeetcodeThu, 22 Feb 2024 14:34:15 +0100https://ask.sagemath.org/question/76164/ModuleNotFoundError when importing Siroccohttps://ask.sagemath.org/question/76152/modulenotfounderror-when-importing-sirocco/Hi,
I am using SageMath 10.2 on a cluster running on Rocky Linux. I am trying to use the Sirocco package, but I run into a `ModuleNotFoundError` when importing:
sage: from sage.libs.sirocco import contpath
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In [2], line 1
----> 1 from sage.libs.sirocco import contpath
ModuleNotFoundError: No module named 'sage.libs.sirocco'
However the module is correctly listed among the installed packages:
sage: from sage.misc.package import installed_packages
sage: sage: print(installed_packages()['sirocco'])
2.1.0
Any idea on what is causing this? I think it might be linked to the fact it is a Cython library. Any help is appreciated.xytsaWed, 21 Feb 2024 23:28:22 +0100https://ask.sagemath.org/question/76152/Is there a plot function for ordered trees?https://ask.sagemath.org/question/76130/is-there-a-plot-function-for-ordered-trees/My workflow is:
# Integer compositions -> Dyck paths
def dyckpath(c):
return DyckWord(sum([[1]*a + [0]*a for a in c], []))
You can print a dyckpath with
dyck = dyckpath(c)
dyck.pretty_print(type="NE-SE")
But my question is related to:
for c in Compositions(5):
dyck = dyckpath(c)
bit = dyck.to_binary_tree()
print(bit.as_ordered_tree())
This gives me something which looks like
[[[[], []], []], [[[], []], [[[], []], []]]]
Is there a plot function that knows this format
and transforms it into a nice plot?
Edit: Taking John's answer as a starting point I tried:
ot = bit.as_ordered_tree()
show(ot.plot())
This works, but note that you have to use additionally
the function 'show'.
According to this logic I would now expect that show(bit.plot())
would also work. Unfortunately, this is not the case. Then you get
the error message: 'BinaryTrees_all_with_category.element_class'
object has no attribute 'plot'. What can I do in this case?Peter LuschnyTue, 20 Feb 2024 22:14:03 +0100https://ask.sagemath.org/question/76130/Differential equation solutionhttps://ask.sagemath.org/question/76120/differential-equation-solution/ I'm still a bit new to sage math and I don't understand the result given by desolve_system, here is my code
t = var('t')
var('w C1 C2 C3 n ')
H = function('H')(t)
phi = (C2 * t + C3)^n #function('\\phi')(t)
sigma = function('\\Sigma')(t)
V = C*phi^2#function('V')(phi)
P = function('P')(t)
######
de1 = H^2-w/6 * (P/phi)^2 - V/(6*phi) - 2*sigma/3 + H*P/phi
de2 = diff(H, t) + w/6 * (P/phi)^2 - V/(3*phi) + 2*sigma/3 + 2*H^2 - 1/(2*phi) * (phi * diff(V, t) - 2*V)/(2*w+3)
de3 = diff(phi, t) == P
des = [de1, de2, de3]
######
vars = [H, sigma, P]
sol= desolve_system(des, vars, ivar = t)
And it gives solutions of the form
$$\newcommand{\Bold}[1]{\mathbf{#1}}P\left(t\right) = \mathcal{L}^{-1}\left(\frac{C_{2}^{n} n e^{\left(\frac{C_{3} g_{63262}}{C_{2}}\right)} \Gamma\left(n, \frac{C_{3} g_{63262}}{C_{2}}\right)}{g_{63262}^{n}}, g_{63262}, t\right)$$
I'm not so sure what is the $\mathcal{L}$ in this case, nor the $g_{63262}$ terms. What am I looking at. I have found no information online, maybe because I wasn't sure how to describe this properly.
Thank you.roux_de_secoursTue, 20 Feb 2024 18:19:47 +0100https://ask.sagemath.org/question/76120/Odd behaviour in computation of intersection in Poincare Dischttps://ask.sagemath.org/question/76140/odd-behaviour-in-computation-of-intersection-in-poincare-disc/I'm trying to compute the intersection of two geodesics in the Poincare disc. My code is a bit too long to paste here so let me just share the short-link to it.
Anyway, I'm getting the following error in the intersection computation in a part of the code. Error message is `ValueError: negative number cannot be raised to a fractional power`.
So, i printed out the geodesics involved in this computation as follows;
Geodesic in PD from 0.9173343623719807 + 0.3981176554884141*I to 0.39811765407683164 + 0.9173343629845988*I
Geodesic in PD from -0.4409894081700523 + 0.8975123073706717*I to 0.7311976448002898 + 0.6821656721343501*I
Now, I understood that this much larger float-point precision sits behind these printed out numbers but I tried to reproduce the error as follows;
from sage.geometry.hyperbolic_space.hyperbolic_interface import HyperbolicPlane
PD = HyperbolicPlane().PD()
l1 = PD.get_geodesic(0.9173343623719807 + 0.3981176554884141 * I, 0.39811765407683164 + 0.9173343629845988 * I)
l2 = PD.get_geodesic(0.4409894081700523 + 0.8975123073706717 * I, 0.7311976448002898 + 0.6821656721343501 * I)
l1.intersection(l2)
But this time I'm getting the `ValueError: geodesics don't intersect`...
Could someone tell me why I can't reproduce the error?Rowing0914Wed, 21 Feb 2024 13:54:31 +0100https://ask.sagemath.org/question/76140/Is there a command or a way in SageMath to collect more than one common variable in an equation? without specifying those common variable or write them manuallyhttps://ask.sagemath.org/question/76078/is-there-a-command-or-a-way-in-sagemath-to-collect-more-than-one-common-variable-in-an-equation-without-specifying-those-common-variable-or-write-them/Is there a command or a way in SageMath to collect more than one common variable in an equation without specifying those common variable or write them manually, for example I want the following equation
-36*beta*t*exp(-4*beta*t) +14*exp(-4*beta*t)-12*beta*t*exp(-6*beta*t) -18*exp(-6*beta*t)+5
to be written like this
(-36*beta*t+14)*exp(-4*beta*t) +(-12*beta*t-18)*exp(-6*beta*t)+5
I do not to specify the common variables since the code I am running is iteration so I do not know the values what will beaqnora21Sun, 18 Feb 2024 23:37:27 +0100https://ask.sagemath.org/question/76078/Finding all integer solutions of binary quadratic formhttps://ask.sagemath.org/question/76116/finding-all-integer-solutions-of-binary-quadratic-form/ I found the following page to calculate one solution for a binary quadratic form $ax^2+bxy +cy^2$: [Link](https://doc.sagemath.org/html/en/reference/quadratic_forms/sage/quadratic_forms/binary_qf.html#sage.quadratic_forms.binary_qf.BinaryQF.solve_integer)
<p>
Is there an algorithm to find, if possible, all integer solutions?imbluedabedeeTue, 20 Feb 2024 16:53:10 +0100https://ask.sagemath.org/question/76116/How to determine if two colorings of a graph are the same?https://ask.sagemath.org/question/76113/how-to-determine-if-two-colorings-of-a-graph-are-the-same/A **coloring** of a graph $G$ with vertex set $V$ is the partitioning of $V$ into so called *color classes* in such a way that no two vertices of the same class are adjacent. A **$k$-coloring** contains exactly $k$ color classes.
We shall think of a $k$-coloring of $G$ as a map $\psi: V \rightarrow\{1,2, \ldots, k\}$ such that $\psi^{-1}(i), i=1,2, \ldots, k$, are the color classes of $G$. Naturally two maps, $\psi_1$ and $\psi_2$, represent the **same $k$-coloring** if and only if $\psi_1=\psi_2 \circ \pi$ for some permutation $\pi$ of $\{1,2, \ldots, k\}$. (See details in B. Bollobás Uniquely colorable graphs[J]. Journal of Combinatorial Theory, Series B, 1978, 25: 54-61.)
**My goal is:** given a graph with two $k$-colorings, I want to determine if they are same. I am unsure which function to use. I also want to determine how many different $k$-colorings of a graph in this sense.
For example,
from sage.graphs.graph_coloring import all_graph_colorings
G = Graph([('a','b'),('a','d'),('b','c'),('c','d'),('a','c')])
for C in all_graph_colorings(G, 3):
print(C)
{0: ['a'], 1: ['b', 'd'], 2: ['c']}
{0: ['a'], 1: ['c'], 2: ['b', 'd']}
{0: ['b', 'd'], 1: ['a'], 2: ['c']}
{0: ['c'], 1: ['a'], 2: ['b', 'd']}
{0: ['b', 'd'], 1: ['c'], 2: ['a']}
{0: ['c'], 1: ['b', 'd'], 2: ['a']}
We obtained six $3$-colorings, and are they the same by definition of same $k$-coloring?
After that, I would like to obtain all uniquely colorable simple graphs up to 10 vertices. See https://oeis.org/A369223 corresponding to their counts.
> Additional information:
>The chromatic number of $G$, denoted by $\chi(G)$, is the minimal $k$
> for which $G$ has a $k$-coloring. A graph with exactly one
> $k$-coloring is called uniquely $k$-colorable. It is obvious that if
> $G$ is uniquely $k$-colorable then $\chi(G)=k$ or $n$, so we shall say
> simply that $G$ is uniquely colorable if it is uniquely $\chi(G)$
> colorable.
[1]: https://i.stack.imgur.com/9z0OO.pnglichengTue, 20 Feb 2024 11:32:41 +0100https://ask.sagemath.org/question/76113/Ideals of $\mathbb Z[x]$https://ask.sagemath.org/question/76119/ideals-of-mathbb-zx/I think the following code should output `True` instead of `False` because we have $1 = (1-2x)+2x \in I$:
R.<x> = ZZ[]
I = R.ideal(1-2*x,2)
I.is_trivial()ThrashTue, 20 Feb 2024 18:11:24 +0100https://ask.sagemath.org/question/76119/Matrix norm using sup normhttps://ask.sagemath.org/question/76114/matrix-norm-using-sup-norm/ Hi all,
I want to make some modifications in the matrix norm. I'm trying to find $\sup_{x\neq0} \frac{\lVert Ax \rVert}{\lVert x \rVert}$
with different norms defined over denominator and numerator. As all other norms are defined I'm just curious about the source codes of them and also interested to see how to get the supremum or infimum in sage where $x\in V$ where V is a vector space.KaunilTue, 20 Feb 2024 12:57:19 +0100https://ask.sagemath.org/question/76114/Could FLINT/ARB-functions be run multi-threaded under Sage?https://ask.sagemath.org/question/76105/could-flintarb-functions-be-run-multi-threaded-under-sage/A number of FLINT/ARB functions, for instance the integral, could be sped up considerably by simply including this command in FLINT/ARB C-program:
flint_set_num_threads(N);
with N the number of the desired threads/available cores.
Is a similar command available when using FLINT/ARB through SageMath? RuudHTue, 20 Feb 2024 00:29:27 +0100https://ask.sagemath.org/question/76105/