From: Michael Orlitzky Date: Fri, 10 Apr 2026 16:24:58 +0000 (-0400) Subject: mjo/clan/normal_decomposition_element.py: argument checking for elt() X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=7e445c25a72dcdcae72f5a73d59709907a095e7a;p=sage.d.git mjo/clan/normal_decomposition_element.py: argument checking for elt() Confirm that the arguments to elt(i,j) make sense; otherwise the basis indexing is far too lenient. Things like x.elt(pi, ZZ) return zero. --- diff --git a/mjo/clan/normal_decomposition_element.py b/mjo/clan/normal_decomposition_element.py index fcb3521..b66543e 100644 --- a/mjo/clan/normal_decomposition_element.py +++ b/mjo/clan/normal_decomposition_element.py @@ -113,14 +113,10 @@ class NormalDecompositionElement(ClanElement): This is in contrast with the usual indexing that returns only a coefficient. - .. WARNING: - - This returns zero if you request a component that does - not exist (with ``i`` strictly less than ``j``). - SETUP:: sage: from mjo.clan.t_algebra_clan import RealSymmetricClan + sage: from mjo.clan.vinberg_clan import VinbergClan EXAMPLES:: @@ -155,7 +151,26 @@ class NormalDecompositionElement(ClanElement): [ 0 0 0] [ 0 0 18] + TESTS:: + + sage: C = VinbergClan() + sage: x = C.random_element() + sage: x.elt(pi, 1) + Traceback (most recent call last): + ... + TypeError: i=pi and j=1 must be integral + sage: x.elt(1, 2) + Traceback (most recent call last): + ... + IndexError: i=1 must be greater than or equal to j=2 + """ + from sage.rings.integer_ring import ZZ + if not (i in ZZ and j in ZZ): + raise TypeError(f"i={i} and j={j} must be integral") + if not j <= i: + raise IndexError (f"i={i} must be greater than or equal to j={j}") + return self.parent().sum_of_terms( item for item in self.items()