def orthogonalize(*vlist, **kwargs):
 orthonormal = kwargs.get('orthonormal', False)
 if (not all((isinstance(vec, Vector) for vec in vlist))):
  raise TypeError('Each element must be of Type Vector')
 ortho_vlist = []
 for (i, term) in enumerate(vlist):
  for j in range(i):
   term -= ortho_vlist[j].projection(vlist[i])
  if simplify(term).equals(Vector.zero):
   raise ValueError('Vector set not linearly independent')
  ortho_vlist.append(term)
 if orthonormal:
  ortho_vlist = [vec.normalize() for vec in ortho_vlist]
 return ortho_vlist

def orthogonalize ( * vlist , ** kwargs ) : orthonormal = kwargs . get ( 'orthonormal' , False ) if ( not all ( ( isinstance ( vec , Vector ) for vec in vlist ) ) ) : raise TypeError ( 'Each element must be of Type Vector' ) ortho_vlist = [ ] for ( i , term ) in enumerate ( vlist ) : for j in range ( i ) : term -= ortho_vlist [ j ] . projection ( vlist [ i ] ) if simplify ( term ) . equals ( Vector . zero ) : raise ValueError ( 'Vector set not linearly independent' ) ortho_vlist . append ( term ) if orthonormal : ortho_vlist = [ vec . normalize ( ) for vec in ortho_vlist ] return ortho_vlist
takes a sequence of independent vectors and orthogonalizes them using the gram - schmidt process .