Skip to content

Commit

Permalink
Merge pull request #24474 from Kishore96in/fix_imag_tens_print_onmaster
Browse files Browse the repository at this point in the history
tensor: fix printing of TensMul with imaginary coefficients
  • Loading branch information
sylee957 committed Jan 9, 2023
2 parents 6f0fd47 + b161676 commit f47b9f2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions .mailmap
Expand Up @@ -787,6 +787,7 @@ Kirill Smelkov <kirr@landau.phys.spbu.ru> convert-repo <devnull@localhost>
Kirill Smelkov <kirr@landau.phys.spbu.ru> kirill.smelkov <devnull@localhost>
Kirtan Mali <kirtanmali555@gmail.com> KIRTAN MALI <43683545+kmm555@users.noreply.github.com>
Kirtan Mali <kirtanmali555@gmail.com> kmm555 <kirtanmali555@gmail.com>
Kishore Gopalakrishnan <kishore96@gmail.com>
Kiyohito Yamazaki <kyamaz@openql.org>
Klaus Rettinghaus <klaus.rettinghaus@enote.com>
Konrad Meyer <konrad.meyer@gmail.com>
Expand Down
4 changes: 2 additions & 2 deletions sympy/tensor/tensor.py
Expand Up @@ -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]
Expand Down
13 changes: 13 additions & 0 deletions 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)"

0 comments on commit f47b9f2

Please sign in to comment.