Opened 6 years ago

Closed 5 years ago

#18888 closed defect (fixed)

failing optional mathematica tests, due to bugs in N() and n()

Reported by: slabbe Owned by:
Priority: major Milestone: sage-7.2
Component: interfaces: optional Keywords: mathematica
Cc: vbraun, slelievre, mkoeppe Merged in:
Authors: Dima Pasechnik Reviewers: Matthias Koeppe, Yuan Zhou
Report Upstream: N/A Work issues:
Branch: eb0bed5 (Commits, GitHub, GitLab) Commit: eb0bed51d49219938c811ee528ed1ada2600bb99
Dependencies: Stopgaps:

Status badges

Description (last modified by dimpase)

With

$ sage --version
SageMath Version 6.8.beta8, Release Date: 2015-07-10
$ mathematica --version
10.0

The command

sage -t --warn-long 2.3 --optional=sage,mathematica src/sage/symbolic/expression.pyx src/sage/tests/benchmark.py src/sage/misc/functional.py src/sage/symbolic/constants.py src/sage/calculus/calculus.py src/sage/interfaces/mathematica.py src/sage/symbolic/integration/integral.py src/sage/symbolic/constants_c.pyx src/sage/matrix/matrix1.pyx src/sage/modules/free_module_element.pyx

gives:

# sage -t --warn-long 2.3 src/sage/symbolic/expression.pyx  # 1 doctest failed
# sage -t --warn-long 2.3 src/sage/symbolic/constants.py  # 3 doctests failed
# sage -t --warn-long 2.3 src/sage/interfaces/mathematica.py  # 30 doctests failed
# sage -t --warn-long 2.3 src/sage/symbolic/constants_c.pyx  # 1 doctest failed
# sage -t --warn-long 2.3 src/sage/matrix/matrix1.pyx  # 2 doctests failed
# sage -t --warn-long 2.3 src/sage/modules/free_module_element.pyx  # 1 doctest failed

Full log is attached. Previous similar tickets are : #16703, #13011.

One reason is a bug in implementation of N(), which is caused by always stripping precision tick away in get(), setting NumberMarks->False. (Or at least it has become a bug - this line of code dates back to 2006).

Attachments (2)

mathematica.log (20.1 KB) - added by slabbe 6 years ago.
mathematica-10.3.1-2016-03-12.log (6.2 KB) - added by mkoeppe 5 years ago.

Download all attachments as: .zip

Change History (53)

Changed 6 years ago by slabbe

comment:1 Changed 6 years ago by slabbe

  • Description modified (diff)

comment:2 Changed 6 years ago by dunfield

I get similar doctest failures with Sage 6.7 and Mathematica 10 running on OS X. It looks to me like it's an issue with how Sage is formatting things; the output of the doctests often looks like it is TeX'ed. In particular, I think somehow the _latex_ method of sage.interfaces.mathematica.MathematicaElement is being called instead of just repr as you would expect. Here's a simple example:

sage: e = mathematica('{{1,2},{3,4}}') 
sage: e
\left(
                 \begin{array}{cc}
                  1 & 2 \                  3 & 4 \                 \end{array}
                 \right)
sage: repr(e)
'{{1, 2}, {3, 4}}'
sage: str(e)
        {{1, 2}, {3, 4}}
sage: e._latex_()
'\\left(\n                  \\begin{array}{cc}\n                   1 & 2 [...]

comment:3 Changed 6 years ago by etn40ff

After fixing my sage install I got similar issues too. I am running 6.8.beta8 with Mathematica 10.1

I did few checks and it looks like repr is the method being called; to see this just do the following changes

diff --git a/src/sage/interfaces/mathematica.py b/src/sage/interfaces/mathematica.py
index aa5a848..e348927 100644
--- a/src/sage/interfaces/mathematica.py
+++ b/src/sage/interfaces/mathematica.py
@@ -654,6 +654,8 @@ class MathematicaElement(ExpectElement):
         return z[i+1:].strip()
 
     def __repr__(self):
+        import traceback
+        for s in traceback.format_stack():
+            print s
         P = self._check_valid()
         return P.get(self._name, ascii_art=False).strip()

Then run

$ sage -br
sage: mathematica(pi)
  File "/opt/sage/src/bin/sage-ipython", line 14, in <module>
    app.start()

  File "/opt/sage/local/lib/python2.7/site-packages/IPython/terminal/ipapp.py", line 371, in start
    self.shell.mainloop()

  File "/opt/sage/local/lib/python2.7/site-packages/IPython/terminal/interactiveshell.py", line 383, in mainloop
    self.interact(display_banner=display_banner)

  File "/opt/sage/local/lib/python2.7/site-packages/IPython/terminal/interactiveshell.py", line 507, in interact
    self.run_cell(source_raw, store_history=True)

  File "/opt/sage/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2871, in run_cell
    interactivity=interactivity, compiler=compiler, result=result)

  File "/opt/sage/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2981, in run_ast_nodes
    if self.run_code(code, result):

  File "/opt/sage/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3035, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-1-568cde928ef5>", line 1, in <module>
    mathematica(pi)

  File "/opt/sage/local/lib/python2.7/site-packages/IPython/core/displayhook.py", line 232, in __call__
    format_dict, md_dict = self.compute_format_data(result)

  File "/opt/sage/local/lib/python2.7/site-packages/IPython/core/displayhook.py", line 138, in compute_format_data
    return self.shell.display_formatter.format(result)

  File "/opt/sage/local/lib/python2.7/site-packages/sage/repl/display/formatter.py", line 128, in format
    return self.dm.displayhook(obj)

  File "/opt/sage/local/lib/python2.7/site-packages/sage/repl/rich_output/display_manager.py", line 745, in displayhook
    plain_text, rich_output = self._rich_output_formatter(obj, dict())

  File "/opt/sage/local/lib/python2.7/site-packages/sage/repl/rich_output/display_manager.py", line 610, in _rich_output_formatter
    plain_text = self._backend.plain_text_formatter(obj, **rich_repr_kwds)

  File "/opt/sage/local/lib/python2.7/site-packages/sage/repl/rich_output/backend_base.py", line 305, in plain_text_formatter
    plain_text = self._apply_pretty_printer(SagePrettyPrinter, obj)

  File "/opt/sage/local/lib/python2.7/site-packages/sage/repl/rich_output/backend_base.py", line 250, in _apply_pretty_printer
    printer.pretty(obj)

  File "/opt/sage/local/lib/python2.7/site-packages/sage/repl/display/pretty_print.py", line 147, in pretty
    ok = representation(obj, self, cycle)

  File "/opt/sage/local/lib/python2.7/site-packages/sage/repl/display/fancy_repr.py", line 276, in __call__
    output = repr(obj)

  File "/opt/sage/local/lib/python2.7/site-packages/sage/interfaces/mathematica.py", line 658, in __repr__
    for s in traceback.format_stack():

\pi

comment:4 follow-up: Changed 6 years ago by dimpase

another annoying bug is that if mathematica is not installed then

sage: mathematica(1) # or whatever

just hangs, and even Ctrl-C is unable to interrupt this.

Last edited 6 years ago by dimpase (previous) (diff)

comment:5 in reply to: ↑ 4 Changed 6 years ago by dimpase

Replying to dimpase:

another annoying bug is that if mathematica is not installed then

sage: mathematica(1) # or whatever

just hangs, and even Ctrl-C is unable to interrupt this.

this is fixed in #18908

comment:6 Changed 6 years ago by dimpase

The root of the "too much TeX" problem seems to be that at the moment by default mathematica interface outputs in LaTeX mode. I think this should be changed to plain. One way to change this is as follows.

--- a/src/sage/interfaces/mathematica.py
+++ b/src/sage/interfaces/mathematica.py
@@ -885,9 +885,10 @@ class MathematicaElement(ExpectElement):
                     self.save, kwds, '.png', OutputImagePng)
         else:
             OutputLatex = display_manager.types.OutputLatex
-            if display_manager.preferences.text == 'plain':
+            dmp = display_manager.preferences.text
+            if dmp is None or dmp == 'plain':
                 return
-            if OutputLatex in display_manager.supported_output():
+            if dmp == 'latex' and OutputLatex in display_manager.supported_output():
                 return OutputLatex(self._latex_())
         
     def show(self, ImageSize=600):

after this change only 9 doctests in sage/interfaces/mathematica.py are failing, and these are mostly due to floating point noise.

Please tell me if I should proceed with this change. (One will have to document this properly too).

comment:7 Changed 6 years ago by dimpase

  • Cc vbraun added
  • Status changed from new to needs_info

changes around display_manager are due to Volker. I wonder whether he overlooked the fact that normally display_manager.preferences.text is None rather than display_manager.preferences.text == 'plain' holds.

comment:8 Changed 6 years ago by dimpase

there is something going on with 'N()' that I don't get:

sage: mathematica('N[Pi,10]')
3.1415926535897932384626433832795028842
sage: mathematica.eval('N[Pi,10]')
         3.141592654
sage: mathematica('Pi').N(10)
3.1415926535897932384626433832795028842
sage: 

unless we do that eval, we get way too many digits.

comment:9 follow-up: Changed 6 years ago by dimpase

  • Branch set to public/18888
  • Commit set to 4853c276c221510b6ef17eaf4c8d415a18a0f3c2

comment:10 in reply to: ↑ 9 Changed 6 years ago by dimpase

Replying to dimpase:

I neither know how to deal with displaying images (via rich_repr...), nor what to do with N(). Otherwise, see the branch

comment:11 Changed 5 years ago by slelievre

  • Cc slelievre added
  • Keywords mathematica added

comment:12 Changed 5 years ago by git

  • Commit changed from 4853c276c221510b6ef17eaf4c8d415a18a0f3c2 to 4fd09adee1cffa4fb7922862d20d2587f7837362

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

4fd09adget rid of default TeX, etc

comment:13 Changed 5 years ago by dimpase

  • Milestone changed from sage-6.8 to sage-7.1
  • Status changed from needs_info to needs_review

comment:14 Changed 5 years ago by dimpase

  • Cc mkoeppe added

with Mathematica 9 on 64-bit Linux, all tests pass with this branch. Please test and tell if this is the case on other systems/versions.

comment:15 follow-ups: Changed 5 years ago by mkoeppe

With Mathematica 10.3.1 for Mac OS X x86 (64-bit), various test failures related to number of displayed digits. See log attached.

Changed 5 years ago by mkoeppe

comment:16 Changed 5 years ago by vbraun

The display_manager.preferences.text == None is for you to decide; Just return what you think a good default for Mathematica objects is. Generally it is the same as plain, so feel free to implement that.

E.g. one difference is the behavior of

sage: pretty_print(1/x)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{x}
sage: %display text plain
sage: pretty_print(1/x)       # I specifically asked for plain text 
1/x

comment:17 in reply to: ↑ 15 Changed 5 years ago by dimpase

Replying to mkoeppe:

With Mathematica 10.3.1 for Mac OS X x86 (64-bit), various test failures related to number of displayed digits. See log attached.

Matthias, it seems that in your setup N() and n() methods of Mathematica objects are mixed up. For me on Linux, with 64-bit Mathematica 9, I have

sage: t=mathematica('Pi')
sage: t.n?
Docstring:
   Return a numerical approximation of x with at least prec bits of
   precision.

   EXAMPLES:
[...]
Init docstring: x.__init__(...) initializes x; see help(type(x)) for signature
File:           /home/scratch/dimpase/sage/sage/src/sage/structure/element.pyx
Type:           builtin_function_or_method
sage: t.N?
Signature:      t.N(*args)
Docstring:
   EXAMPLES:
[...]
Init docstring: x.__init__(...) initializes x; see help(type(x)) for signature
File:           /home/scratch/dimpase/sage/sage/local/lib/python2.7/site-packages/sage/interfaces/mathematica.py
Type:           instancemethod
sage: t.n(20)
3.1416
sage: t.N(20)
3.141592653589793238462643383279502884197169399375105820975

What is the output of these (in particular, two last) commands for you?

comment:18 in reply to: ↑ 15 ; follow-up: Changed 5 years ago by dimpase

Replying to mkoeppe:

With Mathematica 10.3.1 for Mac OS X x86 (64-bit),

it might be that your Mathematica is 32-bit, no?

comment:19 in reply to: ↑ 18 Changed 5 years ago by mkoeppe

Here's the output:

sage: sage: t.n(20)
3.1416
sage: sage: t.N(20)
3.14159265358979323846

Replying to dimpase:

Replying to mkoeppe:

With Mathematica 10.3.1 for Mac OS X x86 (64-bit),

it might be that your Mathematica is 32-bit, no?

No. I copy-pasted from the banner that it displays at start; and also verified by calling mathematica.SystemInformation(). Note that in the docstrings that you copied, it guarantees "at least" ... digits. So the tests should probably not rely on a particular number of digits.

comment:20 Changed 5 years ago by dimpase

OK, at least I understand the reason for N() to output seemingly random length things. I set up logging output to a file, as follows, to see this:

--- a/src/sage/interfaces/mathematica.py
+++ b/src/sage/interfaces/mathematica.py
@@ -401,7 +401,7 @@ class Mathematica(ExtraTabCompletion, Expect):
     """
     Interface to the Mathematica interpreter.
     """
-    def __init__(self, maxread=None, script_subdirectory=None, logfile=None, server=None, server_tmpdir=None):
+    def __init__(self, maxread=None, script_subdirectory=None, logfile="/tmp/xxx.log", server=None, server_tmpdir=None):
         Expect.__init__(self,
                         name = 'mathematica',
                         prompt = 'In[[0-9]+]:=',

Namely, the interface works with M-ca's InputForm; e.g. when mathematica('Pi').N(10) is computed, intermediate data is stored in InputForm, and it is on my system

3.14159265358979323846264338327950419993`10.

In more detail:

In[1]:= x2=N[Pi,10]                                                                                       
Out[1]= 3.141592654
In[2]:= InputForm[x2]                                                                                     
Out[2]//InputForm= 3.14159265358979323846264338327950419993`10.
In[3]:= 3.14159265358979323846264338327950419993`10.                                                      
Out[3]= 3.141592654                                                                                             
In[4]:= InputForm[x2,NumberMarks->False]                                                                  
Out[4]//InputForm= 3.14159265358979323846264338327950419993

Then get() is called, and it does (line 528 of mathematica.py)

return self.eval('InputForm[%s, NumberMarks->False]'%var, strip=True)

stripping 10 after the tick away (this is what NumberMarks->False does)! Oops... One workaround would be to provide an implementation of N() avoiding get all together.

Last edited 5 years ago by dimpase (previous) (diff)

comment:21 Changed 5 years ago by dimpase

  • Description modified (diff)
  • Status changed from needs_review to needs_work
  • Summary changed from failing optional mathematica tests to failing optional mathematica tests, due to bugs in N() and n()
  • Work issues set to fix `N()`

comment:22 Changed 5 years ago by dimpase

And here is a (hilarious) trace of the communications with M-ca, upon calling mathematica('Pi').n(10).

Mathematica 9.0 for Linux x86 (64-bit)
Copyright 1988-2013 Wolfram Research, Inc.
In[1]:= sage0=Pi;
In[2]:= sage1=0;
In[3]:= sage2=gen[sage1];
In[4]:= sage1=prec[sage0];
In[5]:= sage3=1;
In[6]:= sage3=10;
In[7]:= sage3 < sage1
Out[7]= 10 < prec[Pi]
In[8]:= sage3 > sage1
Out[8]= 10 > prec[Pi]
In[9]:= sage3 == sage1
Out[9]= 10 == prec[Pi]
In[10]:= sage3=1.0000;
In[11]:= sage0
Out[11]= Pi
In[12]:= sage3=1.0000*I;
In[13]:= InputForm[sage0, NumberMarks->False]
Out[13]//InputForm= Pi
In[14]:= 

certainly, M-ca does not know gen or prec, and thus the comparisons like

In[7]:= sage3 < sage1
Out[7]= 10 < prec[Pi]

fail miserably. Could anyone advice me on how to get the Sage part of the trace? I have no clue where these gen and prec come from.

Last edited 5 years ago by dimpase (previous) (diff)

comment:23 Changed 5 years ago by dimpase

  • Work issues changed from fix `N()` to fix `N()` and `n()`

comment:24 Changed 5 years ago by dimpase

OK, we don't need to implement n() here, only N(). As far as n() goes, part of trouble comes from Sage being unable to do n() of constants in the SR (symbolic ring) properly. E.g.

sage: pi.n(10)
3.1

We can also implement n() as sage().n(), not sure if we should. E.g. gap(2/3).n() is not implemented. Perhaps explicitly making it throw NotImplementedError is the best?

comment:25 follow-up: Changed 5 years ago by vbraun

Whats wrong? With hindsight you need

sage: log(3.14 / 0.005, 2)
9.29462074889163

bits of precision to know the next decimal digit, and there is probably a guard (binary) digit:

sage: pi.n(11)
3.14
sage: pi.n(digits=10)
3.141592654

comment:26 in reply to: ↑ 25 Changed 5 years ago by dimpase

Replying to vbraun:

Whats wrong? With hindsight you need

sage: log(3.14 / 0.005, 2)
9.29462074889163

bits of precision to know the next decimal digit, and there is probably a guard (binary) digit:

sage: pi.n(11)
3.14
sage: pi.n(digits=10)
3.141592654

well, I am struggling to understand the error here: E.g. how would you explain the following: (it sort of works if the precision is specified...)

sage: mathematica('Pi').n()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-0b9c467a05fb> in <module>()
----> 1 mathematica('Pi').n()

/home/scratch/dimpase/sage/sage/src/sage/structure/element.pyx in sage.structure.element.Element.numerical_approx (build/cythonized/sage/structure/element.c:7330)()
    717         """
    718         from sage.misc.functional import numerical_approx
--> 719         return numerical_approx(self, prec=prec, digits=digits,
    720                                 algorithm=algorithm)
    721     n = numerical_approx

/home/scratch/dimpase/sage/sage/local/lib/python2.7/site-packages/sage/misc/functional.pyc in numerical_approx(x, prec, digits, algorithm)
   1330 
   1331     if prec > inprec:
-> 1332         raise TypeError("cannot approximate to a precision of %s bits, use at most %s bits" % (prec, inprec))
   1333 
   1334     # The issue is not precision, try conversion instead

TypeError: cannot approximate to a precision of 53 bits, use at most          prec[Pi] bits

comment:27 follow-up: Changed 5 years ago by vbraun

Well I don't have Mathematica, you'll have to look at sage.misc.functional.numerical_approx yourself. Whats mathematica('Pi').prec()?

comment:28 in reply to: ↑ 27 Changed 5 years ago by dimpase

Replying to vbraun:

Well I don't have Mathematica, you'll have to look at sage.misc.functional.numerical_approx yourself. Whats mathematica('Pi').prec()?

it is a symbolic Mathematica expression prec[Pi]. It cannot be evaluated to anything. Evaluating mathematica('Pi').n(), on Mathematica side I see the following:

In[1]:= sage0=Pi;
In[2]:= sage1=0;
In[3]:= sage2=gen[sage1];
In[4]:= sage1=prec[sage0];
In[5]:= sage3=1;
In[6]:= sage3=53;
In[7]:= sage1 < sage3
Out[7]= prec[Pi] < 53
In[8]:= sage1 > sage3
Out[8]= prec[Pi] > 53
In[9]:= sage1 == sage3
Out[9]= prec[Pi] == 53
In[10]:= sage1
Out[10]= prec[Pi]

(in comment 22 I posted the corresponding log for .n(10) (I made a typo, wrote that it is .n(), now corrected there).

comment:29 follow-up: Changed 5 years ago by vbraun

The mathematica interface needs to implement prec() and/or n() methods. Right now they just fall through to the __getattr__ hook and are translated in nonsensical Mathematica functions.

comment:30 in reply to: ↑ 29 Changed 5 years ago by dimpase

Replying to vbraun:

The mathematica interface needs to implement prec() and/or n() methods. Right now they just fall through to the __getattr__ hook and are translated in nonsensical Mathematica functions.

OK, I have implemented n(), and it works.

But I am at loss as to how to implement N() (i.e. the Mathematica function call). The problem is that get() method of Mathematica class in https://github.com/sagemath/sage/blob/develop/src/sage/interfaces/mathematica.py#L517 should get the parameter ascii_art set to True while it calls Mathematica via Expect. And I cannot find an interface that would do this for me.

comment:31 follow-up: Changed 5 years ago by vbraun

I don't understand, the .N() method should just be whatever it is by default. I.e. call mathematica and wrap whatever the output of N() is.

comment:32 follow-up: Changed 5 years ago by git

  • Commit changed from 4fd09adee1cffa4fb7922862d20d2587f7837362 to 7f9f0e0a79f3b35e4f78abe10efbbc3977b6964f

Branch pushed to git repo; I updated commit sha1. New commits:

7f9f0e0cleaning up N() and n()

comment:33 in reply to: ↑ 31 Changed 5 years ago by dimpase

  • Status changed from needs_work to needs_review

Replying to vbraun:

I don't understand, the .N() method should just be whatever it is by default. I.e. call mathematica and wrap whatever the output of N() is.

The thing is that

self.parent().N(self, *args)

doe not work properly, as data is kept in InputFormat on Mathematica side, e.g. 1.111111111111 with precision 5 is not kept the way one expects, 1.1111, but as 1.111111111111<backtick>5. And that <backtick> gets stripped off by get(), getting the precision info lost in the process.

So I ended up calling self.parent().eval() directly, took me the whole morning to figure out the right way. Anyhow, ready for review now!

comment:34 follow-up: Changed 5 years ago by mkoeppe

  • Status changed from needs_review to needs_work

All good, except:

File "src/sage/symbolic/constants.py", line 1082, in sage.symbolic.constants.Khinchin
Failed example:
    m.N(200)                                 # optional - mathematica
Expected:
    2.685452001065306445309714835481795693820382293994462953051152345557218859537152002801141174931847697995153465905288090082897677716410963051792533483259668381852315421332119499626039328522044819409618068664166343945732171166692445674          
Got:
            2.6854520010653064453097148354817956938203822939944629530511523455572 
    >    188595371520028011411749318476979951534659052880900828976777164109630517 
    >    925334832596683818523154213321194996260393285220448194096181

comment:35 in reply to: ↑ 34 Changed 5 years ago by dimpase

Replying to mkoeppe:

All good, except:

oh, I forgot to check doctests in these files... Will do shortly.

comment:36 Changed 5 years ago by git

  • Commit changed from 7f9f0e0a79f3b35e4f78abe10efbbc3977b6964f to 8a6c9c4f02c0fe6898f12b6475d03c1f303685e2

Branch pushed to git repo; I updated commit sha1. New commits:

8a6c9c4N() outputs multiline ascii-art now, just like math itself

comment:37 Changed 5 years ago by dimpase

  • Status changed from needs_work to needs_review

comment:38 Changed 5 years ago by mkoeppe

  • Reviewers set to Matthias Koeppe

Tests pass now. Didn't look at your code changes.

comment:39 in reply to: ↑ 32 Changed 5 years ago by slelievre

Replying to git:

Branch pushed to git repo; I updated commit sha1. New commits:

7f9f0e0cleaning up N() and n()

Any reason to use pres rather than prec to abbreviate "precision"?

comment:40 Changed 5 years ago by git

  • Commit changed from 8a6c9c4f02c0fe6898f12b6475d03c1f303685e2 to 53e76e679a7c411aa4f193dabca0d8281fdaf052

Branch pushed to git repo; I updated commit sha1. New commits:

53e76e6renamed pres, added missing #opt tag, docs

comment:41 Changed 5 years ago by dimpase

  • Milestone changed from sage-7.1 to sage-7.2

comment:42 follow-up: Changed 5 years ago by yzh

With Mathematica 10.3.1 for Mac OS X x86 (64-bit), all tests passed.

The old doctests showed that the results of math_bessel_K(nu,x) were different on 32-bit and 64-bit machines.

@@ -310,14 +306,13 @@ For more details, see the documentation for ``._sage_()``.
 OTHER Examples::
 
     sage: def math_bessel_K(nu,x):
     ...       return mathematica(nu).BesselK(x).N(20)
     ...
     sage: math_bessel_K(2,I)                      # optional - mathematica
-    0.180489972066962*I - 2.592886175491197             # 32-bit
-    -2.59288617549119697817 + 0.18048997206696202663*I  # 64-bit
+    -2.5928861754911969782 + 0.1804899720669620266 I

Have they become identical now?

Also, I was puzzled by the discrepancy between

sage: mathematica('Pi').N(10)
         3.141592654

and

sage: mathematica('Pi').n(10)
3.1

After reading up on the code, I understand that MathematicaElement.N() sets the precision in decimal digits, whereas MathematicaElement.n() sets the precision in bits, so that the two examples above behave as

sage: pi.n(digits=10)
3.141592654

and

sage: pi.n(10)
3.1

respectively. Is such difference between .N() and .n() intended for MathematicaElement? Then maybe this should be specified in the documentations? Does it make sense to implement mathematica('Pi').n(digits=10) as well?

comment:43 in reply to: ↑ 42 Changed 5 years ago by dimpase

Replying to yzh:

With Mathematica 10.3.1 for Mac OS X x86 (64-bit), all tests passed.

The old doctests showed that the results of math_bessel_K(nu,x) were different on 32-bit and 64-bit machines.

@@ -310,14 +306,13 @@ For more details, see the documentation for ``._sage_()``.
 OTHER Examples::
 
     sage: def math_bessel_K(nu,x):
     ...       return mathematica(nu).BesselK(x).N(20)
     ...
     sage: math_bessel_K(2,I)                      # optional - mathematica
-    0.180489972066962*I - 2.592886175491197             # 32-bit
-    -2.59288617549119697817 + 0.18048997206696202663*I  # 64-bit
+    -2.5928861754911969782 + 0.1804899720669620266 I

the difference was due to a bug that is now fixed, I think.

Have they become identical now?

they should be. I don't have 32-bit Mathematical to test, but I think it should be the same.

Also, I was puzzled by the discrepancy between

sage: mathematica('Pi').N(10)
         3.141592654

and

sage: mathematica('Pi').n(10)
3.1

After reading up on the code, I understand that MathematicaElement.N() sets the precision in decimal digits, whereas MathematicaElement.n() sets the precision in bits, so that the two examples above behave as

sage: pi.n(digits=10)
3.141592654

and

sage: pi.n(10)
3.1

respectively. Is such difference between .N() and .n() intended for MathematicaElement? Then maybe this should be specified in the documentations? Does it make sense to implement mathematica('Pi').n(digits=10) as well?

the idea is that N() is a Mathematica function, and n() is a Sage function.

comment:44 Changed 5 years ago by dimpase

  • Status changed from needs_review to needs_work
  • Work issues changed from fix `N()` and `n()` to add () in `n()`

Does it make sense to implement mathematica('Pi').n(digits=10) as well?

oops, right, there is a typo in n() implementation. I'll fix it at once.

comment:45 Changed 5 years ago by git

  • Commit changed from 53e76e679a7c411aa4f193dabca0d8281fdaf052 to 031e2219a488ac6c30372952482d17fa3cfa1986

Branch pushed to git repo; I updated commit sha1. New commits:

4468136Merge branch 'public/18888' of trac.sagemath.org:sage into mat72b
031e221added missing **kwargs

comment:46 Changed 5 years ago by dimpase

  • Status changed from needs_work to needs_review
  • Work issues add () in `n()` deleted

OK, fixed. Please have a look.

comment:47 Changed 5 years ago by git

  • Commit changed from 031e2219a488ac6c30372952482d17fa3cfa1986 to eb0bed51d49219938c811ee528ed1ada2600bb99

Branch pushed to git repo; I updated commit sha1. New commits:

eb0bed5right link to the docs of n()

comment:48 Changed 5 years ago by yzh

  • Authors set to ​Dima Pasechnik
  • Reviewers changed from Matthias Koeppe to Matthias Koeppe, Yuan Zhou

Thanks a lot for the nice work.

comment:49 Changed 5 years ago by yzh

  • Status changed from needs_review to positive_review

comment:50 Changed 5 years ago by vbraun

  • Authors changed from ​Dima Pasechnik to Dima Pasechnik

invisible space

comment:51 Changed 5 years ago by vbraun

  • Branch changed from public/18888 to eb0bed51d49219938c811ee528ed1ada2600bb99
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.