You want to use the method _mathematica_init_()
. For matlab, I haven't seen _matlab_init_()
method but there is a _octave_init_()
method and according to Octave website "The Octave syntax is largely compatible with Matlab" :
sage: A = sin(x)
sage: A._mathematica_init_()
'Sin[x]'
sage: A._octave_init_()
'sin(x)'
sage: B = matrix(3, range(9))
sage: B._mathematica_init_()
'{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}'
sage: B._octave_init_()
'[0 1 2]\n[3 4 5]\n[6 7 8]'
You have a bunch of those methods:
sage: [method for method in dir(A) if method.endswith('_init_')]
['_axiom_init_',
'_fricas_init_',
'_gap_init_',
'_giac_init_',
'_gp_init_',
'_interface_init_',
'_kash_init_',
'_macaulay2_init_',
'_magma_init_',
'_maple_init_',
'_mathematica_init_',
'_maxima_init_',
'_maxima_lib_init_',
'_octave_init_',
'_pari_init_',
'_polymake_init_',
'_r_init_',
'_singular_init_']
If you have mathematica installed, you may use it directly from sage by doing things like below. For me it does not work, because I do not have mathematica installed:
sage: Bm = mathematica(B)
...
TypeError: unable to start mathematica: End Of File (EOF). Exception style platform.
sage: Bm.Inverse() # or something like this
Conversely, with sage 8.6 because of ticket #25501 you may do:
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.6, Release Date: 2019-01-15 │
│ Using Python 2.7.15. Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: from sage.symbolic.integration.external import symbolic_expression_from_mathematica_string
sage: symbolic_expression_from_mathematica_string('Sin[x]')
sin(x)
sage: symbolic_expression_from_mathematica_string('{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}')
[[0, 1, 2], [3, 4, 5], [6, 7, 8]]