Deciding about an API for Gram-Schmidt orthogonalization feature

We have added a Gram-Schmidt orthogonalization feature as per issue 178.

There are however some discussions about the way dependent vectors should be handled.

1- the method implemented initially was to throw an exception if input vectors are not independent
2- the Wolfram API generates zero-vectors when dependent vectors appear, hence ensuring the number of ouput vectors is the same as the number of input vectors, but dropping the constraint of an orthonormal basis
3 - another choice could be to ignore dependent vectors and to generate a base with the number of vectors matching the dimension of the span

Option 1 could be combined with either option 2 or 3 by using a flag that the user could flip to select either to throw an exception or fallback to return a basis. Options 2 and 3 seem incompatible to each other.

Could users look at the discussion in the issue and tell which option they prefer?

+1 for option 1 and 2

+1 for “all nonzero vectors in the output are normalized to unit length”

I’m sure the answer depends on the use case and I’m not sure what the use case is. Reading [1] it seems that including zeros in the output makes it straightforward to form the pseudo-inverse and QR decomposition from the result.

Once either 2 or 3 is implemented it seems straightforward to create the other by adding or removing zero vectors. Perhaps both is an option?

[1] Orthogonalize—Wolfram Language Documentation

Fine. I’ll do that, using an enumerate for the flag instead of a boolean. It will even be more clear for users. The enumerate will be something like: DependentVectorsHandling.GENERATE_EXCEPTION, DependentVectorsHandling.ADD_ZERO_VECTOR, DependentVectorsHandling.REDUCE_BASE_TO_SPAN.

I’ll probably add that today.

OK, this is implemented with all three choices.

2 Likes