Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function arithmetic library for python

I'm searching for a library that will let me manipulate functions with the standard operators (*, -, *, /, etc.).

Lets suppose you have a function f(x) = x ** 2 and g(x) = x + 2. I'd like to be able to write f * g and get a new functor that is essentialy x ** 2 * (x + 2) or f(g) and get (x + 2) ** 2.

I know this is not too hard to implement, you'll just have to make a Functor class and overload it's __call__ function, but I'm hoping there is a 3rd party library for it.

I'm not trying to use this for anything heavyweight just for learning. Thanks for the help.

like image 849
terminus Avatar asked Nov 29 '10 22:11

terminus


People also ask

What is the math library in Python?

Introduction. The Python Math Library provides us access to some common math functions and constants in Python, which we can use throughout our code for more complex mathematical computations. The library is a built-in Python module, therefore you don't have to do any installation to use it.

Where is the Python math library?

You can find them (at least on linux) in a subfolder of the lib-folder called lib-dynload. The math module is then in a file math.cpython-33m.so (on windows probably with . dll instead of . so ).

Which library is used for mathematical operations?

The numpy library in Python is most widely used for carrying out mathematical operations that involve matrices.


1 Answers

Sympy should do what you want.

like image 168
Rafe Kettler Avatar answered Oct 26 '22 02:10

Rafe Kettler