def superset_basis(C, T): ''' Input: - C: linearly independent set of Vecs - T: set of Vecs such that every Vec in C is in Span(T) Output: Linearly independent set S consisting of all Vecs in C and some in T such that the span of S is the span of T (i.e. S is a basis for the span of T). Example: >>> from vec import Vec >>> from independence import is_independent >>> a0 = Vec({'a','b','c','d'}, {'a':1}) >>> a1 = Vec({'a','b','c','d'}, {'b':1}) >>> a2 = Vec({'a','b','c','d'}, {'c':1}) >>> a3 = Vec({'a','b','c','d'}, {'a':1,'c':3}) >>> sb = superset_basis({a0, a3}, {a0, a1, a2}) >>> a0 in sb and a3 in sb True >>> is_independent(sb) True >>> all(x in [a0,a1,a2,a3] for x in sb) True ''' S = {x for x in C} for x in T: S.add(x) if is_superfluous(S,x): S.remove(x) return S
def superset_basis(C, T): ''' Input: - C: linearly independent set of Vecs - T: set of Vecs such that every Vec in S is in Span(T) Output: Linearly independent set S consisting of all Vecs in C and some in T such that the span of S is the span of T (i.e. S is a basis for the span of T). Example: >>> from vec import Vec >>> from independence import is_independent >>> a0 = Vec({'a','b','c','d'}, {'a':1}) >>> a1 = Vec({'a','b','c','d'}, {'b':1}) >>> a2 = Vec({'a','b','c','d'}, {'c':1}) >>> a3 = Vec({'a','b','c','d'}, {'a':1,'c':3}) >>> sb = superset_basis({a0, a3}, {a0, a1, a2}) >>> a0 in sb and a3 in sb True >>> is_independent(sb) True >>> all(x in [a0,a1,a2,a3] for x in sb) True ''' S = {s for s in C} for t in T: S.update({t}) if is_superfluous(S,t): S = S - {t} return S
def superset_basis(C, T): ''' Input: - C: linearly independent set of Vecs - T: set of Vecs such that every Vec in C is in Span(T) Output: Linearly independent set S consisting of all Vecs in C and some in T such that the span of S is the span of T (i.e. S is a basis for the span of T). Example: >>> from vec import Vec >>> from independence import is_independent >>> a0 = Vec({'a','b','c','d'}, {'a':1}) >>> a1 = Vec({'a','b','c','d'}, {'b':1}) >>> a2 = Vec({'a','b','c','d'}, {'c':1}) >>> a3 = Vec({'a','b','c','d'}, {'a':1,'c':3}) >>> sb = superset_basis({a0, a3}, {a0, a1, a2}) >>> a0 in sb and a3 in sb True >>> is_independent(sb) True >>> all(x in [a0,a1,a2,a3] for x in sb) True ''' res = C | T A = res - C for v in A: if is_superfluous(res, v): res.remove(v) return res
def subset_basis(T): ''' Input: - T: a set of Vecs Output: - set S containing Vecs from T that is a basis for Span T. Examples: The following tests use the procedure is_independent, provided in module independence >>> from vec import Vec >>> from independence import is_independent >>> a0 = Vec({'a','b','c','d'}, {'a':1}) >>> a1 = Vec({'a','b','c','d'}, {'b':1}) >>> a2 = Vec({'a','b','c','d'}, {'c':1}) >>> a3 = Vec({'a','b','c','d'}, {'a':1,'c':3}) >>> sb = subset_basis({a0, a1, a2, a3}) >>> len(sb) 3 >>> all(v in [a0, a1, a2, a3] for v in sb) True >>> is_independent(sb) True >>> b0 = Vec({0,1,2,3},{0:2,1:2,3:4}) >>> b1 = Vec({0,1,2,3},{0:1,1:1}) >>> b2 = Vec({0,1,2,3},{2:3,3:4}) >>> b3 = Vec({0,1,2,3},{3:3}) >>> sb = subset_basis({b0, b1, b2, b3}) >>> len(sb) 3 >>> all(v in [b0, b1, b2, b3] for v in sb) True >>> is_independent(sb) True >>> D = {'a','b','c','d'} >>> c0, c1, c2, c3, c4 = Vec(D,{'d': one, 'c': one}), Vec(D,{'d': one, 'a': one, 'c': one, 'b': one}), Vec(D,{'a': one}), Vec(D,{}), Vec(D,{'d': one, 'a': one, 'b': one}) >>> subset_basis({c0,c1,c2,c3,c4}) == {c0,c1,c2,c4} True ''' S = set() for x in T: S.add(x) if is_superfluous(S,x): S.remove(x) return S
def subset_basis(T): ''' Input: - T: a set of Vecs Output: - set S containing Vecs from T that is a basis for Span T. Examples: The following tests use the procedure is_independent, provided in module independence >>> from vec import Vec >>> from independence import is_independent >>> a0 = Vec({'a','b','c','d'}, {'a':1}) >>> a1 = Vec({'a','b','c','d'}, {'b':1}) >>> a2 = Vec({'a','b','c','d'}, {'c':1}) >>> a3 = Vec({'a','b','c','d'}, {'a':1,'c':3}) >>> sb = subset_basis({a0, a1, a2, a3}) >>> len(sb) 3 >>> all(v in [a0, a1, a2, a3] for v in sb) True >>> is_independent(sb) True >>> b0 = Vec({0,1,2,3},{0:2,1:2,3:4}) >>> b1 = Vec({0,1,2,3},{0:1,1:1}) >>> b2 = Vec({0,1,2,3},{2:3,3:4}) >>> b3 = Vec({0,1,2,3},{3:3}) >>> sb = subset_basis({b0, b1, b2, b3}) >>> len(sb) 3 >>> all(v in [b0, b1, b2, b3] for v in sb) True >>> is_independent(sb) True >>> D = {'a','b','c','d'} >>> c0, c1, c2, c3, c4 = Vec(D,{'d': one, 'c': one}), Vec(D,{'d': one, 'a': one, 'c': one, 'b': one}), Vec(D,{'a': one}), Vec(D,{}), Vec(D,{'d': one, 'a': one, 'b': one}) >>> subset_basis({c0,c1,c2,c3,c4}) == {c0,c1,c2,c4} True ''' S = {s for s in T} for t in T: if is_superfluous(S,t): S = S - {t} return S