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

2020-02-25 Thread David Mertz
I can imagine the hypothetical binary tilde being pretty for some kind of equivalence. This is definitely not enough to motivate me to actually want to add it. But I think this would read OK as equivalent: numpy.allclose(arr1, arr2) arr1 ~ arr2 However, the problem is that there are lot

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

2020-02-25 Thread Oscar Benjamin
On Mon, 24 Feb 2020 at 17:47, Aaron Hall via Python-ideas wrote: > > 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),"

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

2020-02-24 Thread Eric V. Smith
On 2/24/2020 2:59 PM, Guido van Rossum wrote: The biggest problem remains that 99% of your explanation (and that of others who seem to understand what you want) uses the words of the application domain (statistics, stochastic variables, distributions) in a way that is unhelpful to convey your n

[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 David Mertz
I may have led in that direction, and I know R only passingly, not well. But my understanding is that thinking of a data structure that gets parsed by an evaluator, e.g. "do a linear regression with this structure (and a DataFrame)" is better than a lambda. I'm sure it's possible to describe this

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

2020-02-24 Thread Jim Baker
I am no expert on R, but R lazily evaluates arguments to functions; see https://cran.r-project.org/doc/manuals/r-devel/R-lang.html#Argument-evaluation (plus the rest of that page, which is the language spec). Tilde is strictly used for modeling. Also relevant would be the operator precedence https:

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

2020-02-24 Thread Serhiy Storchaka
24.02.20 22:02, Guido van Rossum пише: Hm, that's actually an interesting take. Can you compare it to the kind of "quoting" that happens in a lambda? Is there some kind of translation of the OP's original example (Lottery ~ Literacy + Wealth + Region) to a lambda involving those words? I thin

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

2020-02-24 Thread Guido van Rossum
On Mon, Feb 24, 2020 at 11:00 AM David Mertz wrote: > Well... also, the meaning in R is quite a bit different from any of the > meanings suggested by Wolfram. In fact, although the most common use in R > is "depends on", it's technically just a generic delayed evaluation without > any inherent s

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

2020-02-24 Thread Dominik Vilsmeier
But that behavior is specific to Jupyter and so it could similarly provide auto-complete or syntax highlighting for usage of `smf.ols(formula=...)`. Like PyCharm provides syntax highlighting for strings used as the `pattern` argument for the various functions of the `re` module. So if it's only fo

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

2020-02-24 Thread Guido van Rossum
The biggest problem remains that 99% of your explanation (and that of others who seem to understand what you want) uses the words of the application domain (statistics, stochastic variables, distributions) in a way that is unhelpful to convey your needs to those who are in a position to implement a

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

2020-02-24 Thread David Mertz
Well... also, the meaning in R is quite a bit different from any of the meanings suggested by Wolfram. In fact, although the most common use in R is "depends on", it's technically just a generic delayed evaluation without any inherent semantics at all. Or, that is to say, tilde is just a certain

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

2020-02-24 Thread jdveiga
Aaron Hall wrote: > 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 (r

[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-24 Thread Brandt Bucher
This seems like a feature looking for a use-case. I don't think the use case presented is good enough, since in this thread I've seen it given three incompatible operator priorities (higher than `+`, lower than `+`, and one that seems to be a sort of assignment?) and a handful of loosely relate

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

2020-02-24 Thread Dominik Vilsmeier
On 24.02.20 13:24, Rhodri James wrote: This seems a lot like trying to shoehorn something in so one can write idiomatic R in Python.  That on the whole sounds like a bad idea; a friend of mine use to say he could write FORTRAN in any language but no one else could read it.  Wouldn't it be more p

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

2020-02-24 Thread Dominik Vilsmeier
I don't see what's wrong with the status quo:     smf.ols(formula='Lottery ~ Literacy + Wealth + Region', data=df) If I understand correctly you want to use instead:     smf.ols(formula=df.Lottery ~ df.Literacy + df.Wealth + df.Region) Or since some people favor indexing over attribute access

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

2020-02-24 Thread David Mertz
In mathematics, in my recollection, the tilde is used for 1. Unary approximate number 2. Binary equivalence 3. Binary congruence/isomorphism The last is more formally an equal sign with tilde on top: ≅. I think maybe just simplified for chalk boards where context makes it clear. Those are all aki

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

2020-02-24 Thread Richard Damon
On 2/24/20 7:24 AM, Rhodri James wrote: This seems a lot like trying to shoehorn something in so one can write idiomatic R in Python.  That on the whole sounds like a bad idea; a friend of mine use to say he could write FORTRAN in any language but no one else could read it.  Wouldn't it be mo

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

2020-02-24 Thread Rhodri James
On 24/02/2020 00:59, Brendan Barnwell wrote: On 2020-02-23 16:32, Guido van Rossum wrote: > Assuming that the reader is familiar with the example `Lottery ~ > Literacy + Wealth + Region` is *not* going to work. I have literally no > idea from what field that is taken or what the purpose of the

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

2020-02-24 Thread Serhiy Storchaka
24.02.20 02:27, 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 ne

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

2020-02-23 Thread Brendan Barnwell
On 2020-02-23 19:35, Aaron Hall via Python-ideas wrote: My main goal here is to increase the flexibility of Python for various domains where I have used `object0 ~ object1` - and can't yet do so in Python. You've said something like this a couple times in this thread, but personally I don't f

[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 David Mertz
Aside from all the other problems, 'sim' (~) in LaTeX and mathematics means something completely different than 'depends on' (~) in R. Trying to overload those meaning makes everything harder. I would recommend doing what NumPy did for many years for matrix multiply. Use an existing operator. Yes

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

2020-02-23 Thread Guido van Rossum
Are you a contributor or core dev on one of those packages? That would be useful context to have. Also, did you see Jim Baker's module? How do you propose to translate Patsy's ':' operator? On Sun, Feb 23, 2020 at 5:22 PM Aaron Hall via Python-ideas < python-ideas@python.org> wrote: > > Is there

[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 Brendan Barnwell
On 2020-02-23 15:58, Aaron Hall via Python-ideas wrote: (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, x

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

2020-02-23 Thread Guido van Rossum
Aaron, It's too soon to start drafting a PEP. However you need to get at least one core dev to understand your proposal well enough that they will act as a *sponsor* for your proposal. Once you have a willing sponsor you can then put it forward in PEP form. See PEP 1 for PEP sponsorship when the a

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

2020-02-23 Thread Jim Baker
Supporting ~ as a binary operator is an interesting idea, especially given the relatively limited usage of unary ~. However, the big hole in this proposal for formulas is that there is a de facto standard "minilanguage" for writing such formulas in Python, namely what Patsy supports: https://patsy.

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

2020-02-23 Thread Brendan Barnwell
On 2020-02-23 16:32, Guido van Rossum wrote: > Assuming that the reader is familiar with the example `Lottery ~ > Literacy + Wealth + Region` is *not* going to work. I have literally no > idea from what field that is taken or what the purpose of the example > is. Please don't expect that I can jus

[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 jdveiga
Aaron Hall wrote: > 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

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

2020-02-23 Thread Guido van Rossum
I still can't follow this explanation. Operators in Python have a priority, which determines order of evaluation. In the example A ~ B + C is this equivalent to A ~ (B + C) or to (A ~ B) + C ??? It's not unheard of to add an operator to Python that's primarily important for a certain

[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 Brendan Barnwell
On 2020-02-23 16:00, João Matos wrote: Hello, Can't you use eval()? This return eval(expr) instead of return expr.evaluate() You can use eval if expr is a string, but then you have the same problems that were mentioned in a recent thread about "SQL strings": it's not syntax-highlighted, s

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

2020-02-23 Thread João Matos
Hello, Can't you use eval()? This return eval(expr) instead of return expr.evaluate() Best regards, João Matos On 23/02/2020 23:04, Brendan Barnwell wrote: On 2020-02-23 14:38, Steven D'Aprano wrote: Hi Aaron, and welcome! Your proposal would be a lot more interesting to me if I knew wha

[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] Re: Make ~ (tilde) a binary operator, e.g. __sim__(self, other)

2020-02-23 Thread Brendan Barnwell
On 2020-02-23 14:38, Steven D'Aprano wrote: Hi Aaron, and welcome! Your proposal would be a lot more interesting to me if I knew what this binary ~ would actually do, without having to go learn R or LaTeX. You say: I think it would be awesome to have in the language, as it would allow modelli

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

2020-02-23 Thread Steven D'Aprano
Hi Aaron, and welcome! Your proposal would be a lot more interesting to me if I knew what this binary ~ would actually do, without having to go learn R or LaTeX. You say: > I think it would be awesome to have in the language, as it would allow > modelling along the lines of R that we currently

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

2020-02-23 Thread Serhiy Storchaka
23.02.20 23:51, Aaron Hall via Python-ideas пише: This is not a fully baked idea, perhaps there's a good reason we haven't added a binary `~`.  It seems like I've seen discussion in the past. But I couldn't find such discussion. And as I'm currently taking some statistics courses, I'm getting R