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, 25 Jun 2020 13:05:25 +0200List of variables as function argumentshttps://ask.sagemath.org/question/52217/list-of-variables-as-function-arguments/ I would like to define a function that takes a 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:03:48 +0200https://ask.sagemath.org/question/52217/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/Define function over symbolic ringhttps://ask.sagemath.org/question/37524/define-function-over-symbolic-ring/I want to define a function over a dynamic number of variables, but find no way to coerce list, tuple or string to symbolic ring. Is there some Python / pre-parse / magic which can make this work?
A failed example follows
sage: var( 'x1 x2 x3' )
sage: function('xxx')(x1,x2) # A function of a fixed, pre-programmed number of variables
xxx(x1, x2)
sage: n = 3
sage: ' '.join('x'+str(i+1) for i in range(n)) # A string
'x1 x2 x3'
sage: eval( ' '.join('x'+str(i+1)+',' for i in range(n)) ) # A tuple
(x1, x2, x3)
sage: function('yyy')( eval( ' '.join('x'+str(i+1)+',' for i in range(n)) ) )
Traceback (most recent call last):
...
TypeError: cannot coerce arguments: no canonical coercion from <type 'tuple'> to Symbolic RingRichard_LSat, 06 May 2017 01:56:28 +0200https://ask.sagemath.org/question/37524/How to define Sage function with Optional arguments?https://ask.sagemath.org/question/35192/how-to-define-sage-function-with-optional-arguments/I need to define a Sage function with optional arguments.
The number of mandatory arguments is 2 and there are up to 3 optional arguments.
How do I do this is Sage?VovaWed, 19 Oct 2016 20:56:35 +0200https://ask.sagemath.org/question/35192/How to create a Sage directory of all functions?https://ask.sagemath.org/question/9904/how-to-create-a-sage-directory-of-all-functions/Can one easily get the list of all defined functions in Sage to something like a directory including at least following information:
[
* function name
* allowed input argument numbers (possibly several)
* allowed input argument types for each allowed input argument
* function result values numbers (possibly several depending on input arguments)
* function result values types for each result value
,
* next similar etc.
]
so that for example one could easily construct an expression-set having all allowed functions in function argument places up to a given level?
For example:
Expression-set for 3 levels is something like:
[
sin(cos(x))
sin(sin(x))
sin(tan(x))
sin(x^a)
(x^a)^b
myfun(sin(k),cos(n))
etc.
];
(All combinations. Here only 3 levels given as an example. Here function myfun may have several return variables each can be a variable, vector, matrix, function name etc.)
JPITue, 12 Mar 2013 10:47:33 +0100https://ask.sagemath.org/question/9904/