sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.43k stars 478 forks source link

Tigonometric functions conversion from Mathematica back to Sage #38852

Open janekj2727 opened 1 week ago

janekj2727 commented 1 week ago

Steps To Reproduce

Among all trigonometric functions, only $\sin$ and $\cos$ (and surprisingly all inverse functions) are correctly converted to their Sage equivalents from Mathematica when using sage() method on a mathematica object. Particularly Tan[x], Cot[x], Csc[x] and Sec[x] are converted to Tan(x), Cot(x), Csc(x) and Sec(x), i.e. the first letter is still uppercase and such functions are not recognized by Sage.

Expected Behavior

All trigonometric functions from Mathematica should be converted back to their Sage equivalents.

Actual Behavior

Capitalization of Tan, Cot, Sec and Csc from Mathematica prevails after conversion to Sage. The conversion table returns:

sage: sage.symbolic.expression.symbol_table['mathematica']
{('I', 0): I,
 ('True', 0): True,
 ('False', 0): False,
 ('Pi', 0): pi,
 ('E', 0): e,
 ('(1+Sqrt[5])/2', 0): golden_ratio,
 ('Log[2]', 0): log2,
 ('EulerGamma', 0): euler_gamma,
 ('Catalan', 0): catalan,
 ('Khinchin', 0): khinchin,
 ('Glaisher', 0): glaisher,
 ('Sin', 1): sin,
 ('Cos', 1): cos,
 ('ArcSin', 1): arcsin,
 ('ArcCos', 1): arccos,
 ('ArcTan', 1): arctan,
 ('ArcCot', 1): arccot,
 ('ArcCsc', 1): arccsc,
 ('ArcSec', 1): arcsec,
 ('Abs', 1): abs,
 ('Sqrt', 2): <function sqrt at 0x779e067cb9c0>,
 ('Surd', 2): real_nth_root,
 ('Arg', 1): arg,
 ('Re', 1): real_part,
 ('Im', 1): imag_part,
 ('Conjugate', 1): conjugate,
 ('Factorial', 1): factorial,
 ('Binomial', 2): binomial,
 ('ArcSinh', 1): arcsinh,
 ('ArcCosh', 1): arccosh,
 ('ArcTanh', 1): arctanh,
 ('ArcCoth', 1): arccoth,
 ('ArcSech', 1): arcsech,
 ('ArcCsch', 1): arccsch,
 ('Log', 1): log,
 ('PolyLog', 2): polylog,
 ('ProductLog', 2): lambert_w,
 ('HarmonicNumber', 1): harmonic_number,
 ('Zeta', 1): zeta,
 ('StieltjesGamma', 1): stieltjes,
 ('HurwitzZeta', 2): hurwitz_zeta,
 ('Gamma', 1): gamma,
 ('LogGamma', 1): log_gamma,
 ('Gamma', 2): gamma,
 ('Gamma', 3): <function _mathematica_gamma3 at 0x779db60b1120>,
 ('PolyGamma', 1): psi,
 ('PolyGamma', 2): psi,
 ('Beta', 2): beta,
 ('BesselJ', 2): bessel_J,
 ('BesselY', 2): bessel_Y,
 ('BesselI', 2): bessel_I,
 ('BesselK', 2): bessel_K,
 ('StruveH', 2): struve_H,
 ('StruveL', 2): struve_L,
 ('HankelH1', 2): hankel1,
 ('HankelH2', 2): hankel2,
 ('SphericalBesselJ', 2): spherical_bessel_J,
 ('SphericalBesselY', 2): spherical_bessel_Y,
 ('SphericalHankelH1', 2): spherical_hankel1,
 ('SphericalHankelH2', 2): spherical_hankel2,
 ('SphericalHarmonicY', 4): spherical_harmonic,
 ('EllipticE', 2): elliptic_e,
 ('EllipticE', 1): elliptic_ec,
 ('EllipticF', 2): elliptic_f,
 ('EllipticK', 1): elliptic_kc,
 ('EllipticPi', 3): elliptic_pi,
 ('JacobiND', 2): jacobi_nd,
 ('JacobiNS', 2): jacobi_ns,
 ('JacobiNC', 2): jacobi_nc,
 ('JacobiDN', 2): jacobi_dn,
 ('JacobiDS', 2): jacobi_ds,
 ('JacobiDC', 2): jacobi_dc,
 ('JacobiSN', 2): jacobi_sn,
 ('JacobiSD', 2): jacobi_sd,
 ('JacobiSC', 2): jacobi_sc,
 ('JacobiCN', 2): jacobi_cn,
 ('JacobiCD', 2): jacobi_cd,
 ('JacobiCS', 2): jacobi_cs,
 ('InverseJacobiND', 2): inverse_jacobi_nd,
 ('InverseJacobiNS', 2): inverse_jacobi_ns,
 ('InverseJacobiNC', 2): inverse_jacobi_nc,
 ('InverseJacobiDN', 2): inverse_jacobi_dn,
 ('InverseJacobiDS', 2): inverse_jacobi_ds,
 ('InverseJacobiDC', 2): inverse_jacobi_dc,
 ('InverseJacobiSN', 2): inverse_jacobi_sn,
 ('InverseJacobiSD', 2): inverse_jacobi_sd,
 ('InverseJacobiSC', 2): inverse_jacobi_sc,
 ('InverseJacobiCN', 2): inverse_jacobi_cn,
 ('InverseJacobiCD', 2): inverse_jacobi_cd,
 ('InverseJacobiCS', 2): inverse_jacobi_cs,
 ('JacobiAmplitude', 2): jacobi_am,
 ('ChebyshevT', 2): chebyshev_T,
 ('ChebyshevU', 2): chebyshev_U,
 ('LegendreP', 2): legendre_P,
 ('LegendreQ', 2): legendre_Q,
 ('LegendreP', 3): gen_legendre_P,
 ('LegendreQ', 3): gen_legendre_Q,
 ('HermiteH', 2): hermite,
 ('JacobiP', 4): jacobi_P,
 ('GegenbauerC', 3): gegenbauer,
 ('LaguerreL', 2): laguerre,
 ('LaguerreL', 3): gen_laguerre,
 ('PrimePi', 1): prime_pi,
 ('DiracDelta', 1): dirac_delta,
 ('HeavisideTheta', 1): heaviside,
 ('UnitStep', 1): unit_step,
 ('Sign', 1): sgn,
 ('KroneckerDelta', 2): kronecker_delta,
 ('AiryAi', 1): airy_ai,
 ('AiryAiPrime', 1): airy_ai_prime,
 ('AiryBi', 1): airy_bi,
 ('AiryBiPrime', 1): airy_bi_prime,
 ('FresnelS', 1): fresnel_sin,
 ('FresnelC', 1): fresnel_cos,
 ('HypergeometricPFQ', 3): hypergeometric,
 ('Hypergeometric1F1', 3): hypergeometric_M,
 ('HypergeometricU', 3): hypergeometric_U}

where tan, cot, sec and csc are missing.

Additional Information

Connected with issue #34087

Environment

Checklist

janekj2727 commented 1 week ago

Temporary fix: call

addsymb = {('Sec', 1): sec, ('Csc', 1): csc, ('Tan', 1): tan, ('Cot', 1): cot}
sage.symbolic.expression.symbol_table['mathematica'].update(addsymb)

before the conversion from Mathematica.