Changeset 8b87364 in git for Singular/LIB/standard.lib


Ignore:
Timestamp:
Nov 5, 2001, 5:06:29 PM (22 years ago)
Author:
Gerhard Pfister <pfister@…>
Branches:
(u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
Children:
16105c8f405ac4e9d787fbd2bae347a9686645db
Parents:
5b3302cc6f7c9964ee19073aca0b273ad9e606a9
Message:
neue proceduren eingefuegt


git-svn-id: file:///usr/local/Singular/svn/trunk@5668 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/standard.lib

    r5b3302c r8b87364  
    11//////////////////////////////////////////////////////////////////////////////
    2 version="$Id: standard.lib,v 1.60 2001-08-28 12:54:05 Singular Exp $";
     2version="$Id: standard.lib,v 1.61 2001-11-05 16:05:08 pfister Exp $";
    33category="Miscellaneous";
    44info="
     
    1414 fprintf(link,fmt,..)   writes formatted string to link
    1515 printf(fmt,...)        displays formatted string
     16 timeStd(i,d)           std(i) if the standard basis computation finished after
     17                        d-1 seconds and i otherwhise
     18 timeFactorize(p,d)     factorize(p) if the factorization finished after d-1
     19                        seconds otherwhise f is considered to be irreducible
     20factorH(p)              changes variables to become the last variable the
     21                        principal one in the multivariate factorization and
     22                        factorizes then the polynomial
     23
    1624";
    1725
     
    10251033}
    10261034
     1035proc timeFactorize(poly i,list #)
     1036"USAGE:  timeFactorize(p,d)  poly p , integer d
     1037RETURN:  factorize(p) if the factorization finished after d-1
     1038         seconds otherwhise f is considered to be irreducible
     1039EXAMPLE: example timeFactorize; shows an example
     1040"
     1041{
     1042  def P=basering;
     1043  if (size(#) > 0)
     1044  {
     1045    if (system("with", "MP"))
     1046    {
     1047      if ((typeof(#[1]) == "int")&&(#[1]))
     1048      {
     1049        int wait = #[1];
     1050        int j = 10;
     1051
     1052        string bs = nameof(basering);
     1053        link l_fork = "MPtcp:fork";
     1054        open(l_fork);
     1055        write(l_fork, quote(system("pid")));
     1056        int pid = read(l_fork);
     1057        write(l_fork, quote(timeFactorize(eval(i))));
     1058
     1059        // sleep in small intervalls for appr. one second
     1060        if (wait > 0)
     1061        {
     1062          while(j < 1000000)
     1063          {
     1064            if (status(l_fork, "read", "ready", j)) {break;}
     1065            j = j + j;
     1066          }
     1067        }
     1068
     1069        // sleep in intervalls of one second from now on
     1070        j = 1;
     1071        while (j < wait)
     1072        {
     1073          if (status(l_fork, "read", "ready", 1000000)) {break;}
     1074          j = j + 1;
     1075        }
     1076
     1077        if (status(l_fork, "read", "ready"))
     1078        {
     1079          def result = read(l_fork);
     1080          if (bs != nameof(basering))
     1081          {
     1082            def PP = basering;
     1083            setring P;
     1084            def result = imap(PP, result);
     1085            kill PP;
     1086          }
     1087          kill (l_fork);
     1088        }
     1089        else
     1090        {
     1091          list result;
     1092          intvec v=1,1;
     1093          result[1]=list(1,i);
     1094          result[2]=v;
     1095          j = system("sh", "kill " + string(pid));
     1096        }
     1097        return (result);
     1098      }
     1099    }
     1100  }
     1101  return(factorH(i));
     1102}
     1103example
     1104{ "EXAMPLE:"; echo = 2;
     1105   ring r=0,(x,y),dp;
     1106   poly p=((x2+y3)^2+xy6)*((x3+y2)^2+x10y);
     1107   p=p^2;
     1108   timeFactorize(p,2);
     1109   timeFactorize(p,20);
     1110}
     1111
     1112proc timeStd(ideal i,list #)
     1113"USAGE:  timeStd(i,d), i ideal, d integer
     1114RETURN:  std(i) if the standard basis computation finished after
     1115         d-1 seconds and i otherwhise
     1116EXAMPLE: example timeStd; shows an example
     1117"
     1118{
     1119  def P=basering;
     1120  if (size(#) > 0)
     1121  {
     1122    if (system("with", "MP"))
     1123    {
     1124      if ((typeof(#[1]) == "int")&&(#[1]))
     1125      {
     1126        int wait = #[1];
     1127        int j = 10;
     1128
     1129        string bs = nameof(basering);
     1130        link l_fork = "MPtcp:fork";
     1131        open(l_fork);
     1132        write(l_fork, quote(system("pid")));
     1133        int pid = read(l_fork);
     1134        write(l_fork, quote(timeStd(eval(i))));
     1135
     1136        // sleep in small intervalls for appr. one second
     1137        if (wait > 0)
     1138        {
     1139          while(j < 1000000)
     1140          {
     1141            if (status(l_fork, "read", "ready", j)) {break;}
     1142            j = j + j;
     1143          }
     1144        }
     1145        j = 1;
     1146        while (j < wait)
     1147        {
     1148          if (status(l_fork, "read", "ready", 1000000)) {break;}
     1149          j = j + 1;
     1150        }
     1151        if (status(l_fork, "read", "ready"))
     1152        {
     1153          def result = read(l_fork);
     1154          if (bs != nameof(basering))
     1155          {
     1156            def PP = basering;
     1157            setring P;
     1158            def result = imap(PP, result);
     1159            kill PP;
     1160          }
     1161          kill (l_fork);
     1162        }
     1163        else
     1164        {
     1165          ideal result=i;
     1166          j = system("sh", "kill " + string(pid));
     1167        }
     1168        return (result);
     1169      }
     1170    }
     1171  }
     1172  return(std(i));
     1173}
     1174example
     1175{ "EXAMPLE:"; echo = 2;
     1176   ring r=32003,(a,b,c,d,e),dp;
     1177   int n=6;
     1178   ideal i=
     1179   a^n-b^n,
     1180   b^n-c^n,
     1181   c^n-d^n,
     1182   d^n-e^n,
     1183   a^(n-1)*b+b^(n-1)*c+c^(n-1)*d+d^(n-1)*e+e^(n-1)*a;
     1184   timeStd(i,2);
     1185   timeStd(i,20);
     1186}
     1187
     1188proc factorH(poly p)
     1189"USAGE:  factorH(p)  p poly
     1190RETURN:  factorize(p)
     1191NOTE:    changes variables to become the last variable the principal
     1192         one in the multivariate factorization and factorizes then
     1193         the polynomial
     1194EXAMPLE: example factorH; shows an example
     1195"
     1196{
     1197   def R=basering;
     1198   int i,j;
     1199   int n=1;
     1200   int d=nrows(coeffs(p,var(1)));
     1201   for(i=1;i<=nvars(R);i++)
     1202   {
     1203      j=nrows(coeffs(p,var(i)));
     1204      if(d>j)
     1205      {
     1206         n=i;
     1207         d=j;
     1208      }
     1209   }
     1210   ideal ma=maxideal(1);    //die letzte Variable ist die Hauptvariable
     1211   ma[nvars(R)]=var(n);
     1212   ma[n]=var(nvars(R));
     1213   map phi=R,ma;
     1214   list fac=factorize(phi(p));
     1215   list re=phi(fac);
     1216   return(re);
     1217}
     1218example
     1219{ "EXAMPLE:"; echo = 2;
     1220  system("random",992851144);
     1221  ring r=32003,(x,y,z,w,t),lp;
     1222  poly p=y2w9+yz7t-yz5w4-z2w4t4-w8t3;
     1223  factorize(p);  //fast
     1224  system("random",992851262);
     1225  factorize(p);  //slow
     1226  system("random",992851262);
     1227  factorH(p);
     1228}
     1229
    10271230/*
    10281231proc minres(list #)
Note: See TracChangeset for help on using the changeset viewer.