/kernel/groebner_walk/walkProc.cc

https://github.com/ederc/Sources · C++ · 358 lines · 246 code · 43 blank · 69 comment · 85 complexity · 452e7a630829d813c8f9604cee20b939 MD5 · raw file

  1. /****************************************
  2. * Computer Algebra System SINGULAR *
  3. ****************************************/
  4. #include "kernel/mod2.h"
  5. #include "kernel/structs.h"
  6. #include "kernel/structs.h"
  7. #include "kernel/polys.h"
  8. #include "kernel/ideals.h"
  9. #include "polys/monomials/ring.h"
  10. #include "polys/monomials/maps.h"
  11. #include "kernel/GBEngine/kstd1.h"
  12. #include "kernel/fglm/fglm.h"
  13. #include "kernel/groebner_walk/walkMain.h"
  14. #include "kernel/groebner_walk/walkSupport.h"
  15. #include "kernel/groebner_walk/walkProc.h"
  16. #include "polys/prCopy.h"
  17. ///////////////////////////////////////////////////////////////////
  18. //Frame procedures for Groebner Walk and Fractal Walk
  19. ///////////////////////////////////////////////////////////////////
  20. //v1.3 2004-11-15
  21. ///////////////////////////////////////////////////////////////////
  22. //implemented by Henrik Strohmayer
  23. ///////////////////////////////////////////////////////////////////
  24. ///////////////////////////////////////////////////////////////////
  25. //walkConsistency
  26. ///////////////////////////////////////////////////////////////////
  27. //Description:
  28. // Checks if the two rings sringHdl and dringHdl are compatible
  29. // enough to be used for the Walk. This means:
  30. // 1) Same Characteristic
  31. // 2) globalOrderings in both rings,
  32. // 3) Same number of variables
  33. // 4) same number of parameters
  34. // 5) variables in one ring have the same names
  35. // and order as variables of the other
  36. // 6) parameters in one ring have the same names
  37. // and order as parameters of the other
  38. // 7) none of the rings are qrings
  39. // vperm must be a vector of length (currRing->N)+1, initialized by 0.
  40. // If both rings are compatible, it stores the permutation of the
  41. // variables if mapped from sringHdl to dringHdl.
  42. // if the rings are compatible, it returns WalkOk.
  43. // Should be called with currRing= IDRING( sringHdl );
  44. ///////////////////////////////////////////////////////////////////
  45. //Uses: IDRING,WerrorS,rPar,omAlloc0,maFindPerm,omFreeSize,sizeof
  46. ///////////////////////////////////////////////////////////////////
  47. WalkState
  48. walkConsistency( ring sring, ring dring, int * vperm )
  49. {
  50. int k;
  51. WalkState state= WalkOk;
  52. if ( sring->cf != dring->cf )
  53. {
  54. WerrorS( "rings must have same characteristic" );
  55. state= WalkIncompatibleRings;
  56. }
  57. else if ( (rHasLocalOrMixedOrdering(sring))
  58. || (rHasLocalOrMixedOrdering(dring)) )
  59. {
  60. WerrorS( "only works for global orderings" );
  61. state= WalkIncompatibleRings;
  62. }
  63. else if ( sring->N != dring->N )
  64. {
  65. WerrorS( "rings must have same number of variables" );
  66. state= WalkIncompatibleRings;
  67. }
  68. else if ( rPar(sring) != rPar(dring) )
  69. {
  70. WerrorS( "rings must have same number of parameters" );
  71. state= WalkIncompatibleRings;
  72. }
  73. if ( state != WalkOk ) return state;
  74. // now the rings have the same number of variables resp. parameters.
  75. // check if the names of the variables resp. parameters do agree:
  76. int nvar = rVar(sring);
  77. int npar = rPar(sring);
  78. int * pperm;
  79. char **snames;
  80. char **dnames;
  81. if ( npar > 0 )
  82. {
  83. snames=sring->cf->extRing->names;
  84. dnames=dring->cf->extRing->names;
  85. pperm= (int *)omAlloc0( (npar+1)*sizeof( int ) );
  86. }
  87. else
  88. {
  89. snames=NULL;
  90. dnames=NULL;
  91. pperm= NULL;
  92. }
  93. maFindPerm( sring->names, nvar, snames, npar,
  94. dring->names, nvar, dnames, npar, vperm, pperm,
  95. dring->cf->type);
  96. for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
  97. if ( vperm[k] <= 0 )
  98. {
  99. WerrorS( "variable names do not agree" );
  100. state= WalkIncompatibleRings;
  101. }
  102. for ( k= npar-1; (k >= 0) && (state == WalkOk); k-- )
  103. if ( pperm[k] >= 0 )
  104. {
  105. WerrorS( "parameter names do not agree" );
  106. state= WalkIncompatibleRings;
  107. }
  108. //remove this to if you want to allow permutations of variables
  109. for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
  110. if ( vperm[k] != (k) )
  111. {
  112. WerrorS( "orders of variables do not agree" );
  113. state= WalkIncompatibleRings;
  114. }
  115. //remove this to if you want to allow permutations of parameters
  116. for ( k= npar; (k > 0) && (state == WalkOk); k-- )
  117. {
  118. if ( pperm[k-1] != (-k) )
  119. {
  120. WerrorS( "orders of parameters do not agree" );
  121. state= WalkIncompatibleRings;
  122. }
  123. }
  124. if (pperm != NULL)
  125. omFreeSize( (ADDRESS)pperm, (npar+1)*sizeof( int ) );
  126. if ( state != WalkOk ) return state;
  127. // check if any of the rings are qrings or not
  128. if ( (sring->qideal != NULL) || (dring->qideal != NULL) )
  129. {
  130. WerrorS( "rings are not allowed to be qrings");
  131. return WalkIncompatibleRings;
  132. }
  133. int i=0;
  134. while(dring->order[i]!=0)
  135. {
  136. if(
  137. !(dring->order[i]==ringorder_a) &&
  138. !(dring->order[i]==ringorder_a64) &&
  139. !(dring->order[i]==ringorder_lp) &&
  140. !(dring->order[i]==ringorder_dp) &&
  141. !(dring->order[i]==ringorder_Dp) &&
  142. !(dring->order[i]==ringorder_wp) &&
  143. !(dring->order[i]==ringorder_Wp) &&
  144. !(dring->order[i]==ringorder_C) &&
  145. !(dring->order[i]==ringorder_M)
  146. )
  147. {
  148. state=WalkIncompatibleDestRing;
  149. }
  150. i++;
  151. }
  152. i=0;
  153. while(sring->order[i]!=0)
  154. {
  155. if(
  156. !(sring->order[i]==ringorder_a) &&
  157. !(sring->order[i]==ringorder_a64) &&
  158. !(sring->order[i]==ringorder_lp) &&
  159. !(sring->order[i]==ringorder_dp) &&
  160. !(sring->order[i]==ringorder_Dp) &&
  161. !(sring->order[i]==ringorder_wp) &&
  162. !(sring->order[i]==ringorder_Wp) &&
  163. !(sring->order[i]==ringorder_C) &&
  164. !(sring->order[i]==ringorder_M)
  165. )
  166. {
  167. state=WalkIncompatibleSourceRing;
  168. }
  169. i++;
  170. }
  171. return state;
  172. }
  173. ///////////////////////////////////////////////////////////////////
  174. ///////////////////////////////////////////////////////////////////
  175. //fractalWalkConsistency
  176. ///////////////////////////////////////////////////////////////////
  177. //Description:
  178. // Checks if the two rings sringHdl and dringHdl are compatible
  179. // enough to be used for the Walk. This means:
  180. // 1) Same Characteristic
  181. // 2) globalOrderings in both rings,
  182. // 3) Same number of variables
  183. // 4) same number of parameters
  184. // 5) variables in one ring have the same names
  185. // and order as variables of the other
  186. // 6) parameters in one ring have the same names
  187. // and order as parameters of the other
  188. // 7) none of the rings are qrings
  189. // vperm must be a vector of length (currRing->N)+1, initialized by 0.
  190. // If both rings are compatible, it stores the permutation of the
  191. // variables if mapped from sringHdl to dringHdl.
  192. // if the rings are compatible, it returns WalkOk.
  193. // Should be called with currRing= IDRING( sringHdl );
  194. ///////////////////////////////////////////////////////////////////
  195. //Uses: IDRING,WerrorS,rPar,omAlloc0,maFindPerm,omFreeSize,sizeof
  196. ///////////////////////////////////////////////////////////////////
  197. WalkState
  198. fractalWalkConsistency( ring sring, ring dring, int * vperm )
  199. {
  200. int k;
  201. WalkState state= WalkOk;
  202. if ( rChar(sring) != rChar(dring) )
  203. {
  204. WerrorS( "rings must have same characteristic" );
  205. state= WalkIncompatibleRings;
  206. }
  207. if ( (rHasLocalOrMixedOrdering(sring))
  208. || (rHasLocalOrMixedOrdering(dring)) )
  209. {
  210. WerrorS( "only works for global orderings" );
  211. state= WalkIncompatibleRings;
  212. }
  213. if ( rVar(sring) != rVar(dring) )
  214. {
  215. WerrorS( "rings must have same number of variables" );
  216. state= WalkIncompatibleRings;
  217. }
  218. if ( rPar(sring) != rPar(dring) )
  219. {
  220. WerrorS( "rings must have same number of parameters" );
  221. state= WalkIncompatibleRings;
  222. }
  223. if ( state != WalkOk ) return state;
  224. // now the rings have the same number of variables resp. parameters.
  225. // check if the names of the variables resp. parameters do agree:
  226. int nvar = sring->N;
  227. int npar = rPar(sring);
  228. int * pperm;
  229. char **snames;
  230. char **dnames;
  231. if ( npar > 0 )
  232. {
  233. snames=sring->cf->extRing->names;
  234. dnames=dring->cf->extRing->names;
  235. pperm= (int *)omAlloc0( (npar+1)*sizeof( int ) );
  236. }
  237. else
  238. {
  239. pperm= NULL;
  240. snames=NULL;
  241. dnames=NULL;
  242. }
  243. maFindPerm( sring->names, nvar, snames, npar,
  244. dring->names, nvar, dnames, npar, vperm, pperm,
  245. dring->cf->type);
  246. for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
  247. if ( vperm[k] <= 0 )
  248. {
  249. WerrorS( "variable names do not agree" );
  250. state= WalkIncompatibleRings;
  251. }
  252. for ( k= npar; (k > 0) && (state == WalkOk); k-- )
  253. if ( pperm[k-1] >= 0 )
  254. {
  255. WerrorS( "parameter names do not agree" );
  256. state= WalkIncompatibleRings;
  257. }
  258. //check if order of variables resp. parameters does agree
  259. //remove this to if you want to allow permutations of variables
  260. for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
  261. if ( vperm[k] != (k) )
  262. {
  263. WerrorS( "orders of variables do not agree" );
  264. state= WalkIncompatibleRings;
  265. }
  266. //remove this to if you want to allow permutations of parameters
  267. for ( k= npar; (k > 0) && (state == WalkOk); k-- )
  268. if ( pperm[k-1] != (-k) )
  269. {
  270. WerrorS( "orders of parameters do not agree" );
  271. state= WalkIncompatibleRings;
  272. }
  273. if (pperm != NULL)
  274. omFreeSize( (ADDRESS)pperm, (npar+1)*sizeof( int ) );
  275. if ( state != WalkOk ) return state;
  276. // check if any of the rings are qrings or not
  277. if ( (sring->qideal != NULL) || (dring->qideal != NULL) )
  278. {
  279. WerrorS( "rings are not allowed to be qrings");
  280. return WalkIncompatibleRings;
  281. }
  282. int i=0;
  283. while(dring->order[i]!=0){
  284. if( !(dring->order[i]==ringorder_lp) &&
  285. !(dring->order[i]==ringorder_dp) &&
  286. !(dring->order[i]==ringorder_Dp) &&
  287. !(dring->order[i]==ringorder_wp) &&
  288. !(dring->order[i]==ringorder_Wp) &&
  289. !(dring->order[i]==ringorder_C) &&
  290. !(dring->order[0]==ringorder_M)
  291. )
  292. {
  293. state=WalkIncompatibleDestRing;
  294. }
  295. i++;
  296. }
  297. i=0;
  298. while(sring->order[i]!=0)
  299. {
  300. if( !(sring->order[i]==ringorder_lp) &&
  301. !(sring->order[i]==ringorder_dp) &&
  302. !(sring->order[i]==ringorder_Dp) &&
  303. !(sring->order[i]==ringorder_wp) &&
  304. !(sring->order[i]==ringorder_Wp) &&
  305. !(sring->order[i]==ringorder_C) &&
  306. !(dring->order[0]==ringorder_M)
  307. )
  308. {
  309. state=WalkIncompatibleSourceRing;
  310. }
  311. i++;
  312. }
  313. return state;
  314. }
  315. ///////////////////////////////////////////////////////////////////