Changeset 0b6efd in git
 Timestamp:
 Mar 6, 2014, 3:17:14 PM (10 years ago)
 Branches:
 (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
 Children:
 d221a2f14103ce45b583cfa80f40efc541b8a20c
 Parents:
 d9184bd7e71c6771eb56c5b567760e3723664237
 gitauthor:
 Martin Lee <martinlee84@web.de>20140306 15:17:14+01:00
 gitcommitter:
 Hans Schoenemann <hannes@mathematik.unikl.de>20140317 18:31:53+01:00
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

factory/libfac/charset/csutil.cc
rd9184bd r0b6efd 12 12 // Charset  Includes 13 13 #include "csutil.h" 14 extern void out_cf(c har *s1,const CanonicalForm &f,char *s2);14 extern void out_cf(const char *s1,const CanonicalForm &f,const char *s2); 15 15 extern CanonicalForm alg_lc(const CanonicalForm &f); 16 16 extern int hasAlgVar(const CanonicalForm &f); … … 794 794 #endif 795 795 796 CanonicalForm 797 alg_content (const CanonicalForm& f, const CFList& as) 798 { 799 if (!f.inCoeffDomain()) 800 { 801 CFIterator i= f; 802 CanonicalForm result= abs (i.coeff()); 803 i++; 804 while (i.hasTerms() && !result.isOne()) 805 { 806 result= alg_gcd (i.coeff(), result, as); 807 i++; 808 } 809 return result; 810 } 811 812 return abs (f); 813 } 814 796 815 CanonicalForm alg_gcd(const CanonicalForm & fff, const CanonicalForm &ggg, 797 816 const CFList &as) 798 817 { 818 if (fff.inCoeffDomain()  ggg.inCoeffDomain()) 819 return 1; 820 bool isRat= isOn (SW_RATIONAL); 799 821 CanonicalForm f=fff; 800 822 CanonicalForm g=ggg; … … 811 833 else return f; 812 834 } 813 //out_cf("alg_gcd(",fff," , "); 814 //out_cf("",ggg,")\n"); 835 //out_cf("alg_gcd fff(",fff," \n "); 836 //out_cf("ggg",ggg,")\n"); 837 int v= as.getLast().level(); 838 if (f.level() <= v  g.level() <= v) 839 return 1; 840 815 841 CanonicalForm res; 816 842 // does as appear in f and g ? … … 858 884 859 885 // gcd of all coefficients: 860 CFIterator i=f; 861 CanonicalForm c_gcd=i.coeff(); i++; 862 while( i.hasTerms()) 863 { 864 c_gcd=alg_gcd(i.coeff(),c_gcd,as); 865 if (c_gcd.inBaseDomain()) break; 866 i++; 867 } 886 CanonicalForm c_f= alg_content (f, as); 887 868 888 //printf("f.mvar=%d (%d), g.mvar=%d (%d)\n",f.level(),mvf,g.level(),mvg); 869 if (mvf!=mvg) // => mvf > mvg 870 { 871 res=alg_gcd(g,c_gcd,as); 872 //out_cf("alg_gcd1=",res,"\n"); 873 //out_cf("of f=",fff," , "); 874 //out_cf("and g=",ggg,"\n"); 889 if (mvf != mvg) // => mvf > mvg 890 { 891 res= alg_gcd (g, c_f, as); 875 892 return res; 876 893 } 894 Variable x= f.mvar(); 877 895 // now: mvf==mvg, f.level()==g.level() 878 if (!c_gcd.inBaseDomain()) 879 { 880 i=g; 881 while( i.hasTerms()) 882 { 883 c_gcd=alg_gcd(i.coeff(),c_gcd,as); 884 if (c_gcd.inBaseDomain()) break; 885 i++; 886 } 887 } 896 // content of g 897 CanonicalForm c_g= alg_content (g, as); 898 899 int delta= degree (f)  degree (g); 888 900 889 901 //f/=c_gcd; 890 902 //g/=c_gcd; 891 if (!c_gcd.isOne()) 892 { 893 f=divide(f,c_gcd,as); 894 g=divide(g,c_gcd,as); 895 } 896 897 CFList gg; 903 f= divide (f, c_f, as); 904 g= divide (g, c_g, as); 905 906 // gcd of contents 907 CanonicalForm c_gcd= alg_gcd (c_f, c_g, as); 908 CanonicalForm tmp; 909 910 if (delta < 0) 911 { 912 tmp= f; 913 f= g; 914 g= tmp; 915 delta= delta; 916 } 917 898 918 CanonicalForm r=1; 899 while (1) 900 { 901 //printf("f.mvar=%d, g.mvar=%d\n",f.level(),g.level()); 902 gg=as; 903 if (!g.inCoeffDomain()) gg.append(g); 904 //out_cf("Prem(",f," , "); 905 //out_cf("",g,")\n"); 906 if (g.inCoeffDomain() g.isZero()) 907 { 908 //printf("in coeff domain:"); 909 if (g.isZero()) { //printf("0\n"); 910 i=f; 911 CanonicalForm f_gcd=i.coeff(); i++; 912 while( i.hasTerms()) 913 { 914 f_gcd=alg_gcd(i.coeff(),f_gcd,as); 915 if (f_gcd.inBaseDomain()) break; 916 i++; 917 } 918 //out_cf("g=0 > f:",f,"\n"); 919 //out_cf("f_gcd:",f_gcd,"\n"); 920 //out_cf("c_gcd:",c_gcd,"\n"); 921 //f/=f_gcd; 922 f=divide(f,f_gcd,as); 923 //out_cf("f/f_gcd:",f,"\n"); 924 f*=c_gcd; 925 //out_cf("f*c_gcd:",f,"\n"); 926 CanonicalForm r_lc=alg_lc(f); 927 //out_cf("r_lc:",r_lc,"\n"); 928 //f/=r_lc; 929 f=divide(f,r_lc,as); 930 //out_cf(" > gcd:",f,"\n"); 931 return f; 932 } 933 else { //printf("c\n"); 934 return c_gcd;} 935 } 936 else if (g.level()==f.level()) r=Prem(f,gg,as); 937 else 938 { 939 //printf("diff. level: %d, %d\n", f.level(), g.level()); 940 // g and f have different levels 941 //out_cf("c_gcd=",c_gcd,"\n"); 942 //out_cf("of f=",fff," , "); 943 //out_cf("and g=",ggg,"\n"); 944 return c_gcd; 945 } 946 //out_cf(">",r,"\n"); 947 f=g; 948 g=r; 949 } 950 if (degree(f,Variable(mvg))==0) 951 { 952 // remark: mvf == mvg == f.level() ==g.level() 953 //out_cf("c_gcd=",c_gcd,"\n"); 954 //out_cf("of f=",fff," , "); 955 //out_cf("and g=",ggg,"\n"); 919 920 while (degree (g, x) > 0) 921 { 922 r= Prem (f, g, as); 923 r= Prem (r, as); 924 if (!r.isZero()) 925 { 926 r= divide (r, alg_content (r,as), as); 927 r /= vcontent (r,Variable (v+1)); 928 } 929 f= g; 930 g= r; 931 } 932 933 if (degree (g, x) == 0) 956 934 return c_gcd; 957 } 958 //out_cf("f=",f,"\n"); 959 i=f; 960 CanonicalForm k=i.coeff(); i++; 961 //out_cf("k=",k,"\n"); 962 while( i.hasTerms()) 963 { 964 if (k.inCoeffDomain()) break; 965 k=alg_gcd(i.coeff(),k,as); 966 //out_cf("k=",k,"\n"); 967 i++; 968 } 969 //out_cf("endk=",k,"\n"); 970 f/=k; 971 //out_cf("f/k=",f,"\n"); 972 res=c_gcd*f; 973 CanonicalForm r_lc=alg_lc(res); 974 res/=r_lc; 975 //CanonicalForm r_lc=alg_lc(res,as); 976 //res/=r_lc; 977 //out_cf("alg_gcd2=",res,"\n"); 978 // out_cf("of f=",fff," , "); 979 // out_cf("and g=",ggg,"\n"); 980 //return res; 981 //if (res.level()<fff.level() && res.level() < ggg.level()) 982 // return alg_gcd(alg_gcd(fff,res,as),ggg,as); 983 //else 984 return res; 985 } 935 936 c_f= alg_content (f, as); 937 938 f= divide (f, c_f, as); 939 940 f *= c_gcd; 941 f /= vcontent (f, Variable (v+1)); 942 943 return f; 944 } 945
Note: See TracChangeset
for help on using the changeset viewer.