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.Fri, 13 Jan 2023 02:15:12 +0100Why are the binary trees immutable?https://ask.sagemath.org/question/65894/why-are-the-binary-trees-immutable/The class BinaryTree is immutable. Is there an advantage to this? mrutkuokurFri, 13 Jan 2023 02:15:12 +0100https://ask.sagemath.org/question/65894/Using CombinatorialFreeModulehttps://ask.sagemath.org/question/7659/using-combinatorialfreemodule/Could I please have some help on using CombinatorialFreeModule? I have looked at the documentation and the only examples are free modules on a finite set. I have designed my own class and I now want to work with linear combinations of instances of the class. I have been told that one issue is that instances have to be immutable (so they can be hashed?). The attributes of my class are all integers and tuples (of integers). However I am not sure if this is sufficient.
Let's say I have defined a class G whose attributes are all integers and tuples. Then the idea would be say M = CombinatorialFreeModule(QQ,G) to define the free module on instances of G with rational coefficients. Then if g,h,k are instances of G I would hope to be able to put say a = (2/3)*g + 4*h and b = (-3)*h + 2*k be able to add these and multiply by rational numbers.
For example, a simple (but inefficient) way to calculate the chromatic polynomial of a graph would be to use contraction/deletion. This starts with a graph and finishes with a polynomial but the intermediate stages are formal linear combinations of graphs. Similarly the skein relation approach to link polynomials has intermediate stages which are formal linear combinations of link projections.
BWWWed, 01 Sep 2010 07:30:58 +0200https://ask.sagemath.org/question/7659/Copying a Matrixhttps://ask.sagemath.org/question/40754/copying-a-matrix/I'm trying to take the Singular Value Decomposition of the adjacency matrix of a graph A, but all my "reasonable" attempts at doing so have failed, see the code below.
I believe the problem has something to do with the matrix being immutable, so I've been trying to copy A into a different matrix M and then perform SVD on M. he only thing that I've found to work is to essentially build A from scratch, but there must be a better method.
sage: A=graphs.CycleGraph(3).adjacency_matrix()
#Method 1: Try and get SVD directly from A; gives error at last step.
#sage: A.change_ring(RDF)
#sage: A.SVD()
#Method 2: Try and copy A to a different matrix and then do SVD; gives error at last step.
# sage: M=copy(A)
# sage: M.change_ring(RDF)
# sage: M.SVD()
#Method 3: Build A up again from scratch and then do SVD; works, but is tedious.
sage: M=matrix(RDF,3,3)
sage: for i in [0..2]:
for j in [0..2]:
if(A[i,j]==1):
M[i,j]=1
sage: M.SVD()zorkkoiTue, 23 Jan 2018 19:44:19 +0100https://ask.sagemath.org/question/40754/