Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#4948 closed enhancement (fixed)

[with patch, positive review] implement the transfer of Mathematica lists back to Sage

Reported by: mabshoff Owned by: was
Priority: major Milestone: sage-4.1.2
Component: interfaces Keywords:
Cc: jason Merged in: Sage 4.1.2.alpha2
Authors: Felix Lawrence Reviewers: William Stein, Minh Van Nguyen
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

Make the following work:

----------------------------------------------------------------------
| Sage Version 3.2.3, Release Date: 2009-01-05                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: slist = [1,2,3]
sage: mathematica(slist) 
{1, 2, 3}
sage: list(mathematica(slist))
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)

/home/mabshoff/.sage/temp/sage/11670/_home_mabshoff__sage_init_sage_0.py in <module>()
----> 1 
      2 
      3 
      4 
      5 

/usr/local/sage/local/lib/python2.5/site-packages/sage/interfaces/expect.pyc in __len__(self)
   1345 
   1346     def __len__(self):
-> 1347         raise NotImplementedError
   1348 
   1349     def __reduce__(self):

NotImplementedError: 

Attachments (2)

trac-4948-mathematica_lists.patch (8.4 KB) - added by flawrence 10 years ago.
trac-4948-mathematica_lists 12660.patch (820 bytes) - added by flawrence 10 years ago.
a further patch adding doctest for generic _exponent_symbol()

Download all attachments as: .zip

Change History (12)

comment:1 Changed 11 years ago by mabshoff

  • Cc jason added

Jason comments:

These are not the right way to do this, but they seem to give results 
for right now, at least until someone fixes this:

sage: a=mathematica([1,2,3])
sage: [a[i] for i in range(1,a.Length()+1)]
[1, 2, 3]

Or

sage: a=mathematica(slist)
sage: a._Expect__sage_list
[1, 2, 3]

Cheers,

Michael

comment:2 Changed 11 years ago by mabshoff

  • Milestone changed from sage-3.4 to sage-3.4.1

Changed 10 years ago by flawrence

comment:3 Changed 10 years ago by flawrence

  • Authors set to flawrence
  • Summary changed from implement the transfer of Mathematica lists back to Sage to [with patch, needs review] implement the transfer of Mathematica lists back to Sage

The patch I just attached does a little more than the scope of this ticket - it also gets mmalist.sage() working, as well as allowing import of floats with exponents (e.g. 4.5e80) from both mathematica and GP (plus it lays the groundwork for importing nonstandard exponent notation from other programs too).

comment:4 Changed 10 years ago by was

  • Summary changed from [with patch, needs review] implement the transfer of Mathematica lists back to Sage to [with patch, positive review] implement the transfer of Mathematica lists back to Sage

Great work! I hope you'll do more to improve the Sage /Mathematica interface. Thanks!

comment:5 Changed 10 years ago by mvngu

What about doctest for this function in sage/interfaces/expect.py?

1142	    def _exponent_symbol(self): 
1143	        """ 
1144	        Return the symbol used to denote *10^ in floats, e.g 'e' in 1.5e6 
1145	        """ 
1146	        return 'e' 

comment:6 Changed 10 years ago by mvngu

  • Summary changed from [with patch, positive review] implement the transfer of Mathematica lists back to Sage to [with patch, needs work] implement the transfer of Mathematica lists back to Sage

Changed 10 years ago by flawrence

a further patch adding doctest for generic _exponent_symbol()

comment:7 Changed 10 years ago by flawrence

  • Component changed from misc to interfaces
  • Owner changed from cwitty to was
  • Summary changed from [with patch, needs work] implement the transfer of Mathematica lists back to Sage to [with patch, partial positive review, needs review] implement the transfer of Mathematica lists back to Sage

I added the requested doctest for the generic _exponent_symbol(), a method that is meant to be overloaded by each derived class (i.e. the interface to gp, mathematica, etc). Since this is meant to be overloaded by each of the interfaces, I didn't use any existing interface in this doctest, as when _exponent_symbol() was overloaded by that interface the doctest would become misleading. Instead I created a fake interface so that the doctest would always call the correct version of _exponent_symbol. It's a bit messy but it's the most stable way of doctesting the function that I could think of.

The approach could be taken to write doctests for the rest of the methods in the Expect class.

comment:8 Changed 10 years ago by mvngu

  • Merged in set to Sage 4.1.2.alpha2
  • Resolution set to fixed
  • Reviewers set to William Stein, Minh Van Nguyen
  • Status changed from new to closed
  • Summary changed from [with patch, partial positive review, needs review] implement the transfer of Mathematica lists back to Sage to [with patch, positive review] implement the transfer of Mathematica lists back to Sage

Merged patches in this order:

  1. trac-4948-mathematica_lists.patch
  2. trac-4948-mathematica_lists 12660.patch

comment:9 Changed 10 years ago by mvngu

  • Authors changed from flawrence to Felix Lawrence

comment:10 Changed 10 years ago by flawrence

N.B. the doctests introduced by the above patches fail on 32-bit systems - see #6999.

Note: See TracTickets for help on using tickets.