How to determine what called __cmp__ method?

Pearu Peterson pearu at ioc.ee
Sat Oct 21 07:48:48 EDT 2000


On Fri, 20 Oct 2000, Erik Max Francis wrote:

> Pearu Peterson wrote:
> 
> > The question is how to determine inside __cmp__ method where it was
> > called? That is I want to know was it called for evaluating
> > either inequality '<', or '>', or '<=', or ...?
> 
> Why would you need to do that?  The purpose of the __cmp__ method is to
> avoid such issues.  I submit that if you _really_ need to know which
> operation was being requested, there's something wrong with either your
> algorithm, your design, or both.

(some may think that the border of Universe is sky and 
 the possibilities of Python language are limited ;-)

What I am trying to do is to extend Python applicability to do symbolic
calculations.
In symbolic calculations the notion of Assumtion is used in
simplification procedures, or in finding integrals symbolically, etc.
So, I thought that it would be nice to define an Assume object and use
it as follows, for example:

x = Symbol("x")
simplify(Sqrt(x**2))    --> the result may not be `x' (e.g. x is complex, 
                            negative)

but

a = Assume(x > 0)
simplify(Sqrt(x**2),assume=a)    --> the result is surely `x'

or even better

simplify(Sqrt(x**2),assume=x>0)  --> `x'

But because there is no rich comparison in Python, I have to use less
elegant way

a = Assume(Greater(x,0))
simplify(Sqrt(x**2),assume=a)

So, let me repeat David's request: any one willing to work on the patch?
In addition, it would be most useful to have rich versions of
`and',`or',`not' operators (not operators `&',`|',`^', they already are
"rich").

Regards,
	Pearu




More information about the Python-list mailing list