Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 7c02ed8

Browse files
committed
Fix display of tensors on free modules of finite rank (#22520)
1 parent fd5f71a commit 7c02ed8

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/sage/tensor/modules/comp.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,13 @@ def display(self, symbol, latex_symbol=None, index_positions=None,
11531153
C_01 = 0.33
11541154
C_21 = 0.29
11551155
1156+
Check that the bug reported in :trac:`22520` is fixed::
1157+
1158+
sage: c = Components(SR, [1, 2], 1)
1159+
sage: c[0] = SR.var('t', domain='real')
1160+
sage: c.display('c')
1161+
c_0 = t
1162+
11561163
"""
11571164
from sage.misc.latex import latex
11581165
from sage.tensor.modules.format_utilities import FormattedExpansion
@@ -1190,7 +1197,8 @@ def display(self, symbol, latex_symbol=None, index_positions=None,
11901197
for ind in generator:
11911198
ind_arg = ind + (format_spec,)
11921199
val = self[ind_arg]
1193-
if val != 0 or not only_nonzero:
1200+
if not (val == 0) or not only_nonzero: # val != 0 would not be
1201+
# correct, see :trac:`22520`
11941202
indices = '' # text indices
11951203
d_indices = '' # LaTeX down indices
11961204
u_indices = '' # LaTeX up indices
@@ -1336,7 +1344,7 @@ def is_zero(self):
13361344
# In other words, the full method should be
13371345
# return self.comp == {}
13381346
for val in itervalues(self._comp):
1339-
if val != 0:
1347+
if not (val == 0):
13401348
return False
13411349
return True
13421350

@@ -3244,7 +3252,7 @@ def __setitem__(self, args, value):
32443252
else:
32453253
sign, ind = self._ordered_indices(indices)
32463254
if sign == 0:
3247-
if value != 0:
3255+
if not (value == 0):
32483256
raise ValueError("by antisymmetry, the component cannot " +
32493257
"have a nonzero value for the indices " +
32503258
str(indices))

src/sage/tensor/modules/free_module_alt_form.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,15 @@ def display(self, basis=None, format_spec=None):
484484
sage: b.display(format_spec=10) # 10 bits of precision
485485
b = 0.33 e^1/\e^2 + 2.5 e^1/\e^3 + 4.0 e^2/\e^3
486486
487+
Check that the bug reported in :trac:`22520` is fixed::
488+
489+
sage: M = FiniteRankFreeModule(SR, 2, name='M')
490+
sage: e = M.basis('e')
491+
sage: a = M.alternating_form(2)
492+
sage: a[0,1] = SR.var('t', domain='real')
493+
sage: a.display()
494+
t e^0/\e^1
495+
487496
"""
488497
from sage.misc.latex import latex
489498
from sage.tensor.modules.format_utilities import is_atomic, \
@@ -497,7 +506,9 @@ def display(self, basis=None, format_spec=None):
497506
for ind in comp.non_redundant_index_generator():
498507
ind_arg = ind + (format_spec,)
499508
coef = comp[ind_arg]
500-
if coef != 0:
509+
if not (coef == 0): # NB: coef != 0 would return False for
510+
# cases in which Sage cannot conclude
511+
# see :trac:`22520`
501512
bases_txt = []
502513
bases_latex = []
503514
for k in range(self._tensor_rank):

src/sage/tensor/modules/free_module_tensor.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,14 @@ def display(self, basis=None, format_spec=None):
641641
sage: v.display(format_spec=10) # 10 bits of precision
642642
v = 0.33 e_1 - 2.0 e_2
643643
644+
Check that the bug reported in :trac:`22520` is fixed::
645+
646+
sage: M = FiniteRankFreeModule(SR, 3, name='M')
647+
sage: e = M.basis('e')
648+
sage: t = SR.var('t', domain='real')
649+
sage: (t*e[0]).display()
650+
t e_0
651+
644652
"""
645653
from sage.misc.latex import latex
646654
from sage.tensor.modules.format_utilities import is_atomic, \
@@ -655,7 +663,9 @@ def display(self, basis=None, format_spec=None):
655663
for ind in comp.index_generator():
656664
ind_arg = ind + (format_spec,)
657665
coef = comp[ind_arg]
658-
if coef != 0:
666+
if not (coef == 0): # NB: coef != 0 would return False for
667+
# cases in which Sage cannot conclude
668+
# see :trac:`22520`
659669
bases_txt = []
660670
bases_latex = []
661671
for k in range(n_con):
@@ -2550,7 +2560,7 @@ def contract(self, *args):
25502560
for pos in range(0,k2):
25512561
if pos not in pos2:
25522562
nb_con_o += 1
2553-
if nb_cov_s != 0 and nb_con_o !=0:
2563+
if nb_cov_s != 0 and nb_con_o != 0:
25542564
# some reodering is necessary:
25552565
p2 = k1 + l1 - ncontr
25562566
p1 = p2 - nb_cov_s

0 commit comments

Comments
 (0)