source: git/kernel/ratgring.cc @ 19370c

spielwiese
Last change on this file since 19370c was 2381568, checked in by Viktor Levandovskyy <levandov@…>, 17 years ago
*levandov: first edition, not to be run yet git-svn-id: file:///usr/local/Singular/svn/trunk@9713 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.8 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/***************************************************************
5 *  File:    ratgring.cc
6 *  Purpose: Ore-noncommutative kernel procedures
7 *  Author:  levandov (Viktor Levandovsky)
8 *  Created: 8/00 - 11/00
9 *  Version: $Id: ratgring.cc,v 1.1 2007-01-14 22:12:33 levandov Exp $
10 *******************************************************************/
11#include "mod2.h"
12#ifdef HAVE_PLURAL
13#include "gring.h"
14#include "febase.h"
15#include "ring.h"
16#include "polys.h"
17#include "numbers.h"
18#include "ideals.h"
19#include "matpol.h"
20#include "kbuckets.h"
21#include "kstd1.h"
22#include "sbuckets.h"
23#include "prCopy.h"
24#include "p_Mult_q.h"
25#include "clapsing.h"
26
27void pLcmRat(poly a, poly b, poly m, int rat_shift)
28{
29  /* shift is the last exp one should count with */
30  int i;
31  for (i=pVariables; i=rat_shift; i--)
32  {
33    pSetExp(m,i, si_max( pGetExp(a,i), pGetExp(b,i)));
34  }
35  pSetComp(m, si_max(pGetComp(a), pGetComp(b)));
36  /* Don't do a pSetm here, otherwise hres/lres chockes */ 
37}
38
39void pLcmRat(poly a, poly b, poly m, poly pshift)
40{
41  /* shift is the exp of rational elements */
42  int i;
43  for (i=pVariables; i; i--)
44  {
45    if (!pGetExp(pshift,i))
46    {
47      pSetExp(m,i, si_max( pGetExp(a,i), pGetExp(b,i)));
48    }
49    else
50    {
51      /* do we really need it? */
52      pSetExp(m,i,0);
53    }
54  }
55  pSetComp(m, si_max(pGetComp(a), pGetComp(b)));
56  /* Don't do a pSetm here, otherwise hres/lres chockes */ 
57}
58
59/* returns a subpoly of p, s.t. its monomials have the same D-part */
60
61poly p_HeadRat(poly p, int ishift, ring r)
62{
63  poly q   = p_Next(p,r);
64  poly res = p_Head(p,r);
65  while ( p_Comp_k_n(p, q, ishift, r) )
66  {
67    res = p_Add_q(res,p_Head(q,r));
68    q   = p_Next(p,r);
69  }
70  return res;
71}
72
73/* returns x-coeff of p, i.e. a poly in x, s.t. corresponding xd-monomials
74have the same D-part */
75
76poly p_GetCoeffRat(poly p, int ishift, ring r)
77{
78  poly q   = p_Next(p,r);
79  poly res = p_Head(p,r);
80  poly s;
81  while ( p_Comp_k_n(p, q, ishift, r) )
82  {
83    s   = p_GetExp_k_n(q, ishift, r->N, r);
84    res = p_Add_q(res,s);
85    q   = p_Next(p,r);
86  }
87  return res;
88}
89
90poly p_LmDeleteAndNextRat(poly p, int ishift, ring r)
91{
92  p_LmCheckPolyRing2(p, r);
93  while ( p_Comp_k_n(p, p_Next(p,r), ishift, r) )
94  {
95    p_LmDelete(&p,r);
96  }
97}
98
99/* PINLINE1 void p_ExpVectorDiff
100   remains as is -> BUT we can do memory shift on smaller number of exp's */
101
102
103/*4 - follow the numbering of gring.cc
104* creates the S-polynomial of p1 and p2
105* do not destroy p1 and p2
106*/
107poly nc_rat_CreateSpoly(poly p1, poly p2, poly spNoether, int ishift, const ring r)
108{
109  if ((p_GetComp(p1,r)!=p_GetComp(p2,r))
110  && (p_GetComp(p1,r)!=0)
111  && (p_GetComp(p2,r)!=0))
112  {
113#ifdef PDEBUG
114    Print("nc_CreateSpoly : different components!");
115#endif
116    return(NULL);
117  }
118  /* prod. crit does not apply yet */
119//   if ((r->nc->type==nc_lie) && pHasNotCF(p1,p2)) /* prod crit */
120//   {
121//     return(nc_p_Bracket_qq(pCopy(p2),p1));
122//   }
123  poly pL=pOne();
124  poly m1=pOne();
125  poly m2=pOne();
126  /* define shift */
127  int is = ishift; /* TODO */
128  pLcmRat(p1,p2,pL,is);
129  p_Setm(pL,r);
130  poly pr1 = p_GetExp_k_n(p1,1,ishift-1); /* rat D-exp of p1 */
131  poly pr2 = p_GetExp_k_n(p2,1,ishift-1); /* rat D-exp of p2 */
132#ifdef PDEBUG
133  p_Test(pL,r);
134#endif
135  p_ExpVectorDiff(m1,pL,p1,r); /* purely in D part by construction */
136  //p_SetComp(m1,0,r);
137  //p_Setm(m1,r);
138#ifdef PDEBUG
139  p_Test(m1,r);
140#endif
141  p_ExpVectorDiff(m2,pL,p2,r); /* purely in D part by construction */
142  //p_SetComp(m2,0,r);
143  //p_Setm(m2,r);
144#ifdef PDEBUG
145  p_Test(m2,r);
146#endif
147  p_Delete(&pL,r);
148  /* zero exponents ! */
149
150  /* EXTRACT LEADCOEF */
151
152  poly H1  = p_HeadRat(p1,r);
153  poly M1  = nc_mm_Mult_p(m1,p_Copy(H1,r),r);
154
155  /* POLY:  number C1  = n_Copy(p_GetCoeff(M1,r),r); */
156  /* RAT: */
157
158  poly C1  = p_GetCoeffRat(M1,ishift,r);
159
160  poly H2  = p_HeadRat(p2,r);
161  poly M2  = nc_mm_Mult_p(m2,p_Copy(H2,r),r);
162
163  /* POLY:  number C2  = n_Copy(p_GetCoeff(M2,r),r); */
164  /* RAT: */
165
166  poly C2  = p_GetCoeffRat(M2,ishift,r);
167
168/* we do not assume that X's commute */
169/* we just run NC syzygies */
170
171/* NEW IDEA: change the ring to K<X>, map things there
172   and return the result back; seems to be a good optimization */
173/* to be done later */
174
175  intvec *w = NULL;
176  ideal h = idInit(2,1);
177  h->m[0] = p_Copy(C1,r);
178  h->m[1] = p_Copy(C2,r);
179#ifdef PDEBUG
180  Print("running syzygy comp. for coeffs");
181#endif
182  ideal sh = idSyzygies(h, testHomog, &w);
183  /* in comm case, there is only 1 syzygy */
184  /*   singclap_gcd(); */
185  poly K,K1,K2;
186  K  = sh->m[0];
187  K1 = pTakeOutComp(&K, 1); // 1st component is taken out from K
188  K2 = pShift(&K,-2); // 2nd component to 0th comp.
189
190  /* checking signs before multiplying */   
191  number ck1 = p_GetCoeff(K1,r);
192  number ck2 = p_GetCoeff(K2,r);
193  BOOLEAN bck1, bck2;
194  bck1 = n_GreaterZero(ck1);
195  bck2 = n_GreaterZero(ck2);
196  /* K1 >0, K2 >0 (K1,-K2)    */
197  /* K1 >0, K2 <0 (K1,-K2)    */
198  /* K1 <0, K2 >0 (-K1,K2)    */
199  /* K1 <0, K2 <0 (-K1,K2)    */
200  if ( (bck1) && (bck2) ) /* +, + */
201  {
202    K2 = p_Neg(K2,r);
203  }
204  if ( (bck1) && (!bck2) ) /* + , - */
205  {
206    K2 = p_Neg(K2,r);
207  }
208  if ( (!bck1) && (bck2) ) /* - , + */
209  {
210    K1 = p_Neg(K1,r);
211  }
212  if ( !(bck1 && bck2) ) /* - , - */
213  {
214    K1 = p_Neg(K1,r);
215  }
216
217  poly P1,P2;
218
219  p_LmDeleteRat(M1,ishift,r); // get tail(D^(gamma-alpha) * lm(p1)) = h_f
220  P1 = p_LmDeleteAndNextRat(p_Copy(p1,r),ishift,r); // get tail(p1) = t_f
221  P1 = nc_mm_Mult_p(m1,P1,r);
222  P1 = p_Add_q(P1,M1,r);
223
224  p_LmDeleteRat(M2,ishift,r);
225  P2 = p_LmDeleteRat(p_Copy(p2,r),ishift,r);// get tail(p2)=t_g
226  P2 = nc_mm_Mult_p(m2,P2,r);
227  P2 = p_Add_q(P2,M2,r);
228
229  /* coeff business */
230
231  P1 = p_Mult_nn(P1,K1,r);
232  P2 = p_Mult_nn(P2,K2,r);
233  P1 = p_Add_q(P1,P2,r);
234
235  /* cleaning up */
236
237#ifdef PDEBUG
238  p_Test(p1,r);
239#endif
240  /* questionable: */
241  if (P1!=NULL) pCleardenom(P1);
242  if (P1!=NULL) pContent(P1);
243  return(P1);
244}
245
246#endif
Note: See TracBrowser for help on using the repository browser.