Opened 3 years ago

# Improve the Sage-to-Maxima interface for symbolic functions

Reported by: Owned by: egourgoulhon major symbolics maxima, symbolic function embray, nbruin N/A

### Description

The interface of Sage with Maxima for symbolic functions (i.e. objects created with function(...)) is broken in two ways:

1. Some user defined names clash with special function names for Maxima; for instance function('psi') on the Sage side clashes with this Maxima special function, as reported in this ask.sagemath question and this sage-devel thread.
2. User defined LaTeX names are sometimes lost when passed to Maxima; for instance:
sage: f = function('a', latex_name=r'\alpha')(x)
sage: latex(f)
\alpha\left(x\right)
sage: latex(f.simplify()) # OK
\alpha\left(x\right)
sage: g = function('b', latex_name=r'\beta')(x)
sage: latex(g)
\beta\left(x\right)
sage: latex(g.simplify()) # \beta is lost...
b\left(x\right)


### comment:1 follow-ups: ↓ 2 ↓ 3 Changed 3 years ago by nbruin

Point number 2 might be specific to the strings-based interface. It's strange that f is not affected, while g is, though. It may be worth investigating why that is the case. To illustrate the strings-specific nature of this issue:

sage: latex(limit(g(x),x=0))
\lim_{x \to 0}\, \beta\left(x\right)
sage: latex(integrate(g(x),x))
\int \beta\left(x\right)\,{d x}


both routines do round-trip through maxima, but do so via sr_to_max and max_to_sr, which translate expression trees rather than going through string representations.

Converting simplify to use this interface would probably work around the issue pointed out in the ticket. That is quite independent from encoding function names in maxima with a sage-specific prefix.

Last edited 3 years ago by nbruin (previous) (diff)

### comment:2 in reply to: ↑ 1 Changed 3 years ago by egourgoulhon

Point number 2 might be specific to the strings-based interface. It's strange that f is not affected, while g is, though. It may be worth investigating why that is the case.

Actually, this depends on the order of the operations: in a fresh session, if we first send g to Maxima, then it's OK, while f fails:

sage: g = function('b', latex_name=r'\beta')(x)
sage: latex(g)
\beta\left(x\right)
sage: latex(g.simplify())  # OK
\beta\left(x\right)
sage: f = function('a', latex_name=r'\alpha')(x)
sage: latex(f)
\alpha\left(x\right)
sage: latex(f.simplify())  # this time \alpha is lost...
a\left(x\right)


All subsequent calls to Maxima seem to fail as well:

sage: h = function('c', latex_name=r'\gamma')(x)
sage: latex(h.simplify())
c\left(x\right)


but, as you pointed out, the round trip to Maxima via sr_to_max and max_to_sr succeeds:

sage: latex(integrate(h(x), x))
\int \gamma\left(x\right)\,{d x}

Last edited 3 years ago by egourgoulhon (previous) (diff)

### comment:3 in reply to: ↑ 1 Changed 3 years ago by egourgoulhon

Converting simplify to use this interface would probably work around the issue pointed out in the ticket. That is quite independent from encoding function names in maxima with a sage-specific prefix.

This looks like the proper fix. One may note that all simplify_* methods are affected:

sage: latex(f.simplify_full())
a\left(x\right)
sage: latex(f.simplify_factorial())
a\left(x\right)
sage: latex(f.simplify_trig())
a\left(x\right)
sage: latex(f.simplify_rational())
a\left(x\right)
a\left(x\right)
sage: latex(f.simplify_log())
a\left(x\right)


### comment:4 Changed 2 years ago by embray

• Milestone changed from sage-8.7 to sage-8.8

Ticket retargeted after milestone closed (if you don't believe this ticket is appropriate for the Sage 8.8 release please retarget manually)

### comment:5 Changed 2 years ago by embray

• Milestone sage-8.8 deleted

As the Sage-8.8 release milestone is pending, we should delete the sage-8.8 milestone for tickets that are not actively being worked on or that still require significant work to move forward. If you feel that this ticket should be included in the next Sage release at the soonest please set its milestone to the next release milestone (sage-8.9).

Note: See TracTickets for help on using tickets.