0

I try to write the function which is determine remainder of long division algorithm Specifically, find the remainder of polynomial f on the divison by F with F is the family of polynomials. I got stuck and here is my code.

    with(Groebner); LT := proc (f, order) 
    return LeadingCoefficient(f, order)*LeadingMonomial(f, order) 
    end proc

    with(Groebner);  
    CHIA:=proc(f,Lf,order)  local Lq,p,i,j,r,divisionoccurred;    
    for j from 1 to nops(Lf) do  
    Lq[j]:=0;  
    od;  
    r:=0;p:=f;  
    while p<>0 do  
    i:=1  
    divisionoccurred:=false  
    while i<=nops(Lf) and divisionoccurred=false do  
    if divide(LT(p,order),LT(Lf[i],order)) then  
    Lq[i]:=Lq[i]+(LT(p,order))/(LT(Lf[i],order));  
    p:=p-((LT(p,order))/(LT(Lf[i],order)))*Lf[i]; 
    divisionoccurred:=true;  
    else  
    i:=i+1;
    fi;
    end do;
    if divisionoccurred=false then   
    r:=r+LT(p,order);  
    p:=p-LT(p,order);
    fi;
    end do;
    return Lq,r   
    end proc;
Soulostar
  • 101
  • 2
  • what exactly are you stuck with? – jtate Oct 25 '18 at 21:11
  • This code does not work. I do not know why. – Soulostar Oct 26 '18 at 02:11
  • Where are the `end do` and `end if` (or `od` and `fi`) that terminate your `while do` loop and two `if-then` clauses? Also, you'll need a colon or semicolon terminator between the assignment to `r` and the assignment to `p`. There's weird invalid syntax on a line that ends with `Lf[i]`. Fix your syntax errors before you can call this procedure. – acer Oct 26 '18 at 03:01
  • Thank you so much. However, although it does not have error but it runs in nonstop. So maybe I need to fix somewhere please help me see it. – Soulostar Oct 26 '18 at 03:45
  • I just fix the code in my posts. – Soulostar Oct 26 '18 at 04:05
  • The code is still not free of syntax errors. Eg, there is no statement terminator after the `end proc` for the definition of `LT`. Are you entering this in 1D or 2D mode (since as 2D Input the space after the first `proc` in the definition of `LT` could get parsed as indicating implicit multiplication). Also, why have you not shown the example where you call CHIA and it runs? Why not attempt debugging it yourself, either 1) using the Maple's debugger, or 2) adding a fixed limit to the loop `while p<>0` and then printing `p` each iteration, or similar. – acer Oct 26 '18 at 04:25

0 Answers0