- Timestamp:
- Jan 22, 1998, 11:54:34 AM (26 years ago)
- Branches:
- (u'spielwiese', 'e7cc1ebecb61be8b9ca6c18016352af89940b21a')
- Children:
- 77aa420ec44c556ecabc45845e40ff2c9a3bddca
- Parents:
- a0093a78296be293e083a8876f3aaaf0ce67c08c
- Location:
- factory
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/int_cf.cc
ra0093a7 r05d0b3 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: int_cf.cc,v 1. 9 1997-12-17 11:30:06schmidt Exp $ */2 /* $Id: int_cf.cc,v 1.10 1998-01-22 10:54:00 schmidt Exp $ */ 3 3 4 4 #include <config.h> … … 109 109 //}}} 110 110 111 //{{{ InternalCF * InternalCF::bgcdsame, bgcdcoeff ( const InternalCF * const ) 112 // docu: see CanonicalForm::bgcd() 113 InternalCF * 114 InternalCF::bgcdsame ( const InternalCF * const ) const 115 { 116 ASSERT1( 0, "bgcd() not implemented for class %s", this->classname() ); 117 return CFFactory::basic( 0 ); 118 } 119 120 InternalCF * 121 InternalCF::bgcdcoeff ( const InternalCF * const ) 122 { 123 ASSERT1( 0, "bgcd() not implemented for class %s", this->classname() ); 124 return CFFactory::basic( 0 ); 125 } 126 //}}} 127 128 //{{{ InternalCF * InternalCF::bextgcdsame ( InternalCF *, CanonicalForm & a, CanonicalForm & b ) 129 // docu: see CanonicalForm::bextgcd() 130 InternalCF * 131 InternalCF::bextgcdsame ( InternalCF *, CanonicalForm & a, CanonicalForm & b ) 132 { 133 ASSERT1( 0, "bextgcd() not implemented for class %s", this->classname() ); 134 a = 0; b = 0; 135 return CFFactory::basic( 0 ); 136 } 137 138 InternalCF * 139 InternalCF::bextgcdcoeff ( InternalCF *, CanonicalForm & a, CanonicalForm & b ) 140 { 141 ASSERT1( 0, "bextgcd() not implemented for class %s", this->classname() ); 142 a = 0; b = 0; 143 return CFFactory::basic( 0 ); 144 } 145 //}}} 146 111 147 int 112 148 InternalCF::intval() const -
factory/int_cf.h
ra0093a7 r05d0b3 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: int_cf.h,v 1. 8 1997-12-17 14:10:13schmidt Exp $ */2 /* $Id: int_cf.h,v 1.9 1998-01-22 10:54:07 schmidt Exp $ */ 3 3 4 4 #ifndef INCL_INT_CF_H … … 61 61 62 62 virtual InternalCF* neg() PVIRT_INTCF("neg"); 63 virtual InternalCF* invert(); // semantically const, changes refCount const63 virtual InternalCF* invert(); // semantically const, changes refCount 64 64 virtual int comparesame ( InternalCF * ) PVIRT_INT("comparesame"); 65 65 virtual int comparecoeff ( InternalCF * ) PVIRT_INT("comparecoeff"); … … 85 85 virtual bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool ) PVIRT_BOOL("divremcoefft"); 86 86 87 virtual InternalCF * bgcdsame ( const InternalCF * const ) const; 88 virtual InternalCF * bgcdcoeff ( const InternalCF * const ); // semantically const, changes refcount 89 90 virtual InternalCF * bextgcdsame ( InternalCF *, CanonicalForm &, CanonicalForm & ); // semantically const, changes refcount 91 virtual InternalCF * bextgcdcoeff ( InternalCF *, CanonicalForm &, CanonicalForm & ); // semantically const, changes refcount 92 87 93 virtual InternalCF* sqrt(); 88 94 virtual int ilog2(); -
factory/int_int.cc
ra0093a7 r05d0b3 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: int_int.cc,v 1.1 0 1997-12-17 11:47:48schmidt Exp $ */2 /* $Id: int_int.cc,v 1.11 1998-01-22 10:54:15 schmidt Exp $ */ 3 3 4 4 #include <config.h> … … 754 754 } 755 755 756 //{{{ InternalCF * InternalInteger::bgcdsame, bgcdcoeff ( const InternalCF * const c ) 757 // docu: see CanonicalForm::bgcd() 758 InternalCF * 759 InternalInteger::bgcdsame ( const InternalCF * const c ) const 760 { 761 ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain, "incompatible base coefficients" ); 762 763 // simply return 1 if we are calculating over the rationals 764 if ( cf_glob_switches.isOn( SW_RATIONAL ) ) 765 return int2imm( 1 ); 766 767 // calculate gcd 768 MP_INT result; 769 mpz_init( &result ); 770 mpz_gcd( &result, &thempi, &MPI( c ) ); 771 mpz_abs( &result, &result ); 772 773 // check for immediate result 774 if ( mpz_is_imm( &result ) ) { 775 InternalCF * res = int2imm( mpz_get_si( &result ) ); 776 mpz_clear( &result ); 777 return res; 778 } 779 else 780 return new InternalInteger( result ); 781 } 782 783 InternalCF * 784 InternalInteger::bgcdcoeff ( const InternalCF * const c ) 785 { 786 ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" ); 787 788 // simply return 1 if we are calculating over the rationals 789 if ( cf_glob_switches.isOn( SW_RATIONAL ) ) 790 return int2imm( 1 ); 791 792 int cInt = imm2int( c ); 793 794 // trivial cases 795 if ( cInt == 1 || cInt == -1 ) 796 return int2imm( 1 ); 797 else if ( cInt == 0 ) 798 return copyObject(); 799 800 // calculate gcd. We need a positive operand since 801 // `mpz_gcd_ui()' operates an unsigned int's only. 802 if ( cInt < 0 ) cInt = -cInt; 803 MP_INT dummy; 804 mpz_init( &dummy ); 805 // we do not need dummy since we know that cInt != 0 806 cInt = mpz_gcd_ui( &dummy, &thempi, cInt ); 807 mpz_clear( &dummy ); 808 if ( cInt < 0 ) cInt = -cInt; 809 return int2imm( cInt ); 810 } 811 //}}} 812 813 //{{{ InternalCF * InternalInteger::bextgcdsame( InternalCF * c, CanonicalForm & a, CanonicalForm & b ) 814 InternalCF * 815 InternalInteger::bextgcdsame( InternalCF * c, CanonicalForm & a, CanonicalForm & b ) 816 { 817 ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain, "incompatible base coefficients" ); 818 819 // simply return 1 if we are calculating over the rationals 820 if ( cf_glob_switches.isOn( SW_RATIONAL ) ) { 821 a = 1/CanonicalForm( copyObject() ); b = 0; 822 return int2imm( 1 ); 823 } 824 825 // calculate extended gcd 826 MP_INT result; 827 MP_INT aMPI; 828 MP_INT bMPI; 829 mpz_init( &result ); 830 mpz_init( &aMPI ); 831 mpz_init( &bMPI ); 832 mpz_gcdext( &result, &aMPI, &bMPI, &thempi, &MPI( c ) ); 833 834 // check and modify signs 835 if ( mpz_sgn( &result ) < 0 ) { 836 mpz_neg( &result, &result ); 837 mpz_neg( &aMPI, &aMPI ); 838 mpz_neg( &bMPI, &bMPI ); 839 } 840 841 // postconditioning of result 842 if ( mpz_is_imm( &aMPI ) ) { 843 a = CanonicalForm( int2imm( mpz_get_si( &aMPI ) ) ); 844 mpz_clear( &aMPI ); 845 } else 846 a = CanonicalForm( new InternalInteger( aMPI ) ); 847 if ( mpz_is_imm( &bMPI ) ) { 848 b = CanonicalForm( int2imm( mpz_get_si( &bMPI ) ) ); 849 mpz_clear( &bMPI ); 850 } else 851 b = CanonicalForm( new InternalInteger( bMPI ) ); 852 if ( mpz_is_imm( &result ) ) { 853 InternalCF * res = int2imm( mpz_get_si( &result ) ); 854 mpz_clear( &result ); 855 return res; 856 } 857 else 858 return new InternalInteger( result ); 859 } 860 861 InternalCF * 862 InternalInteger::bextgcdcoeff( InternalCF * c, CanonicalForm & a, CanonicalForm & b ) 863 { 864 ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" ); 865 866 // simply return 1 if we are calculating over the rationals 867 if ( cf_glob_switches.isOn( SW_RATIONAL ) ) { 868 a = 1/CanonicalForm( copyObject() ); b = 0; 869 return int2imm( 1 ); 870 } 871 872 int cInt = imm2int( c ); 873 874 // trivial cases 875 if ( cInt == 1 || cInt == -1 ) { 876 a = 0; b = cInt; 877 return int2imm( 1 ); 878 } else if ( cInt == 0 ) { 879 a = 1; b = 0; 880 return copyObject(); 881 } 882 883 // calculate q and r such that CO = q*cInt + r 884 InternalCF * q = 0, * r = 0; 885 divremcoeff( c, q, r, false ); 886 887 // we do not repeat all the code to calculate the gcd of two 888 // immediates. Note that r is an immediate since c != 0, so 889 // we do not have to destroy it. q is destroyed by the 890 // CanonicalForm destructor, hence we do not need to worry 891 // about it, either. 892 CanonicalForm aPrime, bPrime; 893 CanonicalForm result = bextgcd( c, r, aPrime, bPrime ); 894 a = bPrime; 895 b = aPrime - CanonicalForm( q ) * bPrime; 896 897 return result.getval(); 898 } 899 //}}} 900 756 901 int InternalInteger::intval() const 757 902 { -
factory/int_int.h
ra0093a7 r05d0b3 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: int_int.h,v 1. 6 1997-07-16 10:34:17schmidt Exp $ */2 /* $Id: int_int.h,v 1.7 1998-01-22 10:54:22 schmidt Exp $ */ 3 3 4 4 #ifndef INCL_INT_INT_H … … 71 71 bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool ); 72 72 73 InternalCF * bgcdsame ( const InternalCF * const ) const; 74 InternalCF * bgcdcoeff ( const InternalCF * const ); 75 76 InternalCF * bextgcdsame ( InternalCF *, CanonicalForm &, CanonicalForm & ); 77 InternalCF * bextgcdcoeff ( InternalCF *, CanonicalForm &, CanonicalForm & ); 78 73 79 int intval() const; 74 80 -
factory/int_rat.cc
ra0093a7 r05d0b3 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: int_rat.cc,v 1. 9 1997-12-17 11:39:32schmidt Exp $ */2 /* $Id: int_rat.cc,v 1.10 1998-01-22 10:54:28 schmidt Exp $ */ 3 3 4 4 #include <config.h> … … 707 707 } 708 708 709 //{{{ InternalCF * InternalRational::bgcdsame, bgcdcoeff ( const InternalCF * const ) 710 // docu: see CanonicalForm::bgcd() 711 InternalCF * 712 InternalRational::bgcdsame ( const InternalCF * const ) const 713 { 714 return int2imm( 1 ); 715 } 716 717 InternalCF * 718 InternalRational::bgcdcoeff ( const InternalCF * const ) 719 { 720 return int2imm( 1 ); 721 } 722 //}}} 723 724 //{{{ InternalCF * InternalRational::bextgcdsame ( InternalCF * c, CanonicalForm & a, CanonicalForm & b ) 725 // docu: see CanonicalForm::bextgcd() 726 InternalCF * 727 InternalRational::bextgcdsame ( InternalCF *, CanonicalForm & a, CanonicalForm & b ) 728 { 729 a = 1/CanonicalForm( copyObject() ); b = 0; 730 return int2imm( 1 ); 731 } 732 733 InternalCF * 734 InternalRational::bextgcdcoeff ( InternalCF *, CanonicalForm & a, CanonicalForm & b ) 735 { 736 a = 1/CanonicalForm( copyObject() ); b = 0; 737 return int2imm( 1 ); 738 } 739 //}}} 740 709 741 InternalCF * InternalRational::normalize_myself() 710 742 { -
factory/int_rat.h
ra0093a7 r05d0b3 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: int_rat.h,v 1. 4 1997-06-19 12:22:22schmidt Exp $ */2 /* $Id: int_rat.h,v 1.5 1998-01-22 10:54:34 schmidt Exp $ */ 3 3 4 4 #ifndef INCL_INT_RAT_H … … 15 15 #include "assert.h" 16 16 17 #include "canonicalform.h" 17 18 #include "int_cf.h" 18 19 #include "imm.h" 19 20 20 21 class InternalRational : public InternalCF … … 81 82 bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool ); 82 83 84 InternalCF * bgcdsame ( const InternalCF * const ) const; 85 InternalCF * bgcdcoeff ( const InternalCF * const ); 86 87 InternalCF * bextgcdsame ( InternalCF *, CanonicalForm &, CanonicalForm & ); 88 InternalCF * bextgcdcoeff ( InternalCF *, CanonicalForm &, CanonicalForm & ); 89 83 90 int intval() const; 84 91
Note: See TracChangeset
for help on using the changeset viewer.