Skip to content

Instantly share code, notes, and snippets.

Last active Dec 15, 2015
What would you like to do?
def find_sets(F,M,d, xRy):
Find M sets of d mutually orthogonal vectors from F (an iterable of vectors) so that each set is related pairwise by xRy
def xRY(v,W):
xRY(v,W) = is v related to every vector in W by the conditions you need
We could just inline this function below, but the code below is a little more readable if we abstract it out
return all(xRy(v,w) for w in W)
bases = []
used = set() # we could also just keep track of the elements left if F is small enough
for m in range(M):
base = []
for v in F:
if tuple(v) in used:
if all(v*w==0 for w in base) and all(xRY(v,S) for S in bases):
if len(base)==d:
# we went all the way through N, but didn't find enough vectors
raise ValueError("couldn't find enough mutually orthogonal vectors")
return bases

This comment has been minimized.

Copy link
Owner Author

@jasongrout jasongrout commented Mar 30, 2013

I see that my code may not find a list of sets because once a mutually orthogonal set is found, it is fixed. Instead, the sets themselves should be re-examined too. So, for example, if that ValueError is raised, you'd have to backtrack and try a different list of sets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment