1

I have two (many) lambdas:

myFoo = lambda x,y: x + y
mySpecFoo = lambda x: myFoo(x, 1)

I want to print resulting expression for mySpecFoo. smth like

x = var('x')
print(mySpecFoo(x))

and I want to see in output:

lambda x: x + 1

Do you know how to do this? Thank you!

1 Answer 1

3

This is called "symbolic evaluation", and you need some external library to do this, for example SymPy:

>>> import sympy
>>> myFoo = lambda x,y: x + y
>>> mySpecFoo = lambda x: myFoo(x, 1)
>>> x = sympy.var("x")
>>> print mySpecFoo(x) 
1 + x
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, Sage is cool but the shell for windows is still under dev :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.