Esempio n. 1
0
def is_invertible(M): 
    '''
    input: A matrix, M
    outpit: A boolean indicating if M is invertible.
    
    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1,
    (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2,
    (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3,
    (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True
    '''
    R=[]
    C=[]
    R_dict = mat2rowdict(M)
    C_dict = mat2coldict(M)
    for k,v in R_dict.items():
        R.append(v)
    for k,v in C_dict.items():
        C.append(v)
        
    if rank(R) != rank(C):
        return False
    elif my_is_independent(R) == False:
        return False
    elif my_is_independent(C) == False:
        return False
    return True
Esempio n. 2
0
def is_invertible(M):
    '''
    input: A matrix, M
    outpit: A boolean indicating if M is invertible.
    
    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1,
    (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2,
    (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3,
    (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True
    '''
    R = []
    C = []
    R_dict = mat2rowdict(M)
    C_dict = mat2coldict(M)
    for k, v in R_dict.items():
        R.append(v)
    for k, v in C_dict.items():
        C.append(v)

    if rank(R) != rank(C):
        return False
    elif my_is_independent(R) == False:
        return False
    elif my_is_independent(C) == False:
        return False
    return True
Esempio n. 3
0
def is_invertible(M):
    numCol = len(M.D[1])
    # print(numCol)
    # print(rank(list((mat2coldict(M)).values())))
    # print(rank(list((mat2rowdict(M)).values())))
    colRank = rank(list((mat2coldict(M)).values()))
    rowRank = rank(list((mat2rowdict(M)).values()))

    if (numCol - colRank) == 0:
        return True
    elif (numCol - rowRank) == 0:
        return True
    else:
        return False
Esempio n. 4
0
File: hw5.py Progetto: varren/matrix
def is_invertible(M): 
    '''
    input: A matrix, M
    outpit: A boolean indicating if M is invertible.
    
    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1, (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2, (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3, (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True
    '''

    col = list(mat2coldict(M).values())
    row = list(mat2rowdict(M).values())

    return rank(col) == len(col) and rank(row) == len(row)
Esempio n. 5
0
def is_invertible(M):
    '''
    input: A matrix, M
    outpit: A boolean indicating if M is invertible.
    
    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1, (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2, (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3, (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True
    '''

    col = list(mat2coldict(M).values())
    row = list(mat2rowdict(M).values())

    return rank(col) == len(col) and rank(row) == len(row)
Esempio n. 6
0
def get_basis(U):
	
	rank_ = rank(U)
	#already contains independent vectors
	if my_is_independent(U):
		return U 
	# if not there are superfluous vectors
	U_basis = []
	r = 0
	for u in U:
		if rank(U_basis+[u]) > r:
			U_basis.append(u)
			r = rank[u]
		if r == rank_:
			return U_basis
Esempio n. 7
0
def my_is_independent(L):
    """
    input:  A list, L, of Vecs
    output: A boolean indicating if the list is linearly independent
    
    >>> L = [Vec({0, 1, 2},{0: 1, 1: 0, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 1, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 0, 2: 1}), Vec({0, 1, 2},{0: 1, 1: 1, 2: 1}), Vec({0, 1, 2},{0: 1, 1: 1, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 1, 2: 1})]
    >>> my_is_independent(L)
    False
    >>> my_is_independent(L[:2])
    True
    >>> my_is_independent(L[:3])
    True
    >>> my_is_independent(L[1:4])
    True
    >>> my_is_independent(L[0:4])
    False
    >>> my_is_independent(L[2:])
    False
    >>> my_is_independent(L[2:5])
    False
    """
    from independence import rank

    rank_num = rank(L)
    if rank_num < len(L):
        return False
    else:
        return True
Esempio n. 8
0
def is_independent_set(v):
    for i in combinations(v, 3):
        a, b = zip(*i)
        M = list(a) + list(b)
        if len(M) != rank(M):
            return False
    return True
Esempio n. 9
0
def my_is_independent(L):
    '''
    Input:
        - L: a list of Vecs
    Output:
        - boolean: true if the list is linearly independent
    Examples:
        >>> D = {0, 1, 2}
        >>> L = [Vec(D,{0: 1}), Vec(D,{1: 1}), Vec(D,{2: 1}), Vec(D,{0: 1, 1: 1, 2: 1}), Vec(D,{0: 1, 1: 1}), Vec(D,{1: 1, 2: 1})]
        >>> my_is_independent(L)
        False
        >>> my_is_independent(L[:2])
        True
        >>> my_is_independent(L[:3])
        True
        >>> my_is_independent(L[1:4])
        True
        >>> my_is_independent(L[0:4])
        False
        >>> my_is_independent(L[2:])
        False
        >>> my_is_independent(L[2:5])
        False
        >>> L == [Vec(D,{0: 1}), Vec(D,{1: 1}), Vec(D,{2: 1}), Vec(D,{0: 1, 1: 1, 2: 1}), Vec(D,{0: 1, 1: 1}), Vec(D,{1: 1, 2: 1})]
        True
    '''
    from independence import rank
    return rank(L) == len(L)
Esempio n. 10
0
def other_vectors():

    while True:
        l_ = [a0, b0]
        for i in range(8):
            l_.append(
                list2vec([
                    randGF2(),
                    randGF2(),
                    randGF2(),
                    randGF2(),
                    randGF2(),
                    randGF2()
                ]))
        ranks = []
        for comb in list(itertools.combinations([0, 2, 4, 6, 8], 3)):

            l = [(l_[i], l_[i + 1]) for i in comb]
            the_three = [item for sublist in l for item in sublist]
            r = rank(the_three)
            if r < 6:
                continue
            else:
                ranks.append(r)

        if set(ranks) == {6}:
            print("yess")
            return l_

    return l_
Esempio n. 11
0
def my_is_independent(L):
    '''
    Input:
        - L: a list of Vecs
    Output:
        - boolean: true if the list is linearly independent
    Examples:
        >>> D = {0, 1, 2}
        >>> L = [Vec(D,{0: 1}), Vec(D,{1: 1}), Vec(D,{2: 1}), Vec(D,{0: 1, 1: 1, 2: 1}), Vec(D,{0: 1, 1: 1}), Vec(D,{1: 1, 2: 1})]
        >>> my_is_independent(L)
        False
        >>> my_is_independent(L[:2])
        True
        >>> my_is_independent(L[:3])
        True
        >>> my_is_independent(L[1:4])
        True
        >>> my_is_independent(L[0:4])
        False
        >>> my_is_independent(L[2:])
        False
        >>> my_is_independent(L[2:5])
        False
        >>> L == [Vec(D,{0: 1}), Vec(D,{1: 1}), Vec(D,{2: 1}), Vec(D,{0: 1, 1: 1, 2: 1}), Vec(D,{0: 1, 1: 1}), Vec(D,{1: 1, 2: 1})]
        True
    '''
    return rank(L) == len(L)
Esempio n. 12
0
def is_independent_set(v):
	for i in combinations(v,3):
		a,b=zip(*i)
		M=list(a)+list(b)
		if len(M) != rank(M):
			return False
	return True
Esempio n. 13
0
def my_is_independent(L):
    '''
    input:  A list, L, of Vecs
    output: A boolean indicating if the list is linearly independent
    
    >>> L = [Vec({0, 1, 2},{0: 1, 1: 0, 2: 0}), Vec({0, 1, 2},{0: 0,
             1: 1, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 0, 2: 1}), Vec({0,
             1, 2},{0: 1, 1: 1, 2: 1}), Vec({0, 1, 2},{0: 1, 1: 1, 2:
             0}), Vec({0, 1, 2},{0: 0, 1: 1, 2: 1})]
    >>> my_is_independent(L)
    False
    >>> my_is_independent(L[:2])
    True
    >>> my_is_independent(L[:3])
    True
    >>> my_is_independent(L[1:4])
    True
    >>> my_is_independent(L[0:4])
    False
    >>> my_is_independent(L[2:])
    False
    >>> my_is_independent(L[2:5])
    False
    '''
    return len(L) == rank(L)
Esempio n. 14
0
def my_is_independent(L):
    if len(L) == independence.rank(L):
        return True
    else:
        return False
    '''
    input:  A list, L, of Vecs
    output: A boolean indicating if the list is linearly independent
    
    >>> L = [Vec({0, 1, 2},{0: 1, 1: 0, 2: 0}), Vec({0, 1, 2},
    {0: 0, 1: 1, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 0, 2: 1}), Vec({0, 1, 2},{0: 1, 1: 1, 2: 1}), Vec({0, 1, 2},{0: 1, 1: 1, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 1, 2: 1})]
    >>> my_is_independent(L)
    False
    >>> my_is_independent(L[:2])
    True
    >>> my_is_independent(L[:3])
    True
    >>> my_is_independent(L[1:4])
    True
    >>> my_is_independent(L[0:4])
    False
    >>> my_is_independent(L[2:])
    False
    >>> my_is_independent(L[2:5])
    False
    '''
    pass
Esempio n. 15
0
def my_is_independent(L): 
    '''
    input:  A list, L, of Vecs
    output: A boolean indicating if the list is linearly independent
    
    >>> L = [Vec({0, 1, 2},{0: 1, 1: 0, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 1, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 0, 2: 1}), Vec({0, 1, 2},{0: 1, 1: 1, 2: 1}), Vec({0, 1, 2},{0: 1, 1: 1, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 1, 2: 1})]
    >>> my_is_independent(L)
    False
    >>> my_is_independent(L[:2])
    True
    >>> my_is_independent(L[:3])
    True
    >>> my_is_independent(L[1:4])
    True
    >>> my_is_independent(L[0:4])
    False
    >>> my_is_independent(L[2:])
    False
    >>> my_is_independent(L[2:5])
    False
    '''
    from independence import rank
    rank_num = rank(L)
    if rank_num < len(L):
        return False
    else:
        return True
Esempio n. 16
0
def is_invertible(M):
    '''
    input: A matrix, M
    outpit: A boolean indicating if M is invertible.
    
    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1, (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2, (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3, (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True
    '''
    from independence import is_independent, rank

    Mcols = list(mat2coldict(M).values())
    Mrows = list(mat2rowdict(M).values())
    colrank = rank(Mcols)

    return len(Mcols) == len(Mrows) == rank(Mcols)
def sel_all_vecs():
    '''
    Algo:
    1. Start with a0,b0, grow a1,b1,a2,b2 randomly so they are linearly independent.
    2. Keep generating random a3,b3 until any 3 pairs of vecs are linearly independent.
    3. Keep generating random a4,b4 until any 3 pairs of vecs are linearly independent.
    '''
    selected = False

    while not selected:
        fivePairs = []
        fivePairs.append((a0, b0))
        fivePairs.append((a1, b1))
        fivePairs.append((a2, b2))
        fivePairs.append((a3, b3))
        fivePairs.append((generateSecretVector(a0.D), generateSecretVector(a0.D)))

        threePairsList = generateAllThreePairsList(fivePairs)
        passed = False

        # Look at the printed value of Threes and modify the list below
        # based on this
        t0 = threePairsList[0]
        t1 = threePairsList[1]
        t2 = threePairsList[2]
        t3 = threePairsList[3]
        t4 = threePairsList[4]
        t5 = threePairsList[5]
        t6 = threePairsList[6]
        t7 = threePairsList[7]
        t8 = threePairsList[8]
        t9 = threePairsList[9]
        r1 = independence.rank(t0[0]+t0[1]+t0[2])
        r2 = independence.rank(t1[0]+t1[1]+t1[2])
        r3 = independence.rank(t2[0]+t2[1]+t2[2])
        r4 = independence.rank(t3[0]+t3[1]+t3[2])
        r5 = independence.rank(t4[0]+t4[1]+t4[2])
        r6 = independence.rank(t5[0]+t5[1]+t5[2])
        r7 = independence.rank(t6[0]+t6[1]+t6[2])
        r8 = independence.rank(t7[0]+t7[1]+t7[2])
        r9 = independence.rank(t8[0]+t8[1]+t8[2])
        r10 = independence.rank(t9[0]+t9[1]+t9[2])

        if r1 == r2 ==r3 == r4==r5==r6==r7==r8==r9==r10 and r1 == 6:
            print(t0)
            print(t1)
            print(t2)
Esempio n. 18
0
def my_rank(L): 
    '''
    input: A list, L, of Vecs
    output: The rank of the list of Vecs
    
    >>> my_rank([list2vec(v) for v in [[1,2,3],[4,5,6],[1.1,1.1,1.1]]])
    2
    '''
    return (rank(subset_basis(L)))
Esempio n. 19
0
def my_is_independent(L): 
    '''
    input:  A list, L, of Vecs
    output: A boolean indicating if the list is linearly independent
    '''

    if len(L) > rank(L):
        return False
    return True
Esempio n. 20
0
def my_is_independent(L):
	cols = len(L)
	rows = len(L[0].D)
	rank_ = min(cols,rows)
	
	if rank(L) == rank_:
		return True
	else:
		False
Esempio n. 21
0
def my_rank(L):
    '''
    input: A list, L, of Vecs
    output: The rank of the list of Vecs
    
    >>> my_rank([list2vec(v) for v in [[1,2,3],[4,5,6],[1.1,1.1,1.1]]])
    2
    '''
    from independence import rank
    return rank(L)
Esempio n. 22
0
def is_invertible(M): 
    '''
    input: A matrix, M
    outpit: A boolean indicating if M is invertible.
    
    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1, (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2, (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3, (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True
    '''
    return True if rank(list(mat2coldict(M).values())) == len(M.D[1]) and len(M.D[1]) == len(M.D[0]) else False
Esempio n. 23
0
def factor_woojoo(N, primeset):
    roots, rowlist = find_candidates(N, primeset)
    M = echelon.transformation_rows(rowlist, sorted(primeset, reverse=True))
    rank = independence.rank(rowlist)
    for i in range(len(M) - 1, rank - 1, -1):
        a, b = find_a_and_b(M[i], roots, N)
        ans = gcd(a - b, N)
        if ans > 1:
            return ans
    return None
Esempio n. 24
0
def my_rank(L): 
    '''
    input: A list, L, of Vecs
    output: The rank of the list of Vecs
    
    >>> my_rank([list2vec(v) for v in [[1,2,3],[4,5,6],[1.1,1.1,1.1]]])
    2
    '''
    from independence import rank
    return rank(L)
Esempio n. 25
0
def is_invertible(M): 
    '''
    input: A matrix, M
    output: A boolean indicating if M is invertible.
    
    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1, (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2, (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3, (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True
    '''
    
    if M.D[0] != M.D[1]: return False
    
    rowdict = mat2rowdict(M)
    rowlist = list (rowdict.values())
    coldict = mat2coldict (M)
    collist = list(coldict.values())
    # check if the matrix is square and the columns are independent
    if rank(rowlist) == rank (collist) and len (collist) == rank (collist): return True
    else: return False
Esempio n. 26
0
def subset_basis(T): 
    '''
    input: A list, T, of Vecs
    output: A list, S, containing Vecs from T, that is a basis for the
    space spanned by T.
    
    >>> 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})
    >>> subset_basis([a0,a1,a2,a3]) == [Vec({'c', 'b', 'a', 'd'},{'a': 1}), Vec({'c', 'b', 'a', 'd'},{'b': 1}), Vec({'c', 'b', 'a', 'd'},{'c': 1})]
    True
    '''
    rank_T = rank(T)
    S = []
    for x in T:
        if(is_independent([S+[x]])):
           S.append(x)
           if rank(S) == rank_T:break
    return S
Esempio n. 27
0
def is_invertible(M):
    '''
		input: A matrix, M
		outpit: A boolean indicating if M is invertible.
		
		>>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1, (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2, (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3, (1, 0): 0, (0, 3): 0})
		>>> is_invertible(M)
		True
		'''
    return len(M.D[0]) == len(M.D[1]) and rank(mat2collist(M)) == len(
        mat2collist(M))
Esempio n. 28
0
def morph(S,B):
	#B is independent list
	#S is list of vectors
	# Span(S) = Span(B)
	returned_list = []
	rank_B = rank(B)
	for b in B:
		# if set(B) == set(S_rem):
		# 	break
		B.pop(0)
		cond = B
		for s in S:

			if rank(cond+[s])==rank_B:
				B.append(s)
				S.remove(s)
				returned_list.append([b,s])
				

	return returned_list
Esempio n. 29
0
def subset_basis(T):
    """
    input: A list, T, of Vecs
    output: A list, S, containing Vecs from T, that is a basis for the
    space spanned by T.
    
    >>> 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})
    >>> subset_basis([a0,a1,a2,a3]) == [Vec({'c', 'b', 'a', 'd'},{'a': 1}), Vec({'c', 'b', 'a', 'd'},{'b': 1}), Vec({'c', 'b', 'a', 'd'},{'c': 1})]
    True
    """
    S = []
    curRank = 0
    for iVec in T:
        if rank(S + [iVec]) > curRank:
            S.append(iVec)
            curRank = rank(S)

    return S
Esempio n. 30
0
def subset_basis(T):
    '''
    input: A list, T, of Vecs
    output: A list, S, containing Vecs from T, that is a basis for the
    space spanned by T.
    
    >>> 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})
    >>> subset_basis([a0,a1,a2,a3]) == [Vec({'c', 'b', 'a', 'd'},{'a': 1}), Vec({'c', 'b', 'a', 'd'},{'b': 1}), Vec({'c', 'b', 'a', 'd'},{'c': 1})]
    True
    '''
    S = []
    curRank = 0
    for iVec in T:
        if rank(S + [iVec]) > curRank:
            S.append(iVec)
            curRank = rank(S)

    return S
Esempio n. 31
0
def is_invertible(M):
    """
    input: A matrix, M
    outpit: A boolean indicating if M is invertible.
    
    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1, (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2, (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3, (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True
    """
    if len(M.D[0]) != len(M.D[1]):
        return False
    L = list(mat2coldict(M).values())
    return rank(L) == len(L)
Esempio n. 32
0
def is_invertible(M): 
    '''
    input: A matrix, M
    outpit: A boolean indicating if M is invertible.
    
    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1, (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2, (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3, (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True
    '''
    # 1. cardinality of row = cardinality of column
    # 2. column vectors are linearly independent
    c=mat2coldict(M)
    return rank([c[x] for x in c]) == len(M.D[1]) and len(M.D[0]) == len(M.D[1])
Esempio n. 33
0
def is_invertible(M): 
    '''
    input: A matrix, M
    outpit: A boolean indicating if M is invertible.
    
    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1, (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2, (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3, (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True
    '''
    if M.D[0]!=M.D[1]:
        return False
    M=mat2coldict(M)
    M=list(M.values())
    return rank(M)==len(M)
Esempio n. 34
0
def is_invertible(M): 
    '''
    input: A matrix, M
    outpit: A boolean indicating if M is invertible.
    
    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1, (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2, (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3, (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True
    '''
    from matutil import mat2coldict
    from independence import rank
    if len(M.D[0]) == len(M.D[1]):
        M = mat2coldict(M)
        M = list(M.values())
        return rank(M) == len(M)
    return False
Esempio n. 35
0
def is_invertible(M): 
    '''
    input: A matrix, M
    outpit: A boolean indicating if M is invertible.
    
    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1, (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2, (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3, (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True
    '''
    nullspace = solve(M, list2vec([0]))
    ker_zero = nullspace == Vec(nullspace.D, {})

    im_f_eq_codomain = independence.rank(subset_basis(matutil.mat2coldict(M).values())) == len(M.D[1])

    # invertible if its one-to-one, onto, and square matrix
    return ker_zero and im_f_eq_codomain and len(matutil.mat2coldict(M)) == len(matutil.mat2rowdict(M))
def is_invertible(M):
    '''
    input: A matrix, M
    outpit: A boolean indicating if M is invertible.

    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1, (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2, (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3, (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True

    >>> M1 = Mat(({0,1,2},{0,1,2}),{(0,0):1,(0,2):2,(1,2):3,(2,2):4})
    >>> is_invertible(M1)
    False
    '''
    if len(M.D[0]) != len(M.D[1]):
        return False
    if rank(list(mat2coldict(M).values())) != len(M.D[1]):
        return False
    return True
Esempio n. 37
0
def is_invertible(M):
    '''
    input: A matrix, M
    outpit: A boolean indicating if M is invertible.
    
    >>> M = Mat(({0, 1, 2, 3}, {0, 1, 2, 3}), {(0, 1): 0, (1, 2): 1, (3, 2): 0, (0, 0): 1, (3, 3): 4, (3, 0): 0, (3, 1): 0, (1, 1): 2, (2, 1): 0, (0, 2): 1, (2, 0): 0, (1, 3): 0, (2, 3): 1, (2, 2): 3, (1, 0): 0, (0, 3): 0})
    >>> is_invertible(M)
    True
    '''
    nullspace = solve(M, list2vec([0]))
    ker_zero = nullspace == Vec(nullspace.D, {})

    im_f_eq_codomain = independence.rank(
        subset_basis(matutil.mat2coldict(M).values())) == len(M.D[1])

    # invertible if its one-to-one, onto, and square matrix
    return ker_zero and im_f_eq_codomain and len(
        matutil.mat2coldict(M)) == len(matutil.mat2rowdict(M))
Esempio n. 38
0
def my_is_independent(L):
    """
    input:  A list, L, of Vecs
    output: A boolean indicating if the list is linearly independent
    
    >>> L = [Vec({0, 1, 2},{0: 1, 1: 0, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 1, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 0, 2: 1}), Vec({0, 1, 2},{0: 1, 1: 1, 2: 1}), Vec({0, 1, 2},{0: 1, 1: 1, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 1, 2: 1})]
    >>> my_is_independent(L)
    False
    >>> my_is_independent(L[:2])
    True
    >>> my_is_independent(L[:3])
    True
    >>> my_is_independent(L[1:4])
    True
    >>> my_is_independent(L[0:4])
    False
    >>> my_is_independent(L[2:])
    False
    >>> my_is_independent(L[2:5])
    False
    """
    return rank(L) == len(L)
def my_is_independent(L):
    '''
    Input:
        - L: a list of Vecs
    Output:
        - boolean: true if the list is linearly independent
    Examples:
        >>> D = {0, 1, 2}
        >>> L = [Vec(D,{0: 1}), Vec(D,{1: 1}), Vec(D,{2: 1}), Vec(D,{0: 1, 1: 1, 2: 1}), Vec(D,{0: 1, 1: 1}), Vec(D,{1: 1, 2: 1})]
        >>> my_is_independent(L)
        False
        >>> my_is_independent(L[:2])
        True
        >>> my_is_independent(L[:3])
        True
        >>> my_is_independent(L[1:4])
        True
        >>> my_is_independent(L[0:4])
        False
        >>> my_is_independent(L[2:])
        False
        >>> my_is_independent(L[2:5])
        False
        >>> L == [Vec(D,{0: 1}), Vec(D,{1: 1}), Vec(D,{2: 1}), Vec(D,{0: 1, 1: 1, 2: 1}), Vec(D,{0: 1, 1: 1}), Vec(D,{1: 1, 2: 1})]
        True
    '''
    """
    for x in L:
        if is_superfluous(set(L),x)==True:
            return False
    return True
    """
    from independence import rank
    rank_num = rank(L)
    if rank_num < len(L):
        return False
    else:
        return True
def my_is_independent(L):
    '''
    Input:
        - L: a list of Vecs
    Output:
        - boolean: true if the list is linearly independent
    Examples:
        >>> D = {0, 1, 2}
        >>> L = [Vec(D,{0: 1}), Vec(D,{1: 1}), Vec(D,{2: 1}), Vec(D,{0: 1, 1: 1, 2: 1}), Vec(D,{0: 1, 1: 1}), Vec(D,{1: 1, 2: 1})]
        >>> my_is_independent(L)
        False
        >>> my_is_independent(L[:2])
        True
        >>> my_is_independent(L[:3])
        True
        >>> my_is_independent(L[1:4])
        True
        >>> my_is_independent(L[0:4])
        False
        >>> my_is_independent(L[2:])
        False
        >>> my_is_independent(L[2:5])
        False
        >>> L == [Vec(D,{0: 1}), Vec(D,{1: 1}), Vec(D,{2: 1}), Vec(D,{0: 1, 1: 1, 2: 1}), Vec(D,{0: 1, 1: 1}), Vec(D,{1: 1, 2: 1})]
        True
    '''
    """
    for x in L:
        if is_superfluous(set(L),x)==True:
            return False
    return True
    """
    from independence import rank
    rank_num = rank(L)
    if rank_num < len(L):
        return False
    else:
        return True
Esempio n. 41
0
def my_is_independent(L): 
    '''
    input:  A list, L, of Vecs
    output: A boolean indicating if the list is linearly independent
    
    >>> L = [Vec({0, 1, 2},{0: 1, 1: 0, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 1, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 0, 2: 1}), Vec({0, 1, 2},{0: 1, 1: 1, 2: 1}), Vec({0, 1, 2},{0: 1, 1: 1, 2: 0}), Vec({0, 1, 2},{0: 0, 1: 1, 2: 1})]
    >>> my_is_independent(L)
    False
    >>> my_is_independent(L[:2])
    True
    >>> my_is_independent(L[:3])
    True
    >>> my_is_independent(L[1:4])
    True
    >>> my_is_independent(L[0:4])
    False
    >>> my_is_independent(L[2:])
    False
    >>> my_is_independent(L[2:5])
    False
    '''
    from independence import rank
    return True if rank(L) == len(L) else False
Esempio n. 42
0
def my_is_independent(veclist):
    return len(veclist) == rank(veclist)
Esempio n. 43
0
def my_is_independent(L):
    return len(L) == rank(L)
Esempio n. 44
0
    '''
    lst = []
    for l in L:
        lst.extend(l)
    return lst

secret_a0 = list2vec([one, one,   0, one,   0, one])
secret_b0 = list2vec([one, one,   0,   0,   0, one])

# make initial list of 6 independent vectors
A = [secret_a0, secret_b0]
r = 2
while r < 6:
    v = list2vec([randGF2() for i in range(6)])
    A.append(v)
    temp_rank = rank(A)
    if temp_rank == r+1: 
        r += 1
    else:
        A.remove(v)

while len(A) < 10:
    v1 = list2vec([randGF2() for i in range(6)])
    v2 = list2vec([randGF2() for i in range(6)])
    L = split_couples(A)
    L.append([v1, v2])
    C = combinations(L, 3)
    valid = all([rank(join_couples(i))==6 for i in C])
    if valid:
        A.extend([v1, v2])
Esempio n. 45
0
		output: The rank of the list of Vecs
		
		>>> my_rank([list2vec(v) for v in [[1,2,3],[4,5,6],[1.1,1.1,1.1]]])
		2
		'''
    return len(subset_basis(L))


## Problem 8
# Please give each answer as a boolean

u1 = [one, 0, one, 0]
u2 = [0, 0, one, 0]
v1 = [0, one, 0, one]
v2 = [0, 0, 0, one]
urank = rank([list2vec(v) for v in [u1, u2]])
vrank = rank([list2vec(v) for v in [v1, v2]])
combinedrank = rank([list2vec(v) for v in [u1, u2, v1, v2]])
only_share_the_zero_vector_1 = combinedrank == urank + vrank
u1 = [1, 2, 3]
u2 = [1, 2, 0]
v1 = [2, 1, 3]
v2 = [2, 1, 3]
urank = my_rank([list2vec(v) for v in [u1, u2]])
vrank = my_rank([list2vec(v) for v in [v1, v2]])
combinedrank = my_rank([list2vec(v) for v in [u1, u2, v1, v2]])
only_share_the_zero_vector_2 = combinedrank == urank + vrank
u1 = [2, 0, 8, 0]
u2 = [1, 1, 4, 0]
v1 = [2, 1, 1, 1]
v2 = [0, 1, 1, 1]
Esempio n. 46
0
File: hw5.py Progetto: pcp135/C-CtM
		output: The rank of the list of Vecs
		
		>>> my_rank([list2vec(v) for v in [[1,2,3],[4,5,6],[1.1,1.1,1.1]]])
		2
		'''
		return len(subset_basis(L))


## Problem 8
# Please give each answer as a boolean

u1=[one,0,one,0]
u2=[0,0,one,0]
v1=[0,one,0,one]
v2=[0,0,0,one]
urank=rank([list2vec(v) for v in [u1,u2]])
vrank=rank([list2vec(v) for v in [v1,v2]])
combinedrank=rank([list2vec(v) for v in [u1,u2,v1,v2]])
only_share_the_zero_vector_1 = combinedrank==urank+vrank
u1=[1,2,3]
u2=[1,2,0]
v1=[2,1,3]
v2=[2,1,3]
urank=my_rank([list2vec(v) for v in [u1,u2]])
vrank=my_rank([list2vec(v) for v in [v1,v2]])
combinedrank=my_rank([list2vec(v) for v in [u1,u2,v1,v2]])
only_share_the_zero_vector_2 = combinedrank==urank+vrank
u1=[2,0,8,0]
u2=[1,1,4,0]
v1=[2,1,1,1]
v2=[0,1,1,1]