# HG changeset patch
# User Peter Bruin <P.Bruin@warwick.ac.uk>
# Date 1385333856 0
# Node ID 9546428dfe045db17d990dd6e6be6b3241776d3a
# Parent 47d71c5b0a4126bbe24905bc8785f4f112a352be
Trac 11868: eliminate the gen.get_nf() method
diff --git a/sage/libs/pari/gen.pyx b/sage/libs/pari/gen.pyx
a
|
b
|
|
710 | 710 | # stored. |
711 | 711 | return self.new_gen(gel(self.g, 1)) |
712 | 712 | |
713 | | def get_nf(self): |
714 | | """ |
715 | | Given a PARI object `self`, convert it to a proper PARI number |
716 | | field (nf) structure. |
| 713 | def nf_get_pol(self): |
| 714 | """ |
| 715 | Returns the defining polynomial of this number field. |
717 | 716 | |
718 | 717 | INPUT: |
719 | 718 | |
720 | 719 | - ``self`` -- A PARI number field being the output of ``nfinit()``, |
721 | 720 | ``bnfinit()`` or ``bnrinit()``. |
722 | 721 | |
723 | | TESTS: |
724 | | |
725 | | We test this indirectly through `nf_get_pol()`:: |
| 722 | EXAMPLES:: |
| 723 | |
| 724 | sage: K.<a> = NumberField(x^4 - 4*x^2 + 1) |
| 725 | sage: pari(K).nf_get_pol() |
| 726 | y^4 - 4*y^2 + 1 |
| 727 | sage: bnr = pari("K = bnfinit(x^4 - 4*x^2 + 1); bnrinit(K, 2*x)") |
| 728 | sage: bnr.nf_get_pol() |
| 729 | x^4 - 4*x^2 + 1 |
| 730 | |
| 731 | For relative extensions, this returns the absolute polynomial, |
| 732 | not the relative one:: |
| 733 | |
| 734 | sage: L.<b> = K.extension(x^2 - 5) |
| 735 | sage: pari(L).nf_get_pol() # Absolute polynomial |
| 736 | y^8 - 28*y^6 + 208*y^4 - 408*y^2 + 36 |
| 737 | sage: L.pari_rnf().nf_get_pol() |
| 738 | x^8 - 28*x^6 + 208*x^4 - 408*x^2 + 36 |
| 739 | |
| 740 | TESTS:: |
726 | 741 | |
727 | 742 | sage: x = polygen(QQ) |
728 | 743 | sage: K.<a> = NumberField(x^4 - 4*x^2 + 1) |
… |
… |
|
730 | 745 | y^4 - 4*y^2 + 1 |
731 | 746 | sage: K.pari_bnf().nf_get_pol() |
732 | 747 | y^4 - 4*y^2 + 1 |
733 | | sage: bnr = pari("K = bnfinit(x^4 - 4*x^2 + 1); bnrinit(K, 2*x)") |
734 | | sage: bnr.nf_get_pol() |
735 | | x^4 - 4*x^2 + 1 |
736 | | |
737 | | It does not work with ``rnfinit()`` or garbage input:: |
738 | | |
739 | | sage: K.extension(x^2 - 5, 'b').pari_rnf().nf_get_pol() |
740 | | Traceback (most recent call last): |
741 | | ... |
742 | | TypeError: Not a PARI number field |
| 748 | |
| 749 | An error is raised for invalid input:: |
| 750 | |
743 | 751 | sage: pari("[0]").nf_get_pol() |
744 | 752 | Traceback (most recent call last): |
745 | 753 | ... |
746 | | TypeError: Not a PARI number field |
747 | | """ |
748 | | cdef GEN nf |
749 | | cdef long nftyp |
750 | | pari_catch_sig_on() |
751 | | nf = get_nf(self.g, &nftyp) |
752 | | if not nf: |
753 | | pari_catch_sig_off() |
754 | | raise TypeError("Not a PARI number field") |
755 | | return P.new_gen(nf) |
756 | | |
757 | | def nf_get_pol(self): |
758 | | """ |
759 | | Returns the defining polynomial of this number field. |
760 | | |
761 | | INPUT: |
762 | | |
763 | | - ``self`` -- A PARI number field being the output of ``nfinit()``, |
764 | | ``bnfinit()`` or ``bnrinit()``. |
765 | | |
766 | | EXAMPLES:: |
767 | | |
768 | | sage: K.<a> = NumberField(x^4 - 4*x^2 + 1) |
769 | | sage: pari(K).nf_get_pol() |
770 | | y^4 - 4*y^2 + 1 |
771 | | sage: bnr = pari("K = bnfinit(x^4 - 4*x^2 + 1); bnrinit(K, 2*x)") |
772 | | sage: bnr.nf_get_pol() |
773 | | x^4 - 4*x^2 + 1 |
774 | | |
775 | | For relative extensions, we can only get the absolute polynomial, |
776 | | not the relative one:: |
777 | | |
778 | | sage: L.<b> = K.extension(x^2 - 5) |
779 | | sage: pari(L).nf_get_pol() # Absolute polynomial |
780 | | y^8 - 28*y^6 + 208*y^4 - 408*y^2 + 36 |
781 | | sage: L.pari_rnf().nf_get_pol() |
782 | | Traceback (most recent call last): |
783 | | ... |
784 | | TypeError: Not a PARI number field |
785 | | """ |
786 | | cdef gen nf = self.get_nf() |
787 | | pari_catch_sig_on() |
788 | | return P.new_gen(nf_get_pol(nf.g)) |
| 754 | PariError: incorrect type in pol |
| 755 | """ |
| 756 | pari_catch_sig_on() |
| 757 | return P.new_gen(member_pol(self.g)) |
789 | 758 | |
790 | 759 | def nf_get_diff(self): |
791 | 760 | """ |
… |
… |
|
802 | 771 | sage: pari(K).nf_get_diff() |
803 | 772 | [12, 0, 0, 0; 0, 12, 8, 0; 0, 0, 4, 0; 0, 0, 0, 4] |
804 | 773 | """ |
805 | | cdef gen nf = self.get_nf() |
806 | | pari_catch_sig_on() |
807 | | # Very bad code, but there doesn't seem to be a better way |
808 | | return P.new_gen(gel(gel(nf.g, 5), 5)) |
| 774 | pari_catch_sig_on() |
| 775 | return P.new_gen(member_diff(self.g)) |
809 | 776 | |
810 | 777 | def nf_get_sign(self): |
811 | 778 | """ |
… |
… |
|
831 | 798 | """ |
832 | 799 | cdef long r1 |
833 | 800 | cdef long r2 |
834 | | cdef gen nf = self.get_nf() |
835 | | nf_get_sign(nf.g, &r1, &r2) |
| 801 | cdef GEN sign |
| 802 | pari_catch_sig_on() |
| 803 | sign = member_sign(self.g) |
| 804 | r1 = itos(gel(sign, 1)) |
| 805 | r2 = itos(gel(sign, 2)) |
| 806 | pari_catch_sig_off() |
836 | 807 | return [r1, r2] |
837 | 808 | |
838 | 809 | def nf_get_zk(self): |
… |
… |
|
851 | 822 | sage: pari(K).nf_get_zk() |
852 | 823 | [1, y, y^3 - 4*y, y^2 - 2] |
853 | 824 | """ |
854 | | cdef gen nf = self.get_nf() |
855 | | pari_catch_sig_on() |
856 | | return P.new_gen(nf_get_zk(nf.g)) |
| 825 | pari_catch_sig_on() |
| 826 | return P.new_gen(member_zk(self.g)) |
857 | 827 | |
858 | 828 | def bnf_get_no(self): |
859 | 829 | """ |
… |
… |
|
8896 | 8866 | [2] |
8897 | 8867 | """ |
8898 | 8868 | pari_catch_sig_on() |
8899 | | cdef gen nf = self.get_nf() |
8900 | 8869 | cdef GEN t0 = P.toGEN(z) |
8901 | | return P.new_gen(gsubst(self.g, nf_get_varn(nf.g), t0)) |
| 8870 | return P.new_gen(gsubst(self.g, gvar(self.g), t0)) |
8902 | 8871 | |
8903 | 8872 | def taylor(self, v=-1): |
8904 | 8873 | pari_catch_sig_on() |