[SCM] an open source computer algebra system branch, cleanedupstream, updated. 6125e540ca6d66c307958938a9d53b245507c323

Bernhard R. Link brlink at debian.org
Tue Apr 24 15:55:42 UTC 2012


The following commit has been merged in the cleanedupstream branch:
commit 0dfdcf572ea442babf4139b15284a3ec678f6cc5
Author: Hans Schoenemann <hannes at mathematik.uni-kl.de>
Date:   Tue Apr 24 14:48:08 2012 +0200

    chg: new version of ffsolve.lib

diff --git a/Singular/LIB/ffsolve.lib b/Singular/LIB/ffsolve.lib
index b454724..28377f5 100644
--- a/Singular/LIB/ffsolve.lib
+++ b/Singular/LIB/ffsolve.lib
@@ -1,5 +1,5 @@
 ////////////////////////////////////////////////////////////////////
-version="$Id$";
+version="$Id: ffsolve.lib f0fdb24 2012-04-23 12:50:26 UTC$";
 category="Symbolic-numerical solving";
 info="
 LIBRARY: ffsolve.lib        multivariate equation solving over finite fields
@@ -8,9 +8,11 @@ KEYWORDS: multivariate equations; finite field
 
 PROCEDURES:
 ffsolve();         finite field solving using heuristically chosen method
-speoff();          solve system of multivariate equations over finite field
-simpleSolver();   solver using modified brute-force search
-gbsolve();         multivariate solver using Groebner-basis
+PEsolve();         solve system of multivariate equations over finite field
+simplesolver();    solver using modified exhausting search
+GBsolve();         multivariate solver using Groebner-basis
+XLsolve();         multivariate polynomial solver using linearization
+ZZsolve();         solve system of multivariate equations over finite field
 ";
 
 LIB "presolve.lib";
@@ -26,8 +28,8 @@ RETURN:         list L, the common roots of I as ideal
 ASSUME:         basering is a finite field of type (p^n,a)
 "
 {
-  list solutions, possibleSolvers, tempsols;
-  int i,j, k, found;
+  list solutions, lSolvers, tempsols;
+  int i,j, k,n, R, found;
   ideal factors, linfacs;
   poly lp;
   // check assumptions
@@ -38,18 +40,31 @@ ASSUME:         basering is a finite field of type (p^n,a)
     ERROR("Basering must have finite characteristic");
   }
 
-  //   heuristic choice of solver
-  //   not yet implemented
   if(size(#)){
     if(size(#)==1 and typeof(#[1])=="list"){
-      possibleSolvers = #[1];
+      lSolvers = #[1];
     }else{
-      possibleSolvers = #;
+      lSolvers = #;
     }
   }else{
-    possibleSolvers = "simpleSolver", "speoff", "gbsolve";
+    if(deg(equations) == 2){
+      lSolvers = "XLsolve", "PEsolve", "simplesolver", "GBsolve", "ZZsolve";
+    }else{
+      lSolvers = "PEsolve", "simplesolver", "GBsolve", "ZZsolve", "XLsolve";
+    }
+    if(deg(equations) == 1){
+      lSolvers = "GBsolve";
+    }
+  }
+  n = size(lSolvers);
+  R = random(1, n*(3*n+1) div 2);
+  for(i=1;i<n+1;i++){
+    if(R<=(2*n+1-i)){
+      string solver = lSolvers[i];
+    }else{
+      R=R-(2*n+1-i);
+    }
   }
-  string solver = possibleSolvers[random(1,size(possibleSolvers))];
 
   if(nvars(basering)==1){
     return(facstd(equations));
@@ -95,7 +110,7 @@ ASSUME:         basering is a finite field of type (p^n,a)
         }
       }
       map recmap = original_ring, mappingIdeal;
-      list tsols = ffsolve(recmap(neweqs), possibleSolvers);
+      list tsols = ffsolve(recmap(neweqs), lSolvers);
       if(size(tsols)==0){
         tsols = list(ideal(1));
       }
@@ -135,18 +150,21 @@ example
   ffsolve(I);
 }
 ////////////////////////////////////////////////////////////////////
-proc speoff (ideal L, list #)
-"USAGE:         speoff(I[, i]); I ideal, i optional integer
+proc PEsolve(ideal L, list #)
+"USAGE:         PEsolve(I[, i]); I ideal, i optional integer
+                solve I (system of multivariate equations) over a
+                finite field using an equvalence property when i is
+                not given or set to 2, otherwise if i is set to 0
+                then check whether common roots exists
 RETURN:         list if optional parameter is not given or set to 2,
-integer if optional is set to 0
+                integer if optional is set to 0
 ASSUME:         basering is a finite field of type (p^n,a)
 NOTE:           When the optional parameter is set to 0, speoff only
-checks if I has common roots, then return 1, otherwise return 0.
+                checks if I has common roots, then return 1, otherwise
+                return 0.
 
 "
 {
-  system("--ticks-per-sec", 1000);
-  int t = rtimer;
   int mode, i,j;
   list results, rs, start;
   poly g;
@@ -167,7 +185,6 @@ checks if I has common roots, then return 1, otherwise return 0.
   g = productOfEqs( L );
 
   if(g == 0){
-    if(voice==2){printf("Runtime: %s ms", rtimer-t)};
     if(mode==0){
       return(0);
     }
@@ -182,12 +199,10 @@ checks if I has common roots, then return 1, otherwise return 0.
       }
       results[size(results)+1] = std(res);
     }
-    if(voice==2){printf("Runtime: %s ms", rtimer-t)};
     return( results );
   }
 
   if( mode == 0 ){
-    if(voice==2){printf("Runtime: %s ms", rtimer-t)};
     return( 1 );
   }else{
     for(i=1; i<=nvars(basering); i++){
@@ -212,8 +227,6 @@ checks if I has common roots, then return 1, otherwise return 0.
       }
     }
   }
-
-  if(voice==2){printf("Runtime: %s ms", rtimer-t)};
   return(results);
 }
 example
@@ -225,16 +238,17 @@ example
   I[1]=x(1)^2*x(2)+(a)*x(1)*x(2)^2+(a+1);
   I[2]=x(1)^2*x(2)*x(3)^2+(a)*x(1);
   I[3]=(a+1)*x(1)*x(3)+(a+1)*x(1);
-  ffsolve(I);
+  PEsolve(I);
 }
 ////////////////////////////////////////////////////////////////////
-proc simpleSolver(ideal E)
-"USAGE:         simpleSolver(I); I ideal
+proc simplesolver(ideal E)
+"USAGE:         simplesolver(I); I ideal
+                solve I (system of multivariate equations) over a
+                finite field by exhausting search
 RETURN:         list L, the common roots of I as ideal
 ASSUME:         basering is a finite field of type (p^n,a)
 "
 {
-  int SStime = rtimer;
   int i,j,k,t, correct;
   list solutions = list(std(ideal()));
   list partial_solutions;
@@ -248,7 +262,6 @@ ASSUME:         basering is a finite field of type (p^n,a)
   if(char(basering)==0){
     ERROR("Basering must have finite characteristic");
   }
-
   for(k=1; k<=nvars(basering); k++){
     partial_solutions = list();
     for(i=1; i<=size(solutions); i++){
@@ -279,7 +292,6 @@ ASSUME:         basering is a finite field of type (p^n,a)
     }
     solutions = partial_solutions;
   }
-  if(voice==2){printf("Runtime: %s ms", rtimer-SStime)};
   return(solutions);
 }
 example
@@ -291,19 +303,18 @@ example
   I[1]=x(1)^2*x(2)+(a)*x(1)*x(2)^2+(a+1);
   I[2]=x(1)^2*x(2)*x(3)^2+(a)*x(1);
   I[3]=(a+1)*x(1)*x(3)+(a+1)*x(1);
-  ffsolve(I);
+  simplesolver(I);
 }
 ////////////////////////////////////////////////////////////////////
-proc gbsolve(ideal equation_system)
-"USAGE:         gbsolve(I); I ideal
+proc GBsolve(ideal equation_system)
+"USAGE:         GBsolve(I); I ideal
+                solve I (system of multivariate equations) over an
+                extension of Z/p by Groebner basis methods
 RETURN:         list L, the common roots of I as ideal
 ASSUME:         basering is a finite field of type (p^n,a)
 "
 {
-  option(redSB);
-  system("--ticks-per-sec",1000);
   int i,j, prop, newelement, number_new_vars;
-  int t=rtimer;
   ideal ls;
   list results, slvbl, linsol, ctrl, new_sols, varinfo;
   ideal I, linear_solution, unsolved_part, univar_part, multivar_part, unsolved_vars;
@@ -326,14 +337,13 @@ ASSUME:         basering is a finite field of type (p^n,a)
     int prime_coeff_field=1;
   }
 
+  option(redSB);
+
   equation_system = simplify(equation_system,15);
 
   ideal standard_basis = std(equation_system);
-  printf("std(): %s ms", rtimer-t);
   list basis_factors = facstd(standard_basis);
-  printf("facstd(): %s ms", rtimer-t);
   if( basis_factors[1][1] == 1){
-    printf("Runtime: %s ms", rtimer-t);
     return(results)
   };
 
@@ -345,9 +355,8 @@ ASSUME:         basering is a finite field of type (p^n,a)
         break;
       }
     }
-
     if(prop == 0){
-      ls = Presolve::solvelinearpart( basis_factors[i] );
+      ls = solvelinearpart( basis_factors[i] );
       if(ncols(ls) == nvars(basering) ){
         ctrl, newelement = add_if_new(ctrl, ls);
         if(newelement){
@@ -358,11 +367,11 @@ ASSUME:         basering is a finite field of type (p^n,a)
       }
     }
   }
-
   if(size(slvbl)<>0){
     for(int E = 1; E<= size(slvbl); E++){
       I = slvbl[E][1];
       linear_solution = slvbl[E][2];
+      attrib(I,"isSB",1);
       unsolved_part = reduce(I,linear_solution);
       univar_part = ideal();
       multivar_part = ideal();
@@ -373,15 +382,13 @@ ASSUME:         basering is a finite field of type (p^n,a)
           multivar_part = multivar_part+I[i];
         }
       }
-
-      //       list varinfo = Presolve::findvars(linear_solution,1);
-      varinfo = Presolve::findvars(univar_part,1);
+      varinfo = findvars(univar_part,1);
       unsolved_vars = varinfo[3];
       unsolved_var_nums = varinfo[4];
       number_new_vars = ncols(unsolved_vars);
 
       new_vars = "@y(1.."+string(number_new_vars)+")";
-      def R_new = Ring::changevar(new_vars, original_ring);
+      def R_new = changevar(new_vars, original_ring);
       setring R_new;
       if( !prime_coeff_field ){
         execute(minpolystr);
@@ -397,7 +404,7 @@ ASSUME:         basering is a finite field of type (p^n,a)
 
       list sol_new;
       int unsolvable = 0;
-      sol_new = simpleSolver(I_new);
+      sol_new = simplesolver(I_new);
       if( size(sol_new) == 0){
         unsolvable = 1;
       }
@@ -423,8 +430,6 @@ ASSUME:         basering is a finite field of type (p^n,a)
       kill R_new;
     }
   }
-
-  if(voice==2){printf("Runtime: %s ms", rtimer-t)};
   return( results  );
 }
 example
@@ -436,13 +441,366 @@ example
   I[1]=x(1)^2*x(2)+(a)*x(1)*x(2)^2+(a+1);
   I[2]=x(1)^2*x(2)*x(3)^2+(a)*x(1);
   I[3]=(a+1)*x(1)*x(3)+(a+1)*x(1);
-  ffsolve(I);
+  GBsolve(I);
 }
+////////////////////////////////////////////////////////////////////
+proc XLsolve(ideal I, list #)
+"USAGE:         XLsolve(I[, d]); I ideal, d optional integer
+                solve I (system of multivariate polynomials) with a
+                variant of the linearization technique, multiplying
+                the polynomials with monomials of degree at most d
+                (default is 2)
+RETURN:         list L of the common roots of I as ideals
+ASSUME:         basering is a finite field of type (p^n,a)"
+{
+  int i,j,k, D;
+  int SD = deg(I);
+  list solutions;
+  if(size(#)){
+    if(typeof(#[1])=="int"){ D = #[1]; }
+  }else{
+    D = 2;
+  }
+  list lMonomialsForMultiplying = monomialsOfDegreeAtMost(D+SD);
 
+  int m = ncols(I);
+  list extended_system;
+  list mm;
+  for(k=1; k<=size(lMonomialsForMultiplying)-SD; k++){
+    mm = lMonomialsForMultiplying[k];
+    for(i=1; i<=m; i++){
+      for(j=1; j<=size(mm); j++){
+        extended_system[size(extended_system)+1] = reduce(I[i]*mm[j], defaultIdeal());
+      }
+    }
+  }
+  ideal new_system = I;
+  for(i=1; i<=size(extended_system); i++){
+    new_system[m+i] = extended_system[i];
+  }
+  ideal reduced_system = linearReduce( new_system, lMonomialsForMultiplying);
+
+  solutions = simplesolver(reduced_system);
+
+  return(solutions);
+}
+example
+{
+  "EXAMPLE:";echo=2;
+  ring R = (2,a),x(1..3),lp;
+  minpoly=a2+a+1;
+  ideal I;
+  I[1]=(a)*x(1)^2+x(2)^2+(a+1);
+  I[2]=(a)*x(1)^2+(a)*x(1)*x(3)+(a)*x(2)^2+1;
+  I[3]=(a)*x(1)*x(3)+1;
+  I[4]=x(1)^2+x(1)*x(3)+(a);
+  XLsolve(I, 3);
+}
 
 ////////////////////////////////////////////////////////////////////
+proc ZZsolve(ideal I)
+"USAGE:         ZZsolve(I); I ideal
+solve I (system of multivariate equations) over a
+finite field by mapping the polynomials to a single
+univariate polynomial over extension of the basering
+RETURN:         list, the common roots of I as ideal
+ASSUME:         basering is a finite field of type (p^n,a)
+"
+{
+  int i, j, nv, numeqs,r,l,e;
+  def original_ring = basering;
+  // check assumptions
+  if(npars(basering)>1){
+    ERROR("Basering must have at most one parameter");
+  }
+  if(char(basering)==0){
+    ERROR("Basering must have finite characteristic");
+  }
+
+  nv = nvars(original_ring);
+  numeqs = ncols(I);
+  l = numeqs % nv;
+  if( l == 0){
+    r = numeqs div nv;
+  }else{
+    r = (numeqs div nv) +1;
+  }
 
 
+  list list_of_equations;
+  for(i=1; i<=r; i++){
+    list_of_equations[i] = ideal();
+  }
+  for(i=0; i<numeqs; i++){
+    list_of_equations[(i div nv)+1][(i % nv) +1] = I[i+1];
+  }
+
+  ring ring_for_matrix = (char(original_ring), at y),(x(1..nv), at X, at c(1..nv)(1..nv)),lp;
+  execute("minpoly="+Z_get_minpoly(size(original_ring)^nv, parstr(1))+";");
+
+  ideal IV;
+  for(i=1; i<=nv; i++){
+    IV[i] = var(i);
+  }
+
+  matrix M_C[nv][nv];
+  for(i=1;i<=nrows(M_C); i++){
+    for(j=1; j<=ncols(M_C); j++){
+      M_C[i,j] = @c(i)(j);
+    }
+  }
+
+  poly X = Z_phi(IV);
+  ideal IX_power_poly;
+  ideal IX_power_var;
+  for(i=1; i<=nv; i++){
+    e = (size(original_ring)^(i-1));
+    IX_power_poly[i] = X^e;
+    IX_power_var[i] = @X^e;
+  }
+  IX_power_poly = reduce(IX_power_poly, Z_default_ideal(nv, size(original_ring)));
+
+  def M = matrix(IX_power_poly,1,nv)*M_C - matrix(IV,1,nv);
+
+  ideal IC;
+  for(i=1; i<=ncols(M); i++){
+    for(j=1; j<=ncols(IV); j++){
+      IC[(i-1)*ncols(M)+j] = coeffs(M[1,i],IV[j])[2,1];
+    }
+  }
+
+  ideal IC_solultion = std(Presolve::solvelinearpart(IC));
+
+
+  matrix M_C_sol[nv][nv];
+  for(i=1;i<=nrows(M_C_sol); i++){
+    for(j=1; j<=ncols(M_C_sol); j++){
+      M_C_sol[i,j] = reduce(@c(i)(j), std(IC_solultion));
+    }
+  }
+  ideal I_subs;
+  I_subs = ideal(matrix(IX_power_var,1,nv)*M_C_sol);
+
+  setring original_ring;
+  string var_str = varstr(original_ring)+", at X, at y";
+  string minpoly_str = "minpoly="+string(minpoly)+";";
+  def ring_for_substitution = Ring::changevar(var_str, original_ring);
+
+  setring ring_for_substitution;
+  execute(minpoly_str);
+
+  ideal I_subs = imap(ring_for_matrix, I_subs);
+  ideal I = imap(original_ring, I);
+  list list_of_equations = imap(original_ring, list_of_equations);
+
+  list list_of_F;
+  for(i=1; i<=r; i++){
+    list_of_F[i] = Z_phi( list_of_equations[i] );
+  }
+
+  for(i=1; i<=nv; i++){
+
+    for(j=1; j<=r; j++){
+      list_of_F[j] = subst( list_of_F[j], var(i), I_subs[i] );
+    }
+  }
+  int s = size(original_ring);
+  if(npars(original_ring)==1){
+    for(j=1; j<=r; j++){
+      list_of_F[j] = subst(list_of_F[j], par(1), (@y^( (s^nv-1) div (s-1) )));
+    }
+  }
+
+  ring temp_ring = (char(original_ring), at y), at X,lp;
+  list list_of_F = imap(ring_for_substitution, list_of_F);
+
+  ring ring_for_factorization = (char(original_ring), at y),X,lp;
+  execute("minpoly="+Z_get_minpoly(size(original_ring)^nv, parstr(1))+";");
+  map rho = temp_ring,X;
+  list list_of_F = rho(list_of_F);
+  poly G = 0;
+  for(i=1; i<=r; i++){
+    G = gcd(G, list_of_F[i]);
+  }
+  if(G==1){
+    return(list());
+  }
+
+  list factors = Presolve::linearpart(factorize(G,1));
+
+  ideal check;
+  for(i=1; i<=nv; i++){
+    check[i] = X^(size(original_ring)^(i-1));
+  }
+  list fsols;
+
+  matrix sc;
+  list sl;
+  def sM;
+  matrix M_for_sol = fetch(ring_for_matrix, M_C_sol);
+  for(i=1; i<=size(factors[1]); i++){
+    sc = matrix(reduce(check, std(factors[1][i])), 1,nv  );
+
+    sl = list();
+    sM = sc*M_for_sol;
+    for(j=1; j<=ncols(sM); j++){
+      sl[j] = sM[1,j];
+    }
+    fsols[i] = sl;
+  }
+  if(size(fsols)==0){
+    return(list());
+  }
+  setring ring_for_substitution;
+  list ssols = imap(ring_for_factorization, fsols);
+  if(npars(original_ring)==1){
+    execute("poly P="+Z_get_minpoly(size(original_ring)^nv, "@y"));
+    poly RP = gcd(P,  (@y^( (s^nv-1) div (s-1) ))-a);
+    for(i=1; i<=size(ssols); i++){
+      for(j=1; j<=size(ssols[i]); j++){
+        ssols[i][j] = reduce( ssols[i][j], std(RP));
+      }
+    }
+  }
+  setring original_ring;
+  list solutions = imap(ring_for_substitution, ssols);
+  list final_solutions;
+  ideal ps;
+  for(i=1; i<=size(solutions); i++){
+    ps = ideal();
+    for(j=1; j<=nvars(original_ring); j++){
+      ps[j] = var(j)-solutions[i][j];
+    }
+    final_solutions = insert(final_solutions, std(ps));
+  }
+  return(final_solutions);
+}
+example
+{
+  "EXAMPLE:";echo=2;
+  ring R = (2,a),x(1..3),lp;
+  minpoly=a2+a+1;
+  ideal I;
+  I[1]=x(1)^2*x(2)+(a)*x(1)*x(2)^2+(a+1);
+  I[2]=x(1)^2*x(2)*x(3)^2+(a)*x(1);
+  I[3]=(a+1)*x(1)*x(3)+(a+1)*x(1);
+  ZZsolve(I);
+}
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+static proc linearReduce(ideal I, list mons)
+{
+  system("--no-warn", 1);
+  int LRtime = rtimer;
+  int i,j ;
+  int prime_field = 1;
+  list solutions, monomials;
+  for(i=1; i<=size(mons); i++){
+    monomials = reorderMonomials(mons[i])+monomials;
+  }
+  int number_of_monomials = size(monomials);
+
+  def original_ring = basering;
+  if(npars(basering)==1){
+    prime_field=0;
+    string minpolystr = "minpoly="
+    +get_minpoly_str(size(original_ring),parstr(original_ring,1))+";" ;
+  }
+  string old_vars = varstr(original_ring);
+  string new_vars = "@y(1.."+string( number_of_monomials )+")";
+
+  def ring_for_var_change = changevar( old_vars+","+new_vars, original_ring);
+  setring ring_for_var_change;
+  if( prime_field == 0){
+    execute(minpolystr);
+  }
+
+  list monomials = imap(original_ring, monomials);
+  ideal I = imap(original_ring, I);
+  ideal C;
+  string weights = "wp(";
+  for(i=1; i<=nvars(original_ring); i++){
+    weights = weights+string(1)+",";
+  }
+  for(i=1; i<= number_of_monomials; i++){
+    C[i] = monomials[i] - @y(i);
+    weights = weights+string(deg(monomials[i])+1)+",";
+  }
+  weights[size(weights)]=")";
+  ideal linear_eqs = I;
+  for(i=1; i<=ncols(C); i++){
+    linear_eqs = reduce(linear_eqs, C[i]);
+  }
+
+  def ring_for_elimination = changevar( new_vars, ring_for_var_change);
+  setring ring_for_elimination;
+  if( prime_field == 0){
+    execute(minpolystr);
+  }
+
+  ideal I = imap(ring_for_var_change, linear_eqs);
+  ideal lin_sol = solvelinearpart(I);
+  string new_ordstr = weights+",C";
+  def ring_for_back_change = changeord( new_ordstr, ring_for_var_change);
+
+  setring ring_for_back_change;
+  if( prime_field == 0){
+    execute(minpolystr);
+  }
+
+  ideal lin_sol = imap(ring_for_elimination, lin_sol);
+  ideal C = imap(ring_for_var_change, C);
+  ideal J = lin_sol;
+  for(i=1; i<=ncols(C); i++){
+    J = reduce(J, C[i]);
+  }
+  setring original_ring;
+  ideal J = imap(ring_for_back_change, J);
+  return(J);
+}
+
+static proc monomialsOfDegreeAtMost(int k)
+{
+  int Mtime = rtimer;
+  list monomials, monoms, monoms_one, lower_monoms;
+  int n = nvars(basering);
+  int t,i,l,j,s;
+  for(i=1; i<=n; i++){
+    monoms_one[i] = var(i);
+  }
+  monomials = list(monoms_one);
+  if(1 < k){
+    for(t=2; t<=k; t++){
+      lower_monoms = monomials[t-1];
+      monoms = list();
+      s = 1;
+      for(i=1; i<=n; i++){
+        for(j=s; j<=size(lower_monoms); j++){
+          monoms = monoms+list(lower_monoms[j]*var(i));
+        }
+        s = s + int(binomial(n+t-2-i, t-2));
+      }
+      monomials[t] = monoms;
+    }
+  }
+  return(monomials);
+}
+
+static proc reorderMonomials(list monomials)
+{
+  list univar_monoms, mixed_monoms;
+
+  for(int j=1; j<=size(monomials); j++){
+    if( univariate(monomials[j])>0 ){
+      univar_monoms = univar_monoms + list(monomials[j]);
+    }else{
+      mixed_monoms = mixed_monoms + list(monomials[j]);
+    }
+  }
+
+  return(univar_monoms + mixed_monoms);
+}
+
 static proc melyseg(poly g, list start)
 {
   list gsub = g;
@@ -486,53 +844,6 @@ static proc productOfEqs(ideal I)
   return( g );
 }
 
-static proc notSoQuickReduce(poly P)
-{
-  int q = ringlist( basering )[1];
-  int nov = nvars( basering );
-  poly reducedPoly = 0;
-  poly M;
-  int i, j, e;
-  intvec exps;
-
-  for(i=1; i<=size(P); i++){
-    if( deg(P[i]) > q-1 ){
-      M = leadcoef( P[i] );
-      exps = leadexp( P[i] );
-      for(j=1; j<=size(exps); j++){
-        if( exps[j] > q-1 ){
-          e = exps[j] % (q-1);
-          if( e == 0 ){ e = q-1; }
-        }else{
-          e = exps[j];
-        }
-        M = M*var(j)^e;
-      }
-    }else{
-      M = P[i];
-    }
-    reducedPoly = reducedPoly + M;
-  }
-  return( reducedPoly );
-}
-
-static proc polypowmod(poly P, int E, ideal I)
-{
-  system("--no-warn", 1);
-  list pot;
-  poly rs = 1;
-
-  while( E > 0 ){
-    pot[ size(pot)+1 ] = E % 2;
-    E = E / 2;
-    if( pot[size(pot)] ){
-      rs = reduce(rs*P, I);
-    }
-    P = reduce(P*P,I);
-  }
-  return( reduce(rs, I) );
-}
-
 static proc clonering(list #)
 {
   def original_ring = basering;
@@ -550,7 +861,7 @@ static proc clonering(list #)
     int newvars = nvars(original_ring);
   }
   string newvarstr = "v(1.."+string(newvars)+")";
-  def newring = Ring::changevar(newvarstr, original_ring);
+  def newring = changevar(newvarstr, original_ring);
   setring newring;
   if( prime_field ){
     execute(minpolystr);
@@ -577,7 +888,6 @@ static proc order_of_extension()
   return(oe);
 }
 
-
 static proc vec2elm(intvec v)
 {
   number g = 1;
@@ -590,16 +900,6 @@ static proc vec2elm(intvec v)
   return(e);
 }
 
-static proc random_vector()
-{
-  int c = char(basering);
-  intvec v = 0:order_of_extension();
-  for(int i=1; i<=size(v); i++){
-    v[i] = random(0, c-1);
-  }
-  return(v);
-}
-
 static proc increment(list l, list #)
 {
   int c, i, j, oe;
@@ -640,8 +940,6 @@ static proc nextVec(intvec l)
   return(l);
 }
 
-
-
 static proc every_vector()
 {
   list element, list_of_elements;
@@ -681,15 +979,6 @@ static proc num2int(number a)
   return(N);
 }
 
-static proc listnum2int(list L){
-  int N=0;
-  int q = size(basering);
-  for(int i=1; i<=nvars(basering); i++){
-    N = N + num2int(number(L[i]))*q^(nvars(basering)-i);
-  }
-  return(N);
-}
-
 static proc get_minpoly_str(int size_of_ring, string parname)
 {
   def original_ring = basering;
@@ -735,6 +1024,7 @@ static proc add_if_new(list L, ideal I)
   int i, newelement;
   poly P;
 
+  I=std(I);
   for(i=1; i<=nvars(basering); i++){
     P = P +  reduce(var(i),I)*var(1)^(i-1);
   }
@@ -750,3 +1040,41 @@ static proc add_if_new(list L, ideal I)
   }
   return(L,newelement);
 }
+
+static proc Z_get_minpoly(int size_of_ring, string parname)
+{
+  def original_ring = basering;
+  ring new_ring = (size_of_ring, A),x,lp;
+  string S = string(minpoly);
+  string SMP;
+  if(S=="0"){
+    SMP = SMP+parname;
+  }else{
+    for(int i=1; i<=size(S); i++){
+      if(S[i]=="A"){
+        SMP = SMP+parname;
+      }else{
+        SMP = SMP+S[i];
+      }
+    }
+  }
+  return(SMP);
+}
+
+static proc Z_phi(ideal I)
+{
+  poly f;
+  for(int i=1; i<= ncols(I); i++){
+    f = f+I[i]*@y^(i-1);
+  }
+  return(f);
+}
+
+static proc Z_default_ideal(int number_of_variables, int q)
+{
+  ideal DI;
+  for(int i=1; i<=number_of_variables; i++){
+    DI[i] = var(i)^q-var(i);
+  }
+  return(std(DI));
+}

-- 
an open source computer algebra system



More information about the debian-science-commits mailing list