Changeset 6142:ef8b37c63d4d
- Timestamp:
- 09/04/07 21:36:42 (6 years ago)
- Branch:
- default
- Location:
- sage
- Files:
-
- 2 edited
-
modular/modform/ambient.py (modified) (1 diff)
-
rings/number_field/number_field.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/modular/modform/ambient.py
r6088 r6142 452 452 def _q_expansion(self, element, prec): 453 453 """ 454 Return the q-expansion of a particular element of this space of modular forms, 455 where telement should be a vector of list (not a ModularFormElement). 454 Return the q-expansion of a particular element of this space 455 of modular forms, where the element should be a vector of list 456 (not a ModularFormElement). 456 457 457 458 INPUT: -
sage/rings/number_field/number_field.py
r6141 r6142 424 424 425 425 def _repr_(self): 426 """ 427 Return string representation of this number field. 428 429 EXAMPLES: 430 sage: k.<a> = NumberField(x^13 - (2/3)*x + 3) 431 sage: k._repr_() 432 'Number Field in a with defining polynomial x^13 - 2/3*x + 3' 433 """ 426 434 return "Number Field in %s with defining polynomial %s"%( 427 435 self.variable_name(), self.polynomial()) 428 436 429 437 def _latex_(self): 438 """ 439 Return latex representation of this number field. This is viewed 440 as a polynomial quotient ring over a field. 441 442 EXAMPLES: 443 sage: k.<a> = NumberField(x^13 - (2/3)*x + 3) 444 sage: k._latex_() 445 '\\mathbf{Q}[a]/(a^{13} - \\frac{2}{3}a + 3)' 446 sage: latex(k) 447 \mathbf{Q}[a]/(a^{13} - \frac{2}{3}a + 3) 448 449 Numbered variables are often correctly typeset: 450 sage: k.<theta25> = NumberField(x^25+x+1) 451 sage: print k._latex_() 452 \mathbf{Q}[\theta_{25}]/(\theta_{25}^{25} + \theta_{25} + 1) 453 """ 430 454 return "%s[%s]/(%s)"%(latex(QQ), self.latex_variable_name(), 431 455 self.polynomial()._latex_(self.latex_variable_name())) … … 457 481 458 482 def _coerce_from_str(self, x): 483 """ 484 Coerce a string representation of an element of this 485 number field into this number field. 486 487 INPUT: 488 x -- string 489 490 EXAMPLES: 491 sage: k.<theta25> = NumberField(x^3+(2/3)*x+1) 492 sage: k._coerce_from_str('theta25^3 + (1/3)*theta25') 493 -1/3*theta25 - 1 494 495 This function is called by the coerce method when it gets a string 496 as input: 497 sage: k('theta25^3 + (1/3)*theta25') 498 -1/3*theta25 - 1 499 """ 459 500 # provide string coercion, as 460 501 # for finite fields … … 467 508 468 509 def _coerce_from_other_number_field(self, x): 510 """ 511 Coerce a number field element x into this number field. 512 513 In most cases this currently doesn't work (since it is 514 barely implemented) -- it only works for constants. 515 516 INPUT: 517 x -- an element of some number field 518 519 EXAMPLES: 520 sage: K.<a> = NumberField(x^3 + 2) 521 sage: L.<b> = NumberField(x^2 + 1) 522 sage: K._coerce_from_other_number_field(L(2/3)) 523 2/3 524 """ 469 525 f = x.polynomial() 470 526 if f.degree() <= 0: … … 474 530 475 531 def _coerce_non_number_field_element_in(self, x): 532 """ 533 Coerce a non-number field element x into this number field. 534 535 INPUT: 536 x -- a non number field element x, e.g., a list, integer, 537 rational, or polynomial. 538 539 EXAMPLES: 540 sage: K.<a> = NumberField(x^3 + 2/3) 541 sage: K._coerce_non_number_field_element_in(-7/8) 542 -7/8 543 sage: K._coerce_non_number_field_element_in([1,2,3]) 544 3*a^2 + 2*a + 1 545 546 The list is just turned into a polynomial in the generator. 547 sage: K._coerce_non_number_field_element_in([0,0,0,1,1]) 548 -2/3*a - 2/3 549 550 Not any polynomial coerces in, e.g., not this one in characteristic 7. 551 sage: f = GF(7)['y']([1,2,3]); f 552 3*y^2 + 2*y + 1 553 sage: K._coerce_non_number_field_element_in(f) 554 Traceback (most recent call last): 555 ... 556 TypeError 557 """ 476 558 if isinstance(x, (int, long, rational.Rational, 477 559 integer.Integer, pari_gen, 478 polynomial_element.Polynomial,479 560 list)): 480 561 return number_field_element.NumberFieldElement(self, x) 562 if isinstance(x, polynomial_element.Polynomial) and x.parent().base_ring() is QQ: 563 return number_field_element.NumberFieldElement(self, x) 564 481 565 try: 482 566 return number_field_element.NumberFieldElement(self, x._rational_()) 483 567 except (TypeError, AttributeError): 484 568 pass 485 raise TypeError , "Cannot coerce %s into %s"%(x,self)569 raise TypeError 486 570 487 571 def _coerce_impl(self, x): 572 """ 573 Canonical coercion of x into self. 574 575 Currently integers, rationals, and this field itself coerce 576 canonical into this field. 577 578 EXAMPLES: 579 sage: S.<y> = NumberField(x^3 + x + 1) 580 sage: S._coerce_impl(int(4)) 581 4 582 sage: S._coerce_impl(long(7)) 583 7 584 sage: S._coerce_impl(-Integer(2)) 585 -2 586 sage: z = S._coerce_impl(-7/8); z, type(z) 587 (-7/8, <type 'sage.rings.number_field.number_field_element.NumberFieldElement'>) 588 sage: S._coerce_impl(y) is y 589 True 590 591 There are situations for which one might imagine canonical 592 coercion could make sense (at least after fixing choices), but 593 which aren't yet implemented: 594 sage: K.<a> = QuadraticField(2) 595 sage: K._coerce_impl(sqrt(2)) 596 Traceback (most recent call last): 597 ... 598 TypeError 599 """ 488 600 if isinstance(x, (rational.Rational, integer.Integer, int, long)): 489 601 return number_field_element.NumberFieldElement(self, x) 490 elif isinstance(x, number_field_element.NumberFieldElement) and x.parent() == self: 491 return number_field_element.NumberFieldElement(self, x.list()) 602 elif isinstance(x, number_field_element.NumberFieldElement): 603 if x.parent() is self: 604 return x 605 elif x.parent() == self: 606 return number_field_element.NumberFieldElement(self, x.list()) 492 607 raise TypeError 493 608 494 609 def category(self): 610 """ 611 Return the category of number fields. 612 613 EXAMPLES: 614 sage: NumberField(x^2 + 3, 'a').category() 615 Category of number fields 616 sage: category(NumberField(x^2 + 3, 'a')) 617 Category of number fields 618 619 The special types of number fields, e.g., quadratic fields, 620 don't have their own category: 621 sage: QuadraticField(2,'d').category() 622 Category of number fields 623 """ 495 624 from sage.categories.all import NumberFields 496 625 return NumberFields() 497 626 498 627 def __cmp__(self, other): 628 """ 629 Compare a number field with something else. 630 631 INPUT: 632 other -- arbitrary Python object. 633 634 If other is not a number field, then the types 635 of self and other are compared. 636 637 638 """ 499 639 if not isinstance(other, NumberField_generic): 500 return -1501 if self.variable_name() != other.variable_name():502 return -1503 return self.__polynomial.__cmp__(other.__polynomial)640 return cmp(type(self), type(other)) 641 c = cmp(self.variable_name(), other.variable_name()) 642 if c: return c 643 return cmp(self.__polynomial, other.__polynomial) 504 644 505 645 def _ideal_class_(self):
Note: See TracChangeset
for help on using the changeset viewer.
