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, 07 Jan 2017 16:10:59 +0100Function dependence flexibilityhttps://ask.sagemath.org/question/36209/function-dependence-flexibility/I'd like to declare an unknown function f. If I had one variable x, I would write
f=function('f')(x)
Instead, I would like to declare this function with a variable list (or tuple) that has unknown length at the beginning of the program. For example,
f=function('f')(x,y)
has two variables or
f=function('f')(x,y,t)
has three.
I can get a list (or tuple) containing my variables just before the function declaration:
vars=[x,y,z,t]
Then how can I declare my function like
f=function('f')(vars)
?
Sat, 07 Jan 2017 09:15:17 +0100https://ask.sagemath.org/question/36209/function-dependence-flexibility/Answer by tmonteil for <p>I'd like to declare an unknown function f. If I had one variable x, I would write</p>
<pre><code>f=function('f')(x)
</code></pre>
<p>Instead, I would like to declare this function with a variable list (or tuple) that has unknown length at the beginning of the program. For example,</p>
<pre><code>f=function('f')(x,y)
</code></pre>
<p>has two variables or</p>
<pre><code>f=function('f')(x,y,t)
</code></pre>
<p>has three. </p>
<p>I can get a list (or tuple) containing my variables just before the function declaration:</p>
<pre><code>vars=[x,y,z,t]
</code></pre>
<p>Then how can I declare my function like</p>
<pre><code>f=function('f')(vars)
</code></pre>
<p>?</p>
https://ask.sagemath.org/question/36209/function-dependence-flexibility/?answer=36212#post-id-36212You have to "remove the brackets" of your list, so that the input of `function` is not a single list of four symbols, but four symbols (note the star before `vars`):
sage: f=function('f')(*vars)
sage: f
f(x, y, z, t)
Sat, 07 Jan 2017 14:22:55 +0100https://ask.sagemath.org/question/36209/function-dependence-flexibility/?answer=36212#post-id-36212Comment by implicitnone for <p>You have to "remove the brackets" of your list, so that the input of <code>function</code> is not a single list of four symbols, but four symbols (note the star before <code>vars</code>):</p>
<pre><code>sage: f=function('f')(*vars)
sage: f
f(x, y, z, t)
</code></pre>
https://ask.sagemath.org/question/36209/function-dependence-flexibility/?comment=36213#post-id-36213Thank you, that works!Sat, 07 Jan 2017 15:04:11 +0100https://ask.sagemath.org/question/36209/function-dependence-flexibility/?comment=36213#post-id-36213Comment by tmonteil for <p>You have to "remove the brackets" of your list, so that the input of <code>function</code> is not a single list of four symbols, but four symbols (note the star before <code>vars</code>):</p>
<pre><code>sage: f=function('f')(*vars)
sage: f
f(x, y, z, t)
</code></pre>
https://ask.sagemath.org/question/36209/function-dependence-flexibility/?comment=36215#post-id-36215^_^ .Sat, 07 Jan 2017 16:10:59 +0100https://ask.sagemath.org/question/36209/function-dependence-flexibility/?comment=36215#post-id-36215