# Developers Planet

HeLi8 February 2016

### What is the mathematical operation called that performs all possible operations on two variables and how would I do this in python?

given two variables x,y what is the mathematical operation called that would recursivley perform:

``````y=y+x
y=y-x
y=y*x
y=y/x
y=y**x
y=y**1/x
...
``````

And is it possible to itterate through the methods in the math object in python performing them on x,y values?

``````    for i in range(1,10):
for method in math:
return math.method(i)?
``````

Scott February 2016

There are an infinite number of possible operations on two variables. In fact, there are an uncountable number of functions on two variables (or one variable for that matter). This means that it is provably impossible to recursively enumerate them.

It is, however, possible to pick some enumerable subset of all possible functions and then iterate over those. For example, the set of integer-coefficient polynomials of two variables. If you have a set in mind, we can help you enumerate them.

sabbahillel February 2016

9.9. operator — Standard operators as functions shows a list of the functions in `import operator` that will name functions that can be used in place of various operators (such as `add`). Create a list containing these operator functions and loop through the list. Note that you must be careful to treat the one argument and two argument functions seperately so as to avoid a fatal error when you call them.

The operator module exports a set of efficient functions corresponding to the intrinsic operators of Python. For example, operator.add(x, y) is equivalent to the expression x+y. The function names are those used for special class methods; variants without leading and trailing __ are also provided for convenience.

The functions fall into categories that perform object comparisons, logical operations, mathematical operations, sequence operations, and abstract type tests.