Jsevillamol
Jsevillamol

Reputation: 2543

Programming a function parameterized by a Domain in Maple

I want to implement the Extended Euclidean Algorithm for arbitrary Euclidean Domains in Maple.

I tried passing the domain as an argument to the procedure, but it does not seem to work.

EEA:=proc(ED,a,b) 
    description 
    "Extended Euclidean Algorithm"
    "INPUT: an Euclidean Domain ED and two elements from said domain"
    "Computes the GCD as a R-linear combination";
    local r_0, r_1, r_aux, s_0, s_1, s_aux, t_0, t_1, t_aux, q;
    # Initialization
    r_0 := a; r_1 := b;
    s_0 := 1; s_1 := 0;
    t_0 := 0; t_1 := 1;

    while r_1 <> 0 do;
        q := ED[quo](r_0, r_1);

        r_aux := r_0 - q * r_1;
        r_0 := r_1; r_1 := r_aux;

        s_aux := s_0 - q * s_1;
        s_0 := s_1; s_1 := s_aux;

        t_aux := t_0 - q * t_1;
        t_0 := t_1; t_1 := t_aux;
    od;
    return r_0, s_0, t_0;
    end proc:

When I execute:

with(Domains):
a := 30; b := 42; 
r, s, t := EEA(Z, a, b); 

The program gets stuck in a loop.

What is going on?

Upvotes: 0

Views: 74

Answers (1)

Jsevillamol
Jsevillamol

Reputation: 2543

Nevermind, I needed to capitalize Z[Quo].

Upvotes: 0

Related Questions