[Python-ideas] Re: symbolic math in Python

2021-06-01 Thread Neil Girdhar
Oh, and I see you're a sympy developer! I hope I'm not coming across as critical in any way. I love that sympy exists and thought it was a really cool project when I first learned about what it can do. Perhaps we should move our discussion to a "Github discussion" under the sympy Github? We

[Python-ideas] Re: symbolic math in Python

2021-06-01 Thread Neil Girdhar
On Tue, Jun 1, 2021 at 6:28 AM Oscar Benjamin wrote: > > On Tue, 1 Jun 2021 at 10:53, Neil Girdhar wrote: > > > > On Tue, Jun 1, 2021 at 5:39 AM Oscar Benjamin > > wrote: > > > > > > On Tue, 1 Jun 2021 at 05:16, Neil Girdhar wrote: > > > > > > > > Hi Oscar, > > > > > > > > The problem that the

[Python-ideas] Re: symbolic math in Python

2021-06-01 Thread Oscar Benjamin
On Tue, 1 Jun 2021 at 10:53, Neil Girdhar wrote: > > On Tue, Jun 1, 2021 at 5:39 AM Oscar Benjamin > wrote: > > > > On Tue, 1 Jun 2021 at 05:16, Neil Girdhar wrote: > > > > > > Hi Oscar, > > > > > > The problem that the original poster was trying to address with > > > additional syntax is the

[Python-ideas] Re: symbolic math in Python

2021-06-01 Thread Neil Girdhar
On Tue, Jun 1, 2021 at 5:39 AM Oscar Benjamin wrote: > > On Tue, 1 Jun 2021 at 05:16, Neil Girdhar wrote: > > > > Hi Oscar, > > > > The problem that the original poster was trying to address with > > additional syntax is the automatic naming of symbols. He wants to > > omit this line: > > > > x

[Python-ideas] Re: symbolic math in Python

2021-06-01 Thread Oscar Benjamin
On Tue, 1 Jun 2021 at 05:16, Neil Girdhar wrote: > > Hi Oscar, > > The problem that the original poster was trying to address with > additional syntax is the automatic naming of symbols. He wants to > omit this line: > > x = symbols("x") > > You're right that if you have many one-character

[Python-ideas] Re: symbolic math in Python

2021-05-31 Thread Oscar Benjamin
On Mon, 31 May 2021 at 13:10, Neil Girdhar wrote: > > Have you considered using the JAX library's trick of decorating functions to > provide automatic symbols? > > For example, your problem could be done in current Python with an > appropriately-coded library: > > @symbolic > def f(x, a, b, c):

[Python-ideas] Re: symbolic math in Python

2021-05-31 Thread Neil Girdhar
Have you considered using the JAX library's trick of decorating functions to provide automatic symbols? For example, your problem could be done in current Python with an appropriately-coded library: @symbolic def f(x, a, b, c): return a * x ** 2 + b * x + c sentinel = Sentinel()

[Python-ideas] Re: symbolic math in Python

2021-05-26 Thread Sergey B Kirpichev
> Although nothing in Python prevents defining __eq__() how you want and > having it return other values can still be problematic to do so > because of the way that __eq__() is tied to __hash__() and used in > dicts and sets. I think, this can work if you guarantee there are no hash collisions.

[Python-ideas] Re: symbolic math in Python

2021-05-25 Thread Oscar Benjamin
On Tue, 25 May 2021 at 13:31, Sergey B Kirpichev wrote: > > > >>> solve(x**2 == 1/2) > > as you might notice, this is fully legal Python syntax. Unfortunately > > the semantics is such that sympy has no way to determine what is > > actually going on, this is why they invented all those helper > >

[Python-ideas] Re: symbolic math in Python

2021-05-25 Thread Sergey B Kirpichev
> >>> solve(x**2 == 1/2) > >>> > >>> > as you might notice, this is fully legal Python syntax. Unfortunately >

[Python-ideas] Re: symbolic math in Python

2021-05-25 Thread Steven D'Aprano
On Mon, May 24, 2021 at 09:49:13PM -, Joren wrote: > It's unfortunate that there is no way to have e.g. `'spam' in > my_symbolic_set` evaluate to something else than a boolean. Also, this > approach will not work with everything else for which there is no > dunder method, e.g.

[Python-ideas] Re: symbolic math in Python

2021-05-24 Thread Joren
Aside from the type conversion dunders (e.g. `__bool__`), and the `and`, `or` and `in` operators, this is possible right now: You can create a `Symbol` class that returns another `Symbol` in the compatible operator dunder methods, while internally maintaining a list of (operator, args,

[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread Oscar Benjamin
On Wed, 19 May 2021 at 07:41, Martin Teichmann wrote: > > Hi list, > > as you might have noticed, I am trying to improve the syntax and semantics > for symbolic math in Python. Until now, I have to say, my ideas were not that > well received, but I learned from the discussion and maybe this

[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread Shreyan Avigyan
People always come up with hacks like Ir. Robert Vanden Eynde has come up with the vertical bar hack. This is why I feel there's no need to have additional performance decrease and new syntax only to solve a little problem that occurs in some third party like sympy.

[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread David Lowry-Duda
> Oh no, not the vertical bar hack. :-( This is my first time seeing the vertical bar hack. I guess this is something that has appeared before? - DLD ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to

[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread Guido van Rossum
Oh no, not the vertical bar hack. :-( ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at

[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread Ir. Robert Vanden Eynde
> solve(x**2 == 1/2) pip install funcoperators >>> solve(x ** 2 |Equals| 1/2) <<< Equals = infix(Eq) <<< from sympy import Eq Le mer. 19 mai 2021 à 08:40, Martin Teichmann a écrit : > Hi list, > > as you might have noticed, I am trying to improve the syntax and semantics > for symbolic math

[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread Ir. Robert Vanden Eynde
SUB Hello everyone, what is the usual way to "like" a mail in the maillist and subscribing to the thread ? By sending a message it adds me to the "Participants" in the webapp which is neat (I can then search for my messages) I could do it in the webapp but not everybody will see it Le mer. 19

[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread David Lowry-Duda
> To frame the problem, let us try to solve the equation x ** 2 == 1/2 > using sympy: > > >>> from sympy import Eq, solve, symbols, S > >>> x = symbols("x") > >>> solve(Eq(x**2, S(1)/2)) > [-sqrt(2)/2, sqrt(2)/2] > > that worked well, but actually we would like to write the

[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread André Roberge
On Wed, May 19, 2021 at 8:14 AM Ricky Teachey wrote: > It's a neat idea but I agree with the others that as proposed, it's > probably too focused on turning python into a better mathematics tool, > rather than turning python into a better programming language. > > That being said, from a more

[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread Shreyan Avigyan
I'm +1 on the idea but -1 on the proposed syntax. Yes it would be kind of nice *but* it's not how Python arithmetic or grammar works. And why should Python have that functionality? AFAICT Python doesn't have a module in stdlib for symbolic math. This looks like a feature request to third party

[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread Ricky Teachey
It's a neat idea but I agree with the others that as proposed, it's probably too focused on turning python into a better mathematics tool, rather than turning python into a better programming language. That being said, from a more generalist standpoint I wonder if it would be useful in many

[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread Jonathan Fine
Martin wrote: as you might have noticed, I am trying to improve the syntax and semantics > for symbolic math in Python. Until now, I have to say, my ideas were not > that well received, but I learned from the discussion and maybe this time I > come up with something people like. > For about 10

[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread Paul Moore
On Wed, 19 May 2021 at 07:41, Martin Teichmann wrote: > that worked well, but actually we would like to write the last line simply as > > >>> solve(x**2 == 1/2) > > as you might notice, this is fully legal Python syntax. Unfortunately the > semantics is such that sympy has no way to

[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread Henk-Jaap Wagenaar
On Wed, 19 May 2021 at 07:41, Martin Teichmann wrote: > Hi list, > > To frame the problem, let us try to solve the equation x ** 2 == 1/2 > using sympy: > > >>> from sympy import Eq, solve, symbols, S > >>> x = symbols("x") > >>> solve(Eq(x**2, S(1)/2)) > [-sqrt(2)/2, sqrt(2)/2]