// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The Division algorithm and Euclidean algorithm // Polynomial ring in one variable // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Here are two choices for a field, and the polynomial ring. // tells magma to use x as the variable. F := Rationals(); F := GF(2); P := PolynomialRing(F); // Just to have shorthand: LT := LeadingTerm; // An important piece of magma language is !, the coercion operator. // The following means the 0 element of P. P!0 MyDivAlg := function(f,h) q := P!0; r := f; while r ne 0 and Degree(r) ge Degree(h) do t := LT(r) div LT(h); q := q + t; r := r-t*h; end while; return q,r ; end function; MyEuclAlg := function(f,h) r := f; s := h; while s ne P!0 do _,rem := MyDivAlg(r,s); // The _ is used to throw away the first returned value. r := s; s := rem; end while; return r; end function;