Macaulay2 Engine
Loading...
Searching...
No Matches

◆ gbvector_replace_2by2_ZZ()

void GBRing::gbvector_replace_2by2_ZZ ( const FreeModule * F,
const FreeModule * Fsyz,
gbvector *& f,
gbvector *& fsyz,
gbvector *& g,
gbvector *& gsyz )

Definition at line 1114 of file gbring.cpp.

1120{
1121 // ASSUMPTIONS: coefficient ring is ZZ
1122 // lead monomial of f and g are the same (with possibly different coeffs)
1123 // If u * leadcoeff(f) + v * leadcoeff(g) = gd is the gcd,
1124 // then:
1125 // g <-- u * f + v * g
1126 // f <-- c * f - d * g, where c = leadcoeff(g)//gd, d = leadcoeff(f)//gd
1127 mpz_t u, v, gd;
1128 mpz_init(u);
1129 mpz_init(v);
1130 mpz_init(gd);
1131 mpz_gcdext(gd, u, v, f->coeff.get_mpz(), g->coeff.get_mpz());
1132
1133 gbvector *new_g = nullptr;
1134 gbvector *g2 = nullptr;
1135 gbvector *new_gsyz = nullptr;
1136 gbvector *gsyz2 = nullptr;
1137
1138 if (mpz_sgn(v) != 0)
1139 {
1140 g2 = gbvector_mult_by_coeff(g, ring_elem(v));
1141 gsyz2 = gbvector_mult_by_coeff(gsyz, ring_elem(v));
1142 }
1143 if (mpz_sgn(u) != 0)
1144 {
1145 new_g = gbvector_mult_by_coeff(f, ring_elem(u));
1146 new_gsyz = gbvector_mult_by_coeff(fsyz, ring_elem(u));
1147 }
1148
1149 gbvector_add_to(F, new_g, g2);
1150 gbvector_add_to(Fsyz, new_gsyz, gsyz2);
1151
1152 mpz_fdiv_q(u, g->coeff.get_mpz(), gd);
1153 mpz_fdiv_q(v, f->coeff.get_mpz(), gd);
1154 mpz_neg(v, v);
1155
1156 gbvector *new_f = gbvector_mult_by_coeff(f, ring_elem(u));
1157 gbvector *new_fsyz = gbvector_mult_by_coeff(fsyz, ring_elem(u));
1158 gbvector *f2 = gbvector_mult_by_coeff(g, ring_elem(v));
1159 gbvector *fsyz2 = gbvector_mult_by_coeff(gsyz, ring_elem(v));
1160
1161 gbvector_add_to(F, new_f, f2);
1162 gbvector_add_to(Fsyz, new_fsyz, fsyz2);
1163
1164 f = new_f;
1165 fsyz = new_fsyz;
1166 g = new_g;
1167 gsyz = new_gsyz;
1168
1169 mpz_clear(u);
1170 mpz_clear(v);
1171 mpz_clear(gd);
1172}
void gbvector_add_to(const FreeModule *F, gbvector *&f, gbvector *&g)
Definition gbring.cpp:668
gbvector * gbvector_mult_by_coeff(const gbvector *f, ring_elem u)
Definition gbring.cpp:567
ring_elem coeff
Definition gbring.hpp:81
mpz_srcptr get_mpz() const
Definition ringelem.hpp:127

References gbvector::coeff, gbvector_add_to(), gbvector_mult_by_coeff(), and ring_elem::get_mpz().