1

I want to display (a**x + b)**3 descending order about x using sympy.latex by LaTeX, however it becomes inverse order only in case of a==-1. The minimum code as follows:

import sympy

x, y, z = sympy.symbols('x, y, z', var = True)

a, b = -1, 5

def f(x):
    return (a*x + b)**3
    
print('Notation after processed by definition of f(x)')
print(f(x))

print('Notation after processed by sympy.latex')
print(sympy.latex(f(x)))

I get following results processed by this code:

Notation after processed by definition of f(x)
(5 - x)**3
Notation after processed by sympy.latex
\left(5 - x\right)^{3}

However, I want to get following notation:

Notation after processed by definition of f(x)
(- x + 5)**3
Notation after processed by sympy.latex
\left(- x + 5 \right)^{3}

I guess that I have to solve problems both of sympy and LaTeX.

Can anyone have solution this problem?

  • 1
    See my last comment [in this post](https://stackoverflow.com/questions/65406726/how-to-propagate-n-to-sympy-latex/65407203#comment115639740_65407203) about the order of monomials. Also see [this comment](https://stackoverflow.com/questions/56652669/printing-a-polynomial-so-that-the-powers-of-x-or-s-are-in-ascending-or-descendin#comment99910480_56652669) about the orderings `lex`,`old`,`grevlex`. – wsdookadr Feb 09 '21 at 12:18
  • 1
    Thank you very much for your useful comment. I solved my problem! – Takahiro Niwa Feb 09 '21 at 23:59

0 Answers0