Changeset 1652:6ce9f84cb399


Ignore:
Timestamp:
10/25/06 23:38:20 (7 years ago)
Author:
William Stein <wstein@…>
Branch:
default
Parents:
1646:adfc7be853bf (diff), 1651:406fd123b1fc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Added some new matrix functions and some examples.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sage/libs/pari/gen.pyx

    r1453 r1652  
    714714            [1, 2, 3, 10, 102, 10] 
    715715            sage: type(w[0]) 
    716             <type 'gen.gen'> 
     716            <type 'sage.libs.pari.gen.gen'> 
    717717        """ 
    718718        if typ(self.g) != t_VEC: 
     
    43294329        If f(t) is a series in t with valuation 1, find the 
    43304330        series g(t) such that g(f(t)) = t. 
     4331 
     4332        EXAMPLES: 
     4333            sage: f = pari('x+x^2+x^3+O(x^4)'); f 
     4334            x + x^2 + x^3 + O(x^4) 
     4335            sage: g = f.serreverse(); g 
     4336            x - x^2 + x^3 + O(x^4) 
     4337            sage: f.subst('x',g) 
     4338            x + O(x^4) 
     4339            sage: g.subst('x',f) 
     4340            x + O(x^4)         
    43314341        """ 
    43324342        _sig_on 
     
    43684378 
    43694379    def ncols(self): 
     4380        """ 
     4381        Return the number of rows of self. 
     4382 
     4383        EXAMPLES: 
     4384            sage: pari('matrix(19,8)').ncols() 
     4385            8         
     4386        """ 
    43704387        cdef long n 
    43714388        _sig_on 
     
    43754392 
    43764393    def nrows(self): 
     4394        """ 
     4395        Return the number of rows of self. 
     4396 
     4397        EXAMPLES: 
     4398            sage: pari('matrix(19,8)').nrows() 
     4399            19 
     4400        """ 
    43774401        cdef long n 
    43784402        _sig_on 
     
    43834407    def mattranspose(self): 
    43844408        """ 
     4409        Transpose of the matrix self. 
     4410         
     4411        EXAMPLES: 
     4412            sage: pari('[1,2,3; 4,5,6;  7,8,9]').mattranspose() 
     4413            [1, 4, 7; 2, 5, 8; 3, 6, 9]         
    43854414        """ 
    43864415        _sig_on         
    43874416        return self.new_gen(gtrans(self.g)).Mat() 
    43884417 
    4389     def transpose(self): 
    4390         return self.mattranspose() 
    4391  
    43924418    def matadjoint(self): 
    43934419        """ 
    43944420        matadjoint(x): adjoint matrix of x. 
     4421 
     4422        EXAMPLES: 
     4423            sage: pari('[1,2,3; 4,5,6;  7,8,9]').matadjoint() 
     4424            [-3, 6, -3; 6, -12, 6; -3, 6, -3] 
     4425            sage: pari('[a,b,c; d,e,f; g,h,i]').matadjoint() 
     4426            [(i*e - h*f), (-i*b + h*c), (f*b - e*c); (-i*d + g*f), i*a - g*c, -f*a + d*c; (h*d - g*e), -h*a + g*b, e*a - d*b]             
    43954427        """ 
    43964428        _sig_on         
    43974429        return self.new_gen(adj(self.g)).Mat() 
    4398  
    4399     def adjoint(self): 
    4400         return self.matadjoint() 
    44014430 
    44024431    def qflllgram(self, long flag=0): 
     
    44474476    def matker(self, long flag=0): 
    44484477        """ 
     4478        Return a basis of the kernel of this matrix. 
     4479 
     4480        INPUT: 
     4481            flag -- optional; may be set to 
     4482                0: default; 
     4483                non-zero: x is known to have integral entries. 
     4484 
     4485        EXAMPLES: 
     4486            sage: pari('[1,2,3;4,5,6;7,8,9]').matker() 
     4487            [1; -2; 1] 
     4488 
     4489        With algorithm 1, even if the matrix has integer entries the 
     4490        kernel need nto be saturated (which is weird): 
     4491            sage: pari('[1,2,3;4,5,6;7,8,9]').matker(1) 
     4492            [3; -6; 3] 
     4493            sage: pari('matrix(3,3,i,j,i)').matker() 
     4494            [-1, -1; 1, 0; 0, 1]             
     4495            sage: pari('[1,2,3;4,5,6;7,8,9]*Mod(1,2)').matker() 
     4496            [Mod(1, 2); Mod(0, 2); 1]             
    44494497        """ 
    44504498        _sig_on         
     
    44534501    def matkerint(self, long flag=0): 
    44544502        """ 
     4503        Return the integer kernel of a matrix. 
     4504 
     4505        This is the LLL-reduced Z-basis of the kernel of the matrix x 
     4506        with integral entries. 
     4507 
     4508        INPUT: 
     4509            flag -- optional, and may be set to 
     4510                   0: default, uses a modified LLL, 
     4511                   1: uses matrixqz. 
     4512                    
     4513        EXAMPLES: 
     4514            sage: pari('[2,1;2,1]').matker() 
     4515            [-1/2; 1] 
     4516            sage: pari('[2,1;2,1]').matkerint() 
     4517            [-1; 2] 
     4518 
     4519        This is worrisome (so be careful!): 
     4520            sage: pari('[2,1;2,1]').matkerint(1) 
     4521            Mat(1)         
    44554522        """ 
    44564523        _sig_on         
    44574524        return self.new_gen(matkerint0(self.g, flag)) 
    44584525 
     4526    def matdet(self, long flag=0): 
     4527        """ 
     4528        Return the determinant of this matrix. 
     4529 
     4530        INPUT: 
     4531            flag  -- (optional) flag 
     4532                     0: using Gauss-Bareiss. 
     4533                     1: use classical gaussian elimination (slightly better for integer entries) 
     4534 
     4535        EXAMPLES: 
     4536            sage: pari('[1,2; 3,4]').matdet(0) 
     4537            -2 
     4538            sage: pari('[1,2; 3,4]').matdet(1) 
     4539            -2 
     4540        """ 
     4541        _sig_on         
     4542        return self.new_gen(det0(self.g, flag)) 
     4543 
    44594544    def trace(self): 
     4545        """ 
     4546        Return the trace of this PARI object. 
     4547 
     4548        EXAMPLES: 
     4549            sage: pari('[1,2; 3,4]').trace()   
     4550            5 
     4551        """ 
    44604552        _sig_on         
    44614553        return self.new_gen(gtrace(self.g)) 
     
    44644556        """ 
    44654557        A.mathnf({flag=0}): (upper triangular) Hermite normal form of 
    4466         A, basis for the lattice formed by the columns of A.  flag is 
    4467         optional whose value range from 0 to 4 (0 if omitted), meaning 
    4468         : 0: naive algorithm. 1: Use Batut's algorithm. Output 
    4469         2-component vector [H,U] such that H is the HNF of A, and U is 
    4470         a unimodular matrix such that xU=H. 3: Use Batut's 
    4471         algorithm. Output [H,U,P] where P is a permutation matrix such 
    4472         that P A U = H. 4: as 1, using a heuristic variant of LLL 
    4473         reduction along the way. 
     4558        A, basis for the lattice formed by the columns of A. 
     4559 
     4560        INPUT: 
     4561            flag -- optional, value range from 0 to 4 (0 if 
     4562            omitted), meaning : 
     4563                0: naive algorithm 
     4564                1: Use Batut's algorithm -- output 2-component vector 
     4565                   [H,U] such that H is the  HNF of A, and U is a 
     4566                   unimodular matrix such that xU=H. 
     4567                3: Use Batut's algorithm. Output [H,U,P] where P is 
     4568                   a permutation matrix such that P A U = H. 
     4569                4: As 1, using a heuristic variant of LLL reduction 
     4570                   along the way. 
     4571 
     4572        EXAMPLES: 
     4573            sage: pari('[1,2,3; 4,5,6;  7,8,9]').mathnf() 
     4574            [6, 1; 3, 1; 0, 1] 
    44744575        """ 
    44754576        _sig_on 
     
    44854586        information corresponding to entries equal to 1 in d. 
    44864587 
     4588        EXAMPLES: 
     4589            sage: pari('[1,2,3; 4,5,6;  7,8,9]').matsnf() 
     4590            [0, 3, 1] 
    44874591        """ 
    44884592        _sig_on 
     
    44904594 
    44914595    def matfrobenius(self, flag=0): 
    4492         """ 
     4596        r""" 
    44934597        M.matfrobenius({flag=0}): Return the Frobenius form of the 
    44944598        square matrix M. If flag is 1, return only the elementary 
     
    45104614            sage: v[1]^(-1)*v[0]*v[1] 
    45114615            [1, 2; 3, 4] 
    4512              
    4513             sage: T = ModularSymbols(43,sign=1).T(2).matrix() 
    4514             sage: T 
    4515             [ 3 -2  0  0] 
    4516             [ 0 -2  0  1] 
    4517             [ 0 -1 -2  2] 
    4518             [ 0 -2  0  2] 
    4519             sage: t = pari(T) 
     4616 
     4617        We let t be the matrix of $T_2$ acting on modular symbols of level 43, 
     4618        which was computed using \code{ModularSymbols(43,sign=1).T(2).matrix()}: 
     4619         
     4620            sage: t = pari('[3, -2, 0, 0; 0, -2, 0, 1; 0, -1, -2, 2; 0, -2, 0, 2]') 
    45204621            sage: t.matfrobenius() 
    45214622            [0, 0, 0, -12; 1, 0, 0, -2; 0, 1, 0, 8; 0, 0, 1, 1] 
    4522             sage: T.charpoly() 
     4623            sage: t.charpoly() 
    45234624            x^4 - x^3 - 8*x^2 + 2*x + 12 
    4524             sage: T.charpoly().factor() 
    4525             (x - 3) * (x + 2) * (x^2 - 2) 
    45264625            sage: t.matfrobenius(1) 
    45274626            [x^4 - x^3 - 8*x^2 + 2*x + 12] 
     
    45444643    def factor(gen self, limit=-1): 
    45454644        """ 
    4546         factor(x,{lim}): factorization of x. lim is optional and can 
    4547         be set whenever x is of (possibly recursive) rational 
    4548         type. If lim is set return partial factorization, using 
    4549         primes up to lim (up to primelimit if lim=0) 
     4645        Return the factorization of x. 
     4646 
     4647        lim is optional and can be set whenever x is of (possibly 
     4648        recursive) rational type. If lim is set return partial 
     4649        factorization, using primes up to lim (up to primelimit if 
     4650        lim=0). 
     4651 
     4652        EXAMPLES: 
     4653            sage: pari('x^10-1').factor() 
     4654            [x - 1, 1; x + 1, 1; x^4 - x^3 + x^2 - x + 1, 1; x^4 + x^3 + x^2 + x + 1, 1] 
     4655            sage: pari(2^100-1).factor() 
     4656            [3, 1; 5, 3; 11, 1; 31, 1; 41, 1; 101, 1; 251, 1; 601, 1; 1801, 1; 4051, 1; 8101, 1; 268501, 1] 
     4657 
     4658        PARI doesn't have an algorithm for factoring multivariate polynomials: 
     4659         
     4660            sage: pari('x^3 - y^3').factor() 
     4661            Traceback (most recent call last): 
     4662            ... 
     4663            PariError: sorry, (15) 
    45504664        """ 
    45514665        _sig_on 
    45524666        return P.new_gen(factor0(self.g, limit)) 
    4553  
    4554  
    4555      
    4556  
     4667     
    45574668 
    45584669    ########################################### 
  • sage/libs/pari/gen.pyx

    r1453 r1652  
    714714            [1, 2, 3, 10, 102, 10] 
    715715            sage: type(w[0]) 
    716             <type 'gen.gen'> 
     716            <type 'sage.libs.pari.gen.gen'> 
    717717        """ 
    718718        if typ(self.g) != t_VEC: 
     
    43294329        If f(t) is a series in t with valuation 1, find the 
    43304330        series g(t) such that g(f(t)) = t. 
     4331 
     4332        EXAMPLES: 
     4333            sage: f = pari('x+x^2+x^3+O(x^4)'); f 
     4334            x + x^2 + x^3 + O(x^4) 
     4335            sage: g = f.serreverse(); g 
     4336            x - x^2 + x^3 + O(x^4) 
     4337            sage: f.subst('x',g) 
     4338            x + O(x^4) 
     4339            sage: g.subst('x',f) 
     4340            x + O(x^4)         
    43314341        """ 
    43324342        _sig_on 
     
    43684378 
    43694379    def ncols(self): 
     4380        """ 
     4381        Return the number of rows of self. 
     4382 
     4383        EXAMPLES: 
     4384            sage: pari('matrix(19,8)').ncols() 
     4385            8         
     4386        """ 
    43704387        cdef long n 
    43714388        _sig_on 
     
    43754392 
    43764393    def nrows(self): 
     4394        """ 
     4395        Return the number of rows of self. 
     4396 
     4397        EXAMPLES: 
     4398            sage: pari('matrix(19,8)').nrows() 
     4399            19 
     4400        """ 
    43774401        cdef long n 
    43784402        _sig_on 
     
    43834407    def mattranspose(self): 
    43844408        """ 
     4409        Transpose of the matrix self. 
     4410         
     4411        EXAMPLES: 
     4412            sage: pari('[1,2,3; 4,5,6;  7,8,9]').mattranspose() 
     4413            [1, 4, 7; 2, 5, 8; 3, 6, 9]         
    43854414        """ 
    43864415        _sig_on         
    43874416        return self.new_gen(gtrans(self.g)).Mat() 
    43884417 
    4389     def transpose(self): 
    4390         return self.mattranspose() 
    4391  
    43924418    def matadjoint(self): 
    43934419        """ 
    43944420        matadjoint(x): adjoint matrix of x. 
     4421 
     4422        EXAMPLES: 
     4423            sage: pari('[1,2,3; 4,5,6;  7,8,9]').matadjoint() 
     4424            [-3, 6, -3; 6, -12, 6; -3, 6, -3] 
     4425            sage: pari('[a,b,c; d,e,f; g,h,i]').matadjoint() 
     4426            [(i*e - h*f), (-i*b + h*c), (f*b - e*c); (-i*d + g*f), i*a - g*c, -f*a + d*c; (h*d - g*e), -h*a + g*b, e*a - d*b]             
    43954427        """ 
    43964428        _sig_on         
    43974429        return self.new_gen(adj(self.g)).Mat() 
    4398  
    4399     def adjoint(self): 
    4400         return self.matadjoint() 
    44014430 
    44024431    def qflllgram(self, long flag=0): 
     
    44474476    def matker(self, long flag=0): 
    44484477        """ 
     4478        Return a basis of the kernel of this matrix. 
     4479 
     4480        INPUT: 
     4481            flag -- optional; may be set to 
     4482                0: default; 
     4483                non-zero: x is known to have integral entries. 
     4484 
     4485        EXAMPLES: 
     4486            sage: pari('[1,2,3;4,5,6;7,8,9]').matker() 
     4487            [1; -2; 1] 
     4488 
     4489        With algorithm 1, even if the matrix has integer entries the 
     4490        kernel need nto be saturated (which is weird): 
     4491            sage: pari('[1,2,3;4,5,6;7,8,9]').matker(1) 
     4492            [3; -6; 3] 
     4493            sage: pari('matrix(3,3,i,j,i)').matker() 
     4494            [-1, -1; 1, 0; 0, 1]             
     4495            sage: pari('[1,2,3;4,5,6;7,8,9]*Mod(1,2)').matker() 
     4496            [Mod(1, 2); Mod(0, 2); 1]             
    44494497        """ 
    44504498        _sig_on         
     
    44534501    def matkerint(self, long flag=0): 
    44544502        """ 
     4503        Return the integer kernel of a matrix. 
     4504 
     4505        This is the LLL-reduced Z-basis of the kernel of the matrix x 
     4506        with integral entries. 
     4507 
     4508        INPUT: 
     4509            flag -- optional, and may be set to 
     4510                   0: default, uses a modified LLL, 
     4511                   1: uses matrixqz. 
     4512                    
     4513        EXAMPLES: 
     4514            sage: pari('[2,1;2,1]').matker() 
     4515            [-1/2; 1] 
     4516            sage: pari('[2,1;2,1]').matkerint() 
     4517            [-1; 2] 
     4518 
     4519        This is worrisome (so be careful!): 
     4520            sage: pari('[2,1;2,1]').matkerint(1) 
     4521            Mat(1)         
    44554522        """ 
    44564523        _sig_on         
    44574524        return self.new_gen(matkerint0(self.g, flag)) 
    44584525 
     4526    def matdet(self, long flag=0): 
     4527        """ 
     4528        Return the determinant of this matrix. 
     4529 
     4530        INPUT: 
     4531            flag  -- (optional) flag 
     4532                     0: using Gauss-Bareiss. 
     4533                     1: use classical gaussian elimination (slightly better for integer entries) 
     4534 
     4535        EXAMPLES: 
     4536            sage: pari('[1,2; 3,4]').matdet(0) 
     4537            -2 
     4538            sage: pari('[1,2; 3,4]').matdet(1) 
     4539            -2 
     4540        """ 
     4541        _sig_on         
     4542        return self.new_gen(det0(self.g, flag)) 
     4543 
    44594544    def trace(self): 
     4545        """ 
     4546        Return the trace of this PARI object. 
     4547 
     4548        EXAMPLES: 
     4549            sage: pari('[1,2; 3,4]').trace()   
     4550            5 
     4551        """ 
    44604552        _sig_on         
    44614553        return self.new_gen(gtrace(self.g)) 
     
    44644556        """ 
    44654557        A.mathnf({flag=0}): (upper triangular) Hermite normal form of 
    4466         A, basis for the lattice formed by the columns of A.  flag is 
    4467         optional whose value range from 0 to 4 (0 if omitted), meaning 
    4468         : 0: naive algorithm. 1: Use Batut's algorithm. Output 
    4469         2-component vector [H,U] such that H is the HNF of A, and U is 
    4470         a unimodular matrix such that xU=H. 3: Use Batut's 
    4471         algorithm. Output [H,U,P] where P is a permutation matrix such 
    4472         that P A U = H. 4: as 1, using a heuristic variant of LLL 
    4473         reduction along the way. 
     4558        A, basis for the lattice formed by the columns of A. 
     4559 
     4560        INPUT: 
     4561            flag -- optional, value range from 0 to 4 (0 if 
     4562            omitted), meaning : 
     4563                0: naive algorithm 
     4564                1: Use Batut's algorithm -- output 2-component vector 
     4565                   [H,U] such that H is the  HNF of A, and U is a 
     4566                   unimodular matrix such that xU=H. 
     4567                3: Use Batut's algorithm. Output [H,U,P] where P is 
     4568                   a permutation matrix such that P A U = H. 
     4569                4: As 1, using a heuristic variant of LLL reduction 
     4570                   along the way. 
     4571 
     4572        EXAMPLES: 
     4573            sage: pari('[1,2,3; 4,5,6;  7,8,9]').mathnf() 
     4574            [6, 1; 3, 1; 0, 1] 
    44744575        """ 
    44754576        _sig_on 
     
    44854586        information corresponding to entries equal to 1 in d. 
    44864587 
     4588        EXAMPLES: 
     4589            sage: pari('[1,2,3; 4,5,6;  7,8,9]').matsnf() 
     4590            [0, 3, 1] 
    44874591        """ 
    44884592        _sig_on 
     
    44904594 
    44914595    def matfrobenius(self, flag=0): 
    4492         """ 
     4596        r""" 
    44934597        M.matfrobenius({flag=0}): Return the Frobenius form of the 
    44944598        square matrix M. If flag is 1, return only the elementary 
     
    45104614            sage: v[1]^(-1)*v[0]*v[1] 
    45114615            [1, 2; 3, 4] 
    4512              
    4513             sage: T = ModularSymbols(43,sign=1).T(2).matrix() 
    4514             sage: T 
    4515             [ 3 -2  0  0] 
    4516             [ 0 -2  0  1] 
    4517             [ 0 -1 -2  2] 
    4518             [ 0 -2  0  2] 
    4519             sage: t = pari(T) 
     4616 
     4617        We let t be the matrix of $T_2$ acting on modular symbols of level 43, 
     4618        which was computed using \code{ModularSymbols(43,sign=1).T(2).matrix()}: 
     4619         
     4620            sage: t = pari('[3, -2, 0, 0; 0, -2, 0, 1; 0, -1, -2, 2; 0, -2, 0, 2]') 
    45204621            sage: t.matfrobenius() 
    45214622            [0, 0, 0, -12; 1, 0, 0, -2; 0, 1, 0, 8; 0, 0, 1, 1] 
    4522             sage: T.charpoly() 
     4623            sage: t.charpoly() 
    45234624            x^4 - x^3 - 8*x^2 + 2*x + 12 
    4524             sage: T.charpoly().factor() 
    4525             (x - 3) * (x + 2) * (x^2 - 2) 
    45264625            sage: t.matfrobenius(1) 
    45274626            [x^4 - x^3 - 8*x^2 + 2*x + 12] 
     
    45444643    def factor(gen self, limit=-1): 
    45454644        """ 
    4546         factor(x,{lim}): factorization of x. lim is optional and can 
    4547         be set whenever x is of (possibly recursive) rational 
    4548         type. If lim is set return partial factorization, using 
    4549         primes up to lim (up to primelimit if lim=0) 
     4645        Return the factorization of x. 
     4646 
     4647        lim is optional and can be set whenever x is of (possibly 
     4648        recursive) rational type. If lim is set return partial 
     4649        factorization, using primes up to lim (up to primelimit if 
     4650        lim=0). 
     4651 
     4652        EXAMPLES: 
     4653            sage: pari('x^10-1').factor() 
     4654            [x - 1, 1; x + 1, 1; x^4 - x^3 + x^2 - x + 1, 1; x^4 + x^3 + x^2 + x + 1, 1] 
     4655            sage: pari(2^100-1).factor() 
     4656            [3, 1; 5, 3; 11, 1; 31, 1; 41, 1; 101, 1; 251, 1; 601, 1; 1801, 1; 4051, 1; 8101, 1; 268501, 1] 
     4657 
     4658        PARI doesn't have an algorithm for factoring multivariate polynomials: 
     4659         
     4660            sage: pari('x^3 - y^3').factor() 
     4661            Traceback (most recent call last): 
     4662            ... 
     4663            PariError: sorry, (15) 
    45504664        """ 
    45514665        _sig_on 
    45524666        return P.new_gen(factor0(self.g, limit)) 
    4553  
    4554  
    4555      
    4556  
     4667     
    45574668 
    45584669    ########################################### 
Note: See TracChangeset for help on using the changeset viewer.