Opened 3 years ago
Closed 3 years ago
#28907 closed defect (fixed)
remove the method MathematicaElement.N()
Reported by: | gh-mwageringel | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | sage-9.1 |
Component: | interfaces | Keywords: | mathematica |
Cc: | dimpase, mkoeppe | Merged in: | |
Authors: | Markus Wageringel | Reviewers: | Dima Pasechnik |
Report Upstream: | N/A | Work issues: | |
Branch: | 52f8c9d (Commits, GitHub, GitLab) | Commit: | 52f8c9d3ff7fdc84be10151c2aa5a152698d26fa |
Dependencies: | Stopgaps: |
Description
Currently, the method MathematicaElement.N()
returns a string (2), which is not useful for further computations. It also contradicts the convention of interface elements that mathematica(1/3).N()
is a more pythonic syntax for mathematica.N(mathematica(1/3))
, as is the case for all the dynamically added methods in interfaces. So for consistencey, the method N()
should return a MathematicaElement
instead of a string.
This ticket removes the method altogether, for simplicity, as it is not needed anymore (1). Now a call to mathematica(1/3).N()
dynamically redirects to Mathematica's N[]
function and returns a MathematicaElement
as expected.
This change also reveaved an issue with serialization of Mathematica elements, which is also fixed by this ticket (see _reduce()
). The corresponding doctest was actually just serializing a string. This is now fixed:
sage: a = mathematica('N[Pi/2,50]') sage: loads(dumps(a)) == a # should be True ... TypeError: Error executing code in Mathematica CODE: sage8= 1.5707963267948966192313216916397514420985846996875529104874722961539082059438`50.; Mathematica ERROR:
More details:
(1) In the past, Sage's object hierarchy used to define a method N()
, so it had to be overwritten in the interface, but that is no longer the case.
(2) The return type was changed to string in #18888 as a workaround to an apparent bug in Mathematica itself. This bug does not seem to exist anymore in Mathematica 12, so the workaround is not needed anymore. Indeed, in the following computation, the decimal representation gets correctly truncated after 10 digits
Mathematica 12.0.0 Kernel for Linux x86 (64-bit) Copyright 1988-2019 Wolfram Research, Inc. In[1]:= x2=N[Pi,10] Out[1]= 3.141592654 In[2]:= InputForm[x2,NumberMarks->False] Out[2]//InputForm= 3.1415926536
whereas, in 18888#comment:20 with Mathematica 10.0, the same computation did not truncate the output
In[4]:= InputForm[x2,NumberMarks->False] Out[4]//InputForm= 3.14159265358979323846264338327950419993
Change History (7)
comment:1 Changed 3 years ago by
- Branch set to u/gh-mwageringel/28907
- Cc dimpase added
- Commit set to 52f8c9d3ff7fdc84be10151c2aa5a152698d26fa
- Status changed from new to needs_review
comment:2 Changed 3 years ago by
Shouldn't there be a deprecation period set up, before removal?
comment:3 Changed 3 years ago by
It is difficult to deprecate this, as the method does not change name, but effectively just changes the return type. However, the string that is currently returned by this method cannot be used to compute anything else in a meaningful way, so it is unlikely that any existing code depends on the return type being a string.
comment:4 Changed 3 years ago by
- Cc mkoeppe added
seems that I don't have access to Mathematica any more, so I can't test :-(
comment:5 Changed 3 years ago by
- Reviewers set to Dima Pasechnik
- Status changed from needs_review to positive_review
OK, got mathematica reinstalled on my desktop, all is good with this branch, thanks!
comment:6 Changed 3 years ago by
Thank you.
comment:7 Changed 3 years ago by
- Branch changed from u/gh-mwageringel/28907 to 52f8c9d3ff7fdc84be10151c2aa5a152698d26fa
- Resolution set to fixed
- Status changed from positive_review to closed
New commits:
28907: fix return type/remove method MathematicaElement.N()