To elaborate...
I've half solved my problem, but here is a more detailled example. I would like the user to have the possibility to get (get_functions method) and to see (info method) the explicit expressions of the created functions into the class, but <lambda + adress> is somewhat cryptic. The problem is now : how can I convert a lamba expression into a : 'sage.symbolic.expression.Expression' ?
Thanks.from sage.functions.piecewise import Piecewise
from sage.symbolic.constants import pi
from sage.symbolic.ring import var
class C:
def __init__(self):
x = var('x')
self.__f = lambda x: pi
self.__g = Piecewise((((0, 1), x**2), ((1, 2), lambda x: 10)))
def get_f_value(self, x):
return self.__f(x)
def get_g_value(self, x):
return self.__g(x)
def get_functions(self):
return (self.__f, self.__g)
def info(self):
print 'funct 1:', self.__f
print 'funct 2:', self.__g
Sage session :
> from C import C
> c = C()
> c.get_f_value(1), c.get_g_value(0.5), c.get_g_value(1.5) # OK, it works.
< (pi, 0.250000000000000, 10)
>
c.info()
< funct 1: <function <lambda> at 0x4acef50>
< funct 2: Piecewise defined function with 2 parts, [[(0, 1), x^2], [(1, 2), <function <lambda> at 0x4acf848>]]
> c.get_functions()
< (<function <lambda> at 0x4acef50>, Piecewise defined function with 2 parts, [[(0, 1), x^2], [(1, 2), <function <lambda> at 0x4acf848>]])