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.Sat, 01 Jul 2023 01:06:12 +0200Defining a graded vector spacehttps://ask.sagemath.org/question/69637/defining-a-graded-vector-space/Hello all. I'm trying to define a (finite) graded vector space using SAGE. I've managed to set up a class which takes names and degrees as input parameters.
Example:
My idea is that if we have names (x,y,z) with degrees (1,1,2), then this is supposed to be Q^2 + Q (taking the base ring to be Q). I am going to be building everything on the category of combinatorial free modules.
I have been struggling to define a method in the element class which is supposed to return the degree of a given expression by taking the maximum of the degrees of all the monomials. I have defined a dictionary (in the parent __init__ definition) which puts the name as key and degree as value. But how can I extract that information from any given arbitrary expression (say, B['x'] + B['y'])?
Example of successful code:
(y+z).degree()
sage: 2
Thanks in advance!adiSat, 01 Jul 2023 01:06:12 +0200https://ask.sagemath.org/question/69637/Defining functions acting on matrix elements?https://ask.sagemath.org/question/38524/defining-functions-acting-on-matrix-elements/Hi guys, how can I define a function able to act on the elements of a matrix, with the matrix being the input to the function? I would like the function to be a callable symbolic expression, which I hear can be differentiated and so on, whereas other entities cannot.
Here's a sample of what I mean:
f(M) = M[0,0]+M[1,1]
that is, the user will ensure that `M` is correctly defined as a matrix of size at least 2x2 before being passed to `f(M)`, but at this stage the symbol `M` is intended just as a dummy variable, similar to `z` in a definition like `g(z) = conjugate(z)`. Unfortunately, my code does not seem to work...
Thank you for your suggestions!AskerMon, 14 Aug 2017 21:58:15 +0200https://ask.sagemath.org/question/38524/problem with list: how to count different elements?https://ask.sagemath.org/question/23310/problem-with-list-how-to-count-different-elements/ Hello experts!
Im working with graphs.
My code is:
import numpy as np
import networkx as nx
M = np.zeros([6,6])
M[0,2]=1
M[2,0]=1
M[2,3]=1
M[3,2]=1
M[2,1]=1
M[1,2]=1
M[4,5]=1
M[5,4]=1
G=nx.Graph(M)
A=nx.node_connected_component(G,2)
Doing that, `A` is a list with all the nodes connected with the node `2`, ie: `A=[0, 1, 2, 3, 2]`
1) Why the element '2' is repeated?
2) If, instead, we use `A=nx.node_connected_component(G,0)`, we get `A=[0, 1, 2, 3]`. In this case: why now the element '0' is not repeated?
3) If we have a list `K=[1,2,3,4,1,1,1]`, and we do `P=list(set(K))`, we get `P=[1,2,3,4]` (doing that we can eliminate the repeated elements in the list). But if I do the same with the list `A` obtained in my code, I get `A=[0, 1, 2, 3, 2]`. Why this doest work?
Please help!
Thanks a lotmresimulatorWed, 09 Jul 2014 16:47:39 +0200https://ask.sagemath.org/question/23310/