[Python-ideas] Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Martin Teichmann
Hi List, some days ago I posted about my idea let integer division result in fractions, not floats. The upshot of the discussion was that it is a pity that we do not have literals for fractions, but that there is nothing to do about it, as all proposed syntaxes were a bit ugly. But why do we n

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Chris Angelico
On Tue, May 18, 2021 at 5:40 PM Martin Teichmann wrote: > I think this is now all good enough to be wrapped in a PEP, Chris, can you > guide me through the bureaucracy? > Sure, but first, I would strongly recommend getting some hard performance numbers. This sort of thing is definitely going to

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Ir. Robert Vanden Eynde
Julia has these kind of builtin things. The main problem is backward compatibility. However your tool is useful as a python-to-python parser (from the) (I remember some static analysis tools like "mpy"?) pip install funcoperators solve the problem differe

[Python-ideas] Re: Python 3.10: ranges in pattern matching

2021-05-18 Thread Ir. Robert Vanden Eynde
Scala also has "match" cases that are Class redefinable, used for regex for example About integers ranges, we already have the master class : builtins.range pip install funcoperators deals with the issue like this : for i in 1 /irange/ 5: print(i) # will print 1 2 3 4 5 Where irange = infix(

[Python-ideas] Re: division of integers should result in fractions not floats

2021-05-18 Thread Stephen J. Turnbull
David Mertz writes: > On Fri, May 14, 2021, 4:31 PM Jonathan Fine wrote: > > > >>> 1/2 + 1/3 > >> 5/6 > >> 1 / 2 + 1 / 3 > >> 0.83 > >> > > > > I'm sighted. I can see the difference. I suspect a blind person using a > > screen reader would struggle a lot to spot

[Python-ideas] Re: division of integers should result in fractions not floats

2021-05-18 Thread Stephen J. Turnbull
Christopher Barker writes: > Python assumes, and converts to, floats all over the place. So users need > to understand and accommodate the limitations of floats anyway. Having > exact fractions in seemingly arbitrary places will not result in more > accurate (or precise) results in most cases

[Python-ideas] Re: division of integers should result in fractions not floats

2021-05-18 Thread Ir. Robert Vanden Eynde
This thread seems related to the other thread I just answered I don't find, I wrote "julia" there, hmmm Le mar. 18 mai 2021 à 12:41, Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> a écrit : > David Mertz writes: > > On Fri, May 14, 2021, 4:31 PM Jonathan Fine > wrote: > > > > >

[Python-ideas] Re: division of integers should result in fractions not floats

2021-05-18 Thread Stephen J. Turnbull
Rob Cliffe via Python-ideas writes: > So what's the big deal about having to write Fraction(1,2) or F(1,2) ? Writing that is never a big deal. Forgetting to write that when you need to incurs immediate loss of precision, which is a big deal in applications where it matters at all. Knuth (Semin

[Python-ideas] Re: division of integers should result in fractions not floats

2021-05-18 Thread Ir. Robert Vanden Eynde
There it is : https://mail.python.org/archives/list/python-ideas@python.org/message/B4EPUQA3GCAXYWB6YMMNAJPMWP5L3QUH/ Le mar. 18 mai 2021 à 12:43, Ir. Robert Vanden Eynde a écrit : > This thread seems related to the other thread I just answered I don't > find, I wrote "julia" there, hmmm > > Le

[Python-ideas] Re: Add a mechanism so that multiple exceptions can be caught using `except E1, E2, E3:`

2021-05-18 Thread Ir. Robert Vanden Eynde
Static analysis and factorisation, I sub ! :D Le mar. 11 mai 2021 à 01:47, Rob Cliffe via Python-ideas < python-ideas@python.org> a écrit : > > > On 10/05/2021 12:43, Chris Angelico wrote: > > On Mon, May 10, 2021 at 9:36 PM Steven D'Aprano > wrote: > >> On Mon, May 10, 2021 at 10:04:58AM +1000,

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Steven D'Aprano
What's the actual problem you are solving with this complex, complicated proposal? In other words, what is the motivation? You mentioned symbolic maths in the previous thread. Python is never going to look good for symbolic maths, because symbolic maths is a two-dimensional layout and Python (l

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Ricky Teachey
On Tue, May 18, 2021, 8:07 AM Steven D'Aprano wrote: > What's the actual problem you are solving with this complex, complicated > proposal? In other words, what is the motivation? You mentioned symbolic > maths in the previous thread. > It seems to me the motivation is only related to looks inso

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Shreyan Avigyan
As I said in my post in your previous thread, I'm -1. Why? Because you're not solving anything. In fact you're making it more complicated. Developers can have difficulties studying your idea, beginners don't stand a chance (In fact I have no idea what you described here in your idea and trust me

[Python-ideas] Re: Python 3.10: ranges in pattern matching

2021-05-18 Thread Chris Angelico
On Tue, May 18, 2021 at 8:26 PM Ir. Robert Vanden Eynde wrote: > About matching, switch case does not exist in python because if/elif/else > cascade exists > > if (x := 5) in irange(1, 5): > println(stuff1) > elif x == 8 > println(stuff2) > else: > println(stuff3) > Hmm, switch statements

[Python-ideas] Re: division of integers should result in fractions not floats

2021-05-18 Thread Oscar Benjamin
On Tue, 18 May 2021 at 11:41, Stephen J. Turnbull wrote: > > Christopher Barker writes: > > > Python assumes, and converts to, floats all over the place. So users need > > to understand and accommodate the limitations of floats anyway. Having > > exact fractions in seemingly arbitrary places w

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Martin Teichmann
Hi Steven, > Python is never going to look good for symbolic maths, because symbolic > maths is a two-dimensional layout and Python (like most programming > languages) is line-oriented in a way that does not lend itself to > complex mathematical notation. While this is certainly true, I think

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Paul Moore
On Tue, 18 May 2021 at 15:16, Martin Teichmann wrote: > > Because reality. People would like to write 1/2 * m * v**2 to mean the > obvious thing, without having to think about the details. And there are many > people like this, this is why it shows up on this mailing list regularly. I > have ne

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Guido van Rossum
On Tue, May 18, 2021 at 12:39 AM Martin Teichmann < martin.teichm...@gmail.com> wrote: > [...] > To give an example (this is not fake, but from the prototype): > > >>> 2/5 > 0.4 > >>> (2/5).denominator > 5 > >>> isinstance(2/5, float) > True > >>> type(2/5) > > > N

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Ricky Teachey
On Tue, May 18, 2021 at 10:55 AM Paul Moore wrote: > On Tue, 18 May 2021 at 15:16, Martin Teichmann > wrote: > > > > Because reality. People would like to write 1/2 * m * v**2 to mean the > obvious thing, without having to think about the details. And there are > many people like this, this is w

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Matt del Valle
Fully agreed on the sentiment that we shouldn't treat compile-time literals differently from runtime operations. It has no precedent in Python and adds a significant mental burden to keep track of. I can only imagine the deluge StackOverflow threads from surprised users if this were to be done. Th

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Martin Teichmann
Hi Paul, > > I'd actually prefer to write (m*v**2)/2. Or (m/2)*v**2. But those > wouldn't work, the way you describe your proposal. And I'd be very > concerned if they behaved differently than 1/2 * m * v**2... Sure they do work, and they work exactly the same way. That is acually the point: cur

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Paul Moore
On Tue, 18 May 2021 at 16:55, Martin Teichmann wrote: > > Hi Paul, > > > > I'd actually prefer to write (m*v**2)/2. Or (m/2)*v**2. But those > > wouldn't work, the way you describe your proposal. And I'd be very > > concerned if they behaved differently than 1/2 * m * v**2... > > Sure they do work

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Oscar Benjamin
On Tue, 18 May 2021 at 15:56, Paul Moore wrote: > > On Tue, 18 May 2021 at 15:16, Martin Teichmann > wrote: > > > > Because reality. People would like to write 1/2 * m * v**2 to mean the > > obvious thing, without having to think about the details. And there are > > many people like this, this

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Martin Teichmann
Hi Paul, > But *not* in sympy, in normal Python, if m == 1 and v == 1, then 1/2 * > m * v**2 is 0.5 (a float) currently, as is (m/2) * v**2. But in your > proposal, the former will be a float/fraction hybrid, whereas the > latter will be a float. No. In my proposal, this will simply be a float. W

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Martin Teichmann
Hi Oscar, > The problem is that while SymPy expressions can define __div__(self, > int) to be exact there isn't a way for SymPy to hook into an > expression like 1/2 which is just a Python expression using the int > type whose __div__ returns floats. The entire point of my proposal is to give Sy

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Shreyan Avigyan
Why do we need this functionality? What are the benefits? What are you trying to solve? Is it worth adding it? ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Martin Teichmann
Hi Shreyan, we need this for symbolic math, e.g. in sympy. Probably you have never seen somebody doing symbolic math with Python, but believe me, there are many. Let me walk you through a toy problem to show where the issues are. Let's say we want to solve the equation x**2 == 3. Not a very tou

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread David Mertz
The more explanation I see from the OP, the more I oppose the idea. It becomes more clear that this is a specialization, basically only to help SymPy, while introducing semantic changes for everyone else (even if minor ones). Moreover, SymPy already has several readily available ways to do this, a

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Steven D'Aprano
On Tue, May 18, 2021 at 05:21:28PM +0100, Oscar Benjamin wrote: > I think that maybe the best solution here is something more like a > domain-specific language that can be used with ipython/jupyter as an > alternative profile. Not just ipython and jupyter. The Python std lib has a module that si

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Chris Angelico
On Wed, May 19, 2021 at 11:17 AM Steven D'Aprano wrote: > It would be nice if it had an input hook as well, so that Martin could > customise "1/2" to "Fraction(1, 2)". I think that would be a much more > useful enhancement than ratiofloat. > Doesn't it? Hmm. Where does readline hook in? Maybe tha

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Ricky Teachey
On Tue, May 18, 2021, 9:18 PM Steven D'Aprano wrote: > On Tue, May 18, 2021 at 05:21:28PM +0100, Oscar Benjamin wrote: > > > I think that maybe the best solution here is something more like a > > domain-specific language that can be used with ipython/jupyter as an > > alternative profile. > > Not

[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Steven D'Aprano
On Tue, May 18, 2021 at 05:30:29PM -, Martin Teichmann wrote: > For most of the time my opinion was: stop dreaming, get real. But then > they pushed structural pattern matching, a super complicated beast of > syntax for not much benefit. https://www.jonathanturner.org/rethinking-the-blub-pa

[Python-ideas] symbolic math in Python

2021-05-18 Thread Martin Teichmann
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 time I come up with something people like. To frame the problem, let