Composite function

i like this post (click again to cancel)
0
i dont like this post (click again to cancel)

If I define:

var('x,y,z,t')

g(t) = (t, t^2, t^3)

f(x,y,z) = (2x,y+x+z,yx)

Is there a way for me to define the composite f(g(t)) without going through:

f(g(t)[0],g(t)[1],g(t)[2])

or something equally ugly?

asked Apr 09 '11

BobB gravatar image BobB
1 1 3

updated Apr 09 '11

2 Answers:

i like this answer (click again to cancel)
2
i dont like this answer (click again to cancel)

If you let g be a tuple of expressions involving t you can use the Python * operator to use the tuple entries as your inputs x, y, and z:

sage: g = (t, t^2, t^3)
sage: f = lambda x,y,z: (2*x, y+x+z, y*x)
sage: f(*g)
(2*t, t^3 + t^2 + t, t^3)

If you want to define both g and f as lambda functions you could do:

sage: g = lambda t: (t, t^2, t^3)
sage: f = lambda x,y,z: (2*x, y+x+z, y*x)
sage: f(*g(t))
(2*t, t^3 + t^2 + t, t^3)
link

posted Apr 09 '11

benjaminfjones gravatar image benjaminfjones
2470 3 33 66
http://bfj7.com/
You don't need f to be a lambda function for this; using "f(x,y,z) = (2*x,y+x+z,y*x)" works just fine. John Palmieri (Apr 09 '11)
Thank you for the alternative. For the moment it looks like non-lambda functions work well. I'm not well versed in python and I'd like to make things look as much like mathematical notation as possible. Also, it seems using other properties (methods, functions?) like jacobian and derivative is more straight forward if lambda functions are avoided. BobB (Apr 10 '11)
i like this answer (click again to cancel)
1
i dont like this answer (click again to cancel)

h(t) = f(*g(t))

link

posted Apr 09 '11

Ben Reynwar gravatar image Ben Reynwar
45 1 5
Great! And very quick, thank you. I suppose I would have known that if I knew something about python? Or is * a sage operator of some sort? BobB (Apr 09 '11)
It's a python thing -- see benjaminfjones' answer. John Palmieri (Apr 09 '11)
But it might be nice to have this work without that. See http://trac.sagemath.org/sage_trac/ticket/11180; if someone can come up with a better title for that ticket, be my guest. kcrisman (Apr 11 '11)

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

Tags:

Stats:

Asked: Apr 09 '11

Seen: 113 times

Last updated: Apr 09 '11

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.