]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
mjo/clan/normal_decomposition_element.py: argument checking for elt()
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 10 Apr 2026 16:24:58 +0000 (12:24 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Fri, 10 Apr 2026 16:24:58 +0000 (12:24 -0400)
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.

mjo/clan/normal_decomposition_element.py

index fcb3521f5f37414789cafe817382e3132c1e23f0..b66543e1ea3f0b83e43c0c10a0c6a8f3c553b1e8 100644 (file)
@@ -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()