MCPcopy Create free account
hub / github.com/Singular/Singular / tryEuclid

Function tryEuclid

factory/cfGcdAlgExt.cc:289–349  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287}
288
289void tryEuclid( const CanonicalForm & A, const CanonicalForm & B, const CanonicalForm & M, CanonicalForm & result, bool & fail )
290{
291 CanonicalForm P;
292 if(A.inCoeffDomain())
293 {
294 tryInvert( A, M, P, fail );
295 if(fail)
296 return;
297 result = 1;
298 return;
299 }
300 if(B.inCoeffDomain())
301 {
302 tryInvert( B, M, P, fail );
303 if(fail)
304 return;
305 result = 1;
306 return;
307 }
308 // here: both not inCoeffDomain
309 if( A.degree() > B.degree() )
310 {
311 P = A; result = B;
312 }
313 else
314 {
315 P = B; result = A;
316 }
317 CanonicalForm inv;
318 if( result.isZero() )
319 {
320 tryInvert( Lc(P), M, inv, fail );
321 if(fail)
322 return;
323 result = inv*P; // monify result (not reduced, yet)
324 result= reduce (result, M);
325 return;
326 }
327 Variable x = P.mvar();
328 CanonicalForm rem, Q;
329 // here: degree(P) >= degree(result)
330 while(true)
331 {
332 tryDivrem (P, result, Q, rem, inv, M, fail);
333 if (fail)
334 return;
335 if( rem.isZero() )
336 {
337 result *= inv;
338 result= reduce (result, M);
339 return;
340 }
341 if(result.degree(x) >= rem.degree(x))
342 {
343 P = result;
344 result = rem;
345 }
346 else

Callers 1

tryBrownGCDFunction · 0.85

Calls 8

tryInvertFunction · 0.85
LcFunction · 0.85
reduceFunction · 0.85
tryDivremFunction · 0.85
mvarMethod · 0.80
inCoeffDomainMethod · 0.45
degreeMethod · 0.45
isZeroMethod · 0.45

Tested by

no test coverage detected