Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How do you define a symbol with a quotient in the subscript?

I tried this:

sage: x = SR.symbol('x')
....: x_0 = SR.symbol('x_0')
....: logr = SR.symbol('L_x/x_0')
....: logr_ex = logr == log(x/x_0)
....: latex(logr_ex)
....: latex(logr_ex.solve(x)[0])
L_{\mathit{x/x}_{0}} = \log\left(\frac{x}{x_{0}}\right)
x = x_{0} e^{\frac{L_{x}}{x_{0}}}

The above attempt at using a symbol with a fraction in the subscript works (see first latex() result) until after an operation like solve(), which scrambles the symbol (second latex() result).

Variations of logr = SR.symbol('L_{x/x}_0') with braces also work until an operation such as logr_ex.solve(x) with the code above, which crashes Maxima with the traceback excerpts:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    731             try:
--> 732                 self._name = parent._create(value, name=name)
    733             except (TypeError, RuntimeError, ValueError) as x:
...
RuntimeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.

During handling of the above exception, another exception occurred:---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    731             try:
--> 732                 self._name = parent._create(value, name=name)
    733             except (TypeError, RuntimeError, ValueError) as x:
...
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    732                 self._name = parent._create(value, name=name)
    733             except (TypeError, RuntimeError, ValueError) as x:
--> 734                 raise TypeError(x)
    735
    736     def _latex_(self):

TypeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.

Looks like a bug, but maybe I've overlooked the correct way to define such symbols.

latex function and operations with fraction subscripts

How do you define a symbol with a quotient in the subscript?

I tried this:

sage: x = SR.symbol('x')
....: x_0 = SR.symbol('x_0')
....: logr = SR.symbol('L_x/x_0')
....: logr_ex = logr == log(x/x_0)
....: latex(logr_ex)
....: latex(logr_ex.solve(x)[0])
L_{\mathit{x/x}_{0}} = \log\left(\frac{x}{x_{0}}\right)
x = x_{0} e^{\frac{L_{x}}{x_{0}}}

The above attempt at using a symbol with a fraction in the subscript works (see first latex() result) until after an operation like solve(), which scrambles the symbol (second latex() result).

Variations of logr = SR.symbol('L_{x/x}_0') with braces also work until an operation such as logr_ex.solve(x) with the code above, which crashes Maxima with the traceback excerpts:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    731             try:
--> 732                 self._name = parent._create(value, name=name)
    733             except (TypeError, RuntimeError, ValueError) as x:
...
RuntimeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.

During handling of the above exception, another exception occurred:---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    731             try:
--> 732                 self._name = parent._create(value, name=name)
    733             except (TypeError, RuntimeError, ValueError) as x:
...
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    732                 self._name = parent._create(value, name=name)
    733             except (TypeError, RuntimeError, ValueError) as x:
--> 734                 raise TypeError(x)
    735
    736     def _latex_(self):

TypeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.

Looks like a bug, but maybe I've overlooked the correct way to define such symbols.

latex function and operations with fraction subscripts

How do you define pickle a symbol with a quotient in the subscript?

The latex_name attribute doesn't seem to pickle:

sage: logr = SR.symbol('logr', domain='complex', latex_name=r'L_{x/x_0}')
....: latex(logr)
L_{x/x_0}

sage: import pickle
....: path_name = '/home/mark/'
....: pickle_file_name = path_name + 'node.p'
....: pickle_write = open(pickle_file_name, 'wb')
....: pickle.dump(logr, pickle_write)
....: pickle_write.close()

[exit and restart Sage]

sage: import pickle
....: path_name = '/home/mark/'
....: pickle_file_name = path_name + 'node.p'
....: pickle_read = open(pickle_file_name, 'rb')
....: some_expr = pickle.load(pickle_read)
....: pickle_read.close()
....: latex(some_expr)
\mathit{logr}

Reading the pickle in the same session does produce the correct results, however.

So I tried this:

sage: x = SR.symbol('x')
....: x_0 = SR.symbol('x_0')
....: logr = SR.symbol('L_x/x_0')
....: logr_ex = logr == log(x/x_0)
....: latex(logr_ex)
....: latex(logr_ex.solve(x)[0])
L_{\mathit{x/x}_{0}} = \log\left(\frac{x}{x_{0}}\right)
x = x_{0} e^{\frac{L_{x}}{x_{0}}}

The above attempt at using a symbol with a fraction in the subscript works (see first latex() result) until after an operation like solve(), which scrambles the symbol (second latex() result).

Variations of logr = SR.symbol('L_{x/x}_0') with braces also work until an operation such as logr_ex.solve(x) with the code above, which crashes Maxima with the traceback excerpts:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    731             try:
--> 732                 self._name = parent._create(value, name=name)
    733             except (TypeError, RuntimeError, ValueError) as x:
...
RuntimeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.

During handling of the above exception, another exception occurred:---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    731             try:
--> 732                 self._name = parent._create(value, name=name)
    733             except (TypeError, RuntimeError, ValueError) as x:
...
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    732                 self._name = parent._create(value, name=name)
    733             except (TypeError, RuntimeError, ValueError) as x:
--> 734                 raise TypeError(x)
    735
    736     def _latex_(self):

TypeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.

Looks like a bug, but maybe I've overlooked the correct way to define such symbols.

latex function and operations with fraction subscripts