PEP: Adding new operators for elementwise/objectwise operations

Huaiyu Zhu hzhu at users.sourceforge.net
Wed Sep 27 20:00:34 EDT 2000


On Wed, 27 Sep 2000 17:03:23 -0400, Tom Loredo
<loredo at spacenet.tn.cornell.edu> wrote: 

>  But if
>they are to be added, I have to say I don't like the choice of
>"~" as the new indicator for the operations.  This symbol is
>currently in wide use in statistics for to indicate "is distributed as."
>Of course, it has other uses in mathematics, but this particular use
>is already widespread in statistical computing for definition

Hi,

The PEP now has a better title "Objectwise/Elementwise Operators".  The idea
is not to assign a specific meaning to individual operators, but rather to
provide a way to distinguish two types of operations.

Yes, ~ is used in mathematics for many meanings, including 'similar',
'proportional to', 'of the same order', in additional to 'distributed as'.
Since the number of Python operators is extremely small compared with
mathematics, it is obviously impossible to accomodate all these.  The only
solution, short of unicode operators, is to provide a broad set of operators
to be overridden in applications.  The new operators only add more choices
to the user.

If you find a need to use ~ as a single operator, it is still allowed in the
same way as the uniary 'bitwise not' operator.  But it was not a binary
operator, and will not be under the PEP.  All working code would continue
working as before.

However, I don't see why an operator is needed to express the idea that a
variable x is distributed as a probability p.  Why not

 isdistributedas(x, p)

or any other names?  You would normally want an operator if the expression
itself is often plugged into a more complicated formula.  In other words, if
all we wanted to say is

  multiply(a,b)

we could do away with the * operator as well.  But the operators are needed
because the composite formulas like

  div(mul(D, add(mul(A,B), C)), E)

would be much easier to write and read using operators, especially with
precedence rules.

Furthermore, I don't think the x~p notation can be well defined in a
composite formula either, because from x~p and y~p you can't infer about
relations between (x, y) without a statement of the joint distribution. Even
if we overload | for statistical indenpendence, this still would not form a
basis for a 'calculus of random variables', so to speak.

>of statistical models in high level modeling"script" style software 
>(e.g., see BUGS: http://www.mrc-bsu.cam.ac.uk/bugs). 

Somehow I couldn't access that page.  So I might have missed the point.

>I am developing
>a statistical computing framework in Python, and may use "~"
>in this already-accepted fashion; I would hate to see its meaning
>"overloaded" this way.

Could you show a line or two of the code for using ~ in this way?
Does it behave any differently with or without the patch?

Huaiyu

PS.  I would also like to hear your comments about the style of the
Stats/distribs module in MatPy.

-- 
Huaiyu Zhu                       hzhu at users.sourceforge.net
Matrix for Python Project        http://MatPy.sourceforge.net 



More information about the Python-list mailing list