Changeset 1652:6ce9f84cb399
- Timestamp:
- 10/25/06 23:38:20 (7 years ago)
- 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. - Files:
-
- 2 edited
-
sage/libs/pari/gen.pyx (modified) (12 diffs)
-
sage/libs/pari/gen.pyx (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/libs/pari/gen.pyx
r1453 r1652 714 714 [1, 2, 3, 10, 102, 10] 715 715 sage: type(w[0]) 716 <type ' gen.gen'>716 <type 'sage.libs.pari.gen.gen'> 717 717 """ 718 718 if typ(self.g) != t_VEC: … … 4329 4329 If f(t) is a series in t with valuation 1, find the 4330 4330 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) 4331 4341 """ 4332 4342 _sig_on … … 4368 4378 4369 4379 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 """ 4370 4387 cdef long n 4371 4388 _sig_on … … 4375 4392 4376 4393 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 """ 4377 4401 cdef long n 4378 4402 _sig_on … … 4383 4407 def mattranspose(self): 4384 4408 """ 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] 4385 4414 """ 4386 4415 _sig_on 4387 4416 return self.new_gen(gtrans(self.g)).Mat() 4388 4417 4389 def transpose(self):4390 return self.mattranspose()4391 4392 4418 def matadjoint(self): 4393 4419 """ 4394 4420 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] 4395 4427 """ 4396 4428 _sig_on 4397 4429 return self.new_gen(adj(self.g)).Mat() 4398 4399 def adjoint(self):4400 return self.matadjoint()4401 4430 4402 4431 def qflllgram(self, long flag=0): … … 4447 4476 def matker(self, long flag=0): 4448 4477 """ 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] 4449 4497 """ 4450 4498 _sig_on … … 4453 4501 def matkerint(self, long flag=0): 4454 4502 """ 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) 4455 4522 """ 4456 4523 _sig_on 4457 4524 return self.new_gen(matkerint0(self.g, flag)) 4458 4525 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 4459 4544 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 """ 4460 4552 _sig_on 4461 4553 return self.new_gen(gtrace(self.g)) … … 4464 4556 """ 4465 4557 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] 4474 4575 """ 4475 4576 _sig_on … … 4485 4586 information corresponding to entries equal to 1 in d. 4486 4587 4588 EXAMPLES: 4589 sage: pari('[1,2,3; 4,5,6; 7,8,9]').matsnf() 4590 [0, 3, 1] 4487 4591 """ 4488 4592 _sig_on … … 4490 4594 4491 4595 def matfrobenius(self, flag=0): 4492 """4596 r""" 4493 4597 M.matfrobenius({flag=0}): Return the Frobenius form of the 4494 4598 square matrix M. If flag is 1, return only the elementary … … 4510 4614 sage: v[1]^(-1)*v[0]*v[1] 4511 4615 [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]') 4520 4621 sage: t.matfrobenius() 4521 4622 [0, 0, 0, -12; 1, 0, 0, -2; 0, 1, 0, 8; 0, 0, 1, 1] 4522 sage: T.charpoly()4623 sage: t.charpoly() 4523 4624 x^4 - x^3 - 8*x^2 + 2*x + 12 4524 sage: T.charpoly().factor()4525 (x - 3) * (x + 2) * (x^2 - 2)4526 4625 sage: t.matfrobenius(1) 4527 4626 [x^4 - x^3 - 8*x^2 + 2*x + 12] … … 4544 4643 def factor(gen self, limit=-1): 4545 4644 """ 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) 4550 4664 """ 4551 4665 _sig_on 4552 4666 return P.new_gen(factor0(self.g, limit)) 4553 4554 4555 4556 4667 4557 4668 4558 4669 ########################################### -
sage/libs/pari/gen.pyx
r1453 r1652 714 714 [1, 2, 3, 10, 102, 10] 715 715 sage: type(w[0]) 716 <type ' gen.gen'>716 <type 'sage.libs.pari.gen.gen'> 717 717 """ 718 718 if typ(self.g) != t_VEC: … … 4329 4329 If f(t) is a series in t with valuation 1, find the 4330 4330 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) 4331 4341 """ 4332 4342 _sig_on … … 4368 4378 4369 4379 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 """ 4370 4387 cdef long n 4371 4388 _sig_on … … 4375 4392 4376 4393 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 """ 4377 4401 cdef long n 4378 4402 _sig_on … … 4383 4407 def mattranspose(self): 4384 4408 """ 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] 4385 4414 """ 4386 4415 _sig_on 4387 4416 return self.new_gen(gtrans(self.g)).Mat() 4388 4417 4389 def transpose(self):4390 return self.mattranspose()4391 4392 4418 def matadjoint(self): 4393 4419 """ 4394 4420 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] 4395 4427 """ 4396 4428 _sig_on 4397 4429 return self.new_gen(adj(self.g)).Mat() 4398 4399 def adjoint(self):4400 return self.matadjoint()4401 4430 4402 4431 def qflllgram(self, long flag=0): … … 4447 4476 def matker(self, long flag=0): 4448 4477 """ 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] 4449 4497 """ 4450 4498 _sig_on … … 4453 4501 def matkerint(self, long flag=0): 4454 4502 """ 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) 4455 4522 """ 4456 4523 _sig_on 4457 4524 return self.new_gen(matkerint0(self.g, flag)) 4458 4525 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 4459 4544 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 """ 4460 4552 _sig_on 4461 4553 return self.new_gen(gtrace(self.g)) … … 4464 4556 """ 4465 4557 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] 4474 4575 """ 4475 4576 _sig_on … … 4485 4586 information corresponding to entries equal to 1 in d. 4486 4587 4588 EXAMPLES: 4589 sage: pari('[1,2,3; 4,5,6; 7,8,9]').matsnf() 4590 [0, 3, 1] 4487 4591 """ 4488 4592 _sig_on … … 4490 4594 4491 4595 def matfrobenius(self, flag=0): 4492 """4596 r""" 4493 4597 M.matfrobenius({flag=0}): Return the Frobenius form of the 4494 4598 square matrix M. If flag is 1, return only the elementary … … 4510 4614 sage: v[1]^(-1)*v[0]*v[1] 4511 4615 [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]') 4520 4621 sage: t.matfrobenius() 4521 4622 [0, 0, 0, -12; 1, 0, 0, -2; 0, 1, 0, 8; 0, 0, 1, 1] 4522 sage: T.charpoly()4623 sage: t.charpoly() 4523 4624 x^4 - x^3 - 8*x^2 + 2*x + 12 4524 sage: T.charpoly().factor()4525 (x - 3) * (x + 2) * (x^2 - 2)4526 4625 sage: t.matfrobenius(1) 4527 4626 [x^4 - x^3 - 8*x^2 + 2*x + 12] … … 4544 4643 def factor(gen self, limit=-1): 4545 4644 """ 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) 4550 4664 """ 4551 4665 _sig_on 4552 4666 return P.new_gen(factor0(self.g, limit)) 4553 4554 4555 4556 4667 4557 4668 4558 4669 ###########################################
Note: See TracChangeset
for help on using the changeset viewer.
