Ask Your Question

Revision history [back]

Why does expand-simplify break print_latex_func?

Here's a minimal example of what I am talking about. Both print statements should return the same output in this scenario.

,var n x
def my_latex_print(self, *args): 
    return "a_{%s}" %(', '.join(map(latex, args)))
a=function('a',nargs=1,print_latex_func=my_latex_print)(n)

sexp=a(n=n+1)+a(n=n)
print latex(sexp)
sexp=simplify(expand(sexp))
print latex(sexp)

However, the outputs differ:

a_{n + 1} + a_{n}
a\left(n + 1\right) + a\left(n\right)

Of course simplify-expand may lead to a different expression, but that's not what I am concerned about. I am concerned about the representation of a(n) instead of a_n in the output.

My main question is: How can I recover a_n out of sexp at the end of my code?

Why does expand-simplify break print_latex_func?

Here's a minimal example of what I am talking about. Both print statements should return the same output in this scenario.

,var n x
def my_latex_print(self, *args): 
    return "a_{%s}" %(', '.join(map(latex, args)))
a=function('a',nargs=1,print_latex_func=my_latex_print)(n)

sexp=a(n=n+1)+a(n=n)
print latex(sexp)
sexp=simplify(expand(sexp))
print latex(sexp)

However, the outputs differ:

a_{n + 1} + a_{n}
a\left(n + 1\right) + a\left(n\right)

Of course simplify-expand may lead to a different expression, but that's not what I am concerned about. I am concerned about the representation of a(n) instead of a_n in the output.

My main question is: How can I recover a_n out of sexp at the end of my code?

Why does expand-simplify simplify break print_latex_func?

Here's a minimal example of what I am talking about. Both print statements should return the same output in this scenario.

,var n x
def my_latex_print(self, *args): 
    return "a_{%s}" %(', '.join(map(latex, args)))
a=function('a',nargs=1,print_latex_func=my_latex_print)(n)

sexp=a(n=n+1)+a(n=n)
print latex(sexp)
sexp=simplify(expand(sexp))
print latex(sexp)

However, the outputs differ:

a_{n + 1} + a_{n}
a\left(n + 1\right) + a\left(n\right)

Of course simplify-expand may lead to a different expression, but that's not what I am concerned about. I am concerned about the representation of a(n) instead of a_n in the output.

My main question is: How can I recover a_n out of sexp at the end of my code?

Why does simplify break print_latex_func?

Here's a minimal example of what I am talking about. Both print statements should return the same output in this scenario.

,var n x
def my_latex_print(self, *args): 
    return "a_{%s}" %(', '.join(map(latex, args)))
a=function('a',nargs=1,print_latex_func=my_latex_print)(n)

sexp=a(n=n+1)+a(n=n)
print latex(sexp)
sexp=simplify(expand(sexp))
print latex(sexp)

However, the outputs differ:

a_{n + 1} + a_{n}
a\left(n + 1\right) + a\left(n\right)

Of course simplify-expand may lead to a different expression, but that's not what I am concerned about. I am concerned about the representation of a(n) instead of a_n in the output.

My main question is: How can I recover a_n out of sexp at the end of my code?