def test__get_mat_1(self): # # Permute a block matrices to obtain rotation along x-axis. # print(get_mat('I', 'Oprpp', 'I')) e_lst = [1, 4, 2, 3, 5, 6, 7, 8] i_lst = sage_Permutation(e_lst).inverse() A_str = 'E' + str(i_lst) B_str = 'Oprpp' C_str = 'E' + str(e_lst) tup = (A_str, B_str, C_str) print(tup) mati = get_emat(A_str) mate = get_emat(C_str) assert mate * mati == sage_identity_matrix(9) out = get_mat(*tup) print(out) print(list(out)) assert str( list(out) ) == '[(1, 0, 0, 0, 0, 0, 0, 0, 0), (0, 1, 0, 0, 0, 0, 0, 0, 0), (0, 0, c0, -s0, 0, 0, 0, 0, 0), (0, 0, s0, c0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 1, 0, 0, 0, 0), (0, 0, 0, 0, 0, 1, 0, 0, 0), (0, 0, 0, 0, 0, 0, 1, 0, 0), (0, 0, 0, 0, 0, 0, 0, 1, 0), (0, 0, 0, 0, 0, 0, 0, 0, 1)]'
def set( self, p_tup, o_tup, v_tup ): ''' Parameters ---------- p_tup : tuple<string> A 3-tuple of strings with format as in the docs of "orb_matrices.get_mat()". o_tup : tuple<string> Same specs as "p_tup". v_tup : tuple<string> Same specs as "p_tup". Returns ------- self Sets "self.pmat", "self.omat" and "self.vmat" according "p_tup", "o_tup" and "v_tup" respectively. The matrices are obtained with "orb_matrices.get_mat()". Set "self.info_dct" with info about the decomposition of the matrices: "self.info_dct['pmat'] = p_tup" "self.info_dct['omat'] = o_tup" "self.info_dct['vmat'] = v_tup" ''' self.pmat = get_mat( p_tup[0], p_tup[1], p_tup[2] ) self.omat = get_mat( o_tup[0], o_tup[1], o_tup[2] ) self.vmat = get_mat( v_tup[0], v_tup[1], v_tup[2] ) self.info_dct['pmat'] = p_tup self.info_dct['omat'] = o_tup self.info_dct['vmat'] = v_tup return self
def test__get_imp( self ): omat = get_mat( 'T[1, 0, 0, 0, 0, 0, 0]', 'Orppp', 'T[-1, 0, 0, 0, 0, 0, 0]' ) vmat = get_mat( 'T[0, 1, 1, 0, 0, 0, 0]', 'Rrrrs[37, 0, 0, 0]', 'T[0, -1, -1, 0, 0, 0, 0]' ) imp_lst = get_imp( omat, vmat ) # ideal of Perseus cyclide print( imp_lst ) assert str( imp_lst ) == '[x7, x6, x5, x4, 100*x1^2 - 4*x0*x3 - 40*x1*x3 + 9*x3^2 - 200*x1*x8 + 44*x3*x8 + 100*x8^2, 100*x0^2 - 100*x2^2 - 4*x0*x3 - 40*x1*x3 - 91*x3^2 - 200*x1*x8 + 44*x3*x8]'
def test__get_mat__I_Orppp_I(self): out = get_mat('I', 'Orppp', 'I') print(out) print(list(out)) assert str( list(out) ) == '[(1, 0, 0, 0, 0, 0, 0, 0, 0), (0, c0, -s0, 0, 0, 0, 0, 0, 0), (0, s0, c0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 1, 0, 0, 0, 0, 0), (0, 0, 0, 0, 1, 0, 0, 0, 0), (0, 0, 0, 0, 0, 1, 0, 0, 0), (0, 0, 0, 0, 0, 0, 1, 0, 0), (0, 0, 0, 0, 0, 0, 0, 1, 0), (0, 0, 0, 0, 0, 0, 0, 0, 1)]'
def random( self, coef_bnd = 3, random_pmat = True ): ''' Sets (restricted) random values for "self.omat", "self.vmat" and "self.pmat". Parameters ---------- coef_bnd : int Positive integer. random_pmat : boolean Returns ------- self Notes ----- The translation coefficients of "self.vmat" are in the interval: [-coef_bnd, +coef_bnd]. If "random_pmat== True", then "self.pmat" is set to a random value (P1), and otherwise "self.pmat" is set to a standard projection (P0). ''' ch_lst = ['r', 's', 'p', 'm', 'a'] # # random self.pmat # Pn = {True:'P1', False:'P0'}[random_pmat] self.pmat = get_mat( Pn, 'I', 'I' ) self.info_dct['pmat'] = ( Pn, 'I', 'I' ) # # random self.omat # rnd = OrbRing.random_elt( [0, 1] ) if rnd == 0: ch_str = ''.join( [OrbRing.random_elt( ch_lst ) for i in range( 4 ) ] ) B_str = 'O' + ch_str rnd2 = OrbRing.random_elt( [0, 1] ) if rnd2 == 0: A_str = 'I' C_str = 'I' else: p = sage_Permutations( range( 1, 8 + 1 ) ) rp = p.random_element() rpI = sage_Permutation( rp ).inverse() A_str = 'E' + str( list( rpI ) ) C_str = 'E' + str( list( rp ) ) elif rnd == 1: A_str = 'I' B_str = 'tT' C_str = 'I' self.omat = get_mat( A_str, B_str, C_str ) self.info_dct['omat'] = ( A_str, B_str, C_str ) # # random self.vmat # # All the coefficients are bound by coef_size-n for some integer n. coef_size = OrbRing.random_elt( range( 1, coef_bnd + 1 ) ) # A -- self.vmat t_lst = [OrbRing.random_int( coef_size ) for i in range( 7 )] A_str = 'T' + str( t_lst ) # B -- self.vmat" # note that small angles means small coefficients angle_lst = [ OrbRing.random_elt( range( 0, 360 ) ) for i in range( 4 ) ] ch_str = ''.join( [OrbRing.random_elt( ch_lst ) for i in range( 4 ) ] ) B_str = 'R' + ch_str + str( angle_lst ) # C -- self.vmat rnd = OrbRing.random_elt( [0, 1, 2] ) if rnd == 0: C_str = 'T' + str( [-t_lst[i] for i in range( 7 )] ) # inverse elif rnd == 1: C_str = 'T' + str( [OrbRing.random_int( coef_size ) for i in range( 7 )] ) elif rnd == 2: C_str = 'I' # A*B*C -- self.vmat self.vmat = get_mat( A_str, B_str, C_str ) self.info_dct['vmat'] = ( A_str, B_str, C_str ) return self