Re: [sage-devel] Discussion and poll: should Sage Integers have a backslash operator?

2023-09-28 Thread Eric Gourgoulhon
+ 1 for getting rid of the preparsing of \

It is particularly annoying when typing (usually long) expressions like

f(x) = x + \ 
   1
in an input cell of a Jupyter notebook. If the \ is followed by a blank 
space, one gets 

Cell In [22], line 1 
__tmp__=var("x"); f = symbolic_expression(x + * BackslashOperator() * 
).function(x)
SyntaxError: invalid syntax

which is particularly disturbing for a new user!

Eric

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/d397d13d-1765-43b1-ac55-17ccc764196fn%40googlegroups.com.


Re: [sage-devel] Discussion and poll: should Sage Integers have a backslash operator?

2023-09-28 Thread kcrisman


On Wednesday, September 27, 2023 at 6:19:16 PM UTC-4 William Stein wrote:

Hi, 

I'm the guilty party who added \ to Sage notation in the first place, 
and I would definitely vote to *remove* it. I wish I had 
never added it in the first place. Nils has some very good points! 


I do think it's worth considering whether people outside of the doctests 
actually use the backslash operator in the Matlab way.  This is a 
well-known shortcut in a lot of the practical computational world, as I've 
seen when people have tried to type it in other contexts and wonder why it 
doesn't "just work".  For instance, one could look at any linear algebra 
textbooks that use Sage and see whether they use it.  Keeping the mission 
in mind!

That said, this is pretty clearly the only strong reason to implement it, 
to keep learning new syntax to a minimum for people coming from 
Matlab/Octave.  And maybe those people are not using Sage for this purpose, 
as it seems to focus more on advanced math(s) capabilities.  But one should 
at least raise the question, and if it's not actively hurting anything, 
then John's suggestion regarding adding the "usual" behavior outside of the 
very narrow matroid/ix-related contexts seems best.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/4311cf1f-6022-4339-862e-b1e741420a7en%40googlegroups.com.


Re: [sage-devel] Discussion and poll: should Sage Integers have a backslash operator?

2023-09-27 Thread Dima Pasechnik
On Thu, Sep 28, 2023 at 12:58 AM Michael Orlitzky  wrote:
>
> On Wed, 2023-09-27 at 14:44 -0700, Nils Bruin wrote:
>
> > Searching the codebase currently only shows "_backslash_" implemented on
> > matroid, matrix, and binary_tree, so extinguishing it should be doable. We
> > should definitely not entrench its use further.
> >
> > If you want to write your denominator first, you can already do ~2 * 3 . I
> > think that's already sufficiently perverse that we don't need another way
> > to spell that.
>
> To keep the flamebait to a minimum, I will just say: +1.
I'd even say, to keep the back(s)lash to a minimum...
+1

>
> --
> You received this message because you are subscribed to the Google Groups 
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sage-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sage-devel/a4d3e780ff4ba16eb2f11cc096b81816b72914aa.camel%40orlitzky.com.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/CAAWYfq28wu4ho1PBBwb0keDjHGQj%3DP7i49faj1LfuNtxCCfaLQ%40mail.gmail.com.


Re: [sage-devel] Discussion and poll: should Sage Integers have a backslash operator?

2023-09-27 Thread Michael Orlitzky
On Wed, 2023-09-27 at 14:44 -0700, Nils Bruin wrote:

> Searching the codebase currently only shows "_backslash_" implemented on 
> matroid, matrix, and binary_tree, so extinguishing it should be doable. We 
> should definitely not entrench its use further.
> 
> If you want to write your denominator first, you can already do ~2 * 3 . I 
> think that's already sufficiently perverse that we don't need another way 
> to spell that.

To keep the flamebait to a minimum, I will just say: +1.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/a4d3e780ff4ba16eb2f11cc096b81816b72914aa.camel%40orlitzky.com.


Re: [sage-devel] Discussion and poll: should Sage Integers have a backslash operator?

2023-09-27 Thread William Stein
Hi,

I'm the guilty party who added \ to Sage notation in the first place,
and I would definitely vote to *remove* it.  I wish I had
never added it in the first place.   Nils has some very good points!

In retrospect, I wish we had a "fully supported" way of using Sage
entirely without the preparser, but that's another discussion.
It's important in the longterm for interoperability with the rest of
the Python ecosystem.  By "fully supported", I perhaps just
mean better documentation (e.g., a switch for the reference and other
docs that shows all examples in a way that works without
the preparser).

 -- William

On Wed, Sep 27, 2023 at 3:09 PM John H Palmieri  wrote:
>
> Okay, so maybe we should open this to other options: should we get rid of 
> preparsing "\" into "BackslashOperator"?


>
> For what it's worth, I removed the line defining `_backslash_` in 
> binary_tree.py and and I only say one doctest failure in any obvious places 
> (combinat and thematic_tutorials). So it's not even used much. Same for 
> matroids.
>
> I think that using \ to escape characters in strings still works, but 
> line-continuation does not: in Sage, these fail:
>
> sage: a = 3 + \
>
> and
>
> sage: \
>
> whereas in pure Python, such backslashes would be treated as 
> line-continuations. It should be possible to fix this while keeping the 
> current preparser behavior for "\" in the middle of a line. Or as Nils 
> proposes, getting rid of the current preparser behavior should also solve it.
>
> On Wednesday, September 27, 2023 at 2:44:19 PM UTC-7 Nils Bruin wrote:
>>
>> I'm quite strongly against because it collides with a well-established 
>> meaning of `\` in python: escape character. It's used to avoid command 
>> termination by newline in things like formulas (as "\> parsed as whitespace rather than command termination outside of brackets).
>>
>> I'm in fact rather shocked that `\` in sage already doesn't work as it's 
>> supposed to in python but instead gets substituted as "BackslashOperator()".
>>
>> Searching the codebase currently only shows "_backslash_" implemented on 
>> matroid, matrix, and binary_tree, so extinguishing it should be doable. We 
>> should definitely not entrench its use further.
>>
>> If you want to write your denominator first, you can already do ~2 * 3 . I 
>> think that's already sufficiently perverse that we don't need another way to 
>> spell that.
>> On Wednesday, 27 September 2023 at 12:16:57 UTC-7 David Joyner wrote:
>>>
>>> On Wed, Sep 27, 2023 at 2:32 PM John H Palmieri  wrote:

 The github issue #36060 (https://github.com/sagemath/sage/issues/36060) 
 proposes adding a backslash operator for Sage integers, so that "2 \ 3" 
 will return the same as "3 / 2". Do you support this?

>>>
>>> I'm not for or against. However, I don't see the problem that implementing 
>>> this "\" is going to solve. The ticket suggests that users will naturally 
>>> type 2\3 instead of 3/2, if I am reading between the lines correctly.
>>>

 BackslashOperator is defined in "sage/misc/misc.py", and the preparser 
 converts "A \ b" to the appropriate Python code. The docstring for 
 BackslashOperator says "Implements Matlab-style backslash operator for 
 solving systems A \ b".

 It seems pretty innocuous to me — in fact I don't care much either way — 
 but since Sage integers are so ubiquitous, it seems like a good idea to 
 ask before implementing it.

 --
 John

 --
 You received this message because you are subscribed to the Google Groups 
 "sage-devel" group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to sage-devel+...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/sage-devel/3f157aa4-74cd-4c5c-bc76-f198c6417432n%40googlegroups.com.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sage-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sage-devel/941e7314-5f78-454a-9017-fe752c630233n%40googlegroups.com.



-- 
William (http://wstein.org)

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/CACLE5GCOEcwTqhz60StnPUfAoLcBGRt9%3D9fvskC3D61weCBpyw%40mail.gmail.com.


Re: [sage-devel] Discussion and poll: should Sage Integers have a backslash operator?

2023-09-27 Thread John H Palmieri
Okay, so maybe we should open this to other options: should we get rid of 
preparsing "\" into "BackslashOperator"?

For what it's worth, I removed the line defining `_backslash_` in 
binary_tree.py and and I only say one doctest failure in any obvious places 
(combinat and thematic_tutorials). So it's not even used much. Same for 
matroids.

I think that using \ to escape characters in strings still works, but 
line-continuation does not: in Sage, these fail:

sage: a = 3 + \

and

sage: \

whereas in pure Python, such backslashes would be treated as 
line-continuations. It should be possible to fix this while keeping the 
current preparser behavior for "\" in the middle of a line. Or as Nils 
proposes, getting rid of the current preparser behavior should also solve 
it.

On Wednesday, September 27, 2023 at 2:44:19 PM UTC-7 Nils Bruin wrote:

> I'm quite strongly against because it collides with a well-established 
> meaning of `\` in python: escape character. It's used to avoid command 
> termination by newline in things like formulas (as "\ parsed as whitespace rather than command termination outside of brackets).
>
> I'm in fact rather shocked that `\` in sage already doesn't work as it's 
> supposed to in python but instead gets substituted as "BackslashOperator()".
>
> Searching the codebase currently only shows "_backslash_" implemented on 
> matroid, matrix, and binary_tree, so extinguishing it should be doable. We 
> should definitely not entrench its use further.
>
> If you want to write your denominator first, you can already do ~2 * 3 . I 
> think that's already sufficiently perverse that we don't need another way 
> to spell that.
> On Wednesday, 27 September 2023 at 12:16:57 UTC-7 David Joyner wrote:
>
>> On Wed, Sep 27, 2023 at 2:32 PM John H Palmieri  
>> wrote:
>>
>>> The github issue #36060 (https://github.com/sagemath/sage/issues/36060) 
>>> proposes adding a backslash operator for Sage integers, so that "2 \ 3" 
>>> will return the same as "3 / 2". Do you support this?
>>>
>>>
>> I'm not for or against. However, I don't see the problem that 
>> implementing this "\" is going to solve. The ticket suggests that users 
>> will naturally type 2\3 instead of 3/2, if I am reading between the lines 
>> correctly. 
>>  
>>
>>> BackslashOperator is defined in "sage/misc/misc.py", and the preparser 
>>> converts "A \ b" to the appropriate Python code. The docstring for 
>>> BackslashOperator says "Implements Matlab-style backslash operator for 
>>> solving systems A \ b". 
>>>
>>> It seems pretty innocuous to me — in fact I don't care much either way — 
>>> but since Sage integers are so ubiquitous, it seems like a good idea to ask 
>>> before implementing it.
>>>
>>> -- 
>>> John
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "sage-devel" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to sage-devel+...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/sage-devel/3f157aa4-74cd-4c5c-bc76-f198c6417432n%40googlegroups.com
>>>  
>>> 
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/941e7314-5f78-454a-9017-fe752c630233n%40googlegroups.com.


Re: [sage-devel] Discussion and poll: should Sage Integers have a backslash operator?

2023-09-27 Thread Nils Bruin
I'm quite strongly against because it collides with a well-established 
meaning of `\` in python: escape character. It's used to avoid command 
termination by newline in things like formulas (as "\ On Wed, Sep 27, 2023 at 2:32 PM John H Palmieri  
> wrote:
>
>> The github issue #36060 (https://github.com/sagemath/sage/issues/36060) 
>> proposes adding a backslash operator for Sage integers, so that "2 \ 3" 
>> will return the same as "3 / 2". Do you support this?
>>
>>
> I'm not for or against. However, I don't see the problem that implementing 
> this "\" is going to solve. The ticket suggests that users will naturally 
> type 2\3 instead of 3/2, if I am reading between the lines correctly. 
>  
>
>> BackslashOperator is defined in "sage/misc/misc.py", and the preparser 
>> converts "A \ b" to the appropriate Python code. The docstring for 
>> BackslashOperator says "Implements Matlab-style backslash operator for 
>> solving systems A \ b". 
>>
>> It seems pretty innocuous to me — in fact I don't care much either way — 
>> but since Sage integers are so ubiquitous, it seems like a good idea to ask 
>> before implementing it.
>>
>> -- 
>> John
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "sage-devel" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to sage-devel+...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sage-devel/3f157aa4-74cd-4c5c-bc76-f198c6417432n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/f7a940bd-ced4-4441-b57c-059b8f65e704n%40googlegroups.com.


Re: [sage-devel] Discussion and poll: should Sage Integers have a backslash operator?

2023-09-27 Thread David Joyner
On Wed, Sep 27, 2023 at 2:32 PM John H Palmieri 
wrote:

> The github issue #36060 (https://github.com/sagemath/sage/issues/36060)
> proposes adding a backslash operator for Sage integers, so that "2 \ 3"
> will return the same as "3 / 2". Do you support this?
>
>
I'm not for or against. However, I don't see the problem that implementing
this "\" is going to solve. The ticket suggests that users will naturally
type 2\3 instead of 3/2, if I am reading between the lines correctly.


> BackslashOperator is defined in "sage/misc/misc.py", and the preparser
> converts "A \ b" to the appropriate Python code. The docstring for
> BackslashOperator says "Implements Matlab-style backslash operator for
> solving systems A \ b".
>
> It seems pretty innocuous to me — in fact I don't care much either way —
> but since Sage integers are so ubiquitous, it seems like a good idea to ask
> before implementing it.
>
> --
> John
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-devel/3f157aa4-74cd-4c5c-bc76-f198c6417432n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/CAEQuuAXnzoHr2p%3DnyShdeV1y0EqsSUX77dzxBvg2mMLFk2KCFw%40mail.gmail.com.


[sage-devel] Discussion and poll: should Sage Integers have a backslash operator?

2023-09-27 Thread John H Palmieri
The github issue #36060 (https://github.com/sagemath/sage/issues/36060) 
proposes adding a backslash operator for Sage integers, so that "2 \ 3" 
will return the same as "3 / 2". Do you support this?

BackslashOperator is defined in "sage/misc/misc.py", and the preparser 
converts "A \ b" to the appropriate Python code. The docstring for 
BackslashOperator says "Implements Matlab-style backslash operator for 
solving systems A \ b". 

It seems pretty innocuous to me — in fact I don't care much either way — 
but since Sage integers are so ubiquitous, it seems like a good idea to ask 
before implementing it.

-- 
John

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/3f157aa4-74cd-4c5c-bc76-f198c6417432n%40googlegroups.com.