コード例 #1
0
ファイル: __main__.py プロジェクト: niels-lubbes/orbital
def usecase_orb_product_implicit_circle(num=10):
    '''
    Outputs "num" random surfaces in the projective n-sphere S^n, 
    that are obtained by rotating or translating an implicit circle.
    The circle is obtained as a random hyperplane section.
    
    The hyperplane section is obtained by applying 
    a random matrix in PGL(8+1) to the hyperplane 
    section { x | x3=..=x8=0=-x0^2+x1^2+...+x8^2=0 }.  
    Since the random matrix is not orthogonal
    we cannot use the matrix to compute parametric 
    presentations for these examples.  
    
    Notice that we can recover the OrbInput object 
    from the short string output 
    (see "usecase_orb_product_investigate_example()")
    
    Parameters
    ----------
    num : int
        Number of times a random surface should be computed.   
    '''

    for idx in range(num):
        try:

            # compute random input
            ch_str = ''.join([
                OrbRing.random_elt(['r', 's', 'p', 'm', 'a']) for i in range(4)
            ])
            pmat = list(sage_MatrixSpace(sage_ZZ, 9, 9).random_element())
            p_tup = ('P1', 'I', 'I')
            o_tup = ('I', 'O' + ch_str, 'I')
            v_tup = ('M' + str(pmat), 'I', 'I')
            input = OrbInput().set(p_tup, o_tup, v_tup)

            # compute only few attributes
            for key in input.do.keys():
                input.do[key] = False
            input.do['imp'] = True
            input.do['dde'] = True

            o = orb_product(input)

            OrbTools.p('(deg, emb, dim ) =',
                       (o.deg, o.emb, o.dim), ' short string =',
                       o.get_short_str())  # output  orbital product

        except BaseException as e:

            # continue with loop regardless of exceptions
            OrbTools.p('Exception occurred: ', e)
            OrbTools.p(input)
            OrbTools.p(o)
コード例 #2
0
    def random(self, bnd=10):
        '''
        Sets attributes to random values. 
                
        Parameters
        ----------
        coef_bnd : int    
            Positive integer.
                             
        Returns
        -------
        self
            Sets self.rota, self.trna, self.sa and
            self.rotb, self.trnb, self.sb with random
            values.
            
        '''
        # OrbRing.random_int( coef_size )

        q4 = sage_QQ(1) / 4

        s_lst = [i * q4 for i in range(4 * bnd)]
        s_lst += [-s for s in s_lst]

        # circle A
        self.rota = [OrbRing.random_elt(range(360)) for i in range(6)]
        self.trna = [OrbRing.random_elt(range(360)) for i in range(3)]
        self.sa = OrbRing.random_elt(s_lst)

        # circle B
        self.rotb = [OrbRing.random_elt(range(360)) for i in range(6)]
        self.trnb = [OrbRing.random_elt(range(360)) for i in range(3)]
        self.sb = OrbRing.random_elt(s_lst)

        return self
コード例 #3
0
    def test__random_elt(self):

        lst = range(10)
        elt = OrbRing.random_elt(lst)
        print(elt)
        assert elt in lst
コード例 #4
0
    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