+ Return a ``domain_dim``-by-``domain_dim`` dense integer identity
+ matrix.
+
+ EXAMPLES:
+
+ >>> print(identity(3))
+ [ 1 0 0]
+ [ 0 1 0]
+ [ 0 0 1]
+ <BLANKLINE>
+
+ """
+ if domain_dim <= 0:
+ raise ValueError('domain dimension must be positive')
+
+ entries = [int(i == j)
+ for i in range(domain_dim)
+ for j in range(domain_dim)]
+ return matrix(entries, (domain_dim, domain_dim))
+
+
+def norm(matrix_or_vector):
+ """
+ Return the Frobenius norm of ``matrix_or_vector``, which is the same
+ thing as its Euclidean norm when it's a vector (when one of its
+ dimensions is unity).
+
+ EXAMPLES:
+
+ >>> v = matrix([1,1])
+ >>> print('{:.5f}'.format(norm(v)))
+ 1.41421
+
+ >>> A = matrix([1,1,1,1], (2,2))
+ >>> norm(A)
+ 2.0
+