Changeset ff2859d in git
- Timestamp:
- Oct 26, 2018, 8:21:54 PM (6 years ago)
- Branches:
- (u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'b4f17ed1d25f93d46dbe29e4b499baecc2fd51bb')
- Children:
- 7e94f3d724c603bff225ef75ac25ce4722b500ca
- Parents:
- 5c73a12e2a76e9452bc04071e2ff07ca8dc0912539ccee4a37dbeac2e9321f1ab6ad47ceb1df2855
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/ncHilb.lib
r39ccee rff2859d 1 1 ////////////////////////////////////////////////////////////////////////////// 2 2 version="version nc_hilb.lib 4.1.1.0 Dec_2017 "; // $Id$ 3 category="Noncommutative algebra";3 category="Noncommutative"; 4 4 info=" 5 LIBRARY: fpahilb.lib: A library for computing graded and multi-graded Hilbert 6 series of general non-commutative algebras (available via Letterplace). 7 It also computes the truncated Hilbert series of the algebras whose Hilbert 8 series are possibly not rational or unknown. 5 LIBRARY: fpahilb.lib: Computation of graded and multi-graded Hilbert series of non-commutative algebras (Letterplace). 9 6 10 7 AUTHOR: Sharwan K. Tiwari shrawant@gmail.com … … 18 15 La Scala R., Tiwari Sharwan K.: Multigraded Hilbert Series of noncommutative modules, https://arxiv.org/abs/1705.01083. 19 16 17 KEYWORDS: finitely presented algebra; infinitely presented algebra; graded Hilbert series; multi-graded Hilbert series; 18 20 19 PROCEDURES: 21 20 fpahilb(L,d,#); Hilbert series of a non-commutative algebra … … 36 35 @* N>2: computation of truncated Hilbert series up to degree N-1, and 37 36 @* nonempty string: the details about the orbit and system of equations will be printed. 38 39 37 Let the orbit be @code{O_I = {T_{w_1}(I),...,T_{w_r}(I)} ($w_i\in W$)}, where we assume that if @code{T_{w_i}(I)=T_{w_i'}(I)} 40 38 for some @code{w'_i\in W}, then @code{deg(w_i)\leq deg(w'_i)} follows. … … 43 41 where @code{{b_j}} is a basis of I. 44 42 Moreover, it also prints the linear system (for the information about adjacency matrix). 45 46 43 EXAMPLE: example fpahilb; shows an example " 47 44 { 48 if (attrib( @R, "isLetterplaceRing")==0)45 if (attrib(basering, "isLetterplaceRing")==0) 49 46 { 50 47 ERROR("Basering should be Letterplace ring"); … … 58 55 string odp=""; 59 56 int i; 60 for(i=sz ;i >= 1; i--)57 for(i=sz; i >= 1; i--) 61 58 { 62 59 if(typeof(#[i])=="string") … … 72 69 } 73 70 i=1; 74 // only one optional parameter (for printing the details) is allowed as a string.75 while( typeof(#[i])=="int" && i<=sz)76 { 77 if( #[i] == 1 && ig==0)71 // VL: changing the old "only one optional parameter (for printing the details) is allowed as a string." 72 while( (typeof(#[i])=="int") && (i<=sz) ) 73 { 74 if( (#[i] == 1) && (ig==0) ) 78 75 { 79 76 ig = 1; … … 81 78 else 82 79 { 83 if (#[i] == 2 && mgrad==0)80 if ( (#[i] == 2) && (mgrad==0) ) 84 81 { 85 82 mgrad = 2; … … 87 84 else 88 85 { 89 if (#[i] > 2 && tdeg==0)86 if ( (#[i] > 2) && (tdeg==0) ) 90 87 { 91 88 tdeg = #[i]; … … 103 100 ERROR("error:only int 1,2, >2, and a string are allowed as optional parameters"); 104 101 } 105 /* new: truncation should be < than degbound */106 if (tdeg > lV)102 /* new: truncation should be < than degbound/2 */ 103 if (tdeg > lV div 2 + 1) 107 104 { 108 ERROR(" unappropriate degree bound");105 ERROR("degree bound is too high"); 109 106 } 110 107 ideal J_lm = I; … … 130 127 def R = makeLetterplaceRing(10); setring R; 131 128 ideal I = Y*Z, Y*Z*X, Y*Z*Z*X, Y*Z*Z*Z*X, Y*Z*Z*Z*Z*X, Y*Z*Z*Z*Z*Z*X, Y*Z*Z*Z*Z*Z*Z*X, Y*Z*Z*Z*Z*Z*Z*Z*X; 132 nchilb(I,10);129 fpahilb(I,5); 133 130 kill R; 134 131 … … 139 136 // inspecting J we see that this is a homogeneous Groebner basis 140 137 // which is potentially infinite, i.e. J is not finitely generated 141 nchilb(I,6,1); //third argument '1' is for non-finitely generated case 142 143 ring r=0,(a,b),dp; 144 ideal I = a^3, a*b^2, a^2*b; 145 nchilb(l3,5,2); //third argument '2' is to compute multi-graded Hilbert series 138 fpahilb(J,5,1,2,"p"); // '1' i for non-finitely generated case, string to print details 139 //'5' here is to compute the truncated HS up to degree 5. 140 //'2' is to compute multi-graded Hilbert series 141 fpahilb(J,3,1,"p"); 142 } 143 144 // overhauled by VL 145 proc rcolon(ideal I, poly W) 146 "USAGE: rcolon(I,w); ideal I, poly w 147 RETURNS: ideal 148 ASSUME: - basering is a Letterplace ring 149 - W is a monomial 150 - I is a monomial ideal 151 PURPOSE: compute a right colon ideal of I by a monomial w 152 NOTE: Output is the set of generators, which should be added to I 153 EXAMPLE: example rcolon; shows an example" 154 { 155 int lV = attrib(R,"isLetterplaceRing"); //nvars(save); 156 if (lV == 0) 157 { 158 ERROR("Basering must be a Letterplace ring"); 159 } 160 poly wc = leadmonom(W); 161 ideal II = lead(I); 162 ideal J = system("rcolon", II, wc, lV); 163 // VL: printlevel here? before only printing was there, no output 164 return(J); 165 } 166 example 167 { 168 "EXAMPLE:"; echo = 2; 169 ring r=0,(X,Y,Z),dp; 170 def R = makeLetterplaceRing(10); setring R; 171 ideal I = Y*Z, Y*Z*X, Y*Z*Z*X, Y*Z*Z*Z*X, Y*Z*Z*Z*Z*X, Y*Z*Z*Z*Z*Z*X, Y*Z*Z*Z*Z*Z*Z*X, Y*Z*Z*Z*Z*Z*Z*Z*X; 172 poly w = Y; 173 ideal J = rcolon(I,w); 174 J; // new generators, which need to be added to I 175 } 176 177 178 /* 179 proc nchilb(list L_wp, int d, list #) 180 "USAGE: fpahilb(I, d[, L]), ideal I, int d, optional list L 181 PURPOSE: compute Hilbert series of a non-commutative algebra 182 ASSUME: 183 NOTE: d is an integer for the degree bound (maximal total degree of 184 polynomials of the generating set of the input ideal), 185 #[]=1, computation for non-finitely generated regular ideals, 186 #[]=2, computation of multi-graded Hilbert series, 187 #[]=tdeg, for obtaining the truncated Hilbert series up to the total degree tdeg-1 (tdeg should be > 2), and 188 #[]=string(p), to print the details about the orbit and system of equations. 189 Let the orbit is O_I = {T_{w_1}(I),...,T_{w_r}(I)} ($w_i\in W$), where we assume that if T_{w_i}(I)=T_{w_i'}(I)$ 190 for some $w'_i\in W$, then $deg(w_i)\leq deg(w'_i)$. 191 Then, it prints words description of orbit: w_1,...,w_r. 192 It also prints the maximal degree and the cardinality of \sum_j R(w_i, b_j) corresponding to each w_i, 193 where {b_j} is a basis of I. 194 Moreover, it also prints the linear system (for the information about adjacency matrix) and its solving time. 195 196 NOTE : A Groebner basis of two-sided ideal of the input should be given in a 197 special form. This form is a list of modules, where each generator 198 of every module represents a monomial times a coefficient in the free 199 associative algebra. The first entry, in each generator, represents a 200 coefficient and every next entry is a variable. 201 202 Ex: module p1=[1,y,z],[-1,z,y], represents the poly y*z-z*y; 203 module p2=[1,x,z,x],[-1,z,x,z], represents the poly x*z*x-z*x*z 204 for more details about the input, see examples. 205 EXAMPLE: example nchilb; shows an example " 206 { 207 if (d<1) 208 { 209 ERROR("bad degree bound"); 210 } 211 212 def save = basering; 213 int sz=size(#); 214 int lV=nvars(save); 215 int ig=0; 216 int mgrad=0; 217 int tdeg=0; 218 string odp=""; 219 int i; 220 for(i=sz ;i >= 1; i--) 221 { 222 if(typeof(#[i])=="string") 223 { 224 if(#[i]!="") 225 { 226 odp = "p"; 227 } 228 # = delete(#,i); 229 sz = sz-1; 230 break; 231 } 232 } 233 i=1; 234 //only one optional parameter (for printing the details) is allowed as a string. 235 while(typeof(#[i])=="int" && i<=sz) 236 { 237 if(#[i] == 1 && ig==0) 238 { 239 ig = 1; 240 } 241 else 242 { 243 if(#[i] == 2 && mgrad==0) 244 { 245 mgrad = 2; 246 } 247 else 248 { 249 if(#[i] > 2 && tdeg==0) 250 { 251 tdeg = #[i]; 252 } 253 else 254 { 255 ERROR("error: only int 1,2 and >2 are allowed as 256 optional parameters"); 257 } 258 } 259 } 260 i = i + 1; 261 } 262 if( i <= sz) 263 { 264 ERROR("error:only int 1,2, >2, and a string are allowed as 265 optional parameters"); 266 } 267 if(tdeg==0) 268 {def R = makeLetterplaceRing(2*d);} 269 else 270 {def R = makeLetterplaceRing(2*(tdeg-1));} 271 setring R; 272 ideal I; 273 poly p; 274 poly q=0; 275 // convert list L_wp of free-poly to letterPlace-poly format 276 setring save; 277 module M; 278 int j,k,sw,sm,slm; 279 vector w; 280 poly pc=0; 281 intvec v; 282 slm = size(L_wp); // number of polys in the given ideal 283 for (i=1; i<=slm; i++) 284 { 285 M = L_wp[i]; 286 sm = ncols(M); // number of words in the free-poly M 287 for (j=1; j<=sm; j++) 288 { 289 w = M[j]; 290 sw = size(w); 291 for (k=2; k<=sw; k++) 292 { 293 v[k-1]=rvar(w[k]); 294 } 295 pc=w[1]; 296 setring R; 297 p=imap(save,pc); 298 for (k=2; k<=sw; k++) 299 { 300 p=p*var(v[k-1]+(k-2)*lV); 301 } 302 q=q+p; 303 setring save; 304 } 305 setring R; 306 I = I,q; //lp-polynomial added to I 307 q=0; //ready for the next polynomial 308 setring save; 309 } 310 setring R; 311 I=simplify(I,2); 312 ideal J_lm; 313 for(i=1;i<=size(I);i++) 314 { 315 J_lm[i]=leadmonom(I[i]); 316 } 317 //compute the Hilbert series 318 if(odp == "") 319 {system("nc_hilb", J_lm, lV, ig, mgrad,tdeg);} 320 else 321 {system("nc_hilb", J_lm, lV, ig, mgrad,tdeg, odp);} 322 } 323 324 example 325 { 326 "EXAMPLE:"; echo = 2; 327 328 ring r=0,(X,Y,Z),dp; 329 module p1 =[1,Y,Z]; //represents the poly Y*Z 330 module p2 =[1,Y,Z,X]; //represents the poly Y*Z*X 331 module p3 =[1,Y,Z,Z,X,Z]; 332 module p4 =[1,Y,Z,Z,Z,X,Z]; 333 module p5 =[1,Y,Z,Z,Z,Z,X,Z]; 334 module p6 =[1,Y,Z,Z,Z,Z,Z,X,Z]; 335 module p7 =[1,Y,Z,Z,Z,Z,Z,Z,X,Z]; 336 module p8 =[1,Y,Z,Z,Z,Z,Z,Z,Z,X,Z]; 337 list l1=list(p1,p2,p3,p4,p5,p6,p7,p8); 338 nchilb(l1,10); 339 340 ring r=0,(x,y,z),dp; 341 342 module p1=[1,y,z],[-1,z,y]; //y*z-z*y 343 module p2=[1,x,z,x],[-1,z,x,z]; // x*z*x-z*x*z 344 module p3=[1,x,z,z,x,z],[-1,z,x,z,z,x]; // x*z^2*x*z-z*x*z^2*x 345 module p4=[1,x,z,z,z,x,z];[-1,z,x,z,z,x,x]; // x*z^3*x*z-z*x*z^2*x^2 346 list l2=list(p1,p2,p3,p4); 347 348 nchilb(l2,6,1); //third argument '1' is for non-finitely generated case 349 350 ring r=0,(a,b),dp; 351 module p1=[1,a,a,a]; 352 module p2=[1,a,b,b]; 353 module p3=[1,a,a,b]; 354 355 list l3=list(p1,p2,p3); 356 nchilb(l3,5,2);//third argument '2' is to compute multi-graded HS 146 357 147 358 ring r=0,(x,y,z),dp; … … 187 398 //'11' is to compute the truncated HS up to degree 10. 188 399 } 189 190 // overhauled by VL191 proc rcolon(ideal I, poly W)192 "USAGE: rcolon(I,w,d); ideal I, poly w193 RETURNS: ideal194 ASSUME: - basering is a Letterplace ring195 - W is a monomial196 - I is a monomial ideal197 PURPOSE: compute a right colon ideal of I by a monomial w198 NOTE: Output is the set of generators, which should be added to I199 EXAMPLE: example rcolon; shows an example"200 {201 if (d<1)202 {203 ERROR("bad degree bound");204 }205 int lV = attrib(R,"isLetterplaceRing"); //nvars(save);206 if (lV == 0)207 {208 ERROR("Basering must be a Letterplace ring");209 }210 poly wc = leadmonom(W);211 ideal II = lead(I);212 ideal J = system("rcolon", II, wc, lV);213 // VL: printlevel here? before only printing was there, no output214 return(J);215 }216 example217 {218 "EXAMPLE:"; echo = 2;219 ring r=0,(X,Y,Z),dp;220 poly w = Y;221 ideal I = Y*Z, Y*Z*X, Y*Z*Z*X, Y*Z*Z*Z*X, Y*Z*Z*Z*Z*X, Y*Z*Z*Z*Z*Z*X, Y*Z*Z*Z*Z*Z*Z*X, Y*Z*Z*Z*Z*Z*Z*Z*X;222 ideal J = rcolon(I,w,10);223 J; // new generators, which need to be added to I224 }225 226 227 /*228 proc nchilb(list L_wp, int d, list #)229 "USAGE: fpahilb(I, d[, L]), ideal I, int d, optional list L230 PURPOSE: compute Hilbert series of a non-commutative algebra231 ASSUME:232 NOTE: d is an integer for the degree bound (maximal total degree of233 polynomials of the generating set of the input ideal),234 #[]=1, computation for non-finitely generated regular ideals,235 #[]=2, computation of multi-graded Hilbert series,236 #[]=tdeg, for obtaining the truncated Hilbert series up to the total degree tdeg-1 (tdeg should be > 2), and237 #[]=string(p), to print the details about the orbit and system of equations.238 Let the orbit is O_I = {T_{w_1}(I),...,T_{w_r}(I)} ($w_i\in W$), where we assume that if T_{w_i}(I)=T_{w_i'}(I)$239 for some $w'_i\in W$, then $deg(w_i)\leq deg(w'_i)$.240 Then, it prints words description of orbit: w_1,...,w_r.241 It also prints the maximal degree and the cardinality of \sum_j R(w_i, b_j) corresponding to each w_i,242 where {b_j} is a basis of I.243 Moreover, it also prints the linear system (for the information about adjacency matrix) and its solving time.244 245 NOTE : A Groebner basis of two-sided ideal of the input should be given in a246 special form. This form is a list of modules, where each generator247 of every module represents a monomial times a coefficient in the free248 associative algebra. The first entry, in each generator, represents a249 coefficient and every next entry is a variable.250 251 Ex: module p1=[1,y,z],[-1,z,y], represents the poly y*z-z*y;252 module p2=[1,x,z,x],[-1,z,x,z], represents the poly x*z*x-z*x*z253 for more details about the input, see examples.254 EXAMPLE: example nchilb; shows an example "255 {256 if (d<1)257 {258 ERROR("bad degree bound");259 }260 261 def save = basering;262 int sz=size(#);263 int lV=nvars(save);264 int ig=0;265 int mgrad=0;266 int tdeg=0;267 string odp="";268 int i;269 for(i=sz ;i >= 1; i--)270 {271 if(typeof(#[i])=="string")272 {273 if(#[i]!="")274 {275 odp = "p";276 }277 # = delete(#,i);278 sz = sz-1;279 break;280 }281 }282 i=1;283 //only one optional parameter (for printing the details) is allowed as a string.284 while(typeof(#[i])=="int" && i<=sz)285 {286 if(#[i] == 1 && ig==0)287 {288 ig = 1;289 }290 else291 {292 if(#[i] == 2 && mgrad==0)293 {294 mgrad = 2;295 }296 else297 {298 if(#[i] > 2 && tdeg==0)299 {300 tdeg = #[i];301 }302 else303 {304 ERROR("error: only int 1,2 and >2 are allowed as305 optional parameters");306 }307 }308 }309 i = i + 1;310 }311 if( i <= sz)312 {313 ERROR("error:only int 1,2, >2, and a string are allowed as314 optional parameters");315 }316 if(tdeg==0)317 {def R = makeLetterplaceRing(2*d);}318 else319 {def R = makeLetterplaceRing(2*(tdeg-1));}320 setring R;321 ideal I;322 poly p;323 poly q=0;324 // convert list L_wp of free-poly to letterPlace-poly format325 setring save;326 module M;327 int j,k,sw,sm,slm;328 vector w;329 poly pc=0;330 intvec v;331 slm = size(L_wp); // number of polys in the given ideal332 for (i=1; i<=slm; i++)333 {334 M = L_wp[i];335 sm = ncols(M); // number of words in the free-poly M336 for (j=1; j<=sm; j++)337 {338 w = M[j];339 sw = size(w);340 for (k=2; k<=sw; k++)341 {342 v[k-1]=rvar(w[k]);343 }344 pc=w[1];345 setring R;346 p=imap(save,pc);347 for (k=2; k<=sw; k++)348 {349 p=p*var(v[k-1]+(k-2)*lV);350 }351 q=q+p;352 setring save;353 }354 setring R;355 I = I,q; //lp-polynomial added to I356 q=0; //ready for the next polynomial357 setring save;358 }359 setring R;360 I=simplify(I,2);361 ideal J_lm;362 for(i=1;i<=size(I);i++)363 {364 J_lm[i]=leadmonom(I[i]);365 }366 //compute the Hilbert series367 if(odp == "")368 {system("nc_hilb", J_lm, lV, ig, mgrad,tdeg);}369 else370 {system("nc_hilb", J_lm, lV, ig, mgrad,tdeg, odp);}371 }372 373 example374 {375 "EXAMPLE:"; echo = 2;376 377 ring r=0,(X,Y,Z),dp;378 module p1 =[1,Y,Z]; //represents the poly Y*Z379 module p2 =[1,Y,Z,X]; //represents the poly Y*Z*X380 module p3 =[1,Y,Z,Z,X,Z];381 module p4 =[1,Y,Z,Z,Z,X,Z];382 module p5 =[1,Y,Z,Z,Z,Z,X,Z];383 module p6 =[1,Y,Z,Z,Z,Z,Z,X,Z];384 module p7 =[1,Y,Z,Z,Z,Z,Z,Z,X,Z];385 module p8 =[1,Y,Z,Z,Z,Z,Z,Z,Z,X,Z];386 list l1=list(p1,p2,p3,p4,p5,p6,p7,p8);387 nchilb(l1,10);388 389 ring r=0,(x,y,z),dp;390 391 module p1=[1,y,z],[-1,z,y]; //y*z-z*y392 module p2=[1,x,z,x],[-1,z,x,z]; // x*z*x-z*x*z393 module p3=[1,x,z,z,x,z],[-1,z,x,z,z,x]; // x*z^2*x*z-z*x*z^2*x394 module p4=[1,x,z,z,z,x,z];[-1,z,x,z,z,x,x]; // x*z^3*x*z-z*x*z^2*x^2395 list l2=list(p1,p2,p3,p4);396 397 nchilb(l2,6,1); //third argument '1' is for non-finitely generated case398 399 ring r=0,(a,b),dp;400 module p1=[1,a,a,a];401 module p2=[1,a,b,b];402 module p3=[1,a,a,b];403 404 list l3=list(p1,p2,p3);405 nchilb(l3,5,2);//third argument '2' is to compute multi-graded HS406 407 ring r=0,(x,y,z),dp;408 module p1=[1,x,z,y,z,x,z];409 module p2=[1,x,z,x];410 module p3=[1,x,z,y,z,z,x,z];411 module p4=[1,y,z];412 module p5=[1,x,z,z,x,z];413 414 list l4=list(p1,p2,p3,p4,p5);415 nchilb(l4,7,"p"); //third argument "p" is to print the details416 // of the orbit and system417 418 ring r=0,(x,y,z),dp;419 420 module p1=[1,y,z,z];421 module p2=[1,y,y,z];422 module p3=[1,x,z,z];423 module p4=[1,x,z,y];424 module p5=[1,x,y,z];425 module p6=[1,x,y,y];426 module p7=[1,x,x,z];427 module p8=[1,x,x,y];428 module p9=[1,y,z,y,z];429 module p10=[1,y,z,x,z];430 module p11=[1,y,z,x,y];431 module p12=[1,x,z,x,z];432 module p13=[1,x,z,x,y];433 module p14=[1,x,y,x,z];434 module p15=[1,x,y,x,y];435 module p16=[1,y,z,y,x,z];436 module p17=[1,y,z,y,x,y];437 module p18=[1,y,z,y,y,x,z];438 module p19=[1,y,z,y,y,x,y];439 module p20=[1,y,z,y,y,y,x,z];440 module p21=[1,y,z,y,y,y,x,y];441 442 list l5=list(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,443 p14,p15,p16,p17,p18,p19,p20,p21);444 nchilb(l5,7,1,2,"p");445 446 nchilb(l5,7,1,2,11,"p");447 //'11' is to compute the truncated HS up to degree 10.448 }449 400 */ 450 401 -
Singular/dyn_modules/cohomo/cohomo.cc
r5c73a12 rff2859d 8 8 #include "kernel/mod2.h" 9 9 10 #include "omalloc/omalloc.h" 10 11 #include "misc/mylimits.h" 11 12 #include "libpolys/misc/intvec.h" … … 25 26 #include "kernel/linear_algebra/linearAlgebra.h"//for printNumber 26 27 #include "kernel/GBEngine/kstd1.h"//for gb 27 28 29 // #include <kernel/structs.h>30 // #include <kernel/polys.h>31 //ADICHANGES:32 28 #include <kernel/ideals.h> 33 // #include <kernel/GBEngine/kstd1.h>34 // #include<gmp.h>35 // #include<vector>36 37 //# define omsai 138 //#if omsai39 //#if HAVE_STANLEYREISNER40 29 #if 1 41 30 … … 47 36 #include <Singular/ipshell.h> 48 37 #include <Singular/libsingular.h> 49 50 51 52 53 54 55 56 /******************************************************************************/ 57 58 59 60 61 62 /***************************print***********************************************/ 63 //print vector 38 #include <time.h> 39 40 41 42 43 44 45 46 /***************************print(only for debugging)***********************************************/ 47 //print vector of integers. 64 48 void listprint(std::vector<int> vec) 65 49 { … … 78 62 79 63 80 //print vector of vectors 64 //print vector of vectors of integers. 81 65 void listsprint(std::vector<std::vector<int> > posMat) 82 66 { … … 97 81 98 82 99 83 //print ideal. 100 84 void id_print(ideal h) 101 85 { … … 106 90 pWrite(h->m[i]); 107 91 PrintLn(); 108 //PrintS(",");109 110 } 111 112 113 114 115 / ************************only for T^2**********************************/92 } 93 } 94 95 96 97 98 //only for T^2, 99 //print vector of polynomials. 116 100 void lpprint( std::vector<poly> pv) 117 101 { … … 130 114 131 115 132 116 //print vector of vectors of polynomials. 133 117 void lpsprint(std::vector<std::vector<poly> > pvs) 134 118 { … … 152 136 153 137 154 /*****************************About simplicial complex and stanly-reisner ring**************************/ 155 156 157 158 159 160 161 162 163 138 139 140 141 142 /*************operations for vectors (regard vectors as sets)*********/ 143 144 //returns true if integer n is in vector vec, 145 //otherwise, returns false 146 bool IsinL(int a, std::vector<int> vec) 147 { 148 int i; 149 for(i=0;i<vec.size();i++) 150 { 151 if(a==vec[i]) 152 { 153 return true; 154 } 155 } 156 return false; 157 } 158 159 160 161 162 163 //returns intersection of vectors p and q, 164 //returns empty if they are disjoint 165 std::vector<int> vecIntersection(std::vector<int> p, std::vector<int> q) 166 { 167 int i; 168 std::vector<int> inte; 169 for(i=0;i<p.size();i++) 170 { 171 if(IsinL(p[i],q)) 172 inte.push_back(p[i]); 173 } 174 return inte; 175 } 176 177 178 179 180 181 182 183 184 185 //returns true if vec1 is equal to vec2 (strictly equal, including the order) 186 //is not used 187 bool vEv(std::vector<int> vec1,std::vector<int> vec2) 188 { 189 int i,j, lg1=vec1.size(),lg2=vec2.size(); 190 if(lg1!=lg2) 191 { 192 return false; 193 } 194 else 195 { 196 for(j=0;j<vec1.size();j++) 197 { 198 if(vec1[j]!=vec2[j]) 199 return false; 200 } 201 } 202 return true; 203 } 204 205 206 207 208 //returns true if vec1 is contained in vec2 209 bool vsubset(std::vector<int> vec1, std::vector<int> vec2) 210 { 211 int i; 212 if(vec1.size()>vec2.size()) 213 return false; 214 for(i=0;i<vec1.size();i++) 215 { 216 if(!IsinL(vec1[i],vec2)) 217 return false; 218 } 219 return true; 220 } 221 222 //not strictly equal(order doesn't matter) 223 bool vEvl(std::vector<int> vec1, std::vector<int> vec2) 224 { 225 if(vec1.size()==0 && vec2.size()==0) 226 return true; 227 if(vsubset(vec1,vec2)&&vsubset(vec2,vec1)) 228 return true; 229 return false; 230 } 231 232 233 //the length of vec must be same to it of the elements of vecs 234 //returns true if vec is as same as some element of vecs ((not strictly same)) 235 //returns false if vec is not in vecs 236 bool vInvsl(std::vector<int> vec, std::vector<std::vector<int> > vecs) 237 { 238 int i; 239 for(i=0;i<vecs.size();i++) 240 { 241 if(vEvl(vec,vecs[i])) 242 { 243 return true; 244 } 245 } 246 return false; 247 } 248 249 250 //the length of vec must be same to it of the elements of vecs (strictly same) 251 //returns the position of vec in vecs, 252 //returns -1 if vec is not in vecs 253 //actrually is not used. 254 int vInvs(std::vector<int> vec, std::vector<std::vector<int> > vecs) 255 { 256 int i; 257 for(i=0;i<vecs.size();i++) 258 { 259 if(vEv(vec,vecs[i])) 260 { 261 return i+1; 262 } 263 } 264 return -1; 265 } 266 267 268 269 //returns the union of two vectors(as the union of sets) 270 std::vector<int> vecUnion(std::vector<int> vec1, std::vector<int> vec2) 271 { 272 std::vector<int> vec=vec1; 273 int i; 274 for(i=0;i<vec2.size();i++) 275 { 276 if(!IsinL(vec2[i],vec)) 277 vec.push_back(vec2[i]); 278 } 279 return vec; 280 } 281 282 283 284 std::vector<int> vecMinus(std::vector<int> vec1,std::vector<int> vec2) 285 { 286 std::vector<int> vec; 287 for(int i=0;i<vec1.size();i++) 288 { 289 if(!IsinL(vec1[i],vec2)) 290 { 291 vec.push_back(vec1[i]); 292 } 293 } 294 return vec; 295 } 296 297 298 299 300 301 302 std::vector<std::vector<int> > vsMinusv(std::vector<std::vector<int> > vecs, std::vector<int> vec) 303 { 304 int i; 305 std::vector<std::vector<int> > rem; 306 for(i=0;i<vecs.size();i++) 307 { 308 if(!vEvl(vecs[i],vec)) 309 { 310 rem.push_back(vecs[i]); 311 } 312 } 313 return (rem); 314 } 315 316 317 std::vector<std::vector<int> > vsUnion(std::vector<std::vector<int> > vs1, std::vector<std::vector<int> > vs2) 318 { 319 int i; 320 std::vector<std::vector<int> > vs=vs1; 321 for(i=0;i<vs2.size();i++) 322 { 323 if(!vInvsl(vs2[i],vs)) 324 { 325 vs.push_back(vs2[i]); 326 } 327 } 328 return vs; 329 } 330 331 332 333 334 335 336 std::vector<std::vector<int> > vsIntersection(std::vector<std::vector<int> > vs1, std::vector<std::vector<int> > vs2) 337 { 338 int i; 339 std::vector<std::vector<int> > vs; 340 for(i=0;i<vs2.size();i++) 341 { 342 if(vInvsl(vs2[i],vs1)) 343 { 344 vs.push_back(vs2[i]); 345 } 346 } 347 return vs; 348 } 349 350 351 352 353 354 /*************************************for transition between ideal and vectors******************************************/ 355 356 //P should be monomial, 357 // vector version of poly support(poly p) 358 std::vector<int> support1(poly p) 359 { 360 int j; 361 std::vector<int> supset; 362 if(p==0) return supset; 363 for(j=1;j<=rVar(currRing);j++) 364 { 365 if(pGetExp(p,j)>0) 366 { 367 supset.push_back(j); 368 } 369 } 370 return (supset); 371 } 372 373 374 375 376 377 378 //simplicial complex(the faces set is ideal h) 379 std::vector<std::vector<int> > supports(ideal h) 380 { 381 std::vector<std::vector<int> > vecs; 382 std::vector<int> vec; 383 if(!idIs0(h)) 384 { 385 for(int s=0;s<IDELEMS(h);s++) 386 { 387 vec=support1(h->m[s]); 388 vecs.push_back(vec); 389 } 390 } 391 return vecs; 392 } 393 394 395 396 397 // only for eqsolve1 398 // p could be any polynomial 399 std::vector<int> support2(poly p) 400 { 401 int j; 402 poly q; 403 std::vector<int> supset; 404 for(j=1;j<=rVar(currRing);j++) 405 { 406 q=pCopy(p); 407 while (q!=NULL) 408 { 409 if(p_GetExp(q,j,currRing)!=0) 410 { 411 supset.push_back(j); 412 break; 413 } 414 q=pNext(q); 415 } 416 } 417 return (supset); 418 } 419 420 421 422 //the supports of ideal 423 std::vector<std::vector<int> > supports2(ideal h) 424 { 425 std::vector<std::vector<int> > vecs; 426 std::vector<int> vec; 427 if(!idIs0(h)) 428 { 429 for(int s=0;s<IDELEMS(h);s++) 430 { 431 vec=support2(h->m[s]); 432 vecs.push_back(vec); 433 } 434 } 435 return vecs; 436 } 437 //convert the vector(vbase[i] are the coefficients of x_{i+1}) to a polynomial w.r.t. current ring 438 //vector vbase has length of currRing->N. 439 poly pMake(std::vector<int> vbase) 440 { 441 int n=vbase.size(); poly p,q=0; 442 for(int i=0;i<n;i++) 443 { 444 if(vbase[i]!=0) 445 { 446 p = pOne();pSetExp(p, i+1, 1);pSetm(p);pSetCoeff(p, nInit(vbase[i])); 447 q = pAdd(q, p); 448 } 449 450 } 451 return q; 452 } 453 454 455 456 457 //convert the vectors to a ideal(for T^1) 458 ideal idMake(std::vector<std::vector<int> > vecs) 459 { 460 int lv=vecs.size(), i, j; 461 poly p; 462 ideal id_re=idInit(1,1); 463 for(i=0;i<lv;i++) 464 { 465 p=pMake(vecs[i]); 466 idInsertPoly(id_re, p); 467 } 468 idSkipZeroes(id_re); 469 return id_re; 470 } 471 472 473 474 /*****************************quotient ring of two ideals*********************/ 475 476 //the quotient ring of h1 respect to h2 477 ideal idmodulo(ideal h1,ideal h2) 478 { 479 int i; 480 ideal gb=kStd(h2,NULL,testHomog,NULL,NULL,0,0,NULL); 481 idSkipZeroes(gb); 482 ideal idq=kNF(gb,NULL,h1); 483 idSkipZeroes(idq); 484 return idq; 485 } 486 487 //returns the coeff of the monomial of polynomial p which involves the mth varialbe 488 //assume the polynomial p has form of y1+y2+... 489 int pcoef(poly p, int m) 490 { 491 int i,j,co; poly q=pCopy(p); 492 for(i=1;i<=currRing->N;i++) 493 { 494 if(p_GetExp(q,m,currRing)!=0) 495 { 496 co=n_Int(pGetCoeff(q),currRing->cf); 497 return co; 498 } 499 else 500 q=pNext(q); 501 } 502 if(q!=NULL) 503 co=0; 504 return co; 505 } 506 507 //returns true if p involves the mth variable of the current ring 508 bool vInp(int m,poly p) 509 { 510 int i; 511 poly q=pCopy(p); 512 while (q!=NULL) 513 { 514 if(p_GetExp(q,m,currRing)!=0) 515 { 516 return true; 517 } 518 q=pNext(q); 519 } 520 return false; 521 } 522 523 524 525 //returns the vector w.r.t. polynomial p 526 std::vector<int> vMake(poly p) 527 { 528 int i; poly q=pCopy(p); 529 std::vector<int> vbase; 530 for(i=1;i<=currRing->N;i++) 531 { 532 if(vInp(i,p)) 533 { 534 vbase.push_back(pcoef(p,i)); 535 } 536 else 537 { 538 vbase.push_back(0); 539 } 540 } 541 return (vbase); 542 } 543 544 545 //returns the vectors w.r.t. ideal h 546 std::vector<std::vector<int> > vsMake(ideal h) 547 { 548 std::vector<int> vec; 549 std::vector<std::vector<int> > vecs; 550 int i; 551 for(i=0;i<IDELEMS(h);i++) 552 { 553 vec=vMake(h->m[i]); 554 vecs.push_back(vec); 555 } 556 return vecs; 557 } 558 559 560 //the quotient ring of two ideals which are represented by vectors, 561 //the result is also represented by vector. 562 std::vector<std::vector<int> > vecqring(std::vector<std::vector<int> > vec1, std::vector<std::vector<int> > vec2) 563 { 564 int i,j; 565 ideal h1=idMake(vec1), h2=idMake(vec2); 566 ideal h=idmodulo(h1,h2); 567 std::vector<std::vector<int> > vecs= vsMake(h); 568 return vecs; 569 } 570 571 572 573 /****************************************************************/ 574 //construct a monomial based on the support of it 575 //returns a squarefree monomial 576 poly pMaken(std::vector<int> vbase) 577 { 578 int n=vbase.size(); 579 poly p,q=pOne(); 580 for(int i=0;i<n;i++) 581 { 582 p = pOne();pSetExp(p, vbase[i], 1);pSetm(p);pSetCoeff(p, nInit(1)); 583 //pWrite(p); 584 q=pp_Mult_mm(q,p,currRing); 585 } 586 return q; 587 } 588 589 // returns a ideal according to a set of supports 590 ideal idMaken(std::vector<std::vector<int> > vecs) 591 { 592 ideal id_re=idInit(1,1); 593 poly p; 594 int i,lv=vecs.size(); 595 for(i=0;i<lv;i++) 596 { 597 p=pMaken(vecs[i]); 598 idInsertPoly(id_re, p); 599 } 600 idSkipZeroes(id_re); 601 //id_print(id_re); 602 return id_re; 603 } 604 605 606 607 /********************************new version for stanley reisner ideal ***********************************************/ 608 609 610 std::vector<std::vector<int> > b_subsets(std::vector<int> vec) 611 { 612 int i,j; 613 std::vector<int> bv; 614 std::vector<std::vector<int> > vecs; 615 for(i=0;i<vec.size();i++) 616 { 617 bv.push_back(vec[i]); 618 vecs.push_back(bv); 619 bv.clear(); 620 } 621 //listsprint(vecs); 622 for(i=0;i<vecs.size();i++) 623 { 624 for(j=i+1;j<vecs.size();j++) 625 { 626 bv=vecUnion(vecs[i], vecs[j]); 627 if(!vInvsl(bv,vecs)) 628 vecs.push_back(bv); 629 } 630 } 631 //listsprint(vecs); 632 return(vecs); 633 } 634 635 636 //the number of the variables 637 int idvert(ideal h) 638 { 639 int i, j, vert=0; 640 if(idIs0(h)) 641 return vert; 642 for(i=currRing->N;i>0;i--) 643 { 644 for(j=0;j<IDELEMS(h);j++) 645 { 646 if(pGetExp(h->m[j],i)>0) 647 { 648 vert=i; 649 return vert; 650 } 651 } 652 } 653 return vert; 654 } 655 656 657 658 659 int pvert(poly p) 660 { 661 int i, j, vert=0; 662 for(i=currRing->N;i>0;i--) 663 { 664 if(pGetExp(p,i)>0) 665 { 666 vert=i; 667 return vert; 668 } 669 } 670 return vert; 671 } 672 673 674 /* 675 //full complex 676 std::vector<std::vector<int> > fullcomplex(ideal h) 677 { 678 int vert=vertnum(h), i, j; 679 //Print("there are %d vertices\n", vert); 680 std::vector<std::vector<int> > fmons; 681 std::vector<int> pre; 682 for(i=1;i<=vert;i++) 683 { 684 pre.push_back(i); 685 } 686 fmons=b_subsets(pre); 687 return fmons; 688 689 }*/ 690 691 692 /* 693 //all the squarefree monomials whose degree is less or equal to n 694 std::vector<std::vector<int> > sfrmons(ideal h, int n) 695 { 696 int vert=vertnum(h), i, j, time=0; 697 std::vector<std::vector<int> > fmons, pres, pres0, pres1; 698 std::vector<int> pre; 699 for(i=1;i<=vert;i++) 700 { 701 pre.push_back(i); 702 pres0.push_back(pre); 703 } 704 pres=pres0; 705 for(i=0;i<size(pres),time<=n;i++) 706 { 707 time++; 708 pre=pres[i]; 709 for(j=0;j<size(pres0);j++) 710 { 711 pre=vecUnion(pre, pres0[j]); 712 if(pre.) 713 } 714 } 715 return fmons; 716 717 } 718 */ 719 720 /* 721 ideal id_complement(ideal h) 722 { 723 int i,j; 724 std::vector<std::vector<int> > full=fullcomplex(h), hvs=supports(h), res; 725 for(i=0;i<full.size();i++) 726 { 727 if(!vInvsl(full[i], hvs)) 728 { 729 res.push_back(full[i]); 730 } 731 } 732 return idMaken(res); 733 }*/ 734 735 736 /*****************About simplicial complex and stanley-reisner ideal and ring **************************/ 164 737 165 738 //h1 minus h2 … … 173 746 for(j=0;j<IDELEMS(h2);j++) 174 747 { 175 if(p_EqualPolys( h1->m[i],h2->m[j], currRing))748 if(p_EqualPolys(pCopy(h1->m[i]),pCopy(h2->m[j]), currRing)) 176 749 { 177 750 eq=1; … … 181 754 if(eq==0) 182 755 { 183 idInsertPoly(h, h1->m[i]);756 idInsertPoly(h, pCopy(h1->m[i])); 184 757 } 185 758 } … … 206 779 } 207 780 208 /*find all squarefree monomials of degree deg in ideal h*/ 781 782 783 //returns the set of all squarefree monomials of degree deg in ideal h 209 784 ideal sfreemon(ideal h,int deg) 210 785 { … … 232 807 233 808 234 235 236 809 //full simplex represented by ideal. 237 810 //(all the squarefree monomials over the polynomial ring) 238 ideal id_sfmon( )811 ideal id_sfmon(ideal h) 239 812 { 240 813 ideal asfmons,sfmons,mons,p; 241 int j ;814 int j, vert=idvert(h); 242 815 mons=id_MaxIdeal(1, currRing); 243 816 asfmons=sfreemon(mons,1); 244 for(j=2;j<= rVar(currRing);j++)817 for(j=2;j<=vert;j++) 245 818 { 246 819 mons=id_MaxIdeal(j, currRing); … … 256 829 257 830 258 259 831 //if the input ideal is simplicial complex, returns the stanley-reisner ideal, 260 832 //if the input ideal is stanley-reisner ideal, returns the monomial ideal according to simplicial complex. 261 833 //(nonfaces and faces). 262 //returns the complement of the ideal h 834 //returns the complement of the ideal h (consisting of only squarefree polynomials) 263 835 ideal id_complement(ideal h) 264 836 { 265 int j; 266 ideal i1=id_sfmon(); 267 ideal i2=idMinus(i1,h); 837 int j, vert=idvert(h); 838 ideal i1=id_sfmon(h); 839 ideal i3=idInit(1,1); 840 poly p; 841 for(j=0;j<IDELEMS(i1);j++) 842 { 843 p=pCopy(i1->m[j]); 844 if(pvert(p)<=vert) 845 { 846 idInsertPoly(i3, p); 847 } 848 } 849 ideal i2=idMinus(i3,h); 850 idSkipZeroes(i2); 268 851 return (i2); 269 852 } … … 272 855 273 856 274 275 276 277 278 279 280 281 282 //returns the monomials in the quotient ring R/(h1+h2) which have degree deg, 283 //and R is currRing 284 ideal qringadd(ideal h1, ideal h2,int deg) 857 //Returns true if p is one of the generators of ideal X 858 //returns false otherwise 859 bool IsInX(poly p,ideal X) 860 { 861 int i,j; 862 for(i=0;i<IDELEMS(X);i++) 863 { 864 if(pEqualPolys(p,X->m[i])) 865 { 866 //PrintS("yes\n"); 867 return(true); 868 } 869 } 870 //PrintS("no\n"); 871 return(false); 872 } 873 874 875 876 877 878 879 //returns the monomials in the quotient ring R/(h1+h2) which have degree deg. 880 ideal qringadd(ideal h1, ideal h2, int deg) 285 881 { 286 882 ideal h,qrh; … … 301 897 for(i=1;i<IDELEMS(h);i++) 302 898 { 303 if(pTotaldegree(h->m[i]) >max)304 max=pTotaldegree(h->m[i]);899 if(pTotaldegree(h->m[i]) > max) 900 max=pTotaldegree(h->m[i]); 305 901 } 306 902 return (max); 307 903 } 308 904 309 //input ideal h is the ideal associated to simplicial complex, 905 906 907 908 909 910 911 //input ideal h (a squarefree monomial ideal) is the ideal associated to simplicial complex, 310 912 //and returns the Stanley-Reisner ideal(minimal generators) 311 913 ideal idsrRing(ideal h) 312 914 { 313 915 int max,i,j,n; 314 ideal hc=idCopy(h); 315 //Print("This is the complement generators\n"); 316 //id_print(hc); 317 ideal pp,qq,rsr,ppp; 916 ideal pp,qq,rsr,ppp,hc=idCopy(h); 318 917 for(i=1;i<=rVar(currRing);i++) 319 918 { … … 324 923 pp=sfreemon(pp,i); 325 924 rsr=pp; 326 //Print("This is the first quotient generators %d:\n",i);327 //id_print(rsr);925 //Print("This is the first quotient generators %d:\n",i); 926 //id_print(rsr); 328 927 break; 329 928 } … … 332 931 { 333 932 qq=sfreemon(hc,n); 334 if(!idIs0(qq)) 335 { 336 pp=qringadd(qq,rsr,n); 337 ppp=sfreemon(pp,n); 338 //Print("This is the quotient generators %d:\n",n); 339 //id_print(ppp); 340 rsr=idAdd(rsr,ppp); 341 //Print("This is the current minimal set\n"); 342 //id_print(rsr); 343 } 933 pp=qringadd(qq,rsr,n); 934 ppp=sfreemon(pp,n); 935 rsr=idAdd(rsr,ppp); 344 936 } 345 937 idSkipZeroes(rsr); 346 //PrintS("This is the minimal generators:\n");347 //id_print(rsr);348 938 return rsr; 349 939 } … … 351 941 352 942 353 //returns the set of subset ofp943 //returns the set of all the polynomials could divide p 354 944 ideal SimFacset(poly p) 355 945 { 356 int i,j; 357 ideal h1,mons; 358 int max=pTotaldegree(p); 359 ideal id_re=idInit(1,1); 946 int i,j,max=pTotaldegree(p); 947 ideal h1,mons,id_re=idInit(1,1); 360 948 for(i=1;i<max;i++) 361 949 { 362 950 mons=id_MaxIdeal(i, currRing); 363 951 h1=sfreemon(mons,i); 952 364 953 for(j=0;j<IDELEMS(h1);j++) 365 954 { 366 955 if(p_DivisibleBy(h1->m[j],p,currRing)) 956 { 367 957 idInsertPoly(id_re, h1->m[j]); 368 } 958 } 959 } 960 369 961 } 370 962 idSkipZeroes(id_re); 371 //PrintS("This is the facset\n");372 //id_print(id_re);373 963 return id_re; 374 964 } 375 965 376 //complicated version(print the polynomial set which can make the input to be a simplex) 377 //input h is at least part of faces 378 bool IsSimplex(ideal h) 379 { 380 int i,j,ifbreak=0; 381 ideal id_re; 382 ideal id_so=idCopy(h); 383 int max=id_maxdeg(h); 966 967 968 ideal idadda(ideal h1, ideal h2) 969 { 970 ideal h=idInit(1,1); 971 for(int i=0;i<IDELEMS(h1);i++) 972 { 973 if(!IsInX(h1->m[i],h)) 974 { 975 idInsertPoly(h, h1->m[i]); 976 } 977 } 978 for(int i=0;i<IDELEMS(h2);i++) 979 { 980 if(!IsInX(h2->m[i],h)) 981 { 982 idInsertPoly(h, h2->m[i]); 983 } 984 } 985 idSkipZeroes(h); 986 return h; 987 } 988 989 990 //complicated version 991 //(returns false if it is not a simplicial complex and print the simplex) 992 //input h is need to be at least part of faces 993 ideal IsSimplex(ideal h) 994 { 995 int i,j,ifbreak=0,max=id_maxdeg(h); 996 poly e=pOne(); 997 ideal id_re, id_so=idCopy(h); 384 998 for(i=0;i<IDELEMS(h);i++) 385 999 { 386 1000 id_re=SimFacset(h->m[i]); 387 //id_print(id_re);388 1001 if(!idIs0(id_re)) 389 1002 { 390 id_so=idAdd(id_so, id_re); 391 } 392 } 1003 id_so=idadda(id_so, id_re);//idAdd(id_so,id_re); 1004 } 1005 } 1006 idInsertPoly(id_so,e); 393 1007 idSkipZeroes(id_so); 394 if(!idIs0(idMinus(id_so,id_re))) 395 { 396 PrintS("It is not simplex.\n"); 397 PrintS("This is the simplicial complex:\n"); 398 id_print(id_so); 399 return false; 400 } 401 PrintS("It is simplex.\n"); 402 return true; 403 } 404 405 406 //input is the subset of the Stainly-Reisner ideal 1008 return (idMinus(id_so,h)); 1009 } 1010 1011 1012 //input is the subset of the Stainley-Reisner ideal 407 1013 //returns the faces 1014 //is not used 408 1015 ideal complementsimplex(ideal h) 409 1016 { 410 int i,j;poly p; 411 ideal h1=idInit(1,1); 412 ideal pp; 413 ideal h3=idInit(1,1); 1017 int i,j;poly p,e=pOne(); 1018 ideal h1=idInit(1,1), pp, h3; 414 1019 for(i=1;i<=rVar(currRing);i++) 415 1020 { 416 1021 p = pOne(); pSetExp(p, i, 2); pSetm(p); pSetCoeff(p, nInit(1)); 417 //pWrite(p);418 1022 idInsertPoly(h1, p); 419 1023 } … … 427 1031 h3=idAdd(h3,pp); 428 1032 } 429 PrintS("This is the simplicial complex:\n");430 id _print(h3);1033 idInsertPoly(h3, e); 1034 idSkipZeroes(h3); 431 1035 return (h3); 432 1036 } … … 434 1038 435 1039 436 437 /*************operations for vectors(sets)*********/ 438 439 //returns true if integer n is in vector vec, 440 //otherwise returns false 441 bool IsinL(int a,std::vector<int> badset) 442 { 443 int i; 444 for(i=0;i<badset.size();i++) 445 { 446 if(a==badset[i]) 447 { 448 return true; 449 } 450 } 451 return false; 452 } 453 454 455 456 457 458 //intersection of vectors p and q, returns empty if they are disjoint 459 std::vector<int> vecIntersection(std::vector<int> p,std::vector<int> q) 460 { 461 int i; 462 std::vector<int> inte; 463 for(i=0;i<p.size();i++) 464 { 465 if(IsinL(p[i],q)) 466 inte.push_back(p[i]); 467 } 468 //listprint(inte); 469 return inte; 470 } 471 472 473 474 475 476 477 478 479 480 //returns true if vec1 is equal to vec2 (including the order) 481 bool vEv(std::vector<int> vec1,std::vector<int> vec2) 482 { 483 int i,j; 484 int lg1=vec1.size(),lg2=vec2.size(); 485 if(lg1!=lg2) 486 { 487 return false; 488 } 489 else 490 { 491 for(j=0;j<vec1.size();j++) 492 { 493 if(vec1[j]!=vec2[j]) 494 return false; 495 } 496 } 497 return true; 498 } 499 500 501 502 503 //returns true if vec1 is contained in vec2 504 bool vsubset(std::vector<int> vec1,std::vector<int> vec2) 505 { 506 int i; 507 if(vec1.size()>vec2.size()) 508 return false; 509 for(i=0;i<vec1.size();i++) 510 { 511 if(!IsinL(vec1[i],vec2)) 512 return false; 513 } 514 return true; 515 } 516 517 //not strictly equal(order doesn't matter) 518 bool vEvl(std::vector<int> vec1,std::vector<int> vec2) 519 { 520 if(vec1.size()==0 && vec2.size()==0) 521 return true; 522 if(vsubset(vec1,vec2)&&vsubset(vec2,vec1)) 523 return true; 524 return false; 525 } 526 527 528 //the length of vec must be same to it of the elements of vecs (not strictly same) 529 //returns false if vec is not in vecs 530 bool vInvsl(std::vector<int> vec, std::vector<std::vector<int> > vecs) 531 { 532 int i; 533 for(i=0;i<vecs.size();i++) 534 { 535 if(vEvl(vec,vecs[i])) 536 { 537 return true; 538 } 539 } 540 return false; 541 } 542 543 544 //the length of vec must be same to it of the elements of vecs (strictly same) 545 //returns the position of vec in vecs, 546 //returns -1 if vec is not in vecs 547 int vInvs(std::vector<int> vec, std::vector<std::vector<int> > vecs) 548 { 549 int i; 550 for(i=0;i<vecs.size();i++) 551 { 552 if(vEv(vec,vecs[i])) 553 { 554 //Print("This is the %dth variable\n",i+1); 555 return i+1; 556 } 557 } 558 //Print("This is not the new variable\n"); 559 //listprint(vec); 560 return -1; 561 } 562 563 564 565 //returns the union of two vectors(like the union of sets) 566 std::vector<int> vecUnion(std::vector<int> vec1, std::vector<int> vec2) 567 { 568 std::vector<int> vec=vec1; 569 int i; 570 for(i=0;i<vec2.size();i++) 571 { 572 if(!IsinL(vec2[i],vec)) 573 vec.push_back(vec2[i]); 574 } 575 return vec; 576 } 577 578 579 580 std::vector<int> vecMinus(std::vector<int> vec1,std::vector<int> vec2) 581 { 582 std::vector<int> vec; 583 for(int i=0;i<vec1.size();i++) 584 { 585 if(!IsinL(vec1[i],vec2)) 586 { 587 vec.push_back(vec1[i]); 588 } 589 } 590 return vec; 591 } 592 1040 int dim_sim(ideal h) 1041 { 1042 int dim=pTotaldegree(h->m[0]), i; 1043 for(i=1; i<IDELEMS(h);i++) 1044 { 1045 if(dim<pTotaldegree(h->m[i])) 1046 { 1047 dim=pTotaldegree(h->m[i]); 1048 } 1049 } 1050 return dim; 1051 } 1052 1053 1054 int num4dim(ideal h, int n) 1055 { 1056 int num=0; 1057 for(int i=0; i<IDELEMS(h); i++) 1058 { 1059 if(pTotaldegree(h->m[i])==n) 1060 { 1061 num++; 1062 } 1063 } 1064 return num; 1065 } 593 1066 594 1067 … … 600 1073 601 1074 602 603 604 605 606 //P should be monomial(not used) vector version of poly support(poly p)607 std::vector<int> support1(poly p)608 {609 int j;610 std::vector<int> supset;611 for(j=1;j<=rVar(currRing);j++)612 {613 if(pGetExp(p,j)>0)614 {615 supset.push_back(j);616 }617 }618 return (supset);619 }620 621 //simplicial complex(the faces set is ideal h)622 std::vector<std::vector<int> > supports(ideal h)623 {624 std::vector<std::vector<int> > vecs;625 std::vector<int> vec;626 if(!idIs0(h))627 {628 for(int s=0;s<IDELEMS(h);s++)629 {630 //pWrite(h->m[s]);631 vec=support1(h->m[s]);632 vecs.push_back(vec);633 }634 }635 return vecs;636 }637 638 639 640 641 642 1075 //h is ideal( monomial ideal) associated to simplicial complex 643 //returns the all the monomials x^b (x^b must be able to divide at least one monomial in Stanley-Reisner ring) 1076 //returns the all the monomials x^b (x^b must be able to divide 1077 //at least one monomial in Stanley-Reisner ring) 1078 //not so efficient 644 1079 ideal findb(ideal h) 645 1080 { 646 ideal ib=id_sfmon(); 647 ideal nonf=id_complement(h); 648 ideal bset=idInit(1,1); 1081 ideal ib=id_sfmon(h), nonf=id_complement(h), bset=idInit(1,1); 649 1082 poly e=pOne(); 650 1083 int i,j; … … 675 1108 ideal finda(ideal h,poly S,int ddeg) 676 1109 { 677 ideal aset=idInit(1,1);678 1110 poly e=pOne(); 679 ideal h2=id_complement(h); 680 poly p; 1111 ideal h2=id_complement(h), aset=idInit(1,1); 681 1112 int i,j,deg1=pTotaldegree(S); 682 1113 int tdeg=deg1+ddeg; … … 688 1119 for(i=0;i<IDELEMS(ia);i++) 689 1120 { 690 //p=support(ia->m[i]);691 1121 v=support1(ia->m[i]); 692 1122 in=vecIntersection(v,bv); … … 696 1126 } 697 1127 } 698 //idInsertPoly(aset,e);699 1128 idSkipZeroes(aset); 700 1129 } … … 712 1141 //returns true if support(p) union support(a) minus support(b) is face, 713 1142 //otherwise returns false 714 // not be used yet,(the vector version of mabcondition)1143 //(the vector version of mabcondition) 715 1144 bool mabconditionv(std::vector<std::vector<int> > hvs,std::vector<int> pv,std::vector<int> av,std::vector<int> bv) 716 1145 { 717 1146 std::vector<int> uv=vecUnion(pv,av); 718 1147 uv=vecMinus(uv,bv); 719 //Print("this is the support of p union a minus b\n");720 //listprint(uv);721 //Print("this is the support of ideal\n");722 //listsprint(hvs);723 1148 if(vInvsl(uv,hvs)) 724 1149 { … … 729 1154 730 1155 1156 // returns the set of nonfaces p where mabconditionv(h, p, a, b) is true 731 1157 std::vector<std::vector<int> > Mabv(ideal h,poly a,poly b) 732 1158 { 733 std::vector<int> pv; 734 std::vector<std::vector<int> > vecs; 735 //Print("this is the support of p\n"); 736 //listprint(pv); 737 std::vector<int> av=support1(a); 738 //Print("this is the support of a\n"); 739 //listprint(av); 740 std::vector<int> bv=support1(b); 741 //Print("this is the support of b\n"); 742 //listprint(bv); 1159 std::vector<int> av=support1(a), bv=support1(b), pv, vec; 743 1160 ideal h2=id_complement(h); 744 std::vector<std::vector<int> > hvs=supports(h); 745 std::vector<std::vector<int> > h2v=supports(h2); 746 std::vector<int> vec; 1161 std::vector<std::vector<int> > hvs=supports(h), h2v=supports(h2), vecs; 747 1162 for(int i=0;i<h2v.size();i++) 748 1163 { … … 767 1182 768 1183 /***************************************************************************/ 769 //For solving the equations which has form of x_i-x_j.(equations got byT_1)1184 //For solving the equations which has form of x_i-x_j.(equations got from T_1) 770 1185 /***************************************************************************/ 771 1186 … … 790 1205 } 791 1206 792 1207 /* 793 1208 //get triangular form(eqs.size()>0) 794 1209 std::vector<std::vector<int> > soleli1( std::vector<std::vector<int> > eqs) 795 1210 { 796 int i,j;std::vector<std::vector<int> > re; 797 std::vector<std::vector<int> > pre=eqs,ppre; 1211 int i,j; 1212 std::vector<int> yaya; 1213 std::vector<std::vector<int> > pre=eqs, ppre, re; 798 1214 if(eqs.size()>0) 799 1215 { … … 801 1217 pre.erase(pre.begin()); 802 1218 } 803 //listsprint(pre); 804 std::vector<int> yaya; 805 for(i=0;(i<re.size()) && (pre.size()>0);i++) 1219 for(i=0;i<re.size(),pre.size()>0;i++) 806 1220 { 807 1221 yaya=eli1(re[i],pre[0]); 808 //listprint(yaya);809 1222 re.push_back(yaya); 810 1223 for(j=1;j<pre.size();j++) 811 1224 { 812 //listprint(pre[j]);813 1225 ppre.push_back(eli1(re[i],pre[j])); 814 1226 } … … 817 1229 } 818 1230 return re; 819 } 820 821 822 // input is a set of equations who is of triangular form(every equations has a form of x_i-x_j) n is the number of variables 1231 }*/ 1232 //make sure the first element is smaller that the second one 1233 std::vector<int> keeporder( std::vector<int> vec) 1234 { 1235 std::vector<int> yaya; 1236 int n; 1237 if(vec[0]>vec[1]) 1238 { 1239 n=vec[0]; 1240 vec[0]=vec[1]; 1241 vec[1]=n; 1242 } 1243 return vec; 1244 } 1245 1246 1247 std::vector<std::vector<int> > soleli1( std::vector<std::vector<int> > eqs) 1248 { 1249 int i,j; 1250 std::vector<int> yaya; 1251 std::vector<std::vector<int> > pre=eqs, ppre, re; 1252 if(eqs.size()>0) 1253 { 1254 re.push_back(eqs[0]); 1255 pre.erase(pre.begin()); 1256 } 1257 while(pre.size()>0) 1258 { 1259 yaya=keeporder(eli1(re[0],pre[0])); 1260 for(i=1;i<re.size();i++) 1261 { 1262 if(!vInvsl(yaya, re)) 1263 { 1264 yaya=eli1(re[i],yaya); 1265 yaya=keeporder(yaya); 1266 } 1267 } 1268 if(!vInvsl(yaya, re)) 1269 { 1270 re.push_back(yaya); 1271 } 1272 pre.erase(pre.begin()); 1273 } 1274 return re; 1275 } 1276 1277 1278 1279 // input is a set of equations who is of triangular form(every equations has a form of x_i-x_j) 1280 // n is the number of variables 823 1281 //get the free variables and the dimension 824 1282 std::vector<int> freevars(int n, std::vector<int> bset, std::vector<std::vector<int> > gset) 825 1283 { 826 int ql=gset.size(); 827 int bl=bset.size(); 828 std::vector<int> mvar; 829 std::vector<int> fvar; 1284 int ql=gset.size(), bl=bset.size(), i; 1285 std::vector<int> mvar, fvar; 1286 for(i=0;i<bl;i++) 1287 { 1288 mvar.push_back(bset[i]); 1289 } 1290 for(i=0;i<ql;i++) 1291 { 1292 mvar.push_back(gset[i][0]); 1293 } 1294 for(i=1;i<=n;i++) 1295 { 1296 if(!IsinL(i,mvar)) 1297 { 1298 fvar.push_back(i); 1299 } 1300 } 1301 return fvar; 1302 } 1303 1304 1305 //return the set of free variables except the vnum one 1306 std::vector<int> fvarsvalue(int vnum, std::vector<int> fvars) 1307 { 830 1308 int i; 831 for(i=0;i<bl;i++) 832 { 833 mvar.push_back(bset[i]); 834 } 835 for(i=0;i<ql;i++) 836 { 837 mvar.push_back(gset[i][0]); 838 } 839 for(i=1;i<=n;i++) 840 { 841 if(!IsinL(i,mvar)) 842 { 843 fvar.push_back(i); 844 } 845 } 846 return fvar; 847 } 848 849 850 //return the set of free variables except vnum 851 std::vector<int> fvarsvalue(int vnum, std::vector<int> fvars) 852 { 853 int i;std::vector<int> fset=fvars; 1309 std::vector<int> fset=fvars; 854 1310 for(i=0;i<fset.size();i++) 855 1311 { … … 865 1321 866 1322 867 1323 //returns the simplified bset and gset 1324 //enlarge bset, simplify gset 868 1325 std::vector<std::vector<int> > vAbsorb( std::vector<int> bset,std::vector<std::vector<int> > gset) 869 1326 { 870 int i,j,m;871 1327 std::vector<int> badset=bset; 872 int bl=badset.size(); 873 int gl=gset.size(); 1328 int i,j,m, bl=bset.size(), gl=gset.size(); 874 1329 for(i=0;i<bl;i++) 875 1330 { … … 915 1370 916 1371 917 //the new variables are started from 1 1372 //the labels of new variables are started with 1 1373 //returns a vector of solution space according to index 918 1374 std::vector<int> vecbase1(int num, std::vector<int> oset) 919 1375 { … … 966 1422 std::vector<int> ofindbases1(int num, int vnum, std::vector<int> bset,std::vector<std::vector<int> > gset) 967 1423 { 968 int i,j,m;std::vector<std::vector<int> > goodset; 969 std::vector<int> fvars=freevars(num, bset, gset); 1424 int i,j,m; 1425 std::vector<std::vector<int> > goodset; 1426 std::vector<int> fvars=freevars(num, bset, gset), oset, base; 970 1427 std::vector<int> zset=fvarsvalue(vnum, fvars); 971 1428 zset=vecUnion(zset,bset); 972 std::vector<int> oset;973 1429 oset.push_back(vnum); 974 1430 goodset=vAbsorb(oset, gset); 975 1431 oset=goodset[goodset.size()-1]; 976 1432 goodset.erase(goodset.end()); 977 //PrintS("This is the 1 set:\n"); 978 //listprint(oset); 979 //goodset=vAbsorb(zset, goodset); 980 //zset=goodset[goodset.size()-1]; 981 //goodset.erase(goodset.end()); 982 //PrintS("This is the 0 set:\n"); 983 //listprint(zset); 984 //Print("thet size of goodset is %ld\n", goodset.size()); 985 std::vector<int> base= vecbase1(num, oset); 1433 base= vecbase1(num, oset); 986 1434 return base; 987 1435 } … … 999 1447 { 1000 1448 int i,j,m; 1001 std::vector<int> base1;1002 1449 std::vector<std::vector<int> > bases; 1003 std::vector<int> fvars=freevars(num, bset, gset) ;1450 std::vector<int> fvars=freevars(num, bset, gset), base1; 1004 1451 if (fvars.size()==0) 1005 1452 { … … 1031 1478 //num is the number of varialbes also the length of the set which we need to consider 1032 1479 //output is trigular form of gset and badset where x_i=0 1033 std::vector<std::vector<int> > eli2(int num, std::vector<int> bset,std::vector<std::vector<int> > gset)1480 std::vector<std::vector<int> > eli2(int num, std::vector<int> bset,std::vector<std::vector<int> > gset) 1034 1481 { 1035 1482 int i,j; 1036 1483 std::vector<int> badset; 1037 std::vector<std::vector<int> > goodset; 1038 std::vector<std::vector<int> > solve; 1484 std::vector<std::vector<int> > goodset, solve; 1485 //PrintS("This is the input bset\n");listprint(bset); 1486 //PrintS("This is the input gset\n");listsprint(gset); 1039 1487 if(gset.size()!=0)//gset is not empty 1040 1488 { 1041 //find all the variables which are zeroes1489 //find all the variables which are zeroes 1042 1490 1043 1491 if(bset.size()!=0)//bset is not empty … … 1052 1500 goodset=gset;//badset is empty 1053 1501 }//goodset is already the set which doesn't contain zero variables 1054 1502 //PrintS("This is the badset after absorb \n");listprint(badset); 1503 //PrintS("This is the goodset after absorb \n");listsprint(goodset); 1055 1504 goodset=soleli1(goodset);//get the triangular form of goodset 1056 //PrintS("the triangular form of the good set is:\n");1505 //PrintS("This is the goodset after triangulization \n");listsprint(goodset); 1057 1506 solve=ofindbases(num,badset,goodset); 1058 // goodset.push_back(badset);1059 //listsprint(goodset);1060 1507 } 1061 1508 else … … 1063 1510 solve=ofindbases(num,bset,gset); 1064 1511 } 1512 //PrintS("This is the solution\n");listsprint(solve); 1065 1513 return solve; 1066 1514 } … … 1070 1518 1071 1519 1072 //convert the vector to a polynomial w.r.t. current ring 1073 //vector vbase has length of currRing->N. 1074 poly pMake(std::vector<int> vbase) 1075 { 1076 int n=vbase.size();poly p,q=0; 1077 for(int i=0;i<n;i++) 1078 { 1079 if(vbase[i]!=0) 1080 { 1081 p = pOne();pSetExp(p, i+1, 1);pSetm(p);pSetCoeff(p, nInit(vbase[i])); 1082 q = pAdd(q, p); 1083 } 1084 1085 } 1086 return q; 1087 } 1088 1089 1090 1091 1092 //convert the vectors to a ideal(for T^1) 1093 ideal idMake(std::vector<std::vector<int> > vecs) 1094 { 1095 int lv=vecs.size();poly p; 1096 int i,j; 1097 ideal id_re=idInit(1,1); 1098 for(i=0;i<lv;i++) 1099 { 1100 p=pMake(vecs[i]); 1101 idInsertPoly(id_re, p); 1102 } 1103 idSkipZeroes(id_re); 1104 return id_re; 1105 } 1106 1107 1108 1109 /*****************************quotient ring of two ideals*********************/ 1110 1111 //the quotient ring of h1 respect to h2 1112 ideal idmodulo(ideal h1,ideal h2) 1113 { 1114 int i; 1115 ideal gb=kStd(h2,NULL,testHomog,NULL,NULL,0,0,NULL); 1116 ideal idq=kNF(gb,NULL,h1); 1117 idSkipZeroes(idq); 1118 return idq; 1119 } 1120 1121 //returns the coeff of the monomial of polynomial p which involves the mth varialbe 1122 //assume the polynomial p has form of y1+y2+... 1123 int pcoef(poly p, int m) 1124 { 1125 int i,j,co;poly q=pCopy(p); 1126 for(i=1;i<=currRing->N;i++) 1127 { 1128 if(p_GetExp(q,m,currRing)!=0) 1129 { 1130 co=n_Int(pGetCoeff(q),currRing->cf); 1131 return co; 1132 } 1133 else 1134 q=pNext(q); 1135 } 1136 if(q!=NULL) 1137 co=0; 1138 return co; 1139 } 1140 1141 //returns true if p involves the mth variable of the current ring 1142 bool vInp(int m,poly p) 1143 { 1144 int i; 1145 poly q=pCopy(p); 1146 while (q!=NULL) 1147 { 1148 if(p_GetExp(q,m,currRing)!=0) 1149 { 1150 return true; 1151 } 1152 q=pNext(q); 1153 } 1154 return false; 1155 } 1156 1157 1158 1159 //returns the vector w.r.t. polynomial p 1160 std::vector<int> vMake(poly p) 1161 { 1162 int i;poly q=pCopy(p); 1163 std::vector<int> vbase; 1164 for(i=1;i<=currRing->N;i++) 1165 { 1166 if(vInp(i,p)) 1167 { 1168 vbase.push_back(pcoef(p,i)); 1169 } 1170 else 1171 { 1172 vbase.push_back(0); 1173 } 1174 } 1175 return (vbase); 1176 } 1177 1178 1179 //returns the vectors w.r.t. ideal h 1180 std::vector<std::vector<int> > vsMake(ideal h) 1181 { 1182 std::vector<int> vec; 1183 std::vector<std::vector<int> > vecs; 1184 int i; 1185 for(i=0;i<IDELEMS(h);i++) 1186 { 1187 vec=vMake(h->m[i]); 1188 vecs.push_back(vec); 1189 } 1190 return vecs; 1191 } 1192 1193 1194 //the quotient ring of two ideals which are represented by vectors, 1195 //the result is also represented by vector. 1196 std::vector<std::vector<int> > vecqring(std::vector<std::vector<int> > vec1, std::vector<std::vector<int> > vec2) 1197 { 1198 int i,j; 1199 ideal h1=idMake(vec1); 1200 //id_print(h1); 1201 ideal h2=idMake(vec2); 1202 //id_print(h2); 1203 ideal h=idmodulo(h1,h2); 1204 std::vector<std::vector<int> > vecs= vsMake(h); 1205 return vecs; 1206 } 1207 1208 /***********************************************************/ 1209 1210 1211 1212 1213 //returns the link of face a in simplicial complex X 1520 1521 1522 1523 1524 1525 /************************links***********************************/ 1526 1527 1528 //returns the links of face a in simplicial complex X 1214 1529 std::vector<std::vector<int> > links(poly a, ideal h) 1215 1530 { … … 1220 1535 { 1221 1536 U=vecUnion(av,X[i]); 1222 //PrintS("**********************\n");1223 //listprint(X[i]);1224 //PrintS("The union of them is:\n");1225 //listprint(U);1226 1537 In=vecIntersection(av,X[i]); 1227 //PrintS("The intersection of them is:\n");1228 //listprint(In);1229 1538 if( In.size()==0 && vInvsl(U,X)) 1230 1539 { … … 1242 1551 1243 1552 1244 1245 /*vector version 1246 //returns the link of face a in simplicial complex X 1247 std::vector<std::vector<int> > links(std::vector<int> a, std::vector<std::vector<int> > X) 1248 { 1249 int i; 1250 std::vector<std::vector<int> > lk; 1251 std::vector<int> U; 1252 std::vector<int> In; 1253 for(i=0;i<X.size();i++) 1254 { 1255 U=vecUnion(a,X[i]); 1256 //PrintS("**********************\n"); 1257 //listprint(X[i]); 1258 //PrintS("The union of them is:\n"); 1259 //listprint(U); 1260 In=vecIntersection(a,X[i]); 1261 //PrintS("The intersection of them is:\n"); 1262 //listprint(In); 1263 if( In.size()==0 && vInvsl(U,X)) 1264 { 1265 //PrintS("The union of them is FACE and intersection is EMPTY!\n"); 1266 lk.push_back(X[i]); 1553 int redefinedeg(poly p, int num) 1554 { 1555 int deg=0, deg0; 1556 for(int i=1;i<=currRing->N;i++) 1557 { 1558 deg0=pGetExp(p, i); 1559 if(i>num) 1560 { 1561 deg= deg+2*deg0; 1267 1562 } 1268 1563 else 1269 1564 { 1270 ; 1271 } 1272 } 1273 return lk; 1274 } 1275 */ 1565 deg=deg+deg0; 1566 } 1567 } 1568 //Print("the new degree is: %d\n", deg); 1569 return (deg); 1570 } 1571 1572 1573 // the degree of variables should be same 1574 ideal p_a(ideal h) 1575 { 1576 poly e=pOne(), p; 1577 int i,j,deg=0,deg0; 1578 ideal aset=idCopy(h),ia,h1=idsrRing(h); 1579 //PrintS("idsrRing is:\n");id_print(h1); 1580 std::vector<int> as; 1581 std::vector<std::vector<int> > hvs=supports(h); 1582 for(i=0;i<IDELEMS(h1);i++) 1583 { 1584 deg0=pTotaldegree(h1->m[i]); 1585 if(deg < deg0) 1586 deg=deg0; 1587 } 1588 for(i=2;i<=deg;i++) 1589 { 1590 ia=id_MaxIdeal(i, currRing); 1591 for(j=0;j<IDELEMS(ia);j++) 1592 { 1593 p=pCopy(ia->m[j]); 1594 if(!IsInX(p,h)) 1595 { 1596 as=support1(p); 1597 if(vInvsl(as,hvs)) 1598 { 1599 idInsertPoly(aset, p); 1600 } 1601 } 1602 } 1603 } 1604 idSkipZeroes(aset); 1605 return(aset); 1606 } 1607 1608 1609 /*only for the exampels whose variables has degree more than 1*/ 1610 /*ideal p_a(ideal h) 1611 { 1612 poly e=pOne(), p; 1613 int i,j,deg=0,deg0, ord=4; 1614 ideal aset=idCopy(h),ia,h1=idsrRing(h); 1615 //PrintS("idsrRing is:\n");id_print(h1); 1616 std::vector<int> as; 1617 std::vector<std::vector<int> > hvs=supports(h); 1618 for(i=0;i<IDELEMS(h1);i++) 1619 { 1620 deg0=redefinedeg(h1->m[i],ord); 1621 if(deg < deg0) 1622 deg=deg0; 1623 } 1624 for(i=2;i<=deg;i++) 1625 { 1626 ia=id_MaxIdeal(i, currRing); 1627 for(j=0;j<IDELEMS(ia);j++) 1628 { 1629 p=pCopy(ia->m[j]); 1630 if(!IsInX(p,h)) 1631 { 1632 as=support1(p); 1633 if(vInvsl(as,hvs)) 1634 { 1635 idInsertPoly(aset, p); 1636 } 1637 } 1638 } 1639 } 1640 idSkipZeroes(aset); 1641 return(aset); 1642 }*/ 1643 1644 1645 1646 1647 std::vector<std::vector<int> > id_subsets(std::vector<std::vector<int> > vecs) 1648 { 1649 int i,j; 1650 std::vector<std::vector<int> > vvs, res; 1651 for(i=0;i<vecs.size();i++) 1652 { 1653 vvs=b_subsets(vecs[i]); 1654 //listsprint(vvs); 1655 for(j=0;j<vvs.size();j++) 1656 { 1657 if(!vInvsl(vvs[j],res)) 1658 res.push_back(vvs[j]); 1659 } 1660 } 1661 //listsprint(res); 1662 return (res); 1663 } 1664 1665 1666 1667 1668 std::vector<int> vertset(std::vector<std::vector<int> > vecs) 1669 { 1670 int i,j; 1671 std::vector<int> vert; 1672 std::vector<std::vector<int> > vvs; 1673 for(i=1;i<=currRing->N;i++) 1674 { 1675 for(j=0;j<vecs.size();j++) 1676 { 1677 if(IsinL(i, vecs[j])) 1678 { 1679 if(!IsinL(i , vert)) 1680 { 1681 vert.push_back(i); 1682 } 1683 break; 1684 } 1685 } 1686 } 1687 return (vert); 1688 } 1689 1690 //smarter way 1691 ideal p_b(ideal h, poly a) 1692 { 1693 std::vector<std::vector<int> > pbv,lk=links(a,h), res; 1694 std::vector<int> vert=vertset(lk), bv; 1695 res=b_subsets(vert); 1696 int i, j, nu=res.size(), adg=pTotaldegree(a); 1697 poly e=pOne(); 1698 ideal idd=idInit(1,1); 1699 for(i=0;i<res.size();i++) 1700 { 1701 if(res[i].size()==adg) 1702 pbv.push_back(res[i]); 1703 } 1704 if(pEqualPolys(a,e)) 1705 { 1706 idInsertPoly(idd, e); 1707 idSkipZeroes(idd); 1708 return (idd); 1709 } 1710 idd=idMaken(pbv); 1711 return(idd); 1712 } 1713 1714 /*//dump way to get pb 1715 // the degree of variables should be same 1716 ideal p_b(ideal h, poly a) 1717 { 1718 std::vector<std::vector<int> > pbv,lk=links(a,h),res; 1719 // PrintS("Its links are :\n");id_print(idMaken(lk)); 1720 res=id_subsets(lk); 1721 //PrintS("res is :\n");listsprint(res); 1722 std::vector<int> bv; 1723 ideal bset=findb(h); 1724 int i,j,nu=res.size(),adg=pTotaldegree(a); 1725 poly e=pOne();ideal idd=idInit(1,1); 1726 for(i=0;i<res.size();i++) 1727 { 1728 if(res[i].size()==adg) 1729 pbv.push_back(res[i]); 1730 } 1731 if(pEqualPolys(a,e)){idInsertPoly(idd, e); idSkipZeroes(idd); return (idd);} 1732 for(i=0;i<nu;i++) 1733 { 1734 for(j=i+1;j<nu;j++) 1735 { 1736 if(res[i].size()!=0 && res[j].size()!=0) 1737 { 1738 bv = vecUnion(res[i], res[j]); 1739 if(IsInX(pMaken(bv),bset) && bv.size()==adg && !vInvsl(bv,pbv)) 1740 {pbv.push_back(bv);} 1741 } 1742 } 1743 } 1744 idd=idMaken(pbv); 1745 //id_print(idd); 1746 return(idd); 1747 }*/ 1748 1749 // also only for the examples whose variables have degree more than 1(ndegreeb and p_b) 1750 /*int ndegreeb(std::vector<int> vec, int num) 1751 { 1752 int deg, deg0=0; 1753 for(int i=0;i<vec.size();i++) 1754 { 1755 if(vec[i]>num) 1756 { 1757 deg0++; 1758 } 1759 } 1760 deg=vec.size()+deg0; 1761 return(deg); 1762 } 1763 1764 ideal p_b(ideal h, poly a) 1765 { 1766 std::vector<std::vector<int> > pbv,lk=links(a,h),res; 1767 // PrintS("Its links are :\n");id_print(idMaken(lk)); 1768 res=id_subsets(lk); 1769 //PrintS("res is :\n");listsprint(res); 1770 std::vector<int> bv; 1771 ideal bset=findb(h); 1772 int i,j,nu=res.size(),ord=4,adg=redefinedeg(a, ord); 1773 poly e=pOne();ideal idd=idInit(1,1); 1774 for(i=0;i<res.size();i++) 1775 { 1776 if(ndegreeb(res[i],ord)==adg) 1777 pbv.push_back(res[i]); 1778 } 1779 if(pEqualPolys(a,e)){idInsertPoly(idd, e); idSkipZeroes(idd); return (idd);} 1780 for(i=0;i<nu;i++) 1781 { 1782 for(j=i+1;j<nu;j++) 1783 { 1784 if(res[i].size()!=0 && res[j].size()!=0) 1785 { 1786 bv = vecUnion(res[i], res[j]); 1787 //PrintS("bv is :\n");listprint(bv); 1788 //Print("bv's degree is : %d\n", ndegreeb(bv,ord)); 1789 if(IsInX(pMaken(bv),bset) && ndegreeb(bv,ord)==adg && !vInvsl(bv,pbv)) 1790 { 1791 pbv.push_back(bv); 1792 } 1793 } 1794 } 1795 } 1796 idd=idMaken(pbv); 1797 //id_print(idd); 1798 return(idd); 1799 }*/ 1800 1276 1801 1277 1802 … … 1281 1806 ideal psubset(poly p) 1282 1807 { 1283 int i,j; 1284 ideal h1,mons; 1285 int max=pTotaldegree(p); 1286 ideal id_re=idInit(1,1); 1808 int i,j,max=pTotaldegree(p); 1809 ideal h1,mons, id_re=idInit(1,1); 1287 1810 for(i=1;i<max;i++) 1288 1811 { … … 1337 1860 poly pMake3(std::vector<int> vbase) 1338 1861 { 1339 int n=vbase.size();poly p,q=0; 1340 int co=1; 1341 //equmab(n); 1862 int n=vbase.size(),co=1; 1863 poly p,q=0; 1342 1864 for(int i=0;i<3;i++) 1343 1865 { … … 1346 1868 if(i==1) co=-1; 1347 1869 p = pOne();pSetExp(p, vbase[i], 1);pSetm(p);pSetCoeff(p, nInit(co)); 1348 //Print("attention! ");pWrite(p);1349 1870 } 1350 1871 else p=0; … … 1352 1873 co=1; 1353 1874 } 1354 //PrintS("the polynomial according to the metrix M is:\n");1355 //listprint(vbase);1356 //pWrite(q);1357 1875 return q; 1358 1876 } … … 1366 1884 for(i=0;i<lv;i++) 1367 1885 { 1368 //Print("The vector is: ");1369 //listprint(vecs[i]);1370 1886 p=pMake3(vecs[i]); 1371 //Print("The polynomial is: ");1372 //pWrite(p);1373 1887 idInsertPoly(id_re, p); 1374 1888 } 1375 //PrintS("This is the metrix M:\n");1376 //listsprint(vecs);1377 //PrintS("the ideal according to metrix M is:\n");1378 1889 idSkipZeroes(id_re); 1379 1890 return id_re; … … 1386 1897 { 1387 1898 int i,j; 1388 //Print("There are %d variables in total.\n",num);1899 //Print("There are %d new variables for equations solving.\n",num); 1389 1900 ring r=currRing; 1390 1901 char** tt; … … 1396 1907 sprintf (tt[i], "t(%d)", i+1); 1397 1908 tt[i]=omStrDup(tt[i]); 1398 //Print("%s\n",tt[i]);1399 1909 } 1400 1910 ring R=rDefault(cf,num,tt,ringorder_lp); … … 1409 1919 std::vector<int> subspace1(std::vector<std::vector<int> > mv, std::vector<int> bv) 1410 1920 { 1411 int i; 1412 int num=mv.size(); 1921 int i, num=mv.size(); 1413 1922 std::vector<int> base; 1414 std::vector<int> pv;1415 1923 for(i=0;i<num;i++) 1416 1924 { … … 1428 1936 1429 1937 1430 /****************************************************************/1431 //construct a monomial based on the support of it1432 //returns a squarefree monomial1433 poly pMaken(std::vector<int> vbase)1434 {1435 int n=vbase.size();1436 poly p,q=pOne();1437 //equmab(n);1438 for(int i=0;i<n;i++)1439 {1440 p = pOne();pSetExp(p, vbase[i], 1);pSetm(p);pSetCoeff(p, nInit(1));1441 //Print("attention! ");pWrite(p);1442 q=pp_Mult_mm(q,p,currRing);1443 }1444 //PrintS("the polynomial according to the metrix M is:\n");1445 //listprint(vbase);1446 //pWrite(q);1447 return q;1448 }1449 1450 // returns a ideal according to a set of supports1451 ideal idMaken(std::vector<std::vector<int> > vecs)1452 {1453 ideal id_re=idInit(1,1);1454 poly p;1455 int i,lv=vecs.size();1456 for(i=0;i<lv;i++)1457 {1458 //Print("The vector is: ");1459 //listprint(vecs[i]);1460 1461 p=pMaken(vecs[i]);1462 //Print("The polynomial is: ");1463 //pWrite(p);1464 idInsertPoly(id_re, p);1465 }1466 //PrintS("This is the metrix M:\n");1467 //listsprint(vecs);1468 //PrintS("the ideal according to metrix M is:\n");1469 idSkipZeroes(id_re);1470 //id_print(id_re);1471 return id_re;1472 }1473 1474 1475 1938 1476 1939 … … 1493 1956 } 1494 1957 1958 1959 1495 1960 // returns a ideal according to a set of supports 1496 1961 std::vector<std::vector<poly> > idMakei(std::vector<std::vector<int> > mv,std::vector<std::vector<int> > vecs) … … 1520 1985 1521 1986 //return the graded pieces of cohomology T^1 according to a,b 1987 //original method (only for debugging) 1522 1988 void gradedpiece1(ideal h,poly a,poly b) 1523 1989 { 1524 int i,j; 1525 std::vector<std::vector<int> > hvs=supports(h); 1526 std::vector<int> av=support1(a); 1527 std::vector<int> bv=support1(b); 1990 int i,j,m; 1528 1991 ideal sub=psubset(b); 1529 std::vector<std::vector<int> > sbv=supports(sub); 1530 //ideal M=Mab(h,a,b); 1531 std::vector<std::vector<int> > mv=Mabv(h,a,b); 1532 PrintS("The homophisim is map onto the set:\n"); 1533 id_print(idMaken(mv)); 1534 int m=mv.size(); 1535 std::vector<std::vector<int> > good; 1536 std::vector<int> bad,vv; 1992 std::vector<int> av=support1(a), bv=support1(b), bad, vv; 1993 std::vector<std::vector<int> > hvs=supports(h), sbv=supports(sub), mv=Mabv(h,a,b),good; 1994 m=mv.size(); 1537 1995 ring r=currRing; 1538 1996 if( m > 0 ) … … 1564 2022 if(bv.size()!=1) 1565 2023 { 1566 PrintS("This is the solution of coefficients:\n");2024 //PrintS("This is the solution of coefficients:\n"); 1567 2025 listsprint(solve); 1568 2026 } … … 1576 2034 equmab(solve[0].size()); 1577 2035 std::vector<std::vector<int> > solves=vecqring(solve,suu); 1578 PrintS("This is the solution of coefficients:\n");2036 //PrintS("This is the solution of coefficients:\n"); 1579 2037 listsprint(solves); 1580 2038 rChangeCurrRing(r); … … 1697 2155 std::vector<int> numfree(ideal h) 1698 2156 { 1699 int i,j,num=0; poly p;2157 int i,j,num=0; 1700 2158 std::vector<int> fvar; 1701 2159 for(j=1;j<=currRing->N;j++) … … 1751 2209 ideal h1=getpresolve(h2); 1752 2210 poly q,e=pOne(); 1753 int lg=IDELEMS(h1) ;2211 int lg=IDELEMS(h1),n,i,j,t; 1754 2212 std::vector<int> fvar=numfree(h1); 1755 int n=fvar.size(); 1756 //Print("*************&&&&&&&&&&&*******************There are %d free variables in total\n",n); 1757 int i,j,t; 1758 //Print("lg is %d\n",lg); 2213 n=fvar.size(); 1759 2214 if(n==0) 1760 2215 { … … 1768 2223 for(i=0;i<lg;i++) 1769 2224 { 1770 //Print("The polynomial is the %dth one:\n",i+1);1771 2225 q=pCopy(h1->m[i]); 1772 2226 //pWrite(q); … … 1792 2246 else 1793 2247 { 1794 //Print("aiyamaya is %d \n",n_Int(pGetCoeff(q),currRing->cf));1795 2248 vec.push_back(n_Int(pGetCoeff(q),currRing->cf)); 1796 2249 } … … 1845 2298 std::vector<int> subspacet1(int num, std::vector<std::vector<int> > ntvs) 1846 2299 { 1847 int i,j,t; 1848 int n=ntvs.size(); 2300 int i, j, t, n=ntvs.size(); 1849 2301 std::vector<int> subase; 1850 2302 for(t=0;t<n;t++) … … 1877 2329 { 1878 2330 int i,j; 1879 std::vector<int> alset=findalpha(mv,bv); 1880 std::vector<int> subase; 2331 std::vector<int> alset=findalpha(mv,bv), subase; 1881 2332 std::vector<std::vector<int> > subases; 1882 2333 for(i=0;i<alset.size();i++) … … 1919 2370 1920 2371 //fix the problem of the number of the new variables 2372 //original method for T^2(only for debugging) 1921 2373 void gradedpiece2(ideal h,poly a,poly b) 1922 2374 { 1923 int t0,t1,t2,i,j,t; 2375 int t0,t1,t2,i,j,t,m; 2376 ideal sub=psubset(b); 1924 2377 ring r=rCopy(currRing); 1925 std::vector<std::vector<int> > hvs=supports(h); 1926 std::vector<int> av=support1(a); 1927 std::vector<int> bv=support1(b); 1928 ideal sub=psubset(b); 1929 std::vector<std::vector<int> > mv=Mabv(h,a,b); 1930 std::vector<std::vector<int> > mts=mabtv(hvs,mv,av,bv); 2378 std::vector<std::vector<int> > hvs=supports(h), mv=Mabv(h,a,b), mts, vecs,vars; 2379 std::vector<int> av=support1(a), bv=support1(b), vec,var; 2380 mts=mabtv(hvs,mv,av,bv); 1931 2381 PrintS("The homomorphism should map onto:\n"); 1932 2382 lpsprint(idMakei(mv,mts)); 1933 int m=mv.size(); 1934 //ideal M=Mab(h,a,b); 1935 std::vector<std::vector<int> > vecs,vars; 1936 std::vector<int> vec,var; 2383 m=mv.size(); 1937 2384 if(m > 0) 1938 2385 { … … 2031 2478 2032 2479 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2480 /**********************************************************************/ 2048 2481 //For the method of N_{a-b} … … 2054 2487 bool nabconditionv(std::vector<std::vector<int> > hvs, std::vector<int> pv, std::vector<int> av, std::vector<int> bv) 2055 2488 { 2056 std::vector<int> vec1=vecIntersection(pv,bv); 2057 std::vector<int> vec2=vecUnion(pv,bv); 2489 std::vector<int> vec1=vecIntersection(pv,bv), vec2=vecUnion(pv,bv); 2058 2490 int s1=vec1.size(); 2059 2491 if(!vInvsl(vec2,hvs) && s1==0 && vsubset(av,pv)) … … 2079 2511 { 2080 2512 if(nabconditionv(hvs,hvs[i],av,bv)) 2513 { 2514 //PrintS("satisfy:\n"); 2081 2515 vecs.push_back(hvs[i]); 2516 } 2082 2517 } 2083 2518 return vecs; … … 2097 2532 if(vInvsl(v1,hvs)) 2098 2533 { 2099 //PrintS("They are in Nab2\n");2100 2534 return (true); 2101 2535 } 2102 //PrintS("They are not in Nab2\n");2103 2536 return (false); 2104 2537 } … … 2146 2579 if(!vInvsl(sv,hvs)) 2147 2580 { 2148 //PrintS("TRUE! It is in tilde Nab!\n");2149 2581 return true; 2150 2582 } 2151 2583 } 2152 //PrintS("FALSE! It is not in tilde Nab!\n");2153 2584 return false; 2154 2585 } … … 2162 2593 std::vector<int> tnab(std::vector<std::vector<int> > hvs,std::vector<std::vector<int> > nvs,std::vector<std::vector<int> > bvs) 2163 2594 { 2164 std::vector<int> pv; 2165 std::vector<int> vec; 2595 std::vector<int> pv, vec; 2166 2596 for(int j=0;j<nvs.size();j++) 2167 2597 { … … 2196 2626 std::vector<std::vector<int> > value1(std::vector<std::vector<int> > mvs, std::vector<std::vector<int> > nvs, std::vector<std::vector<int> > vecs,std::vector<int> av, std::vector<int> bv) 2197 2627 { 2198 std::vector<int> pv;2199 std::vector<int> base;2628 int j; 2629 std::vector<int> pv, base; 2200 2630 std::vector<std::vector<int> > bases; 2201 2631 for(int t=0;t<vecs.size();t++) … … 2204 2634 { 2205 2635 pv=phimage(mvs[i],av,bv); 2206 for( intj=0;j<nvs.size();j++)2636 for( j=0;j<nvs.size();j++) 2207 2637 { 2208 2638 if(vEvl(pv,nvs[j])) 2639 { 2209 2640 base.push_back(vecs[t][j]); 2641 break; 2642 } 2210 2643 } 2644 if(j==nvs.size()) 2645 { 2646 base.push_back(0); 2647 } 2211 2648 } 2212 2649 if(base.size()!=mvs.size()) 2213 2650 { 2214 WerrorS("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1"); 2651 //WerrorS("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1"); 2652 WerrorS("Errors in Equations solving (Values Finding)!"); 2215 2653 usleep(1000000); 2216 2654 assert(false); 2217 WerrorS("Errors in Nab set!"); 2655 2218 2656 } 2219 2657 … … 2238 2676 //vtm(solve); 2239 2677 intvec *m; 2240 int i,j; 2241 int a=vecs.size(); 2678 int i,j, a=vecs.size(); 2242 2679 if(a==0) 2243 2680 { … … 2264 2701 2265 2702 2266 /*void ppppp(int l) 2267 { 2268 int i; 2269 std::vector<std::vector<int> > vecs; 2270 std::vector<int> vec; 2271 for(i=0;i<l;i++) 2272 { 2273 for(int j=i*l;j<i*l+l;j++) 2274 { 2275 vec.push_back(j); 2276 } 2277 vecs.push_back(vec); 2278 vec.clear(); 2279 } 2280 PrintS("May I have your attention please!\n"); 2281 listsprint(vecs); 2282 intvec *m=T1mat(vecs); 2283 PrintS("May I have your attention again!\n"); 2284 m->show(0,0); 2285 }*/ 2286 2287 2288 2289 2290 2703 2704 2705 2706 //returns the set of position number of minimal gens in M 2291 2707 std::vector<int> gensindex(ideal M, ideal ids) 2292 2708 { … … 2311 2727 { 2312 2728 int i; 2313 ideal hi=idInit(1,1);2314 2729 std::vector<std::vector<int> > mv=Mabv(h,a,b); 2315 ideal M=idMaken(mv); 2316 //PrintS("mab\n"); 2317 //id_print(M); 2318 //PrintS("idsrRing\n"); 2319 //id_print(idsrRing(h)); 2730 ideal M=idMaken(mv), hi=idInit(1,1); 2320 2731 std::vector<int> index = gensindex(M, idsrRing(h)); 2321 //PrintS("index\n");2322 //listprint(index);2323 2732 for(i=0;i<index.size();i++) 2324 2733 { … … 2326 2735 } 2327 2736 idSkipZeroes(hi); 2328 //PrintS("over\n");2329 // id_print(hi);2330 2737 return (hi); 2331 2738 } … … 2336 2743 { 2337 2744 int i,j; 2338 std::vector<int> vec ;2745 std::vector<int> vec,solm; 2339 2746 std::vector<std::vector<int> > solsm; 2340 std::vector<int> solm;2341 2747 for(i=0;i<solve.size();i++) 2342 2748 { … … 2355 2761 2356 2762 //T_1 graded piece(N method) 2763 //frame of the most efficient version 2764 //regardless of links 2357 2765 2358 2766 intvec * gradedpiece1n(ideal h,poly a,poly b) 2359 2767 { 2360 int i,j,co; 2361 std::vector<std::vector<int> > hvs=supports(h); 2362 std::vector<int> av=support1(a); 2363 //listprint(av); 2364 std::vector<int> bv=support1(b); 2365 //listprint(bv); 2366 ideal sub=psubset(b); 2367 //id_print(sub); 2368 std::vector<std::vector<int> > sbv=supports(sub); 2369 //listsprint(sbv); 2370 std::vector<std::vector<int> > nv=Nabv(hvs,av,bv); 2371 //PrintS("The N set is:\n"); 2372 //listsprint(nv); 2373 std::vector<std::vector<int> > mv=Mabv(h,a,b); 2374 //listsprint(mv); 2375 ideal M=idMaken(mv); 2376 std::vector<int> index = gensindex(M, idsrRing(h)); 2377 //ideal gens=mingens(M,index); 2378 int n=nv.size(); 2379 //PrintS("The homophisim is map onto the set:\n"); 2380 //id_print(M); 2381 std::vector<std::vector<int> > good,solve; 2382 std::vector<int> bad; 2768 int i,j,co,n; 2769 std::vector<std::vector<int> > hvs=supports(h),mv=Mabv(h,a,b),sbv,nv,good,solve; 2770 std::vector<int> av=support1(a), bv=support1(b), bad, tnv, index; 2771 ideal sub=psubset(b),M; 2772 sbv=supports(sub); 2773 nv=Nabv(hvs,av,bv); 2774 M=idMaken(mv); 2775 index = gensindex(M, idsrRing(h)); 2776 n=nv.size(); 2383 2777 ring r=currRing; 2384 std::vector<int> tnv;2385 2778 if(n > 0) 2386 2779 { … … 2439 2832 2440 2833 2441 /* 2442 void vtm(std::vector<std::vector<int> > vecs) 2443 { 2444 int i,j; 2445 2446 intvec *m; 2447 2448 int r=vecs.size(); 2449 Print("r is %d\n",r); 2450 // c=(vecs[0]).size(); 2451 2452 PrintS("no error yet:\n"); 2453 m=new intvec(r); 2454 2455 for(i=0;i<r;i++) 2456 { 2457 2458 for(j=0;j<r;j++) 2459 { 2460 (*m)[i]=*(vecs[i]); 2461 Print("%d",IMATELEM(*m,i,j)); 2462 } 2463 } 2464 // return matt; 2465 } 2466 */ 2467 2468 2469 2470 2471 2834 2835 2836 2837 //for debugging 2472 2838 void T1(ideal h) 2473 2839 { … … 2479 2845 for(int i=0;i<IDELEMS(bi);i++) 2480 2846 { 2481 PrintS("This is aset according to:");2847 //PrintS("This is aset according to:"); 2482 2848 b=pCopy(bi->m[i]); 2483 2849 pWrite(b); … … 2547 2913 { 2548 2914 int i,j; 2549 std::vector<int> alset=findalphan(N,tN); 2550 std::vector<int> subase; 2915 std::vector<int> alset=findalphan(N,tN), subase; 2551 2916 std::vector<std::vector<int> > subases; 2552 2917 for(i=0;i<alset.size();i++) … … 2568 2933 std::vector<std::vector<int> > value2(std::vector<std::vector<int> > mvs, std::vector<std::vector<int> > nvs, std::vector<std::vector<int> > mts, std::vector<std::vector<int> > nts, std::vector<std::vector<int> > vecs,std::vector<int> av, std::vector<int> bv) 2569 2934 { 2570 std::vector<int> pv,qv; 2571 std::vector<int> base; 2572 int row,col; 2935 int row,col,j; 2936 std::vector<int> pv,qv, base; 2573 2937 std::vector<std::vector<int> > bases; 2574 2938 //PrintS("This is the nabt:\n"); … … 2578 2942 //listsprint(mts); 2579 2943 //PrintS("mabt ends:\n"); 2580 2581 2944 for(int t=0;t<vecs.size();t++) 2582 2945 { … … 2589 2952 if(vEvl(pv,qv)) 2590 2953 base.push_back(0); 2591 //PrintS("This is image of p and q:\n");2592 //listprint(pv); PrintS("*********************\n");listprint(qv);2593 //PrintS("nabt ends:\n");2594 2954 else 2595 2955 { 2596 for( intj=0;j<nts.size();j++)2956 for(j=0;j<nts.size();j++) 2597 2957 { 2598 2958 row=nts[j][0]; 2599 2959 col=nts[j][1]; 2600 //PrintS("This is nvs:\n");2601 //listprint(nvs[row]); PrintS("*********************\n");listprint(nvs[col]);2602 //PrintS("nabt ends:\n");2603 2960 if(vEvl(pv,nvs[row])&&vEvl(qv,nvs[col])) 2604 2961 { 2605 2962 base.push_back(vecs[t][j]);break; 2606 //PrintS("This is nvs,they are the same:\n");2607 //listprint(nvs[row]); listprint(nvs[col]);2608 //PrintS("nabt ends:\n");2609 2963 } 2610 else 2964 else if(vEvl(pv,nvs[col])&&vEvl(qv,nvs[row])) 2611 2965 { 2612 2966 base.push_back(-vecs[t][j]);break; 2613 //PrintS("This is nvs,they are the same:\n");2614 //listprint(nvs[row]); listprint(nvs[col]);2615 //PrintS("nabt ends:\n");2616 2967 } 2617 2968 } 2969 if(j==nts.size()) {base.push_back(0);} 2618 2970 } 2619 2971 } 2620 2972 if(base.size()!=mts.size()) 2621 2973 { 2622 WerrorS("Errors in Nab set!");2623 //WerrorS("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1");2974 WerrorS("Errors in Values Finding(value2)!"); 2975 //WerrorS("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1"); 2624 2976 usleep(1000000); 2625 2977 assert(false); … … 2637 2989 { 2638 2990 int i,j; 2639 std::vector<std::vector<int> > hvs=supports(h) ;2991 std::vector<std::vector<int> > hvs=supports(h),mv,mts; 2640 2992 std::vector<int> av=support1(a), bv=support1(b); 2641 std::vector<std::vector<int> > mv=Mabv(h,a,b), mts=mabtv(hvs,mv,av,bv); 2993 mv=Mabv(h,a,b); 2994 mts=mabtv(hvs,mv,av,bv); 2642 2995 std::vector<std::vector<poly> > pvs=idMakei(mv,mts); 2643 2996 ideal gens=idInit(1,1); … … 2648 3001 } 2649 3002 idSkipZeroes(gens); 2650 //PrintS("This is the mix set of mab2!\n");2651 //id_print(gens);2652 3003 return (gens); 2653 3004 } … … 2662 3013 intvec * gradedpiece2n(ideal h,poly a,poly b) 2663 3014 { 2664 int i,j,t; 2665 std::vector<std::vector<int> > hvs=supports(h); 2666 std::vector<int> av=support1(a); 2667 std::vector<int> bv=support1(b); 3015 int i,j,t,n; 3016 std::vector<std::vector<int> > hvs=supports(h),nv,mv,mts,sbv,vecs,vars,ntvs,solve; 3017 std::vector<int> av=support1(a), bv=support1(b),tnv,vec,var; 2668 3018 ideal sub=psubset(b); 2669 s td::vector<std::vector<int> > sbv=supports(sub);2670 std::vector<std::vector<int> >nv=Nabv(hvs,av,bv);2671 intn=nv.size();2672 std::vector<int>tnv=tnab(hvs,nv,sbv);3019 sbv=supports(sub); 3020 nv=Nabv(hvs,av,bv); 3021 n=nv.size(); 3022 tnv=tnab(hvs,nv,sbv); 2673 3023 ring r=currRing; 2674 std::vector<std::vector<int> >mv=Mabv(h,a,b);2675 std::vector<std::vector<int> >mts=mabtv(hvs,mv,av,bv);3024 mv=Mabv(h,a,b); 3025 mts=mabtv(hvs,mv,av,bv); 2676 3026 //PrintS("The relations are:\n"); 2677 3027 //listsprint(mts); 2678 3028 //PrintS("The homomorphism should map onto:\n"); 2679 3029 //lpsprint(idMakei(mv,mts)); 2680 std::vector<std::vector<int> > vecs,vars,ntvs;2681 std::vector<int> vec,var;2682 std::vector<std::vector<int> > solve;2683 3030 if(n>0) 2684 3031 { … … 2693 3040 if(tNab(hvs,nv[i],sbv)&&tNab(hvs,nv[j],sbv))//condition 1 2694 3041 { 2695 //pWrite(pMaken(nv[i]));pWrite(pMaken(nv[j]));2696 //PrintS("They are both in tilde N.\n");2697 //PrintS("tilde N is:\n"); listprint(tnv);2698 3042 vec=makeequation(t0+1,0,0); 2699 3043 vecs.push_back(vec); … … 2750 3094 2751 3095 2752 3096 //for debugging 2753 3097 void T2(ideal h) 2754 3098 { … … 2794 3138 2795 3139 2796 3140 /*****************************for links*******************************************/ 3141 //the image phi(pv)=pv minus av minus bv 3142 std::vector<int> phimagel(std::vector<int> fv, std::vector<int> av, std::vector<int> bv) 3143 { 3144 std::vector<int> nv; 3145 nv=vecMinus(fv,bv); 3146 nv=vecMinus(nv,av); 3147 return nv; 3148 } 3149 3150 3151 3152 //mvs and nvs are the supports of ideal Mab and Nab 3153 //vecs is the solution of nab 3154 std::vector<std::vector<int> > value1l(std::vector<std::vector<int> > mvs, std::vector<std::vector<int> > lks, std::vector<std::vector<int> > vecs,std::vector<int> av, std::vector<int> bv) 3155 { 3156 int j; 3157 std::vector<int> pv; 3158 std::vector<int> base; 3159 std::vector<std::vector<int> > bases; 3160 for(int t=0;t<vecs.size();t++) 3161 { 3162 for(int i=0;i<mvs.size();i++) 3163 { 3164 pv=phimagel(mvs[i], av, bv); 3165 for(j=0;j<lks.size();j++) 3166 { 3167 if(vEvl(pv,lks[j])) 3168 { 3169 base.push_back(vecs[t][j]);break; 3170 } 3171 } 3172 //if(j==lks.size()) {base.push_back(0);} 3173 } 3174 if(base.size()!=mvs.size()) 3175 { 3176 WerrorS("Errors in Values Finding(value1l)!"); 3177 usleep(1000000); 3178 assert(false); 3179 3180 } 3181 3182 bases.push_back(base); 3183 base.clear(); 3184 } 3185 return bases; 3186 } 3187 3188 /***************************************************/ 3189 clock_t t_begin, t_mark, t_start, t_construct=0, t_solve=0, t_value=0, t_total=0; 3190 /**************************************************/ 3191 3192 3193 static void TimeShow(clock_t t_construct, clock_t t_solve, clock_t t_value ,clock_t t_total) 3194 { 3195 Print("The time of value matching for first order deformation: %.2f sec ;\n", ((double) t_value)/CLOCKS_PER_SEC); 3196 Print("The total time of fpiece: %.2f sec ;\n", ((double) t_total)/CLOCKS_PER_SEC); 3197 Print("The time of equations construction for fpiece: %.2f sec ;\n", ((double) t_construct)/CLOCKS_PER_SEC); 3198 Print("The total time of equations solving for fpiece: %.2f sec ;\n", ((double) t_solve)/CLOCKS_PER_SEC); 3199 PrintS("__________________________________________________________\n"); 3200 } 3201 3202 3203 3204 std::vector<std::vector<int> > gpl(ideal h,poly a,poly b) 3205 { 3206 int i,j,co; 3207 std::vector<std::vector<int> > hvs=supports(h),sbv,nv,mv,good,solve; 3208 std::vector<int> av=support1(a), bv=support1(b),index,bad,tnv; 3209 ideal sub=psubset(b); 3210 sbv=supports(sub); 3211 nv=Nabv(hvs,av,bv); 3212 mv=Mabv(h,a,b); 3213 ideal M=idMaken(mv); 3214 index = gensindex(M, idsrRing(h)); 3215 int n=nv.size(); 3216 ring r=currRing; 3217 t_begin=clock(); 3218 if(n > 0) 3219 { 3220 tnv=tnab(hvs,nv,sbv); 3221 for(i=0;i<tnv.size();i++) 3222 { 3223 co=tnv[i]; 3224 bad.push_back(co+1); 3225 } 3226 for(i=0;i<n;i++) 3227 { 3228 for(j=i+1;j<n;j++) 3229 { 3230 if(nabtconditionv(hvs,nv[i],nv[j],av,bv)) 3231 { 3232 good=listsinsertlist(good,i+1,j+1); 3233 } 3234 else 3235 { 3236 ; 3237 } 3238 } 3239 } 3240 t_construct=t_construct+clock()-t_begin; 3241 t_begin=clock(); 3242 solve=eli2(n,bad,good); 3243 t_solve=t_solve+clock()-t_begin; 3244 if(bv.size()!=1) 3245 {; 3246 } 3247 else 3248 { 3249 std::vector<int> su=make1(n); 3250 std::vector<std::vector<int> > suu; 3251 suu.push_back(su); 3252 equmab(n); 3253 solve=vecqring(solve,suu); 3254 rChangeCurrRing(r); 3255 } 3256 } 3257 else 3258 { 3259 solve.clear(); 3260 } 3261 //listsprint(solve); 3262 //sl->show(0,0); 3263 return solve; 3264 } 3265 3266 3267 //T^1 3268 //only need to consider the links of a, and reduce a to empty set 3269 intvec * gradedpiece1nl(ideal h,poly a,poly b, int set) 3270 { 3271 t_start=clock(); 3272 int i,j,co; 3273 poly e=pOne(); 3274 std::vector<int> av=support1(a),bv=support1(b),index, em; 3275 std::vector<std::vector<int> > solve, hvs=supports(h), lks=links(a,h), mv=Mabv(h,a,b), nvl; 3276 ideal id_links=idMaken(lks); 3277 ideal M=idMaken(mv); 3278 index = gensindex(M, idsrRing(h)); 3279 solve=gpl(id_links,e,b); 3280 t_mark=clock(); 3281 nvl=Nabv(lks,em,bv); 3282 solve=value1l(mv, nvl , solve, av, bv); 3283 if(set==1) 3284 { 3285 solve=minisolve(solve,index); 3286 } 3287 intvec *sl=Tmat(solve); 3288 t_value=t_value+clock()-t_mark; 3289 t_total=t_total+clock()-t_start; 3290 return sl; 3291 } 3292 3293 3294 3295 3296 //for finding values of T^2 3297 std::vector<std::vector<int> > value2l(std::vector<std::vector<int> > mvs, std::vector<std::vector<int> > lks, std::vector<std::vector<int> > mts, std::vector<std::vector<int> > lkts, std::vector<std::vector<int> > vecs,std::vector<int> av, std::vector<int> bv) 3298 { 3299 std::vector<int> pv,qv,base; 3300 int row,col,j; 3301 std::vector<std::vector<int> > bases; 3302 if(vecs.size()==0) 3303 { 3304 3305 } 3306 for(int t=0;t<vecs.size();t++) 3307 { 3308 for(int i=0;i<mts.size();i++) 3309 { 3310 row=mts[i][0]; 3311 col=mts[i][1]; 3312 pv=phimagel(mvs[row],av,bv); 3313 qv=phimagel(mvs[col],av,bv); 3314 if(vEvl(pv,qv)) 3315 base.push_back(0); 3316 else 3317 { 3318 for(j=0;j<lkts.size();j++) 3319 { 3320 row=lkts[j][0]; 3321 col=lkts[j][1]; 3322 if(vEvl(pv,lks[row])&&vEvl(qv,lks[col])) 3323 { 3324 base.push_back(vecs[t][j]);break; 3325 } 3326 else if(vEvl(qv,lks[row])&&vEvl(pv,lks[col])) 3327 { 3328 base.push_back(-vecs[t][j]);break; 3329 } 3330 } 3331 //if(j==lkts.size()) 3332 //{ 3333 //base.push_back(0); 3334 //} 3335 } 3336 } 3337 if(base.size()!=mts.size()) 3338 { 3339 WerrorS("Errors in Values Finding!"); 3340 //WerrorS("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1"); 3341 usleep(1000000); 3342 assert(false); 3343 } 3344 bases.push_back(base); 3345 base.clear(); 3346 } 3347 return bases; 3348 } 3349 3350 3351 std::vector<std::vector<int> > gpl2(ideal h,poly a,poly b) 3352 { 3353 int i,j,t,n; 3354 std::vector<std::vector<int> > hvs=supports(h),sbv,nv,mv,mts,vecs,vars,ntvs,solve; 3355 std::vector<int> av=support1(a), bv=support1(b),vec,var,tnv; 3356 ideal sub=psubset(b); 3357 sbv=supports(sub); 3358 nv=Nabv(hvs,av,bv); 3359 n=nv.size(); 3360 tnv=tnab(hvs,nv,sbv); 3361 ring r=currRing; 3362 mv=Mabv(h,a,b); 3363 mts=mabtv(hvs,mv,av,bv); 3364 if(n>0) 3365 { 3366 ntvs=nabtv( hvs, nv, av, bv); 3367 int l=ntvs.size(); 3368 if(l>0) 3369 { 3370 for(int t0=0;t0<l;t0++) 3371 { 3372 i=ntvs[t0][0]; 3373 j=ntvs[t0][1]; 3374 if(tNab(hvs,nv[i],sbv)&&tNab(hvs,nv[j],sbv))//condition 1 3375 { 3376 vec=makeequation(t0+1,0,0); 3377 vecs.push_back(vec); 3378 vec.clear(); 3379 } 3380 for(int t1=t0+1;t1<ntvs.size();t1++) 3381 { 3382 for(int t2=t1+1;t2<ntvs.size();t2++) 3383 { 3384 if(ntvs[t0][0]==ntvs[t1][0]&&ntvs[t1][1]==ntvs[t2][1]&&ntvs[t0][1]==ntvs[t2][0]) 3385 { 3386 i=ntvs[t0][0]; 3387 j=ntvs[t0][1]; 3388 t=ntvs[t1][1]; 3389 if(condition2for2nv(hvs,nv[i],nv[j],nv[t])) 3390 { 3391 vec=makeequation(t0+1,t1+1,t2+1); 3392 vecs.push_back(vec); 3393 vec.clear(); 3394 } 3395 } 3396 } 3397 } 3398 } 3399 if(n==1) {l=1;} 3400 equmab(l); 3401 ideal id_re=idMake3(vecs); 3402 std::vector<std::vector<int> > re=getvector(id_re,l); 3403 rChangeCurrRing(r); 3404 std::vector<std::vector<int> > sub=subspacetn(nv, tnv,ntvs); 3405 equmab(l); 3406 solve=vecqring(re, sub); 3407 rChangeCurrRing(r); 3408 } 3409 else 3410 { 3411 solve.clear(); 3412 } 3413 } 3414 else 3415 solve.clear(); 3416 return solve; 3417 } 3418 3419 3420 3421 3422 3423 3424 intvec * gradedpiece2nl(ideal h,poly a,poly b) 3425 { 3426 int i,j,t; 3427 poly e=pOne(); 3428 std::vector<int> av=support1(a), bv=support1(b), em; 3429 std::vector<std::vector<int> > hvs=supports(h), mv=Mabv(h,a,b),mts,solve,lks,nvl,ntsl; 3430 mts=mabtv(hvs,mv,av,bv); 3431 lks=links(a,h); 3432 ideal id_links=idMaken(lks); 3433 //PrintS("This is the links of a:\n"); id_print(id_links); 3434 nvl=Nabv(lks,em,bv); 3435 //PrintS("This is the N set:\n"); id_print(idMaken(nvl)); 3436 ntsl=nabtv(lks,nvl,em,bv); 3437 //PrintS("This is N^2:\n"); listsprint(ntsl); 3438 solve=gpl2(id_links,e,b); 3439 //PrintS("This is pre solution of N:\n"); listsprint(solve); 3440 if(solve.size() > 0) 3441 { 3442 solve=value2l(mv, nvl, mts, ntsl, solve, av, bv); 3443 } 3444 //PrintS("This is solution of N:\n"); listsprint(solve); 3445 intvec *sl=Tmat(solve); 3446 return sl; 3447 } 3448 3449 3450 3451 //for debugging 3452 /* 2797 3453 void Tlink(ideal h,poly a,poly b,int n) 2798 3454 { … … 2820 3476 gradedpiece2n(li,p,b); 2821 3477 } 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 3478 */ 3479 3480 3481 3482 /******************************for triangulation***********************************/ 3483 3484 3485 3486 //returns all the faces which are triangles 3487 ideal trisets(ideal h) 3488 { 3489 int i; 3490 ideal ids=idInit(1,1); 3491 std::vector<int> pv; 3492 for(i=0;i<IDELEMS(h);i++) 3493 { 3494 pv= support1(h->m[i]); 3495 if(pv.size()==3) 3496 idInsertPoly(ids, pCopy(h->m[i])); 3497 } 3498 idSkipZeroes(ids); 3499 return ids; 3500 } 3501 3502 3503 3504 3505 // case 1 new faces 3506 std::vector<std::vector<int> > triface(poly p, int vert) 3507 { 3508 int i; 3509 std::vector<int> vec, fv=support1(p); 3510 std::vector<std::vector<int> > fvs0, fvs; 3511 vec.push_back(vert); 3512 fvs.push_back(vec); 3513 fvs0=b_subsets(fv); 3514 fvs0=vsMinusv(fvs0,fv); 3515 for(i=0;i<fvs0.size();i++) 3516 { 3517 vec=fvs0[i]; 3518 vec.push_back(vert); 3519 fvs.push_back(vec); 3520 } 3521 return (fvs); 3522 } 3523 3524 3525 3526 3527 3528 3529 3530 // the size of p's support must be 3 3531 //returns the new complex which is a triangulation based on the face p 3532 ideal triangulations1(ideal h, poly p, int vert) 3533 { 3534 std::vector<int> vec, pv=support1(p); 3535 std::vector<std::vector<int> > vecs=supports(h),vs,vs0; 3536 vs0=triface(p,vert); 3537 vecs=vsMinusv(vecs, pv); 3538 vecs=vsUnion(vecs,vs0); 3539 //PrintS("This is the new simplicial complex according to the face \n"); pWrite(p); 3540 //PrintS("is:\n"); 3541 //listsprint(vecs); 3542 3543 ideal re=idMaken(vecs); 3544 3545 return re; 3546 } 3547 3548 3549 3550 3551 /* 3552 ideal triangulations1(ideal h) 3553 { 3554 int i,vert=currRing->N+1; 3555 std::vector<int> vec; 3556 std::vector<std::vector<int> > vecs=supports(h),vs,vs0; 3557 for (i=0;i<vecs.size();i++) 3558 { 3559 if((vecs[i]).size()==3) 3560 { 3561 vs0=triface(vecs[i],vert); 3562 vs=vsMinusv(vecs,vecs[i]); 3563 vs=vsUnion(vs,vs0); 3564 PrintS("This is the new simplicial complex according to the face \n");listprint(vecs[i]); 3565 PrintS("is:\n"); 3566 listsprint(vs); 3567 } 3568 //else if((vecs[i]).size()==4) 3569 //tetraface(vecs[i]); 3570 } 3571 //ideal hh=idMaken(vs); 3572 return h; 3573 }*/ 3574 3575 3576 std::vector<int> commonedge(poly p, poly q) 3577 { 3578 int i,j; 3579 std::vector<int> ev, fv1= support1(p), fv2= support2(q); 3580 for(i=0;i<fv1.size();i++) 3581 { 3582 if(IsinL(fv1[i], fv2)) 3583 ev.push_back(fv1[i]); 3584 } 3585 return ev; 3586 } 3587 3588 3589 intvec *edgemat(poly p, poly q) 3590 { 3591 intvec *m; 3592 int i,j; 3593 std::vector<int> dg=commonedge(p, q); 3594 int lg=dg.size(); 3595 m=new intvec(lg); 3596 if(lg!=0) 3597 { 3598 m=new intvec(lg); 3599 for(i=0;i<lg;i++) 3600 { 3601 (*m)[i]=dg[i]; 3602 } 3603 } 3604 return (m); 3605 } 3606 3607 // case 2 the new face 3608 std::vector<std::vector<int> > tetraface(poly p, poly q, int vert) 3609 { 3610 int i; 3611 std::vector<int> ev=commonedge(p, q), vec, fv1=support1(p), fv2=support1(q); 3612 std::vector<std::vector<int> > fvs1, fvs2, fvs; 3613 vec.push_back(vert); 3614 fvs.push_back(vec); 3615 fvs1=b_subsets(fv1); 3616 fvs2=b_subsets(fv2); 3617 fvs1=vsMinusv(fvs1, fv1); 3618 fvs2=vsMinusv(fvs2, fv2); 3619 fvs2=vsUnion(fvs1, fvs2); 3620 fvs2=vsMinusv(fvs2, ev); 3621 for(i=0;i<fvs2.size();i++) 3622 { 3623 vec=fvs2[i]; 3624 vec.push_back(vert); 3625 fvs.push_back(vec); 3626 } 3627 return (fvs); 3628 } 3629 3630 3631 //if p and q have a common edge 3632 ideal triangulations2(ideal h, poly p, poly q, int vert) 3633 { 3634 int i,j; 3635 std::vector<int> ev, fv1=support1(p), fv2=support1(q); 3636 std::vector<std::vector<int> > vecs=supports(h), vs1; 3637 ev=commonedge(p, q); 3638 vecs=vsMinusv(vecs, ev); 3639 vecs=vsMinusv(vecs,fv1); 3640 vecs=vsMinusv(vecs,fv2); 3641 vs1=tetraface(p, q, vert); 3642 vecs=vsUnion(vecs,vs1); 3643 ideal hh=idMaken(vecs); 3644 return hh; 3645 } 3646 3647 3648 3649 3650 // case 2 the new face 3651 std::vector<std::vector<int> > penface(poly p, poly q, poly g, int vert) 3652 { 3653 int i, en=0; 3654 std::vector<int> ev1=commonedge(p, q), ev2=commonedge(p, g), ev3=commonedge(q, g), ind, vec, fv1=support1(p), fv2=support1(q), fv3=support1(g); 3655 std::vector<std::vector<int> > fvs1, fvs2, fvs3, fvs, evec; 3656 evec.push_back(ev1); 3657 evec.push_back(ev2); 3658 evec.push_back(ev3); 3659 for(i=0;i<evec.size();i++) 3660 { 3661 if(evec[i].size()==2) 3662 { 3663 en++; 3664 } 3665 } 3666 if(en==2) 3667 { 3668 vec.push_back(vert); 3669 fvs.push_back(vec); 3670 fvs1=b_subsets(fv1); 3671 fvs2=b_subsets(fv2); 3672 fvs3=b_subsets(fv3); 3673 fvs1=vsMinusv(fvs1, fv1); 3674 fvs2=vsMinusv(fvs2, fv2); 3675 fvs3=vsMinusv(fvs3, fv3); 3676 fvs3=vsUnion(fvs3, fvs2); 3677 fvs3=vsUnion(fvs3, fvs1); 3678 for(i=0;i<evec.size();i++) 3679 { 3680 if(evec[i].size()==2) 3681 { 3682 fvs3=vsMinusv(fvs3, evec[i]); 3683 } 3684 } 3685 for(i=0;i<fvs3.size();i++) 3686 { 3687 vec=fvs3[i]; 3688 vec.push_back(vert); 3689 fvs.push_back(vec); 3690 } 3691 } 3692 return (fvs); 3693 } 3694 3695 3696 3697 ideal triangulations3(ideal h, poly p, poly q, poly g, int vert) 3698 { 3699 int i,j; 3700 std::vector<int> ev1=commonedge(p, q), ev2=commonedge(p, g), ev3=commonedge(q, g), fv1=support1(p), fv2=support1(q), fv3=support1(g); 3701 std::vector<std::vector<int> > vecs=supports(h), vs1, evec; 3702 evec.push_back(ev1); 3703 evec.push_back(ev2); 3704 evec.push_back(ev3); 3705 for(i=0;i<evec.size();i++) 3706 { 3707 if(evec[i].size()==2) 3708 { 3709 vecs=vsMinusv(vecs, evec[i]); 3710 } 3711 } 3712 vecs=vsMinusv(vecs,fv1); 3713 vecs=vsMinusv(vecs,fv2); 3714 vecs=vsMinusv(vecs,fv3); 3715 vs1=penface(p, q, g, vert); 3716 vecs=vsUnion(vecs,vs1); 3717 ideal hh=idMaken(vecs); 3718 return hh; 3719 } 3720 3721 3722 //returns p's valency in h 3723 //p must be a vertex 3724 int valency(ideal h, poly p) 3725 { 3726 int i, val=0; 3727 std::vector<int> ev=support1(pCopy(p)); 3728 int ver=ev[0]; 3729 //PrintS("the vertex is :\n"); listprint(p); 3730 std::vector<std::vector<int> > vecs=supports(idCopy(h)); 3731 for(i=0;i<vecs.size();i++) 3732 { 3733 if(vecs[i].size()==2 && IsinL(ver, vecs[i])) 3734 val++; 3735 } 3736 return (val); 3737 } 3738 3739 /*ideal triangulations2(ideal h) 3740 { 3741 int i,j,vert=currRing->N+1; 3742 std::vector<int> ev; 3743 std::vector<std::vector<int> > vecs=supports(h),vs,vs0,vs1; 3744 vs0=tetrasets(h); 3745 for (i=0;i<vs0.size();i++) 3746 { 3747 for(j=i;j<vs0.size();j++) 3748 { 3749 ev=commonedge(vs0[i],vs0[j]); 3750 if(ev.size()==2) 3751 { 3752 vecs=vsMinusv(vecs, ev); 3753 vs=vsMinusv(vecs,vs0[i]); 3754 vs=vsMinusv(vecs,vs0[j]); 3755 vs1=tetraface(vs0[i],vs0[j],vert); 3756 vs=vsUnion(vs,vs1); 3757 PrintS("This is the new simplicial complex according to the face 1 \n");listprint(vecs[i]); 3758 PrintS("face 2: \n"); 3759 PrintS("is:\n"); 3760 listsprint(vs); 3761 } 3762 } 3763 3764 //else if((vecs[i]).size()==4) 3765 //tetraface(vecs[i]); 3766 } 3767 //ideal hh=idMaken(vs); 3768 return h; 3769 }*/ 3770 3771 3772 3773 /*********************************For computation of X_n***********************************/ 3774 std::vector<std::vector<int> > vsMinusvs(std::vector<std::vector<int> > vs1, std::vector<std::vector<int> > vs2) 3775 { 3776 int i; 3777 std::vector<std::vector<int> > vs=vs1; 3778 for(i=0;i<vs2.size();i++) 3779 { 3780 vs=vsMinusv(vs, vs2[i]); 3781 } 3782 return vs; 3783 } 3784 3785 3786 std::vector<std::vector<int> > vs_subsets(std::vector<std::vector<int> > vs) 3787 { 3788 std::vector<std::vector<int> > sset, bv; 3789 for(int i=0;i<vs.size();i++) 3790 { 3791 bv=b_subsets(vs[i]); 3792 sset=vsUnion(sset, bv); 3793 } 3794 return sset; 3795 } 3796 3797 3798 3799 std::vector<std::vector<int> > p_constant(ideal Xo, ideal Sigma) 3800 { 3801 std::vector<std::vector<int> > xs=supports(idCopy(Xo)), ss=supports(idCopy(Sigma)), fvs1; 3802 fvs1=vs_subsets(ss); 3803 fvs1=vsMinusvs(xs, fvs1); 3804 return fvs1; 3805 } 3806 3807 3808 std::vector<std::vector<int> > p_change(ideal Sigma) 3809 { 3810 std::vector<std::vector<int> > ss=supports(idCopy(Sigma)), fvs; 3811 fvs=vs_subsets(ss); 3812 return (fvs); 3813 } 3814 3815 3816 3817 std::vector<std::vector<int> > p_new(ideal Xo, ideal Sigma) 3818 { 3819 int vert=0; 3820 std::vector<std::vector<int> > ss=supports(idCopy(Sigma)), fvs; 3821 for(int i=1;i<=currRing->N;i++) 3822 { 3823 for(int j=0;j<IDELEMS(Xo);j++) 3824 { 3825 if(pGetExp(Xo->m[j],i)>0) 3826 { 3827 vert=i+1; 3828 break; 3829 } 3830 } 3831 } 3832 int typ=ss.size(); 3833 if(typ==1) 3834 { 3835 fvs=triface(Sigma->m[0], vert); 3836 } 3837 else if(typ==2) 3838 { 3839 fvs=tetraface(Sigma->m[0], Sigma->m[1], vert); 3840 } 3841 else 3842 { 3843 fvs=penface(Sigma->m[0], Sigma->m[1], Sigma->m[2], vert); 3844 } 3845 return (fvs); 3846 } 3847 3848 3849 3850 3851 ideal c_New(ideal Io, ideal sig) 3852 { 3853 poly p, q, g; 3854 std::vector<std::vector<int> > vs1=p_constant(Io, sig), vs2=p_change(sig), vs3=p_new(Io, sig), vsig=supports(sig), vs; 3855 std::vector<int> ev; 3856 int ednum=vsig.size(); 3857 if(ednum==2) 3858 { 3859 vsig.push_back(commonedge(sig->m[0], sig->m[1])); 3860 } 3861 else if(ednum==3) 3862 { 3863 for(int i=0;i<IDELEMS(sig);i++) 3864 { 3865 for(int j=i+1;j<IDELEMS(sig);j++) 3866 { 3867 ev=commonedge(sig->m[i], sig->m[j]); 3868 if(ev.size()==2) 3869 { 3870 vsig.push_back(ev); 3871 } 3872 } 3873 } 3874 } 3875 //PrintS("the first part is:\n");id_print(idMaken(vs1)); 3876 //PrintS("the second part is:\n");id_print(idMaken(vsig)); 3877 //PrintS("the third part is:\n");id_print(idMaken(vs3)); 3878 vs2=vsMinusvs(vs2, vsig); 3879 //PrintS("the constant part2 is:\n");id_print(idMaken(vs2)); 3880 vs=vsUnion(vs2, vs1); 3881 //PrintS("the constant part is:\n");id_print(idMaken(vs)); 3882 vs=vsUnion(vs, vs3); 3883 //PrintS("the whole part is:\n");id_print(idMaken(vs)); 3884 return(idMaken(vs)); 3885 } 3886 3887 3888 3889 3890 std::vector<std::vector<int> > phi1(poly a, ideal Sigma) 3891 { 3892 std::vector<std::vector<int> > ss=supports(idCopy(Sigma)), fvs; 3893 std::vector<int> av=support1(a), intvec, vv; 3894 for(int i=0;i<ss.size();i++) 3895 { 3896 intvec=vecIntersection(ss[i], av); 3897 if(intvec.size()==av.size()) 3898 { 3899 vv=vecMinus(ss[i], av); 3900 fvs.push_back(vv); 3901 } 3902 } 3903 return fvs; 3904 } 3905 3906 3907 3908 std::vector<std::vector<int> > phi2(poly a, ideal Xo, ideal Sigma, int vert) 3909 { 3910 3911 std::vector<std::vector<int> > ss=p_new(Sigma, Xo), fvs; 3912 std::vector<int> av=support1(a), intvec, vv; 3913 for(int i=0;i<ss.size();i++) 3914 { 3915 intvec=vecIntersection(ss[i], av); 3916 if(intvec.size()==av.size()) 3917 { 3918 vv=vecMinus(ss[i], av); 3919 fvs.push_back(vv); 3920 } 3921 } 3922 return fvs; 3923 } 3924 3925 3926 std::vector<std::vector<int> > links_new(poly a, ideal Xo, ideal Sigma, int vert, int ord) 3927 { 3928 std::vector<int> av=support1(a); 3929 std::vector<std::vector<int> > lko, lkn, lk1, lk2; 3930 lko=links(a, Xo); 3931 if(ord==1) 3932 return lko; 3933 if(ord==2) 3934 { 3935 3936 lk1=phi1(a, Sigma); 3937 lk2=phi2(a, Xo, Sigma, vert); 3938 lkn=vsMinusvs(lko, lk1); 3939 lkn=vsUnion(lkn, lk2); 3940 return lkn; 3941 } 3942 if(ord==3) 3943 { 3944 lkn=phi2(a, Xo, Sigma, vert); 3945 return lkn; 3946 } 3947 WerrorS("Cannot find the links smartly!"); 3948 } 3949 3950 3951 3952 3953 //returns 1 if there is a real divisor of b not in Xs 3954 int existIn(poly b, ideal Xs) 3955 { 3956 std::vector<int> bv=support1(pCopy(b)); 3957 std::vector<std::vector<int> > xvs=supports(idCopy(Xs)), bs=b_subsets(bv); 3958 bs=vsMinusv(bs, bv); 3959 for(int i=0;i<bs.size();i++) 3960 { 3961 if(!vInvsl(bs[i], xvs)) 3962 { 3963 return 1; 3964 } 3965 } 3966 return 0; 3967 } 3968 3969 3970 int isoNum(poly p, ideal I, poly a, poly b) 3971 { 3972 int i; 3973 std::vector<std::vector<int> > vs=supports(idCopy(I)); 3974 std::vector<int> v1=support1(a), v2=support1(b), v=support1(p); 3975 std::vector<int> vp, iv=phimagel(v, v1, v2); 3976 for(i=0;i<IDELEMS(I);i++) 3977 { 3978 vp=support1(pCopy(I->m[i])); 3979 if(vEvl(iv, phimagel(vp, v1, v2))) 3980 { 3981 return (i+1); 3982 } 3983 } 3984 return (0); 3985 } 3986 3987 3988 3989 3990 int ifIso(poly p, poly q, poly f, poly g, poly a, poly b) 3991 { 3992 int i; 3993 std::vector<int> va=support1(a), vb=support1(b), vp=support1(p), vq=support1(q), vf=support1(f), vg=support1(g); 3994 std::vector<int> v1=phimagel(vp, va, vb), v2=phimagel(vq, va, vb), v3=phimagel(vf, va, vb), v4=phimagel(vg, va, vb); 3995 if((vEvl(v1, v3)&& vEvl(v2,v4))||(vEvl(v1, v4)&& vEvl(v2,v3)) ) 3996 { 3997 return (1); 3998 } 3999 return (0); 4000 } 4001 4002 4003 4004 4005 ideal idMinusp(ideal I, poly p) 4006 { 4007 ideal h=idInit(1,1); 4008 int i,j,eq=0; 4009 for(i=0;i<IDELEMS(I);i++) 4010 { 4011 if(!p_EqualPolys(I->m[i], p, currRing)) 4012 { 4013 idInsertPoly(h, pCopy(I->m[i])); 4014 } 4015 } 4016 idSkipZeroes(h); 4017 return h; 4018 } 2836 4019 2837 4020 … … 2867 4050 } 2868 4051 std::vector<int> vec=v_minus(av,bv); 2869 //PrintS("the degree is:\n");2870 //listprint(vec);4052 //PrintS("The degree is:\n"); 4053 //listprint(vec); 2871 4054 return vec; 2872 4055 } … … 2875 4058 2876 4059 4060 4061 4062 /********************************for stellar subdivision******************************/ 4063 4064 4065 std::vector<std::vector<int> > star(poly a, ideal h) 4066 { 4067 int i; 4068 std::vector<std::vector<int> > st,X=supports(h); 4069 std::vector<int> U,av=support1(a); 4070 for(i=0;i<X.size();i++) 4071 { 4072 U=vecUnion(av,X[i]); 4073 if(vInvsl(U,X)) 4074 { 4075 st.push_back(X[i]); 4076 } 4077 } 4078 return st; 4079 } 4080 4081 4082 std::vector<std::vector<int> > boundary(poly a) 4083 { 4084 std::vector<int> av=support1(a), vec; 4085 std::vector<std::vector<int> > vecs; 4086 vecs=b_subsets(av); 4087 vecs.push_back(vec); 4088 vecs=vsMinusv(vecs, av); 4089 return vecs; 4090 } 4091 4092 4093 4094 4095 4096 4097 std::vector<std::vector<int> > stellarsub(poly a, ideal h) 4098 { 4099 std::vector<std::vector<int> > vecs_minus, vecs_plus, lk=links(a,h), hvs=supports(h), sub, bys=boundary(a); 4100 std::vector<int> av=support1(a), vec, vec_n; 4101 int i,j,vert=0; 4102 for(i=1;i<=currRing->N;i++) 4103 { 4104 for(j=0;j<IDELEMS(h);j++) 4105 { 4106 if(pGetExp(h->m[j],i)>0) 4107 { 4108 vert=i+1; 4109 break; 4110 } 4111 } 4112 } 4113 vec_n.push_back(vert); 4114 for(i=0;i<lk.size();i++) 4115 { 4116 vec=vecUnion(av, lk[i]); 4117 vecs_minus.push_back(vec); 4118 for(j=0;j<bys.size();j++) 4119 { 4120 vec=vecUnion(lk[i], vec_n); 4121 vec=vecUnion(vec, bys[j]); 4122 vecs_plus.push_back(vec); 4123 } 4124 } 4125 sub=vsMinusvs(hvs, vecs_minus); 4126 sub=vsUnion(sub, vecs_plus); 4127 return(sub); 4128 } 4129 4130 4131 std::vector<std::vector<int> > bsubsets_1(poly b) 4132 { 4133 std::vector<int> bvs=support1(b), vs; 4134 std::vector<std::vector<int> > bset; 4135 for(int i=0;i<bvs.size();i++) 4136 { 4137 for(int j=0;j<bvs.size(), j!=i; j++) 4138 { 4139 vs.push_back(bvs[j]); 4140 } 4141 bset.push_back(vs); 4142 vs.resize(0); 4143 } 4144 return bset; 4145 } 4146 4147 4148 4149 /***************************for time testing******************************/ 4150 ideal T_1h(ideal h) 4151 { 4152 int i, j; 4153 //std::vector < intvec > T1; 4154 ideal ai=p_a(h), bi; 4155 //intvec *L; 4156 for(i=0;i<IDELEMS(ai);i++) 4157 { 4158 bi=p_b(h,ai->m[i]); 4159 if(!idIs0(bi)) 4160 { 4161 for(j=0;j<IDELEMS(bi);j++) 4162 { 4163 //PrintS("This is for:\n");pWrite(ai->m[i]); pWrite(bi->m[j]); 4164 gradedpiece1nl(h,ai->m[i],bi->m[j], 0); 4165 //PrintS("Succeed!\n"); 4166 //T1.push_back(L); 4167 } 4168 } 4169 } 4170 TimeShow(t_construct, t_solve, t_value, t_total); 4171 return h; 4172 4173 } 2877 4174 /**************************************interface T1****************************************/ 2878 4175 /* … … 2905 4202 2906 4203 4204 4205 BOOLEAN SRideal(leftv res, leftv args) 4206 { 4207 leftv h=args; 4208 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4209 { 4210 ideal hh=(ideal)h->Data(); 4211 res->rtyp =IDEAL_CMD; 4212 res->data =idsrRing(hh); 4213 } 4214 return false; 4215 } 4216 4217 4218 4219 4220 4221 2907 4222 BOOLEAN idcomplement(leftv res, leftv args) 2908 4223 { … … 2920 4235 2921 4236 4237 4238 4239 BOOLEAN t1h(leftv res, leftv args) 4240 { 4241 leftv h=args; 4242 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4243 { 4244 ideal hh=(ideal)h->Data(); 4245 res->rtyp =IDEAL_CMD; 4246 res->data =T_1h(hh); 4247 } 4248 return false; 4249 } 4250 4251 2922 4252 BOOLEAN idsr(leftv res, leftv args) 2923 4253 { … … 2926 4256 { 2927 4257 ideal h1= (ideal)h->Data(); 2928 //T1(h1);2929 4258 h = h->next; 2930 4259 if((h != NULL)&&(h->Typ() == POLY_CMD)) … … 2948 4277 int i,j; 2949 4278 std::vector<int> dg=gdegree(a,b); 2950 //PrintS("This is the degree of a and b\n");2951 //listprint(dg);2952 4279 int lg=dg.size(); 2953 4280 m=new intvec(lg); … … 2958 4285 { 2959 4286 (*m)[i]=dg[i]; 2960 //Print("This is the %dth degree of a and b: %d, and %d is copied\n",i,dg[i],(*m)[i]); 2961 } 2962 } 2963 /*for(j=0;j<lg;j++) 2964 { 2965 Print("[%d]: %d\n",j+1,(*m)[j]); 2966 }*/ 2967 //(m)->show(1,1); 2968 return (m); 4287 } 4288 } 4289 return (m); 2969 4290 } 2970 4291 … … 2990 4311 2991 4312 4313 BOOLEAN comedg(leftv res, leftv args) 4314 { 4315 leftv h=args; 4316 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4317 { 4318 poly p= (poly)h->Data(); 4319 h = h->next; 4320 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4321 { 4322 poly q= (poly)h->Data(); 4323 res->rtyp =INTVEC_CMD; 4324 res->data =edgemat(p,q); 4325 } 4326 } 4327 return false; 4328 } 4329 4330 4331 4332 2992 4333 BOOLEAN fb(leftv res, leftv args) 2993 4334 { … … 2998 4339 res->rtyp =IDEAL_CMD; 2999 4340 res->data =findb(h1); 4341 } 4342 return false; 4343 } 4344 4345 4346 BOOLEAN pa(leftv res, leftv args) 4347 { 4348 leftv h=args; 4349 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4350 { 4351 ideal h1= (ideal)h->Data(); 4352 res->rtyp =IDEAL_CMD; 4353 res->data =p_a(h1); 4354 } 4355 return false; 4356 } 4357 4358 4359 4360 BOOLEAN makeSimplex(leftv res, leftv args) 4361 { 4362 leftv h=args; 4363 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4364 { 4365 ideal h1= (ideal)h->Data(); 4366 res->rtyp =IDEAL_CMD; 4367 res->data =complementsimplex(h1); 4368 } 4369 return false; 4370 } 4371 4372 4373 BOOLEAN pb(leftv res, leftv args) 4374 { 4375 leftv h=args; 4376 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4377 { 4378 ideal h1= (ideal)h->Data(); 4379 h = h->next; 4380 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4381 { 4382 poly p= (poly)h->Data(); 4383 res->rtyp =IDEAL_CMD; 4384 res->data =p_b(h1,p); 4385 } 3000 4386 } 3001 4387 return false; … … 3050 4436 3051 4437 4438 BOOLEAN fgpl(leftv res, leftv args) 4439 { 4440 leftv h=args; 4441 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4442 { 4443 ideal h1= (ideal)h->Data(); 4444 h = h->next; 4445 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4446 { 4447 poly p= (poly)h->Data(); 4448 h = h->next; 4449 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4450 { 4451 poly q= (poly)h->Data(); 4452 h = h->next; 4453 if((h != NULL)&&(h->Typ() == INT_CMD)) 4454 { 4455 int d= (int)(long)h->Data(); 4456 res->rtyp =INTVEC_CMD; 4457 res->data =gradedpiece1nl(h1,p,q,d); 4458 } 4459 } 4460 } 4461 } 4462 return false; 4463 } 4464 4465 3052 4466 3053 4467 BOOLEAN genstt(leftv res, leftv args) … … 3097 4511 3098 4512 4513 BOOLEAN sgpl(leftv res, leftv args) 4514 { 4515 leftv h=args; 4516 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4517 { 4518 ideal h1= (ideal)h->Data(); 4519 h = h->next; 4520 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4521 { 4522 poly p= (poly)h->Data(); 4523 h = h->next; 4524 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4525 { 4526 poly q= (poly)h->Data(); 4527 res->rtyp =INTVEC_CMD; 4528 res->data =gradedpiece2nl(h1,p,q); 4529 } 4530 } 4531 } 4532 return false; 4533 } 4534 4535 3099 4536 BOOLEAN Links(leftv res, leftv args) 3100 4537 { … … 3115 4552 } 3116 4553 4554 BOOLEAN isSim(leftv res, leftv args) 4555 { 4556 leftv h=args; 4557 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4558 { 4559 ideal h1= (ideal)h->Data(); 4560 res->rtyp =IDEAL_CMD; 4561 res->data =IsSimplex(h1); 4562 } 4563 return false; 4564 } 4565 4566 4567 BOOLEAN nfaces1(leftv res, leftv args) 4568 { 4569 leftv h=args; 4570 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4571 { 4572 ideal h1= (ideal)h->Data(); 4573 h = h->next; 4574 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4575 { 4576 poly p= (poly)h->Data(); 4577 h = h->next; 4578 if((h != NULL)&&(h->Typ() == INT_CMD)) 4579 { 4580 int d= (int)(long)h->Data(); 4581 res->rtyp =IDEAL_CMD; 4582 res->data =triangulations1(h1, p, d); 4583 } 4584 } 4585 } 4586 return false; 4587 } 4588 4589 4590 BOOLEAN nfaces2(leftv res, leftv args) 4591 { 4592 leftv h=args; 4593 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4594 { 4595 ideal h1= (ideal)h->Data(); 4596 h = h->next; 4597 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4598 { 4599 poly p= (poly)h->Data(); 4600 h = h->next; 4601 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4602 { 4603 poly q= (poly)h->Data(); 4604 h = h->next; 4605 if((h != NULL)&&(h->Typ() == INT_CMD)) 4606 { 4607 int d= (int)(long)h->Data(); 4608 res->rtyp =IDEAL_CMD; 4609 res->data =triangulations2(h1,p,q,d); 4610 } 4611 } 4612 } 4613 } 4614 return false; 4615 } 4616 4617 4618 BOOLEAN nfaces3(leftv res, leftv args) 4619 { 4620 leftv h=args; 4621 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4622 { 4623 ideal h1= (ideal)h->Data(); 4624 h = h->next; 4625 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4626 { 4627 poly p= (poly)h->Data(); 4628 h = h->next; 4629 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4630 { 4631 poly q= (poly)h->Data(); 4632 h = h->next; 4633 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4634 { 4635 poly g= (poly)h->Data(); 4636 h = h->next; 4637 if((h != NULL)&&(h->Typ() == INT_CMD)) 4638 { 4639 int d= (int)(long)h->Data(); 4640 res->rtyp =IDEAL_CMD; 4641 res->data =triangulations3(h1,p,q,g,d); 4642 } 4643 } 4644 } 4645 } 4646 } 4647 return false; 4648 } 4649 4650 4651 4652 4653 4654 BOOLEAN eqsolve1(leftv res, leftv args) 4655 { 4656 leftv h=args;int i; 4657 std::vector<int> bset,bs; 4658 std::vector<std::vector<int> > gset; 4659 if((h != NULL)&&(h->Typ() == INT_CMD)) 4660 { 4661 int n= (int)(long)h->Data(); 4662 h = h->next; 4663 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4664 { 4665 ideal bi= (ideal)h->Data(); 4666 h = h->next; 4667 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4668 { 4669 ideal gi= (ideal)h->Data(); 4670 for(i=0;i<IDELEMS(bi);i++) 4671 { 4672 bs=support1(bi->m[i]); 4673 if(bs.size()==1) 4674 bset.push_back(bs[0]); 4675 else if(bs.size()==0) 4676 ; 4677 else 4678 { 4679 WerrorS("Errors in T^1 Equations Solving!"); 4680 usleep(1000000); 4681 assert(false); 4682 } 4683 4684 } 4685 gset=supports2(gi); 4686 res->rtyp =INTVEC_CMD; 4687 std::vector<std::vector<int> > vecs=eli2(n,bset,gset); 4688 res->data =Tmat(vecs); 4689 } 4690 } 4691 } 4692 return false; 4693 } 4694 4695 4696 BOOLEAN tsets(leftv res, leftv args) 4697 { 4698 leftv h=args; 4699 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4700 { 4701 ideal h1= (ideal)h->Data(); 4702 res->rtyp =IDEAL_CMD; 4703 res->data =trisets(h1); 4704 } 4705 return false; 4706 } 4707 4708 4709 4710 4711 4712 BOOLEAN Valency(leftv res, leftv args) 4713 { 4714 leftv h=args; 4715 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4716 { 4717 ideal h1= (ideal)h->Data(); 4718 h = h->next; 4719 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4720 { 4721 poly p= (poly)h->Data(); 4722 res->rtyp =INT_CMD; 4723 res->data =(void *)(long)valency(h1,p); 4724 } 4725 } 4726 return false; 4727 } 4728 4729 4730 4731 4732 BOOLEAN nabvl(leftv res, leftv args) 4733 { 4734 leftv h=args; 4735 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4736 { 4737 ideal h1= (ideal)h->Data(); 4738 h = h->next; 4739 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4740 { 4741 poly p= (poly)h->Data(); 4742 h = h->next; 4743 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4744 { 4745 poly q= (poly)h->Data(); 4746 res->rtyp =IDEAL_CMD; 4747 std::vector<std::vector<int> > vecs=supports(h1); 4748 std::vector<int> pv=support1(p), qv=support1(q); 4749 res->data =idMaken(Nabv(vecs,pv,qv)); 4750 } 4751 } 4752 } 4753 return false; 4754 } 4755 4756 4757 4758 BOOLEAN tnabvl(leftv res, leftv args) 4759 { 4760 leftv h=args; 4761 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4762 { 4763 ideal h1= (ideal)h->Data(); 4764 h = h->next; 4765 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4766 { 4767 poly p= (poly)h->Data(); 4768 h = h->next; 4769 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4770 { 4771 poly q= (poly)h->Data(); 4772 res->rtyp =IDEAL_CMD; 4773 std::vector<std::vector<int> > vecs=supports(h1), sbv,tnbr; 4774 std::vector<int> pv=support1(p), qv=support1(q); 4775 std::vector<std::vector<int> > nvs=Nabv(vecs, pv, qv); 4776 ideal sub=psubset(q); 4777 sbv=supports(sub); 4778 std::vector<int> tnv =tnab(vecs,nvs,sbv); 4779 for(int i=0;i<tnv.size();i++) 4780 { 4781 tnbr.push_back(nvs[tnv[i]]); 4782 } 4783 res->data =idMaken(tnbr); 4784 } 4785 } 4786 } 4787 return false; 4788 } 4789 4790 4791 BOOLEAN vsIntersec(leftv res, leftv args) 4792 { 4793 leftv h=args; 4794 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4795 { 4796 ideal h1= (ideal)h->Data(); 4797 h = h->next; 4798 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4799 { 4800 ideal h2= (ideal)h->Data(); 4801 res->rtyp =INT_CMD; 4802 std::vector<std::vector<int> > vs1=supports(h1), vs2=supports(h2); 4803 res->data =(void *)(long)(vsIntersection(vs1, vs2).size()); 4804 } 4805 } 4806 return false; 4807 } 4808 4809 4810 BOOLEAN mabvl(leftv res, leftv args) 4811 { 4812 leftv h=args; 4813 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4814 { 4815 ideal h1= (ideal)h->Data(); 4816 h = h->next; 4817 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4818 { 4819 poly p= (poly)h->Data(); 4820 h = h->next; 4821 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4822 { 4823 poly q= (poly)h->Data(); 4824 res->rtyp =IDEAL_CMD; 4825 res->data =idMaken(Mabv(h1,p,q)); 4826 } 4827 } 4828 } 4829 return false; 4830 } 4831 4832 4833 4834 BOOLEAN nabtvl(leftv res, leftv args) 4835 { 4836 leftv h=args; 4837 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4838 { 4839 ideal h1= (ideal)h->Data(); 4840 h = h->next; 4841 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4842 { 4843 poly p= (poly)h->Data(); 4844 h = h->next; 4845 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4846 { 4847 poly q= (poly)h->Data(); 4848 std::vector<std::vector<int> > hvs=supports(h1), nv, ntvs; 4849 std::vector<int> av=support1(p), bv=support1(q); 4850 nv=Nabv(hvs,av,bv); 4851 ntvs=nabtv( hvs, nv, av, bv); 4852 std::vector<std::vector<poly> > pvs=idMakei(nv,ntvs); 4853 ideal gens=idInit(1,1); 4854 for(int i=0;i<pvs.size();i++) 4855 { 4856 idInsertPoly(gens,pvs[i][0]); 4857 idInsertPoly(gens,pvs[i][1]); 4858 } 4859 idSkipZeroes(gens); 4860 res->rtyp =IDEAL_CMD; 4861 res->data =gens; 4862 } 4863 } 4864 } 4865 return false; 4866 } 4867 4868 4869 BOOLEAN linkn(leftv res, leftv args) 4870 { 4871 leftv h=args; 4872 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4873 { 4874 poly a= (poly)h->Data(); 4875 h = h->next; 4876 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4877 { 4878 ideal Xo= (ideal)h->Data(); 4879 h = h->next; 4880 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4881 { 4882 ideal Sigma= (ideal)h->Data(); 4883 h = h->next; 4884 if((h != NULL)&&(h->Typ() == INT_CMD)) 4885 { 4886 int vert= (int)(long)h->Data(); 4887 h = h->next; 4888 if((h != NULL)&&(h->Typ() == INT_CMD)) 4889 { 4890 int ord= (int)(long)h->Data(); 4891 res->rtyp =IDEAL_CMD; 4892 res->data =idMaken(links_new(a, Xo, Sigma, vert, ord)); 4893 } 4894 } 4895 } 4896 } 4897 } 4898 return false; 4899 } 4900 4901 4902 4903 BOOLEAN existsub(leftv res, leftv args) 4904 { 4905 leftv h=args; 4906 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4907 { 4908 poly p= (poly)h->Data(); 4909 h = h->next; 4910 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4911 { 4912 ideal h1= (ideal)h->Data(); 4913 res->rtyp =INT_CMD; 4914 res->data =(void *)(long)existIn(p, h1); 4915 } 4916 } 4917 return false; 4918 } 4919 4920 4921 BOOLEAN pConstant(leftv res, leftv args) 4922 { 4923 leftv h=args; 4924 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4925 { 4926 ideal h1= (ideal)h->Data(); 4927 h = h->next; 4928 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4929 { 4930 ideal h2= (ideal)h->Data(); 4931 res->rtyp =IDEAL_CMD; 4932 res->data =idMaken(p_constant(h1,h2)); 4933 } 4934 } 4935 return false; 4936 } 4937 4938 BOOLEAN pChange(leftv res, leftv args) 4939 { 4940 leftv h=args; 4941 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4942 { 4943 ideal h1= (ideal)h->Data(); 4944 res->rtyp =IDEAL_CMD; 4945 res->data =idMaken(p_change(h1)); 4946 } 4947 return false; 4948 } 4949 4950 4951 4952 BOOLEAN p_New(leftv res, leftv args) 4953 { 4954 leftv h=args; 4955 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4956 { 4957 ideal h1= (ideal)h->Data(); 4958 h = h->next; 4959 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 4960 { 4961 ideal h2= (ideal)h->Data(); 4962 res->rtyp =IDEAL_CMD; 4963 res->data =idMaken(p_new(h1,h2)); 4964 } 4965 } 4966 return false; 4967 } 4968 4969 4970 4971 4972 BOOLEAN support(leftv res, leftv args) 4973 { 4974 leftv h=args; 4975 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4976 { 4977 poly p= (poly)h->Data(); 4978 res->rtyp =INT_CMD; 4979 res->data =(void *)(long)(support1(p).size()); 4980 } 4981 return false; 4982 } 4983 4984 4985 4986 4987 4988 4989 BOOLEAN bprime(leftv res, leftv args) 4990 { 4991 leftv h=args; 4992 if((h != NULL)&&(h->Typ() == POLY_CMD)) 4993 { 4994 poly p= (poly)h->Data(); 4995 res->rtyp =IDEAL_CMD; 4996 res->data =idMaken(bsubsets_1(p)); 4997 } 4998 return false; 4999 } 5000 5001 5002 5003 BOOLEAN psMinusp(leftv res, leftv args) 5004 { 5005 leftv h=args; 5006 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 5007 { 5008 ideal h1= (ideal)h->Data(); 5009 h = h->next; 5010 if((h != NULL)&&(h->Typ() == POLY_CMD)) 5011 { 5012 poly p= (poly)h->Data(); 5013 res->rtyp =IDEAL_CMD; 5014 res->data =idMinusp(h1, p); 5015 } 5016 } 5017 return false; 5018 } 5019 5020 5021 5022 BOOLEAN stellarremain(leftv res, leftv args) 5023 { 5024 leftv h=args; 5025 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 5026 { 5027 ideal h1= (ideal)h->Data(); 5028 h = h->next; 5029 if((h != NULL)&&(h->Typ() == POLY_CMD)) 5030 { 5031 poly p= (poly)h->Data(); 5032 std::vector<std::vector<int> > st=star(p, h1); 5033 std::vector<std::vector<int> > hvs=supports(h1); 5034 std::vector<std::vector<int> > re= vsMinusvs(hvs, st); 5035 res->rtyp =IDEAL_CMD; 5036 res->data =idMaken(re); 5037 } 5038 } 5039 return false; 5040 } 5041 5042 5043 BOOLEAN cNew(leftv res, leftv args) 5044 { 5045 leftv h=args; 5046 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 5047 { 5048 ideal h1= (ideal)h->Data(); 5049 h = h->next; 5050 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 5051 { 5052 ideal h2= (ideal)h->Data(); 5053 res->rtyp =IDEAL_CMD; 5054 res->data =c_New(h1, h2); 5055 } 5056 } 5057 return false; 5058 } 5059 5060 5061 5062 5063 BOOLEAN stars(leftv res, leftv args) 5064 { 5065 leftv h=args; 5066 if((h != NULL)&&(h->Typ() == POLY_CMD)) 5067 { 5068 poly p= (poly)h->Data(); 5069 h = h->next; 5070 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 5071 { 5072 ideal h1= (ideal)h->Data(); 5073 res->rtyp =IDEAL_CMD; 5074 res->data =idMaken(star(p, h1)); 5075 } 5076 } 5077 return false; 5078 } 5079 5080 5081 5082 5083 BOOLEAN stellarsubdivision(leftv res, leftv args) 5084 { 5085 leftv h=args; 5086 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 5087 { 5088 ideal h2= (ideal)h->Data(); 5089 h = h->next; 5090 if((h != NULL)&&(h->Typ() == POLY_CMD)) 5091 { 5092 poly p= (poly)h->Data(); 5093 res->rtyp =IDEAL_CMD; 5094 res->data =idMaken(stellarsub(p, h2)); 5095 } 5096 } 5097 return false; 5098 } 5099 5100 5101 5102 BOOLEAN idModulo(leftv res, leftv args) 5103 { 5104 leftv h=args; 5105 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 5106 { 5107 ideal h1= (ideal)h->Data(); 5108 h = h->next; 5109 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 5110 { 5111 ideal h2= (ideal)h->Data(); 5112 res->rtyp =IDEAL_CMD; 5113 res->data =idmodulo(h1, h2); 5114 } 5115 } 5116 return false; 5117 } 5118 5119 5120 BOOLEAN idminus(leftv res, leftv args) 5121 { 5122 leftv h=args; 5123 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 5124 { 5125 ideal h1= (ideal)h->Data(); 5126 h = h->next; 5127 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 5128 { 5129 ideal h2= (ideal)h->Data(); 5130 res->rtyp =IDEAL_CMD; 5131 res->data =idMinus(h1, h2); 5132 } 5133 } 5134 return false; 5135 } 5136 5137 5138 5139 BOOLEAN isoNumber(leftv res, leftv args) 5140 { 5141 leftv h=args; 5142 if((h != NULL)&&(h->Typ() == POLY_CMD)) 5143 { 5144 poly p= (poly)h->Data(); 5145 h = h->next; 5146 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 5147 { 5148 ideal h1= (ideal)h->Data(); 5149 h = h->next; 5150 if((h != NULL)&&(h->Typ() == POLY_CMD)) 5151 { 5152 poly a= (poly)h->Data(); 5153 h = h->next; 5154 if((h != NULL)&&(h->Typ() == POLY_CMD)) 5155 { 5156 poly b= (poly)h->Data(); 5157 res->rtyp =INT_CMD; 5158 res->data =(void *)(long)isoNum(p, h1, a, b); 5159 } 5160 } 5161 } 5162 } 5163 return false; 5164 } 5165 5166 5167 5168 BOOLEAN ifIsomorphism(leftv res, leftv args) 5169 { 5170 leftv h=args; 5171 if((h != NULL)&&(h->Typ() == POLY_CMD)) 5172 { 5173 poly p= (poly)h->Data(); 5174 h = h->next; 5175 if((h != NULL)&&(h->Typ() == POLY_CMD)) 5176 { 5177 poly q= (poly)h->Data(); 5178 h = h->next; 5179 if((h != NULL)&&(h->Typ() == POLY_CMD)) 5180 { 5181 poly f= (poly)h->Data(); 5182 h = h->next; 5183 if((h != NULL)&&(h->Typ() == POLY_CMD)) 5184 { 5185 poly g= (poly)h->Data(); 5186 h = h->next; 5187 if((h != NULL)&&(h->Typ() == POLY_CMD)) 5188 { 5189 poly a= (poly)h->Data(); 5190 h = h->next; 5191 if((h != NULL)&&(h->Typ() == POLY_CMD)) 5192 { 5193 poly b= (poly)h->Data(); 5194 res->rtyp =INT_CMD; 5195 res->data =(void *)(long)ifIso(p,q,f,g, a, b); 5196 } 5197 } 5198 } 5199 } 5200 } 5201 } 5202 return false; 5203 } 5204 5205 5206 BOOLEAN newDegree(leftv res, leftv args) 5207 { 5208 leftv h=args; 5209 if((h != NULL)&&(h->Typ() == POLY_CMD)) 5210 { 5211 poly p= (poly)h->Data(); 5212 h = h->next; 5213 if((h != NULL)&&(h->Typ() == INT_CMD)) 5214 { 5215 int num= (int)(long)h->Data(); 5216 res->rtyp =INT_CMD; 5217 res->data =(void *)(long)redefinedeg( p, num); 5218 } 5219 } 5220 return false; 5221 } 5222 5223 5224 5225 BOOLEAN nonf2f(leftv res, leftv args) 5226 { 5227 leftv h=args; 5228 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 5229 { 5230 ideal h1= (ideal)h->Data(); 5231 res->rtyp =IDEAL_CMD; 5232 res->data =complementsimplex(h1); 5233 } 5234 return false; 5235 } 5236 5237 5238 5239 BOOLEAN dimsim(leftv res, leftv args) 5240 { 5241 leftv h=args; 5242 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 5243 { 5244 ideal h1= (ideal)h->Data(); 5245 res->rtyp =INT_CMD; 5246 res->data =(void *)(long)dim_sim(h1); 5247 } 5248 return false; 5249 } 5250 5251 5252 5253 BOOLEAN numdim(leftv res, leftv args) 5254 { 5255 leftv h=args; 5256 if((h != NULL)&&(h->Typ() == IDEAL_CMD)) 5257 { 5258 ideal h1= (ideal)h->Data(); 5259 h = h->next; 5260 if((h != NULL)&&(h->Typ() == INT_CMD)) 5261 { 5262 int num= (int)(long)h->Data(); 5263 res->rtyp =INT_CMD; 5264 res->data =(void *)(long)num4dim( h1, num); 5265 } 5266 } 5267 return false; 5268 } 3117 5269 3118 5270 /**************************************interface T2****************************************/ … … 3127 5279 p->iiAddCproc("","findaset",FALSE,fa); 3128 5280 p->iiAddCproc("","fgp",FALSE,fgp); 3129 p->iiAddCproc("","idcomplement",FALSE,idcomplement); 5281 p->iiAddCproc("","fgpl",FALSE,fgpl); 5282 p->iiAddCproc("","idcomplements",FALSE,idcomplement); 3130 5283 p->iiAddCproc("","genst",FALSE,genstt); 3131 5284 p->iiAddCproc("","sgp",FALSE,sgp); 5285 p->iiAddCproc("","sgpl",FALSE,sgpl); 3132 5286 p->iiAddCproc("","Links",FALSE,Links); 3133 } 3134 3135 3136 3137 extern "C" int SI_MOD_INIT(cohomo)(SModulFunctions* p) 5287 p->iiAddCproc("","eqsolve1",FALSE,eqsolve1); 5288 p->iiAddCproc("","pb",FALSE,pb); 5289 p->iiAddCproc("","pa",FALSE,pa); 5290 p->iiAddCproc("","makeSimplex",FALSE,makeSimplex); 5291 p->iiAddCproc("","isSim",FALSE,isSim); 5292 p->iiAddCproc("","nfaces1",FALSE,nfaces1); 5293 p->iiAddCproc("","nfaces2",FALSE,nfaces2); 5294 p->iiAddCproc("","nfaces3",FALSE,nfaces3); 5295 p->iiAddCproc("","comedg",FALSE,comedg); 5296 p->iiAddCproc("","tsets",FALSE,tsets); 5297 p->iiAddCproc("","valency",FALSE,Valency); 5298 p->iiAddCproc("","nab",FALSE,nabvl); 5299 p->iiAddCproc("","tnab",FALSE,tnabvl); 5300 p->iiAddCproc("","mab",FALSE,mabvl); 5301 p->iiAddCproc("","SRideal",FALSE,SRideal); 5302 p->iiAddCproc("","Linkn",FALSE,linkn); 5303 p->iiAddCproc("","Existb",FALSE,existsub); 5304 p->iiAddCproc("","pConstant",FALSE,pConstant); 5305 p->iiAddCproc("","pChange",FALSE,pChange); 5306 p->iiAddCproc("","pNew",FALSE,p_New); 5307 p->iiAddCproc("","pSupport",FALSE,support); 5308 p->iiAddCproc("","psMinusp",FALSE,psMinusp); 5309 p->iiAddCproc("","cNew",FALSE,cNew); 5310 p->iiAddCproc("","isoNumber",FALSE,isoNumber); 5311 p->iiAddCproc("","vsInsec",FALSE,vsIntersec); 5312 p->iiAddCproc("","getnabt",FALSE,nabtvl); 5313 p->iiAddCproc("","idmodulo",FALSE,idModulo); 5314 p->iiAddCproc("","ndegree",FALSE,newDegree); 5315 p->iiAddCproc("","nonf2f",FALSE,nonf2f); 5316 p->iiAddCproc("","ifIsom",FALSE,ifIsomorphism); 5317 p->iiAddCproc("","stellarsubdivision",FALSE,stellarsubdivision); 5318 p->iiAddCproc("","star",FALSE,stars); 5319 p->iiAddCproc("","numdim",FALSE,numdim); 5320 p->iiAddCproc("","dimsim",FALSE,dimsim); 5321 p->iiAddCproc("","bprime",FALSE,bprime); 5322 p->iiAddCproc("","remainpart",FALSE,stellarremain); 5323 p->iiAddCproc("","idminus",FALSE,idminus); 5324 p->iiAddCproc("","time1",FALSE,t1h); 5325 5326 } 5327 5328 5329 5330 extern "C" int SI_MOD_INIT0(cohomo)(SModulFunctions* p) 3138 5331 { 3139 5332 firstorderdef_setup(p); -
gfanlib/Makefile.am
r5c73a12 rff2859d 17 17 SOURCES = gfanlib_circuittableint.cpp gfanlib_mixedvolume.cpp gfanlib_paralleltraverser.cpp gfanlib_polyhedralfan.cpp gfanlib_polymakefile.cpp gfanlib_symmetriccomplex.cpp gfanlib_symmetry.cpp gfanlib_traversal.cpp gfanlib_zcone.cpp gfanlib_zfan.cpp 18 18 libgfan_la_SOURCES = $(SOURCES) 19 libgfan_la_LDFLAGS = $(SINGULAR_LDFLAGS) $(CDDGMPLDFLAGS) 19 libgfan_la_LDFLAGS = $(SINGULAR_LDFLAGS) $(CDDGMPLDFLAGS) -release ${PACKAGE_VERSION} 20 20 21 21 libgfan_includedir =$(includedir)/gfanlib
Note: See TracChangeset
for help on using the changeset viewer.