0

I am new to Maple and trying to implement the gcd of 2 polynomials using euclide's algorithm.

I was quite sure of my code, but i am getting weird fractional results

with(Algebraic);

euclide:=proc(a, b)
local r0, r1, tmp, q;
  r0 := a;
  r1 := b;
  while (degree(r0) > degree(r1)) and (r1 <> 0) do
    q := Quotient(r0, r1, x);
    tmp := r0 - q * r1;
    r0 := r1;
    r1 := tmp;
    r0 := expand(r0);
    r1 := expand(r1);
  od;
  return expand(r0);
end;

When running my algorithm on random polynomials, The result I get is a very weird fractional result, while the gcd function in Maple gives output 1. I don't understand the bug in my program.

acer
  • 6,671
  • 15
  • 15
  • 1
    Which fractions, for example? Getting GCD equal to 1/34254353 is the same as GCD equal to 1. Since the first is an invertible element in the ring of polynomials. – conditionalMethod Sep 30 '19 at 14:33
  • 2
    GCD is unique up to multiplication by an invertible element, in a ring with Euclidean division. In your case, the invertible elements are probably the non-zero constant polynomials. – conditionalMethod Sep 30 '19 at 14:40

0 Answers0