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, 18 Dec 2020 03:46:59 +0100Quickly recalling the definition of a temporary function to make minor edits?https://ask.sagemath.org/question/54736/quickly-recalling-the-definition-of-a-temporary-function-to-make-minor-edits/Suppose you're working with the sage console primarily as a calculator, and define some temporary shorthand function, such as,
sage: R = GF(751)
sage: def f(x):
....: return R(x^3-x+188)
After I've used this `f` several times, I may want to change the output to something similar, like `x^3-x+376`. Is there a quick way to recall the definition of `f` within the console so that I can edit in the minor change, instead of having to define a new function?vikahdv@gmail.comFri, 18 Dec 2020 03:46:59 +0100https://ask.sagemath.org/question/54736/List of variables as function argumentshttps://ask.sagemath.org/question/52218/list-of-variables-as-function-arguments/ I would like to define a function that takes an arbitrary long list of variables as input and some complicated expression of my variables as my output, but I just don't seem to be able to make it work.
Something along the line of:
var('x_1,x_2,x_3')
long_list_of_variables = [x_1, x_2,x_3]
complicated_expression=(x_1^2+x_2^2-x_3)^2
f(tuple(long_list_of_variables))=complicated_expression
But with much more variables.
I've tried different variations of this but I always seem to end up with the 'can't assign to function call'-error.
Are there any way to achieve what I'm trying to do?ubeThu, 25 Jun 2020 13:05:25 +0200https://ask.sagemath.org/question/52218/Import Functions defined in fileshttps://ask.sagemath.org/question/45124/import-functions-defined-in-files/How to load a file with
- functions?
Is there any documentation on this?
What happens if there are some variables also defined in this file.
thethaMon, 21 Jan 2019 14:55:12 +0100https://ask.sagemath.org/question/45124/Create multivariate function of a list of variableshttps://ask.sagemath.org/question/41185/create-multivariate-function-of-a-list-of-variables/I have created a list of variables, `myvars`
I'd like to create a function of those variables, but
myvars = var('x y z')
f = function('f')(myvars)
doesn't work.
Of course in my actual code I'm creating `myvars` programatically, so doing
f = unction('f')(myvars[0], myvars[1], myvars[2])
is not convenientMLainzMon, 19 Feb 2018 19:45:29 +0100https://ask.sagemath.org/question/41185/define function on two setshttps://ask.sagemath.org/question/39472/define-function-on-two-sets/ Hi.
I have two sets: X, Y. I want to define a function
F : X ->Y
and I have the values of f(x). I searched the net but found nothing. thanks.hosseinmp76Fri, 10 Nov 2017 09:53:26 +0100https://ask.sagemath.org/question/39472/Function with Matrix inputhttps://ask.sagemath.org/question/31787/function-with-matrix-input/ Hello Guys i have the following problem.
I want to write a function whose input is a Matrix. A small example:
def Dimension(Matrix):
n = Matrix.nrows()
return n
A = ([1,0,0],[0,1,0],[0,0,1])
print Dimension(A)
but then i get :
AttributeError: 'tuple' object has no attribute 'nrows'
How can I write i function that has an Matrix as input?bruno171092Wed, 23 Dec 2015 10:55:33 +0100https://ask.sagemath.org/question/31787/defining function for graph (help needed)https://ask.sagemath.org/question/9859/defining-function-for-graph-help-needed/I need help defining a function that does the following (I'm very new to Python/Sage).
I need a function called ihara(G) where G is any graph input by the user.
I need the function ihara(G) to return the Z resulting from all the calculations below:
D = G.to_directed()
L = D.line_graph()
L.delete_edges([((x,y,None), (y,x,None)) for x,y in G.edges( labels=None)])
L.delete_edges([((x,y,None), (y,x,None)) for y,x in G.edges( labels=None)])
IM = identity_matrix(QQ,D.size())
T = L.adjacency.matrix()
var('u')
X = IM-u*T
Z = X.det()
Could anybody help me with this? or at least get me started in the right direction...jtaaWed, 27 Feb 2013 14:14:51 +0100https://ask.sagemath.org/question/9859/nilpotent adjacency matrixhttps://ask.sagemath.org/question/9870/nilpotent-adjacency-matrix/i wish to define a nilpotent adjacency matrix.
example vertex adjacency matrix of a graph ($K_4$ minus an edge) is
A=
[0 1 1 0]
[1 0 1 1]
[1 1 0 1]
[0 1 1 0]
where N=4 vertices
so for all entries $A_{ij}$ i wish to define a function to replace the 1's by $b_j$
so for the example above i get a nilpotent matrix
B=
[0 $b_2$ $b_3$ 0]
[$b_1$ 0 $b_3$ $b_4$]
[$b_1$ $b_2$ 0 1]
[0 $b_2$ $b_3$ 0]
where the $b_j$ where $i,j\in${1,2,3,4} obey the following rules of multiplication:
$b_jb_i=b_ib_j$ and $b_j^2=0$ (so i also need to define a function for these rules)
so for the nilpotent adjacency matrix i can define matrix multiplication using the above rules for its entries i.e. $B^N$
i'd like the function to be something like nil(B,k)
and for it to print the trace of $B^k$
e.g. $nil(B,2)=2b_1b_2+2b_1b_3+2b_2b_3+2b_2b_4+2b_3b_4$
i'll try to work on this myself too in the meantime, but this is probably the most complicated function i've had to do.. mainly due to redefining the adjacency matrixjtaaSun, 03 Mar 2013 08:59:48 +0100https://ask.sagemath.org/question/9870/