| 378 | } |
| 379 | |
| 380 | poly singclap_gcd ( poly f, poly g, const ring r ) |
| 381 | { |
| 382 | poly res=NULL; |
| 383 | |
| 384 | if (f!=NULL) |
| 385 | { |
| 386 | //if (r->cf->has_simple_Inverse) p_Norm(f,r); |
| 387 | if (rField_is_Zp(r)) p_Norm(f,r); |
| 388 | else if (!rField_is_Ring(r)) p_Cleardenom(f, r); |
| 389 | } |
| 390 | if (g!=NULL) |
| 391 | { |
| 392 | //if (r->cf->has_simple_Inverse) p_Norm(g,r); |
| 393 | if (rField_is_Zp(r)) p_Norm(g,r); |
| 394 | else if (!rField_is_Ring(r)) p_Cleardenom(g, r); |
| 395 | } |
| 396 | else return f; // g==0 => gcd=f (but do a p_Cleardenom/pNorm) |
| 397 | if (f==NULL) return g; // f==0 => gcd=g (but do a p_Cleardenom/pNorm) |
| 398 | if(!rField_is_Ring(r) |
| 399 | && (p_IsConstant(f,r) |
| 400 | ||p_IsConstant(g,r))) |
| 401 | { |
| 402 | res=p_One(r); |
| 403 | } |
| 404 | else if (r->cf->convSingNFactoryN!=ndConvSingNFactoryN) |
| 405 | { |
| 406 | res=singclap_gcd_r(f,g,r); |
| 407 | } |
| 408 | else |
| 409 | { |
| 410 | ideal I=idInit(2,1); |
| 411 | I->m[0]=f; |
| 412 | I->m[1]=p_Copy(g,r); |
| 413 | intvec *w=NULL; |
| 414 | ring save_ring=currRing; |
| 415 | if (r!=currRing) rChangeCurrRing(r); |
| 416 | int save_opt; |
| 417 | SI_SAVE_OPT1(save_opt); |
| 418 | si_opt_1 &= ~(Sy_bit(OPT_PROT)); |
| 419 | ideal S1=idSyzygies(I,testHomog,&w); |
| 420 | if (w!=NULL) delete w; |
| 421 | // expect S1->m[0]=(-g/gcd,f/gcd) |
| 422 | if (IDELEMS(S1)!=1) WarnS("error in syzygy computation for GCD"); |
| 423 | int lp; |
| 424 | p_TakeOutComp(&S1->m[0],1,&res,&lp,r); |
| 425 | p_Delete(&S1->m[0],r); |
| 426 | // GCD is g divided iby (-g/gcd): |
| 427 | res=p_Divide(g,res,r); |
| 428 | // restore, r, opt: |
| 429 | SI_RESTORE_OPT1(save_opt); |
| 430 | if (r!=save_ring) rChangeCurrRing(save_ring); |
| 431 | // clean the result |
| 432 | res=p_Cleardenom(res,r); |
| 433 | if (nCoeff_is_Ring(r->cf)) p_Content(res,r); |
| 434 | return res; |
| 435 | } |
| 436 | p_Delete(&f, r); |
| 437 | p_Delete(&g, r); |
no test coverage detected