Opened 2 years ago

Closed 16 months ago

#30477 closed defect (fixed)

preparser: implicit multiplication conflicts with Python's complex literals

Reported by: gh-mwageringel Owned by:
Priority: minor Milestone: sage-9.5
Component: misc Keywords: preparser
Cc: Merged in:
Authors: Markus Wageringel Reviewers: Marc Mezzarobba
Report Upstream: N/A Work issues:
Branch: 1a171d2 (Commits, GitHub, GitLab) Commit: 1a171d26e83b9c00e9b6f9429db1b4a8c0d578dc
Dependencies: Stopgaps:

GitHub link to the corresponding issue

Description (last modified by gh-mwageringel)

When implicit multiplication is enabled, using complex literals does not work.

sage: implicit_multiplication(True)
sage: preparse('1jr'), preparse('1rj')
('Integer(1)*jr', 'Integer(1)*rj')

Instead, it should behave like when implicit multiplication is disabled.

sage: implicit_multiplication(False)
sage: preparse('1jr'), preparse('1rj')
('1J', '1J')

Change History (10)

comment:1 Changed 2 years ago by slelievre

Milestone: sage-9.2sage-duplicate/invalid/wontfix
Status: newneeds_review

To signal a complex literal as raw, place the r at the very end:

sage: 1jr
1j
sage: 1r + 1jr
(1+1j)

I suggest to close as invalid or wontfix.

But I will listen to arguments for doing otherwise.

comment:2 Changed 2 years ago by gh-mwageringel

Description: modified (diff)
Priority: majorminor
Summary: preparsing Python's complex literals is broken in the REPLpreparser: implicit multiplication conflicts with Python's complex literals

Oh, it turns out this is a conflict with implicit multiplication, which I had enabled in my init.sage file. Both 1rj and 1jr work when implicit multiplication is disabled. I have updated the description.

comment:3 Changed 2 years ago by slelievre

Status: needs_reviewneeds_info

Should we make 1jr the only valid form?

comment:4 Changed 2 years ago by gh-mwageringel

There is no need for that I think.

comment:5 Changed 2 years ago by gh-mwageringel

Authors: Markus Wageringel
Branch: u/gh-mwageringel/30477
Commit: 1a171d26e83b9c00e9b6f9429db1b4a8c0d578dc
Milestone: sage-duplicate/invalid/wontfixsage-9.3
Status: needs_infoneeds_review

Here is a minimal fix. I have also changed the regular expressions to be case-insensitive, which solves the following problem with scientific notation and implicit multiplication:

sage: implicit_multiplication(True)
sage: 1e3
1000.00000000000
sage: 1E3
...
NameError: name 'E3' is not defined

New commits:

1a171d230477: fix conflict between implicit multiplication and complex literals

comment:6 Changed 23 months ago by mkoeppe

Milestone: sage-9.3sage-9.4

Sage development has entered the release candidate phase for 9.3. Setting a new milestone for this ticket based on a cursory review of ticket status, priority, and last modification date.

comment:7 Changed 19 months ago by mkoeppe

Milestone: sage-9.4sage-9.5

Setting a new milestone for this ticket based on a cursory review.

comment:8 Changed 17 months ago by mmezzarobba

Reviewers: Marc Mezzarobba

Lgtm, thank you!

comment:9 Changed 17 months ago by mmezzarobba

Status: needs_reviewpositive_review

comment:10 Changed 16 months ago by vbraun

Branch: u/gh-mwageringel/304771a171d26e83b9c00e9b6f9429db1b4a8c0d578dc
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.