sage: v = [v1,v2,v3]
sage: len(gram_schmidt(v)) == 2
True
+
"""
if len(v) == 0:
# cool
if inner_product is None:
inner_product = lambda x,y: x.inner_product(y)
- def norm(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 V.base_ring()(inner_product(x,x).sqrt())
-
sc = lambda x,a: a*x
if hasattr(V, 'cartesian_factors'):
# Only use the slow implementation if necessary.
return sc(x, (inner_product(x,y)/inner_product(x,x)))
def normalize(x):
- return sc(x, ~norm(x))
+ # Don't extend the given field with the necessary
+ # square roots. This will probably throw weird
+ # errors about the symbolic ring if you e.g. try
+ # to use it on a set of rational vectors that isn't
+ # already orthonormalized.
+ return sc(x, ~inner_product(x,x).sqrt())
v_out = [] # make a copy, don't clobber the input