On Tue, Jun 23, 2020 at 11:09 AM Rhodri James <rho...@kynesim.co.uk> wrote:

> On 23/06/2020 15:12, Ricky Teachey wrote:
> > On Tue, Jun 23, 2020 at 9:08 AM Mathew Elman <mathew.el...@ocado.com>
> wrote:
> >
> >> Well there you go, good point.
> >> I didn't really like it being an operator myself. But I can see having a
> >> math.tolerance class being useful.
> >>
> >> On Tue, 23 Jun 2020 at 13:53, Jonathan Goble <jcgob...@gmail.com>
> wrote:
> >>
> >>> On Tue, Jun 23, 2020 at 8:44 AM Mathew Elman <mathew.el...@ocado.com>
> >>> wrote:
> >>>
> >>>> Perhaps a more versatile operator would be to introduce a +- operator
> >>>> that would return an object with an __eq__ method that checks for
> equality
> >>>> in the tolerance i.e
> >>>>
> >>>>      a == b +- 0.5
> >>>>
> >>>
> >>> This is already valid syntax, because unary minus is a thing. So this
> is
> >>> currently parsed as "a == b + (-0.5)".
> >>>
> >>> Reversing it to use -+ won't work because unary plus is also a thing.
> >>>
> >>
> > A little bit out of the box, but what about:
> >
> > a == b +/- 0.5
> >
> > ...or even:
> >
> > a == b +or- 0.5
>
> Is "math.isclose(a, b, abs_tol=0.5)" really so hard to use?
>

TLDR:

Of course it's not that hard to use. But the friction from "python code" to
"mathematical calculations" is too large to make reaching for python as my
go-to tool the first inclination. I'd really like to see this improved.

I'm not strongly opinionated that this is a large, glaring need that simply
*must* be rectified. Only that it would be VERY nice for those of us that
use python primarily for mathematical calculations.

BORING LONGER VERSION, BIT OF A RANT, SORRY:

As a civil engineer, when I reach for a tool with which I am intending to
do MATH, I generally do not reach for python right now-- even inside a
Jupyter notebook. I reach for Mathcad or even Excel (blech).

One of the biggest reasons is python code doesn't READ like real math in so
many instances; this is a problem for me partly for my own reading, but
also for my colleagues and clients. I would like to not have to spend a lot
of time changing bits of the code to an output form for other
non-programming people to read. My clients are not dumb, but if I were to
print a jupyter notebook out and hand it to someone to read who doesn't
know what python is, this:

import math
math.isclose(a, b, abs_tol=0.5)

...is just a step too far for them to read. So I have to use something
else, or spend a lot of time massaging things to look more presentable.

It would be nice-- for ME-- if there were ways to write functional code
that looked more like calculations in python code. And something like +/-
fits that bill.

But I understand that not everyone-- perhaps not even close to significant
% of people-- has the same needs I do, spending their days focused on
producing, writing/reading mostly mathematical calculations with
explanations. And that not everyone has the difficulty of having to present
the math they are performing with their code to other people who are
expecting to be reading calculations, not computer code.

SIDEBAR

Another BIG pain point for the "gee it would be nice if python code could
look more like mathematical calculations" problem is the function writing
syntax-- I love python, but sometimes I want to write a simple
mathematical-looking structural engineering function:

∆y(P, H,L, E, I) = H * L^4 * P / (384 * E * I)

...and not:

def ∆y(P, H,L, E, I):
    return H * L**4 * P / (384 * E * I)

Boy would it be cool if we could use the walrus to write one-liner math
functions!

  ∆y(P, H,L, E, I) := H * L^4 * P / (384 * E * I)

THAT right there would change my life.

---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home
or actually going home." - Happy Chandler
_______________________________________________
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/U4SDAOP36DV7MMPSMJOPQYVRPIMSDT5L/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to