Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve conversion from interface to sage objects (i.e., the dot sage method) #1491

Closed
williamstein opened this issue Dec 13, 2007 · 3 comments

Comments

@williamstein
Copy link
Contributor



On Dec 13, 2007 11:54 AM, Timothy Clemans <timothy.clemans@gmail.com> wrote:
> 
> I'm getting
> 
> {{{id=2|
> def math_bessel_K(nu,x):
>        return mathematica(nu).BesselK(x).N(20).sage()
> math_bessel_K(2,I)
> ///
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/home/tclemans/.sage/sage_notebook/worksheets/admin/5/code/
> 9.py", line 6, in <module>
>     exec compile(ur'math_bessel_K(Integer(2),I)' + '\n', '', 'single')
>   File "/home/was/s/data/extcode/sage/", line 1, in <module>
> 
>   File "/home/tclemans/.sage/sage_notebook/worksheets/admin/5/code/
> 9.py", line 5, in math_bessel_K
>     return mathematica(nu).BesselK(x).N(Integer(20)).sage()
>   File "/home/was/s/local/lib/python2.5/site-packages/sage/interfaces/
> expect.py", line 1086, in sage
>     return self._sage_()
>   File "/home/was/s/local/lib/python2.5/site-packages/sage/interfaces/
> expect.py", line 1079, in _sage_
>     return sage.misc.sage_eval.sage_eval(repr(self))
>   File "/home/was/s/local/lib/python2.5/site-packages/sage/misc/
> sage_eval.py", line 112, in sage_eval
>     raise SyntaxError, "%s\nError using SAGE to evaluate '%s'"%(msg,
> p)
> SyntaxError: invalid syntax (<string>, line 1)
> Error using SAGE to evaluate '-
> RealNumber('2.592886175491196978167651322538251462935637034451900356688')
> +
> 
> RealNumber('0.180489972066962026629620880838378650496225604668529521981')*I'
> }}}

That's coming from a newline, which appears in Mathematica 5 I guess, but not 6.  Anyway,
the patch I justed posted at 

fixes the problem.  Alternatively rewrite the function like this:

sage: def math_bessel_K(nu,x):
  return sage_eval(repr(mathematica(nu).BesselK(x).N(20)).replace('\n',''))

Important note: The conversion from Mathematica to Sage, i.e., mathematica_object.sage()
is very naive still -- all it is is basically sage_eval(repr(...))!   This could/would be improved
if somebody cared a lot.

William

Component: interfaces

Issue created by migration from https://trac.sagemath.org/ticket/1491

@williamstein williamstein added this to the sage-2.9 milestone Dec 13, 2007
@williamstein williamstein self-assigned this Dec 13, 2007
@williamstein
Copy link
Contributor Author

Attachment: trac-1491.patch.gz

@sagetrac-cwitty
Copy link
Mannequin

sagetrac-cwitty mannequin commented Dec 15, 2007

comment:1

Looks good. (Looks reasonable, and sage/interfaces/mathematica.py doctests pass on sage.math.)

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Dec 15, 2007

comment:2

Merged in 2.9.rc0.

@sagetrac-mabshoff sagetrac-mabshoff mannequin closed this as completed Dec 15, 2007
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant