]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: improve a gram_schmidt() error message.
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 4 Mar 2021 22:43:59 +0000 (17:43 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 4 Mar 2021 22:43:59 +0000 (17:43 -0500)
mjo/eja/eja_utils.py

index 2402d9f0e5f6d1b174690688b8f9b2d7f17eba61..d4e9990ecc6749057905d3b1d5ac700bd34cdc71 100644 (file)
@@ -230,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