Anonymous symbolic functions? [closed]

asked 2016-09-04 16:34:53 -0600

math4tots gravatar image

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!

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by tmonteil
close date 2016-09-05 04:49:36.465359

Comments

Duplicate of https://ask.sagemath.org/question/347... see the answer there.

tmonteil gravatar imagetmonteil ( 2016-09-05 04:49:30 -0600 )edit