Today, I got to thinking about how to test that a matrix was upper-triangular. So I had a try at it.
Algorithm
$\quad \quad a_{ij}=0 $ Or $i \leq j$ $\Rightarrow$ $True$
My solution is
upperTriangularMatrixQ[mat_?MatrixQ] /; Equal @@ Dimensions@mat :=
And @@ Flatten @ MapIndexed[#1 == 0 || LessEqual @@ #2 &, mat, {2}]
Performance testing
Sample data
testMat1 = UpperTriangularize@RandomInteger[{1, 100}, {1000, 1000}];
testMat2 = RandomInteger[{1, 100}, {1000, 1000}];
Test
upperTriangularMatrixQ@testMat1 // Timing
{3.151, True}
upperTriangularMatrixQ@testMat2 // Timing
{3.978, False}
My question
Can you come up with a better performing algorithm to solve this problem?