UpperTriangularMatrixQ¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
UpperTriangularMatrixQ[m]
gives True if m is upper triangular, and False otherwise.
UpperTriangularMatrixQ[m, k]
gives True if m is upper triangular starting from the k-th diagonal (every entry m[i,j] with j - i \< k is zero), and False otherwise. Positive k refers to superdiagonals above the main diagonal; negative k refers to subdiagonals below it. Works for rectangular as well as square matrices.
Notes
Option: With Tolerance -\> t, sub-diagonal entries e are taken to be zero when Abs\[e\] \<= t evaluates to True. Without a tolerance the test is structural: only literal numeric zeros (Integer 0, Real 0.0, BigInt 0) count as zero. Returns False on non-matrix, ragged, empty (i.e. {}), or higher-rank tensor inputs; an n-by-0 matrix (e.g. {{}, {}}) is vacuously upper triangular.Examples (13)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (7)¶
In[1]:= UpperTriangularMatrixQ[{{a, b, c}, {0, e, f}, {0, 0, g}}]
Out[1]= True
In[2]:= UpperTriangularMatrixQ[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}]
Out[2]= False
In[3]:= UpperTriangularMatrixQ[{{0, 1, 2}, {0, 0, 3}, {0, 0, 0}}, 1]
Out[3]= True
In[4]:= UpperTriangularMatrixQ[{{1, 2, 3}, {4, 5, 6}, {0, 7, 9}}, -1]
Out[4]= True
In[5]:= UpperTriangularMatrixQ[{{1, 2, 3}, {0, 4, 5}}]
Out[5]= True
In[6]:= UpperTriangularMatrixQ[{{1, 2}, {0, 4}, {0, 0}}]
Out[6]= True
In[7]:= UpperTriangularMatrixQ[IdentityMatrix[5]]
Out[7]= True
Options (1)¶
In[8]:= UpperTriangularMatrixQ[{{1., 2., 3.}, {10^-12, 4., 5.}, {0, 10^-13, 6.}}, Tolerance -> 10^-12]
Out[8]= True
Applications (5)¶
In[9]:= UpperTriangularMatrixQ[{{1, 2}, {0, 3}}]
Out[9]= True
In[10]:= UpperTriangularMatrixQ[{{1, 0}, {2, 3}}]
Out[10]= False
In[11]:= UpperTriangularMatrixQ[Table[If[j >= i, a[i, j], 0], {i, 4}, {j, 4}]]
Out[11]= True
In[12]:= UpperTriangularMatrixQ[{{0, 1, 2}, {0, 0, 3}, {0, 0, 0}}, 1]
Out[12]= True
In[13]:= UpperTriangularMatrixQ[{{1.0, 2}, {1*10^-15, 3}}, Tolerance -> 10^-10]
Out[13]= True
Implementation notes¶
builtin_upper_triangular_matrix_q validates that the argument is a non-empty rectangular List of equal-length Lists (no deeper nesting), then returns True iff every entry strictly below the k-th diagonal (column−row < k, default k = 0) is zero. The optional second Integer argument selects the diagonal k; a Tolerance -> t option relaxes the zero test (otherwise a structural zero check is used). Bad arguments/options emit UpperTriangularMatrixQ::nonopt / ::argt; shape rejections return False.
Protected.- Works for rectangular matrices, not only square -- only the entry-zero predicate and the shape constraints matter.
- Default test is structural: only literal numeric zeros (
Integer 0,Real 0.0,BigInt 0) count as zero. Symbolic sub-diagonal entries fail the test, so the predicate is conservative. - Returns
False(rather than leaving unevaluated) on non-list, scalar, vector, ragged, or higher-rank tensor inputs.{}is rejected; ann-by-0matrix (e.g.{{}, {}}) is vacuously upper triangular and returnsTrue. - Zero positional arguments emits a Mathematica-compatible
UpperTriangularMatrixQ::argt: UpperTriangularMatrixQ called with 0 arguments; 1 or 2 arguments are expected.
to stderr and leaves the call unevaluated.
- More than two positional arguments (or any non-
Rulejunk in the option region) emits
UpperTriangularMatrixQ::nonopt: Options expected (instead of <expr>) beyond position 2 in UpperTriangularMatrixQ[...]. An option must be a rule or a list of rules.
to stderr and leaves the call unevaluated.
Attributes: Protected.
References¶
See also: Rule
- Source:
src/info.c - Specification:
docs/spec/builtins/linear-algebra.md - Tests:
tests/test_schurdecomp.c - Tests:
tests/test_upper_triangular_matrix_q.c
Notes & additional examples¶
Notes¶
A matrix is upper triangular when every entry below the main diagonal is zero. The two-argument form UpperTriangularMatrixQ[m, k] tests against the k-th diagonal (positive k for superdiagonals, negative for subdiagonals), and a Tolerance option relaxes the zero test for approximate matrices. Rectangular matrices are supported.