1 | initial version |
I played with this a little, and I think I've been able to at least focus the problem a little more (using your f
above):
sage: lambdas = [lambda x,y:f(x,y,t) for t in [0,1]]
sage: lambdas[0](.5,.5)
e^(-1)*sin(0.500000000000000*pi)^2
sage: lambdas[1](.5,.5)
e^(-1)*sin(0.500000000000000*pi)^2
So one aspect of the problem seems to be that the second lambda is overwriting the first
2 | checked code in python instead of sage |
I played with this a little, and I think I've been able to at least focus the problem a little more (using your f
above):
sage: lambdas = [lambda x,y:f(x,y,t) for t in [0,1]]
sage: lambdas[0](.5,.5)
e^(-1)*sin(0.500000000000000*pi)^2
sage: lambdas[1](.5,.5)
e^(-1)*sin(0.500000000000000*pi)^2
So one aspect of the problem seems to be that the second lambda is overwriting the firstfirst..
UPDATE:
Oh wow -- this is a python bug!
>>> lambdas = [lambda x,y: x*y*t for t in [1,2]]
>>> lambdas[0](2,3)
12
>>> lambdas[1](2,3)
12
3 | nested lambda functions |
I played with this a little, and I think I've been able to at least focus the problem a little more (using your f
above):
sage: lambdas = [lambda x,y:f(x,y,t) for t in [0,1]]
sage: lambdas[0](.5,.5)
e^(-1)*sin(0.500000000000000*pi)^2
sage: lambdas[1](.5,.5)
e^(-1)*sin(0.500000000000000*pi)^2
So one aspect of the problem seems to be that the second lambda is overwriting the first..
UPDATE:
Oh wow -- this is a python bug!
>>> lambdas = [lambda x,y: x*y*t for t in [1,2]]
>>> lambdas[0](2,3)
12
>>> lambdas[1](2,3)
12
UPDATE 2:
This morning I realized how to work around this problem: use nested lambda functions!
A python example:
>>> f = lambda t: lambda x,y: x*y*t
>>> f(2)(2,3)
12
>>> f(1)(2,3)
6
And a 3d plot example:
def f(x,y,t): return(sin(pi*x)*sin(pi*y)*e^(-t))
base_frame = point3d((.5,.5,1), color='red', size=10)
L = lambda t: lambda x,y: f(x,y,t)
var('x,y')
(x, y)
frames = [plot3d(L(t)(x,y), (x, 0, 1), (y, 0, 1))+base_frame for t in [0,1]]
frames[0]
frames[1]
4 | pep 227 |
I played with this a little, and I think I've been able to at least focus the problem a little more (using your f
above):
sage: lambdas = [lambda x,y:f(x,y,t) for t in [0,1]]
sage: lambdas[0](.5,.5)
e^(-1)*sin(0.500000000000000*pi)^2
sage: lambdas[1](.5,.5)
e^(-1)*sin(0.500000000000000*pi)^2
So one aspect of the problem seems to be that the second lambda is overwriting the first..
UPDATE:
Oh wow -- this is a python bug!bug! (Or is it a feature? PEP 227 seems to address something relevant; note especially the "Discussion" and "Examples" sections)
>>> lambdas = [lambda x,y: x*y*t for t in [1,2]]
>>> lambdas[0](2,3)
12
>>> lambdas[1](2,3)
12
UPDATE 2:
This morning I realized how to work around this problem: use nested lambda functions!
A python example:
>>> f = lambda t: lambda x,y: x*y*t
>>> f(2)(2,3)
12
>>> f(1)(2,3)
6
And a 3d plot example:
def f(x,y,t): return(sin(pi*x)*sin(pi*y)*e^(-t))
base_frame = point3d((.5,.5,1), color='red', size=10)
L = lambda t: lambda x,y: f(x,y,t)
var('x,y')
(x, y)
frames = [plot3d(L(t)(x,y), (x, 0, 1), (y, 0, 1))+base_frame for t in [0,1]]
frames[0]
frames[1]