diff --git a/.mailmap b/.mailmap index ecc9cfd823c2..4b106d6f6eb4 100644 --- a/.mailmap +++ b/.mailmap @@ -787,6 +787,7 @@ Kirill Smelkov convert-repo Kirill Smelkov kirill.smelkov Kirtan Mali KIRTAN MALI <43683545+kmm555@users.noreply.github.com> Kirtan Mali kmm555 +Kishore Gopalakrishnan Kiyohito Yamazaki Klaus Rettinghaus Konrad Meyer diff --git a/sympy/tensor/tensor.py b/sympy/tensor/tensor.py index f01ce4704a08..feea5d0a0025 100644 --- a/sympy/tensor/tensor.py +++ b/sympy/tensor/tensor.py @@ -3629,10 +3629,10 @@ def __getitem__(self, item): def _get_args_for_traditional_printer(self): args = list(self.args) - if (self.coeff < 0) == True: + if self.coeff.could_extract_minus_sign(): # expressions like "-A(a)" sign = "-" - if self.coeff == S.NegativeOne: + if args[0] == S.NegativeOne: args = args[1:] else: args[0] = -args[0] diff --git a/sympy/tensor/tests/test_printing.py b/sympy/tensor/tests/test_printing.py new file mode 100644 index 000000000000..9f3cf7f0591a --- /dev/null +++ b/sympy/tensor/tests/test_printing.py @@ -0,0 +1,13 @@ +from sympy.tensor.tensor import TensorIndexType, tensor_indices, TensorHead +from sympy import I + +def test_printing_TensMul(): + R3 = TensorIndexType('R3', dim=3) + p, q = tensor_indices("p q", R3) + K = TensorHead("K", [R3]) + + assert repr(2*K(p)) == "2*K(p)" + assert repr(-K(p)) == "-K(p)" + assert repr(-2*K(p)*K(q)) == "-2*K(p)*K(q)" + assert repr(-I*K(p)) == "-I*K(p)" + assert repr(I*K(p)) == "I*K(p)"