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.Mon, 05 Sep 2016 11:49:30 +0200Anonymous symbolic functions?https://ask.sagemath.org/question/34718/anonymous-symbolic-functions/
I'd like to be able to define symbolic functions recursively, for instance like the following:
f(0)(a, b) = a * b
f(n)(a, b) = f(n-1)(a + 2*b, a - b)
g = f(5)
print(g(1, 2))
The above program doesn't run because "f(...)(...) = <expression>" isn't valid sage code.
How do I achieve something similar in sage?
Essentially I want:
f(0)(a, b) = a * b
f(1)(a, b) = (a+b) * (a-b)
f(2)(a, b) = ((a+b) + (a-b)) * ((a+b) - (a-b))
...
I am not very familiar with Sage, and am open to different ways of approaching this. Is there some other abstraction I should look into when I want to work with a recursively defined sequence of functions?
Thank you!Sun, 04 Sep 2016 23:34:53 +0200https://ask.sagemath.org/question/34718/anonymous-symbolic-functions/Comment by tmonteil for <p>I'd like to be able to define symbolic functions recursively, for instance like the following:</p>
<pre><code>f(0)(a, b) = a * b
f(n)(a, b) = f(n-1)(a + 2*b, a - b)
g = f(5)
print(g(1, 2))
</code></pre>
<p>The above program doesn't run because "f(...)(...) = <expression>" isn't valid sage code.</p>
<p>How do I achieve something similar in sage?</p>
<p>Essentially I want:</p>
<pre><code>f(0)(a, b) = a * b
f(1)(a, b) = (a+b) * (a-b)
f(2)(a, b) = ((a+b) + (a-b)) * ((a+b) - (a-b))
...
</code></pre>
<p>I am not very familiar with Sage, and am open to different ways of approaching this. Is there some other abstraction I should look into when I want to work with a recursively defined sequence of functions?</p>
<p>Thank you!</p>
https://ask.sagemath.org/question/34718/anonymous-symbolic-functions/?comment=34727#post-id-34727Duplicate of https://ask.sagemath.org/question/34721/sequence-of-functions/ see the answer there.Mon, 05 Sep 2016 11:49:30 +0200https://ask.sagemath.org/question/34718/anonymous-symbolic-functions/?comment=34727#post-id-34727