Re: PEP 638: Syntactic macros

Stéfane Fermigier <[email protected]> Thu, 2 Feb 2023 10:55:50 +0100
Newsgroups gmane.comp.python.devel
Message-ID <CABuJJj6hmj4jm-H8PqGAdLF2xcydrWSHgAyb-dFijJoJSsmJmw@mail.gmail.com>
--===============2784532344412963461==
Content-Type: multipart/alternative; boundary="0000000000009098ee05f3b492a2"

--0000000000009098ee05f3b492a2
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Thu, Feb 2, 2023 at 8:34 AM Stephen J. Turnbull <
[email protected]> wrote:

> [email protected] writes:
>
>  > I don't want to be forced to learn lots of weird little functions
>  > like `np.matmul(x1, x2)` when there's already one obvious syntax
>  > I'm very familiar with: `x1 * x2`.
>
> I don't recall ever writing matrix multiplication that way in
> mathematics though.  That's universally written as juxtaposition in my
> experience.  And the obvious way to write it in Python (and np) has
> been "x1 @ x2" for some years now.  In np, "*" means element-wise
> multiplication, I believe.
>

My 2 cents as a former mathematician:

Mathematicians have come up with hundreds of symbols to express the variety
of structures they are dealing with.

Just to list a few:

https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode
https://oeis.org/wiki/List_of_LaTeX_mathematical_symbols

So +, *, -, /, @ and ** are a good start to express the most common
mathematical structures (groups, rings, vector spaces), and <, >, <=3D, >=
=3D,
=3D=3D, !=3D for ordered sets, but that's it.

It's great that Python supports overloading these operations. That's
something that drew me to Python when I was still working in computational
number theory, 25 years ago.

But that's probably not enough for some people. A way to add new symbols
(including non-ascii Unicode characters) and operations could have some
value, but also the drawback of tremendous additional complexity, specially
if done in the most generic way.

NB: on a very basic level, I remember trying, a few years ago, to use the
Unicode "empty set" symbol as a synonym for set(), and it didn't end well,
for several reasons, including the fact that Python didn't like it as a
variable name.

  S.

--=20
Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier -
http://linkedin.com/in/sfermigier
Founder & CEO, Abilian - Enterprise Social Software -
http://www.abilian.com/
Co-Founder & Co-Chairman, National Council for Free & Open Source Software
(CNLL) - http://cnll.fr/
Co-Founder & Chairman, Association Professionnelle Europ=C3=A9enne du Logic=
iel
Libre (APELL) - https://www.apell.info/
Co-Founder & Spokesperson, European Cloud Industrial Alliance (EUCLIDIA) -
https://www.euclidia.eu/

"I wish you were as accurate, & as much to be relied on, as I am myself" -
Lady Ada Lovelace

--0000000000009098ee05f3b492a2
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">On Thu, Feb 2, 2023 at 8:34 AM Stephe=
n J. Turnbull &lt;<a href=3D"mailto:[email protected]">stephenjtur=
[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" s=
tyle=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pad=
ding-left:1ex"><a href=3D"mailto:[email protected]" target=3D"_blank">cdp49@c=
am.ac.uk</a> writes:<br>
<br>
=C2=A0&gt; I don&#39;t want to be forced to learn lots of weird little func=
tions<br>
=C2=A0&gt; like `np.matmul(x1, x2)` when there&#39;s already one obvious sy=
ntax<br>
=C2=A0&gt; I&#39;m very familiar with: `x1 * x2`.<br>
<br>
I don&#39;t recall ever writing matrix multiplication that way in<br>
mathematics though.=C2=A0 That&#39;s universally written as juxtaposition i=
n my<br>
experience.=C2=A0 And the obvious way to write it in Python (and np) has<br=
>
been &quot;x1 @ x2&quot; for some years now.=C2=A0 In np, &quot;*&quot; mea=
ns element-wise<br>
multiplication, I believe.<br></blockquote><div><br></div><div>My 2 cents a=
s a former mathematician: <br></div><div><br></div><div>Mathematicians have=
 come up with hundreds of symbols to express the variety of structures they=
 are dealing with.<br></div><div><br></div><div>Just to list a few:</div><d=
iv><br></div><div><a href=3D"https://en.wikipedia.org/wiki/Mathematical_ope=
rators_and_symbols_in_Unicode">https://en.wikipedia.org/wiki/Mathematical_o=
perators_and_symbols_in_Unicode</a></div><div><a href=3D"https://oeis.org/w=
iki/List_of_LaTeX_mathematical_symbols">https://oeis.org/wiki/List_of_LaTeX=
_mathematical_symbols</a></div><div><br></div><div>So +, *, -, /, @ and ** =
are a good start to express the most common mathematical structures (groups=
, rings, vector spaces), and &lt;, &gt;, &lt;=3D, &gt;=3D, =3D=3D, !=3D for=
 ordered sets, but that&#39;s it.</div><div><br></div><div>It&#39;s great t=
hat Python supports overloading these operations. That&#39;s something that=
 drew me to Python when I was still working in computational number theory,=
 25 years ago.<br></div><div><br></div><div>But that&#39;s probably not eno=
ugh for some people. A way to add new symbols (including non-ascii Unicode =
characters) and operations could have some value, but also the drawback of =
tremendous additional complexity, specially if done in the most generic way=
.</div><div><br></div><div>NB: on a very basic level, I remember trying, a =
few years ago, to use the Unicode &quot;empty set&quot; symbol as a synonym=
 for set(), and it didn&#39;t end well, for several reasons, including the =
fact that Python didn&#39;t like it as a variable name.</div><div><br></div=
><div>=C2=A0 S.</div></div><div class=3D"gmail_quote"><br></div><div class=
=3D"gmail_quote">-- <br></div><div dir=3D"ltr" class=3D"gmail_signature"><d=
iv dir=3D"ltr"><div><div dir=3D"ltr"><div><div dir=3D"ltr"><div><div dir=3D=
"ltr"><div><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"l=
tr">Stefane Fermigier - <a href=3D"http://fermigier.com/" target=3D"_blank"=
>http://fermigier.com/</a> - <a href=3D"http://twitter.com/sfermigier" targ=
et=3D"_blank">http://twitter.com/sfermigier</a> - <a href=3D"http://linkedi=
n.com/in/sfermigier" target=3D"_blank">http://linkedin.com/in/sfermigier</a=
><br>Founder &amp; CEO, Abilian - Enterprise Social Software - <a href=3D"h=
ttp://www.abilian.com/" target=3D"_blank">http://www.abilian.com/</a></div>=
<div dir=3D"ltr">Co-Founder &amp; Co-Chairman, National Council for Free &a=
mp; Open Source Software (CNLL) - <a href=3D"http://cnll.fr/" target=3D"_bl=
ank">http://cnll.fr/</a></div><div dir=3D"ltr">Co-Founder &amp; Chairman, A=
ssociation Professionnelle Europ=C3=A9enne du Logiciel Libre (APELL) -=C2=
=A0<a href=3D"https://www.apell.info/" target=3D"_blank">https://www.apell.=
info/</a></div><div dir=3D"ltr">Co-Founder &amp; Spokesperson, European Clo=
ud Industrial Alliance (EUCLIDIA) -=C2=A0<a href=3D"https://www.euclidia.eu=
/" target=3D"_blank">https://www.euclidia.eu/</a> <br></div><div dir=3D"ltr=
"><br></div><div dir=3D"ltr">&quot;<span>I wish you were as accurate,  &amp=
; as much to be relied on, as I am myself&quot; - Lady Ada Lovelace<br></sp=
an></div></div></div></div></div></div></div></div></div></div></div></div>=
</div></div>

--0000000000009098ee05f3b492a2--

--===============2784532344412963461==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline