thelamecamel wrote:
> Hi guys,
>
> For the benefit of others stuck as I was, or for those working on the
> ticket, here's a simplified version of what's been working for me over
> the last few months:
>
> res = mathematica(mathcommand)
> res_s = repr(res).replace('{','[').replace('}',']').replace
> ('*^','e').replace('\n','') #Convert string from mathematica syntax to
> SAGE syntax
> eval(res_s, {'I': numpy.complex(0,1)})
>
> Note that mathematica uses *^ instead of 10^ or e. There are some
> other rules in sympy's parser, which is included with sage but is
> seemingly unused (and possibly has minor whitespace issues?)
>
> I had to use Python's eval, rather than sage_eval, because sage_eval
> seems to die with some long inputs. eval can crash too (with the same
> EOF error), but it seems to be more robust. Below is an example for
> which both sage_eval() and eval() die. If anyone could shed light on
> the matter it would be appreciated. N.B. the string should be a
> single line, but may get wrapped by your email client.
>
> This is Sage Version 3.2.3, Release Date: 2009-01-05 running on Mac OS
> X 10.5.6, on a Core 2 Duo.
>
>
> Cheers,
> Felix
>
>
> sage: import numpy
> sage: sage_eval("[[-1.8932465265296008 + 1.893245401219096*I,
> 1.6087131626818518e-13 + 0.2695869628135388*I, 4.038436252074007e-13 +
> 0.5773220560437329*I, 0.040116139014415714 - 1.817230393941216e-12*I,
> 0.08763251260817738 + 5.075925790798408e-12*I], [-0.31896241585415663
> - 0.3189619384222391*I, -0.7736920455160119 + 6.955547249276606e-14*I,
> -0.09760283144392495 - 1.446620601086579e-13*I,
> -4.7592693674936015e-12 + 0.11967794129700637*I, 4.505212175542894e-12
> - 0.03242615482565919*I], [0.15796096006135588 + 0.1579558759160282*I,
> 0.1033123763011309 + 5.815070647230414e-13*I, -0.760297341093265 -
> 1.257605131144146e-12*I, -1.7810239394400185e-11 +
> 0.16226566764622224*I, 1.135841420918382e-12 - 0.12040909205325775*I],
> [-0.04396392304349049 + 0.04395777885494245*I, -6.296074772649263e-13
> + 0.32696955556039625*I, 4.616307336391401e-12 -
> 0.25810574383773044*I, -1.2307441793242817 - 1.56307189
You are missing a closing bracket and comma at the end of this line
(i.e., "],"). The number looks a little smaller as well. Was something
chopped off?
Jason
> [0.03422429098964126 - 0.03425285256357742*I, 3.7616437742471476e-13 +
> 0.04103981205323293*I, -6.284223141861389e-12 - 0.28800856674905706*I,
> -0.21213614940591977 + 1.0860881638485864e-10*I, -1.1903766525513024 +
> 8.411160656862648e-12*I]]", {'I': numpy.complex(0,1)})
> ------------------------------------------------------------
> File "<string>", line 1
> [[-RealNumber('1.8932465265296008')
> <SNIP>
> SyntaxError: unexpected EOF while parsing
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---