Index: kernel/gfan.cc
===================================================================
--- kernel/gfan.cc	(revision 832b70058672520c5e80a49ba96723f3a316ad73)
+++ kernel/gfan.cc	(revision 2126c0d13d7a85352b229c0bd8232fb6cd6d726d)
@@ -2,7 +2,7 @@
 Compute the Groebner fan of an ideal
 $Author: monerjan $
-$Date: 2009-06-25 08:52:03 $
-$Header: /exports/cvsroot-2/cvsroot/kernel/gfan.cc,v 1.67 2009-06-25 08:52:03 monerjan Exp $
-$Id: gfan.cc,v 1.67 2009-06-25 08:52:03 monerjan Exp $
+$Date: 2009-06-29 14:46:58 $
+$Header: /exports/cvsroot-2/cvsroot/kernel/gfan.cc,v 1.68 2009-06-29 14:46:58 monerjan Exp $
+$Id: gfan.cc,v 1.68 2009-06-29 14:46:58 monerjan Exp $
 */
 
@@ -397,5 +397,5 @@
  			this->gcBasis=idCopy(f.flipGB);
 			this->inputIdeal=idCopy(this->gcBasis);
-			this->baseRing=rCopy0(f.flipRing);
+			this->baseRing=rCopy(f.flipRing);
 			this->numFacets=0;
 			//rComplete(this->baseRing);
@@ -587,6 +587,6 @@
 
 #ifdef gfan_DEBUG
-			cout << "The inequality matrix is" << endl;
-			dd_WriteMatrix(stdout, ddineq);
+ 			cout << "The inequality matrix is" << endl;
+ 			dd_WriteMatrix(stdout, ddineq);
 #endif
 
@@ -608,8 +608,8 @@
 			ddcols = ddineq->colsize;
 #ifdef gfan_DEBUG
-			cout << "Having removed redundancies, the normals now read:" << endl;
-			dd_WriteMatrix(stdout,ddineq);
-			cout << "Rows = " << ddrows << endl;
-			cout << "Cols = " << ddcols << endl;
+ 			cout << "Having removed redundancies, the normals now read:" << endl;
+ 			dd_WriteMatrix(stdout,ddineq);
+ 			cout << "Rows = " << ddrows << endl;
+ 			cout << "Cols = " << ddcols << endl;
 #endif
 			
@@ -744,10 +744,11 @@
 					
 #ifdef gfan_DEBUG
-//  				dd_WriteMatrix(stdout,ddakt);
+// 				cout << "Codim2 matrix"<<endl;
+//   				dd_WriteMatrix(stdout,ddakt);
 #endif
 				ddpolyh=dd_DDMatrix2Poly(ddakt, &err);
 				P=dd_CopyGenerators(ddpolyh);
 #ifdef gfan_DEBUG
-//  				dd_WriteMatrix(stdout,P);
+//   				dd_WriteMatrix(stdout,P);
 #endif
 					
@@ -807,7 +808,12 @@
 			std::cout << "===" << std::endl;
 			std::cout << "running gcone::flip" << std::endl;
-// 			std::cout << "fNormal=";
-// 			fNormal->show();
-// 			std::cout << std::endl;
+			std::cout << "flipping" << endl;
+			for(int ii=0;ii<IDELEMS(gb);ii++)
+			{
+				pWrite((poly)gb->m[ii]);
+			}
+			cout << "over facet" << endl;
+ 			fNormal->show();
+ 			std::cout << std::endl;
 #endif				
 			/*1st step: Compute the initial ideal*/
@@ -902,6 +908,6 @@
 			ina=idrCopyR(initialForm,srcRing);			
 #ifdef gfan_DEBUG
- 			cout << "ina=";
- 			idShow(ina); cout << endl;
+//  			cout << "ina=";
+//  			idShow(ina); cout << endl;
 #endif
 			ideal H;
@@ -910,5 +916,5 @@
 			idSkipZeroes(H);
 #ifdef gfan_DEBUG
- 			cout << "H="; idShow(H); cout << endl;
+//  			cout << "H="; idShow(H); cout << endl;
 #endif
 			/*Substep 2.2
@@ -920,11 +926,11 @@
 			srcRing_H=idrCopyR(H,tmpRing);
 #ifdef gfan_DEBUG
- 			cout << "srcRing_H = ";
- 			idShow(srcRing_H); cout << endl;
+//  			cout << "srcRing_H = ";
+//  			idShow(srcRing_H); cout << endl;
 #endif
 			srcRing_HH=ffG(srcRing_H,this->gcBasis);		
 #ifdef gfan_DEBUG
- 			cout << "srcRing_HH = ";
- 			idShow(srcRing_HH); cout << endl;
+//  			cout << "srcRing_HH = ";
+//  			idShow(srcRing_HH); cout << endl;
 #endif
 			/*Substep 2.2.1
@@ -1033,5 +1039,7 @@
 				dd_set_si(intPointMatrix->matrix[aktrow][jj],1);
 			}
-			dd_WriteMatrix(stdout,intPointMatrix);
+#ifdef gfan_DEBUG
+// 			dd_WriteMatrix(stdout,intPointMatrix);
+#endif
 			intvec *iv_weight = new intvec(this->numVars);
 			interiorPoint(intPointMatrix, *iv_weight);	//iv_weight now contains the interior point
@@ -1081,5 +1089,5 @@
 			ring dstRing=rCopy0(tmpRing);
 			int length=iv_weight->length();
-			int *A=(int *)omAlloc(length*sizeof(int));
+			int *A=(int *)omAlloc0(length*sizeof(int));
 			for(int jj=0;jj<length;jj++)
 			{
@@ -1116,5 +1124,5 @@
 			
 			f->setFlipGB(dstRing_I);//store the flipped GB
-			f->flipRing=rCopy0(dstRing);	//store the ring on the other side
+			f->flipRing=rCopy(dstRing);	//store the ring on the other side
 #ifdef gfan_DEBUG
 			cout << "Flipped GB is: " << endl;
@@ -1134,5 +1142,5 @@
 		poly restOfDiv(poly const &f, ideal const &I)
 		{
-			cout << "Entering restOfDiv" << endl;
+// 			cout << "Entering restOfDiv" << endl;
 			poly p=f;
 			//pWrite(p);
@@ -1196,5 +1204,5 @@
 		ideal ffG(ideal const &H, ideal const &G)
 		{
-			cout << "Entering ffG" << endl;
+// 			cout << "Entering ffG" << endl;
 			int size=IDELEMS(H);
 			ideal res=idInit(size,1);
@@ -1725,41 +1733,4 @@
 				SearchListAct = fAct->next;				
 			}
-						
-// 			while(SearchListAct->next!=NULL)
-// 			{
-// 				fAct = SearchListAct;
-// 				do
-// 				{
-// 					gcAct->flip(gcAct->gcBasis,fAct);
-// 					ring rTmp = rCopy(fAct->flipRing);
-// 					rComplete(rTmp);
-// 					rChangeCurrRing(rTmp);
-// 					gcone *gcTmp = new gcone(*gcAct,*fAct);
-// 					gcTmp->getConeNormals(gcTmp->gcBasis,FALSE);
-// 					gcTmp->getCodim2Normals(*gcTmp);
-// 					gcPtr->next = gcTmp;
-// 					gcPtr = gcPtr->next;
-// 					/*add facets to SLA here*/
-// 					rChangeCurrRing(gcAct->baseRing);
-// 					fAct = fAct->next;
-// 				}while( (fAct->next!=NULL) &&  (fAct->getUCN()==fAct->next->getUCN()));
-// 				SearchListAct = SearchListAct->next;//fAct;				
-// 			}
-			
-// 			while(SearchListAct->next!=NULL)
-// 			{
-// 				gcAct->flip(gcAct->gcBasis,SearchListAct);
-// 				ring rTmp=rCopy(fAct->flipRing);
-// 				rComplete(rTmp);
-// 				rChangeCurrRing(rTmp);
-// 				gcone *gcTmp = new gcone(*gcAct,*SearchListAct);
-// 				gcTmp->getConeNormals(gcTmp->gcBasis,FALSE);
-// 				gcTmp->getCodim2Normals(*gcTmp);
-// 				rChangeCurrRing(gcAct->baseRing);
-// 				SearchListAct = SearchListAct->next;
-// 				
-// 				//gcone *gcNew = new gcone(SearchListAct->flipRing,SearchListAct->flipGB);
-// 				//gcAct = gcNew;
-// 			}
 		
 			//NOTE Hm, comment in and get a crash for free...
@@ -1802,4 +1773,19 @@
 			}
 			
+			//Check whether denom is all ones, in which case we will divide out the gcd of the nominators
+// 			mpz_t checksum; mpz_t rop;
+// 			mpz_init(checksum);
+// 			mpz_init(rop);
+// 			bool divideOutGcd=FALSE;
+// 			for(int ii=0;ii<this->numVars;ii++)
+// 			{
+// 				mpz_add(rop, checksum, denom[ii]);
+// 				mpz_set(checksum, rop);
+// 			}
+// 			if( (int)mpz_get_ui(checksum)==this->numVars)
+// 			{
+// 				divideOutGcd=TRUE;
+// 			}
+			
 			/*Compute lcm of the denominators*/
 			mpz_set(tmp,denom[0]);
@@ -1833,7 +1819,7 @@
 		}
 		/**
-		 * We compute the gcd of the components of the codim-2-facets and 
-		 * multiply the each codim-2facet by it. Thus we get a normalized representation of each
-		 * (codim-2)-facet normal.
+		 * For all codim-2-facets we compute the gcd of the components of the facet normal and 
+		 * divide it out. Thus we get a normalized representation of each
+		 * (codim-2)-facet normal, i.e. a primitive vector
 		*/
 		void normalize()
@@ -1852,12 +1838,14 @@
 					ggT = intgcd(ggT,(*n)[ii]);
 				}
+				for(int ii=0;ii<this->numVars;ii++)
+				{
+					(*n)[ii] = ((*n)[ii])/ggT;
+				}
 				codim2Act = codim2Act->next;				
 			}
 			//delete n;
-			codim2Act = this->facetPtr->codim2Ptr;	//reset to start of linked list
-			//while(codim2Act->next!=NULL)
+			/*codim2Act = this->facetPtr->codim2Ptr;	//reset to start of linked list			
 			while(codim2Act!=NULL)
-			{
-				//intvec *n = new intvec(this->numVars);
+			{				
 				n=codim2Act->getFacetNormal();
 				intvec *new_n = new intvec(this->numVars);
@@ -1870,5 +1858,5 @@
 				//delete n;
 				//delete new_n;
-			}			
+			}	*/		
 		}
 		/** 
@@ -1885,4 +1873,6 @@
 			facet *codim2Act;
 			codim2Act = this->facetPtr->codim2Ptr;
+			facet *sl2Act;
+			sl2Act = f.codim2Ptr;
 			bool doNotAdd=FALSE;
 			while(slEnd->next!=NULL)
@@ -1902,23 +1892,30 @@
 				while(slAct!=NULL)
 				{
-					slNormal = slAct->getFacetNormal();
-					/*if(!isParallel(fNormal,slNormal))
-					{
-						slEnd->next = new facet();
-						slEnd = slEnd->next;
-						slEnd->setUCN(this->getUCN());
-						slEnd->setFacetNormal(fNormal);
-						break;
-											
-					}
-					else
-					{
-						//NOTE check codim2facets here
-						break;	//hopefully breaks the while loop
-					}*/
+					slNormal = slAct->getFacetNormal();					
+					/*If the normals are parallel we check whether the
+					codim-2-normals coincide as well*/
 					if(isParallel(fNormal,slNormal))
 					{
 						//NOTE check codim2facets here
-						doNotAdd=TRUE;
+// 						while(codim2Act!=NULL)
+// 						{
+// 							f2Normal = codim2Act->getFacetNormal();
+// 							sl2Act = f.codim2Ptr;
+// 							while(sl2Act!=NULL)
+// 							{
+// 								sl2Normal = sl2Act->getFacetNormal();
+// 								if(!isParallel(f2Normal,sl2Normal))
+// 								{
+// 									doNotAdd=FALSE;
+// 									break;
+// 								}
+// 								sl2Act = sl2Act->next;
+// 							}
+// 							if(doNotAdd==FALSE)
+// 								break;
+// 							codim2Act = codim2Act->next;
+// 							
+// 						}
+						doNotAdd=FALSE;
 						break;
 					}
@@ -1975,5 +1972,6 @@
 			
 			int jj=0;
-			while(fAct->next!=NULL)
+			//while(fAct->next!=NULL)
+			while(fAct!=NULL)
 			{
 				intvec *comp;
@@ -2037,5 +2035,6 @@
 				
 				gcOutputFile << "FACETS" << endl;								
-				while(fAct->next!=NULL)
+				//while(fAct->next!=NULL)
+				while(fAct!=NULL)
 				{	
  					intvec *iv = new intvec(gc.numVars);
