def solve(A, b): M = echelon.transformation(A) U = M * A col_label_list = sorted(A.D[1]) U_rows_dict = mat2rowdict(U) row_list = [U_rows_dict[i] for i in sorted(U_rows_dict)] return echelon_solve(row_list, col_label_list, M * b)
def solve2(A, b): M = transformation(A) U = M * A U_rowdict = mat2rowdict(U) rowlist = [U_rowdict[i] for i in sorted(U_rowdict)] label_list = (A.D[1]) return echelon_solve(rowlist, label_list, M * b)
def solve(A, b): M = echelon.transformation(A) U = M*A col_label_list = sorted(A.D[1]) U_rows_dict = mat2rowdict(U) rowlist = [U_rows_dict[i] for i in U_rows_dict] return echelon_solve(rowlist,col_label_list, M*b)
def solve(A, b): col_label_list = sorted(A.D[1]) M = echelon.transformation(A, col_label_list) U = M*A U_rows_dict = mat2rowdict(U) rowlist = [U_rows_dict[i] for i in U_rows_dict] x = M*b return echelon_solve(rowlist, col_label_list, [x[item] for item in x.D])
def basis_AT(A): basis = [] M = transformation(A) U = M * A M_rowdict = mat2rowdict(M) U_rowdict = mat2rowdict(U) M_rowlist = [M_rowdict[i] for i in sorted(M_rowdict)] U_rowlist = [U_rowdict[i] for i in sorted(U_rowdict)] zero_vector = zero_vec(U_rowlist[0].D) for i in range(len(U_rowlist)): if (U_rowlist[i] == zero_vector): basis.append(M_rowlist[i]) return basis
def echelon_solve(rowlist, label_list, b): ''' Input: - rowlist: a list of Vecs - label_list: a list of labels establishing an order on the domain of Vecs in rowlist - b: a vector (represented as a list) Output: - Vec x such that rowlist * x is b >>> D = {'A','B','C','D','E'} >>> U_rows = [Vec(D, {'A':one, 'E':one}), Vec(D, {'B':one, 'E':one}), Vec(D,{'C':one})] >>> b_list = [one,0,one]>>> cols = ['A', 'B', 'C', 'D', 'E'] >>> echelon_solve(U_rows, cols, b_list) Vec({'B', 'C', 'A', 'D', 'E'},{'B': 0, 'C': one, 'A': one}) ''' A=rowdict2mat(rowlist) M=echelon.transformation(A) U=M*A rowlist=mat2rowdict(U) temp=M*list2vec(b) res = [] for label in range(len(b)): if label in temp.f and temp.f[label]: res.append(one) else: res.append(0) b=res result = Vec(set(label_list), {}) counter = len(b)-1 for row in reversed(list(rowlist.values())): for label in label_list: if label in row.f and row.f[label]!=0: result.f[label] = b[counter]-row*result break counter = counter -1 return result
print(gcd(23, 15)) N = 367160330145890434494322103 a = 67469780066325164 b = 9429601150488992 c = a * a - b * b print(gcd(a - b, N)) print(make_Vec({2, 3, 5, 7, 11}, [(3, 1)])) print(make_Vec({2, 3, 5, 7, 11}, [(2, 17), (3, 0), (5, 1), (11, 3)])) print(find_candidates(2419, primes(32))[1]) A = listlist2mat([[0, 2, 3, 4, 5], [0, 0, 0, 3, 2], [1, 2, 3, 4, 5], [0, 0, 0, 6, 7], [0, 0, 0, 9, 8]]) print(A) M = transformation(A) print(M) # print(M * A) print(M * A) # print() # print(listlist2mat([[0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [1, 0, 0, 0, 0], [0, 0, 2, 1, 0], [0, 0, 3.004, 0.667, 1]]) * (M * A)) print( row_reduce([ list2vec([one, one, 0, 0]), list2vec([one, 0, one, 0]), list2vec([0, one, one, one]), list2vec([one, 0, 0, 0]) ])) # *********************** PROBLEMS *************************
U_rows_dict = mat2rowdict(U) rowlist = [U_rows_dict[i] for i in U_rows_dict] x = M*b return echelon_solve(rowlist, col_label_list, [x[item] for item in x.D]) D = {'A', 'B', 'C', 'D'} A = Mat(({'a', 'b', 'c', 'd'}, {'A', 'B', 'C', 'D'}), {('a', 'B'): one, ('a', 'C'): 0, ('d', 'C'): one, ('a', 'A'): one, ('d', 'D'): one, ('d', 'A'): 0, ('d', 'B'): 0, ('b', 'B'): 0, ('c', 'B'): one, ('a', 'C'): 0, ('c', 'A'): one, ('b', 'D'): one, ('c', 'D'): one, ('c', 'C'): one, ('b', 'A'): one, ('a', 'D'): one}) r = Vec({'a', 'b', 'c', 'd'}, {'a': one, 'c': one}) col_label_list = sorted(A.D[1]) M = echelon.transformation(A) U = M*A U_rows_dict = mat2rowdict(U) x = M*r rowlist = [U_rows_dict[i] for i in U_rows_dict] label_list = col_label_list b = [x[item] for item in x.D] ## Problem 7 null_space_rows_a = {3, 4} # Put the row numbers of M from the PDF