return r <= max(1, n-2)
+def E(matrix_space, i,j):
+ """
+ Return the ``i``,``j``th element of the standard basis in
+ ``matrix_space``.
+
+ INPUT:
+
+ - ``matrix_space`` - The underlying matrix space of whose basis
+ the returned matrix is an element
+
+ - ``i`` - The row index of the single nonzero entry
+
+ - ``j`` - The column index of the single nonzero entry
+
+ OUTPUT:
+
+ A basis element of ``matrix_space``. It has a single \"1\" in the
+ ``i``,``j`` row,column and zeros elsewhere.
+
+ EXAMPLES::
+
+ sage: M = MatrixSpace(ZZ, 2, 2)
+ sage: E(M,0,0)
+ [1 0]
+ [0 0]
+ sage: E(M,0,1)
+ [0 1]
+ [0 0]
+ sage: E(M,1,0)
+ [0 0]
+ [1 0]
+ sage: E(M,1,1)
+ [0 0]
+ [0 1]
+ sage: E(M,2,1)
+ Traceback (most recent call last):
+ ...
+ IndexError: Index `i` is out of bounds.
+ sage: E(M,1,2)
+ Traceback (most recent call last):
+ ...
+ IndexError: Index `j` is out of bounds.
+
+ """
+ # We need to check these ourselves, see below.
+ if i >= matrix_space.nrows():
+ raise IndexError('Index `i` is out of bounds.')
+ if j >= matrix_space.ncols():
+ raise IndexError('Index `j` is out of bounds.')
+
+ # The basis here is returned as a one-dimensional list, so we need
+ # to compute the offset into it based on ``i`` and ``j``. Since we
+ # compute the index ourselves, we need to do bounds-checking
+ # manually. Otherwise for e.g. a 2x2 matrix space, the index (0,2)
+ # would be computed as offset 3 into a four-element list and we
+ # would succeed incorrectly.
+ idx = matrix_space.ncols()*i + j
+ return matrix_space.basis()[idx]
+
+
+
def is_extreme_doubly_nonnegative(A):
"""
Returns ``True`` if the given matrix is an extreme matrix of the