代码之家  ›  专栏  ›  技术社区  ›  Jsevillamol

在Maple中编程一个由域参数化的函数

  •  0
  • Jsevillamol  · 技术社区  · 7 年前

    我想在Maple中实现任意欧几里德域的扩展欧几里德算法。

    我试图将域作为参数传递给过程,但似乎不起作用。

    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:
    

    当我执行时:

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

    程序陷入了循环。

    怎么回事?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Jsevillamol    7 年前

    不管怎样,我需要资本化 Z[Quo] .

    推荐文章