[Python-ideas] Re: Make ~ (tilde) a binary operator, e.g. __sim__(self, other)

2020-02-24 Thread Aaron Hall via Python-ideas
Yes, at this point I think I must concede the battle. I thought I had discussed this with core developers in the past, but I couldn't find the results. So here we have it - making `~` a binary operator as well is a no-go. Perhaps some better advocate than I will take it up in the future. Thank

[Python-ideas] Re: Make ~ (tilde) a binary operator, e.g. __sim__(self, other)

2020-02-24 Thread Aaron Hall via Python-ideas
The context for this is statistics , so I'll quote Wolfram on tilde in the context of statistics: http://mathworld.wolfram.com/Tilde.html "In statistics, the tilde is frequently used to mean "has the distribution (of)," for instance, X∼N(0,1) means "the stochastic (random) variable X has the di

[Python-ideas] Re: Make ~ (tilde) a binary operator, e.g. __sim__(self, other)

2020-02-23 Thread Aaron Hall via Python-ideas
Thanks for the feedback, David. Sources that demonstrate that "sim" is the wrong semantic would be very much appreciated. I chose "sim" because it's the same name and usual top usual result for an infixed tilde in LaTeX. And note that there is an implied relationship between the two sides in the

[Python-ideas] Re: Make ~ (tilde) a binary operator, e.g. __sim__(self, other)

2020-02-23 Thread Aaron Hall via Python-ideas
I am not yet a contributor to either, I have an invitation to contribute to Sympy, and I have contributed to CPython, and I would like to be a contributor on all of these libraries (You might know me from my answers on Stack Overflow, and I gave the slots talk at PyCon 2017 where we met - now

[Python-ideas] Re: Make ~ (tilde) a binary operator, e.g. __sim__(self, other)

2020-02-23 Thread Aaron Hall via Python-ideas
Jim, thanks for your feedback. I didn't intend for this to address the interaction term syntax. As you can see the R language has several ways of representing the same information: https://stat.ethz.ch/R-manual/R-devel/library/stats/html/formula.html I would prefer to write, e.g.: `y ~ interac

[Python-ideas] Re: Make ~ (tilde) a binary operator, e.g. __sim__(self, other)

2020-02-23 Thread Aaron Hall via Python-ideas
> Is there an existing function in one of the libraries you mention > that has the desired behavior (in the context of that library)? That would > help. Yes, and we are currently parsing and evaluating strings to convey the meaning. Patsy is currently used by statsmodels to parse strings in the

[Python-ideas] Re: Make ~ (tilde) a binary operator, e.g. __sim__(self, other)

2020-02-23 Thread Aaron Hall via Python-ideas
Guido, thank you so much for your kind review. I think I would prefer ``` (A ~ B) + C ``` as it would first create a coalescing object to which it knows C is added, and this is the usual way it is used. I believe Sympy could handle it easily either way, but dataframes/arrays less well so (sinc

[Python-ideas] Re: Make ~ (tilde) a binary operator, e.g. __sim__(self, other)

2020-02-23 Thread Aaron Hall via Python-ideas
I have no behavior for integers in mind. I would expect high-level libraries to want to implement behavior for it. - sympy - pandas, numpy, sklearn, statsmodels - other mathematically minded libraries (monadic bind or compose?) To do this we need a name. I like `__sim__`. Then we'll need `__rsi

[Python-ideas] Re: Make ~ (tilde) a binary operator, e.g. __sim__(self, other)

2020-02-23 Thread Aaron Hall via Python-ideas
(Apologies for the html email, it was poorly formatted, making my example very difficult to follow. So let me try to give better examples.) With sympy we would be able to create meaningful behavior for: ``` from sympy import symbols y, x1, x2 = symbols('y x1 x2') model = y ~ x1 + x2 model.is_

[Python-ideas] Make ~ (tilde) a binary operator, e.g. __sim__(self, other)

2020-02-23 Thread Aaron Hall via Python-ideas
Currently, Python only has ~ (tilde) in the context of a unary operation (like `-`, with __neg__(self), and `+`, __pos__(self)).  `~` currently calls `__invert__(self)` in the unary context. I think it would be awesome to have in the language, as it would allow modelling along the lines of R that