]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/eja/eja_utils.py
eja: improve a gram_schmidt() error message.
[sage.d.git] / mjo / eja / eja_utils.py
index 6690a80d395f000e3d8e588b3c0d407f8b7678c6..d4e9990ecc6749057905d3b1d5ac700bd34cdc71 100644 (file)
@@ -86,6 +86,16 @@ def _all2list(x):
         sage: _all2list(OctonionMatrixAlgebra(1).one())
         [1, 0, 0, 0, 0, 0, 0, 0]
 
+    ::
+
+        sage: V1 = VectorSpace(QQ,2)
+        sage: V2 = OctonionMatrixAlgebra(1,field=QQ)
+        sage: C = cartesian_product([V1,V2])
+        sage: x1 = V1([3,4])
+        sage: y1 = V2.one()
+        sage: _all2list(C( (x1,y1) ))
+        [3, 4, 1, 0, 0, 0, 0, 0, 0, 0]
+
     """
     if hasattr(x, 'to_vector'):
         # This works on matrices of e.g. octonions directly, without
@@ -220,7 +230,14 @@ def gram_schmidt(v, inner_product=None):
     """
     if inner_product is None:
         inner_product = lambda x,y: x.inner_product(y)
-    norm = lambda x: inner_product(x,x).sqrt()
+    def norm(x):
+        ip = inner_product(x,x)
+        # Don't expand the given field; the inner-product's codomain
+        # is already correct. For example QQ(2).sqrt() returns sqrt(2)
+        # in SR, and that will give you weird errors about symbolics
+        # when what's really going wrong is that you're trying to
+        # orthonormalize in QQ.
+        return ip.parent()(ip.sqrt())
 
     v = list(v) # make a copy, don't clobber the input