20 mpz_init_set_ui(coef[0],0);
31 for (
int i=0;
i<=n;
i++)
33 mpz_mod_ui(a[
i],a[i],
mod);
34 mpz_init_set(coef[i], a[i]);
58 mpz_mod_ui(coef[
i],f.
coef[i],p);
63 while(mpz_sgn(coef[k])==0 && k>=0)
82 for (
int i=0;
i<=b.
deg;
i++)
89 mpz_init_set(coef[
i],a.
coef[i]);
94 while(mpz_divisible_ui_p(coef[k],
mod)!=0 && k>=0)
100 else {p_poly_add(b,a); }
108 this->p_poly_add(*
this,g);
114 if (f.
is_zero()==1 && mpz_divisible_ui_p(a,f.
mod)==0)
117 else if (mpz_divisible_ui_p(a,f.
mod)==0)
120 mpz_add(coef[0],coef[0],a);
135 this->p_poly_add_const(*
this,a);
142 if (i<=deg && is_zero()==0)
144 mpz_add(coef[i],coef[i],a);
146 else if (is_zero()==1 && mpz_divisible_ui_p(a,f.
mod)==0)
149 for(
int j=0;
j<=
i;
j++)
151 mpz_init_set_ui(coef[
j],0);
154 mpz_init_set_ui(temp,0);
155 mpz_mod_ui(temp,a,
mod);
156 mpz_add(coef[i],coef[i],temp);
159 else if(i>deg && mpz_divisible_ui_p(a,f.
mod)==0)
162 for(
int j=i;
j>deg;
j--)
164 mpz_init_set_ui(coef[
j],0);
167 mpz_init_set_ui(temp,0);
168 mpz_mod_ui(temp,a,
mod);
169 mpz_add(coef[i],coef[i],temp);
184 if (i<=deg && is_zero()==0)
186 mpz_add(coef[i],coef[i],a);
188 else if (is_zero()==1 && mpz_divisible_ui_p(a,
mod)==0)
191 for(
int j=0;
j<=
i;
j++)
193 mpz_init_set_ui(coef[
j],0);
196 mpz_init_set_ui(temp,0);
197 mpz_mod_ui(temp,a,
mod);
198 mpz_add(coef[i],coef[i],temp);
201 else if(i>deg && mpz_divisible_ui_p(a,
mod)==0)
204 for(
int j=i;
j>deg;
j--)
206 mpz_init_set_ui(coef[
j],0);
209 mpz_init_set_ui(temp,0);
210 mpz_mod_ui(temp,a,
mod);
211 mpz_add(coef[i],coef[i],temp);
230 for (
int i=0;
i<=b.
deg;
i++)
237 mpz_init_set(coef[
i],a.
coef[i]);
242 while(mpz_divisible_ui_p(coef[k],
mod)!=0 && k>=0)
247 else {p_poly_sub(b,a);p_poly_neg(); }
256 this->p_poly_sub(*
this,b);
270 mpz_sub(coef[0],coef[0],a);
284 this->p_poly_sub_const(*
this,a);
293 p_poly_add_mon(f,temp,i);
301 p_poly_add_mon_to(temp,i);
316 for (
int i=deg;
i>=n;
i--)
318 mpz_init_set(coef[
i],f.
coef[i-n]);
320 for (
int i=n-1;
i>=0;
i--)
322 mpz_init_set_ui(coef[
i],0);
334 this->p_poly_mon_mult(*
this,n);
342 if (mpz_divisible_ui_p(n,g.
mod)!=0)
350 mpz_init_set_ui(temp,0);
351 for(
int i=0;
i<=deg;
i++)
353 mpz_mul(temp,n,g.
coef[
i]);
354 mpz_init_set(coef[
i],temp);
363 if (mpz_divisible_ui_p(n,g.
mod)!=0)
372 mpz_init_set_ui(temp,0);
373 for(
int i=0;
i<=deg;
i++)
375 mpz_mul(temp,n,g.
coef[
i]);
376 mpz_init_set(coef[
i],temp);
388 this->p_poly_scalar_mult(*
this,n);
397 for (
int i=0;
i<=deg;
i++)
399 mpz_neg(coef[
i],coef[i]);
415 mpz_init_set_ui(temp,0);
422 for(
int i=a.
deg+1;
i<=deg;
i++)
424 mpz_init_set_ui(atemp.
coef[
i],0);
426 for(
int i=b.
deg+1;
i<=deg;
i++)
428 mpz_init_set_ui(btemp.
coef[
i],0);
434 for (
int k=0;
k<=deg;
k++)
436 mpz_init_set_ui(coef[
k],0);
437 for (
int i=0;
i<=
k;
i++)
440 mpz_add(coef[k],coef[k],temp);
458 this->p_poly_mult_n(*
this,g);
481 n =
static_cast<int>(ceil(
log(n)/
log(2)));
482 n =
static_cast<int>(
pow(2,n));
488 p_poly_set(AB,A.
mod);
489 this->p_poly_reduce(*
this,A.
mod);
523 while(mpz_divisible_ui_p(coef[k],
mod)!=0 && k>=0)
535 if (mpz_divisible_ui_p(n,g.
mod)==0)
543 mpz_init_set_ui(temp,0);
544 mpz_init_set_ui(p,
mod);
545 for(
int i=0;
i<=deg;
i++)
547 mpz_invert(temp,n,p);
548 mpz_mul(temp,g.
coef[
i],temp);
549 mpz_init_set(coef[
i],temp);
562 this->p_poly_scalar_div(*
this,n);
577 for (
int i=0;
i<=f.
deg-n;
i++)
579 mpz_init_set(coef[
i],f.
coef[n+i]);
597 for (
int i=0;
i<=n-1;
i++)
599 mpz_init_set(coef[
i],f.
coef[i]);
624 mpz_init_set_ui(p,A.
mod);
625 mpz_init_set_ui(a,0);
626 mpz_init_set_ui(u,0);
656 this->p_poly_div_rem(*
this,B);
681 mpz_init_set_ui(p,A.
mod);
682 mpz_init_set_ui(a,0);
683 mpz_init_set_ui(b,0);
722 this->p_poly_div(Q ,R,*
this,B);
762 mpz_init_set(erg,coef[deg]);
763 for (
int i=deg;
i>=1;
i--)
766 mpz_add(erg,erg,coef[
i-1]);
770 mpz_mod_ui(erg,erg,
mod);
787 for (
int i=A.
deg;
i>=1;
i--)
790 p_poly_add_const_to(A.
coef[
i-1]);
810 for(
int i=0;
i<=deg;
i++)
812 mpz_init_set(coef[
i],b.
coef[i]);
823 if (mpz_divisible_ui_p(b,
mod)!=0)
828 mpz_init_set(temp,b);
829 mpz_mod_ui(temp,temp,p);
830 mpz_init_set(coef[0],b);
850 for (
int i=deg;
i>=0;
i--)
852 if (mpz_cmp(coef[
i],g.
coef[i])!=0)
873 if (mpz_cmp_ui(coef[0],1)==0) {
return 1; }
881 if (mpz_cmpabs_ui(coef[deg],1)==0)
930 p_poly_extgcd(t,s,g,B,A);
937 mpz_init_set_ui(temp,1);
944 mpz_init_set_ui(temp,1);
974 p_poly_div(Q,R3,R1,R2);
1007 cout <<
"Bitte geben Sie ein p_polynom ein! Zunächst den Grad: " << endl;
1009 cout <<
"Jetzt den modul: " << endl;
1012 for (
int i=0;
i<=deg;
i++)
1014 mpz_init_set_ui(coef[
i],0);
1015 printf(
"Geben Sie nun f[%i] ein:",i);
1016 mpz_inp_str(coef[i],stdin, 10);
1019 this->p_poly_reduce(*
this,mod);
1030 this->p_poly_reduce(*
this,
mod);
1034 cout <<
"0" <<
"\n" <<endl;
1037 for (
int i=deg;
i>=1;
i--)
1039 mpz_out_str(stdout,10, coef[
i]);
1042 mpz_out_str(stdout,10, coef[0]);
void p_poly_sub_mon_to(mpz_t, int)
const CanonicalForm int s
void p_poly_sub_const_to(const mpz_t)
void p_poly_div_to(p_poly &, p_poly &, p_poly)
void p_poly_mult_n(p_poly, p_poly)
void p_poly_scalar_div(const p_poly, const mpz_t n)
void p_poly_div(p_poly &, p_poly &, p_poly, p_poly)
void p_poly_add_const(p_poly, const mpz_t)
void p_poly_scalar_div_to(const mpz_t n)
gmp_float log(const gmp_float &a)
int is_equal(const p_poly) const
void p_poly_multsub_to(const p_poly, const p_poly)
void p_poly_multadd_to(const p_poly, const p_poly)
void p_poly_sub(const p_poly, const p_poly)
void p_poly_sub_mon(const p_poly, mpz_t, int)
void p_poly_mon_mult_to(const int)
void p_poly_sub_const(p_poly, const mpz_t)
void p_poly_reduce(p_poly, int)
void p_poly_add_mon(const p_poly, mpz_t, int)
void p_poly_gcd(p_poly, p_poly)
void p_poly_horner(mpz_t, const mpz_t)
void p_poly_div_rem(p_poly, p_poly)
void p_poly_scalar_mult_to(const mpz_t)
void p_poly_div_rem_to(p_poly)
void p_poly_mon_div(const p_poly, const int)
void p_poly_extgcd(p_poly &, p_poly &, p_poly &, p_poly, p_poly)
void p_poly_mult_n_to(const p_poly)
void p_poly_add_const_to(const mpz_t)
void p_poly_horner_p_poly(p_poly, p_poly)
void p_poly_sub_to(const p_poly)
void p_poly_set(const p_poly)
void p_poly_mon_mult(p_poly, const int)
void p_poly_add(const p_poly, const p_poly)
void p_poly_scalar_mult(const mpz_t, const p_poly)
Rational pow(const Rational &a, int e)
void p_poly_add_to(const p_poly)
void p_poly_mon_div_rem(const p_poly, const int)
void p_poly_add_mon_to(mpz_t, int)
void p_poly_mult_ka(p_poly, p_poly)