source: git/kernel/ringgb.cc @ cea6f3

spielwiese
Last change on this file since cea6f3 was cea6f3, checked in by Oliver Wienand <wienand@…>, 18 years ago
RING2TOM Merger git-svn-id: file:///usr/local/Singular/svn/trunk@8900 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.6 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: ringgb.cc,v 1.3 2006-01-13 18:10:05 wienand Exp $ */
5/*
6* ABSTRACT: ringgb interface
7*/
8//#define HAVE_TAIL_RING
9#define NO_BUCKETS
10
11#include "mod2.h"
12#include "kutil.h"
13#include "structs.h"
14#include "omalloc.h"
15#include "polys.h"
16#include "p_polys.h"
17#include "ideals.h"
18#include "febase.h"
19#include "kstd1.h"
20#include "khstd.h"
21#include "kbuckets.h"
22#include "weight.h"
23#include "intvec.h"
24#include "pInline1.h"
25#ifdef HAVE_PLURAL
26#include "gring.h"
27#endif
28
29#include "ringgb.h"
30
31poly reduce_poly_fct(poly p, ring r) {
32   return NULL;
33}
34
35/*
36 * Returns maximal k, such that
37 * 2^k | n
38 */
39int indexOf2(number n) {
40  long test = (long) n;
41  int i = 0;
42  while (test%2 == 0) {
43    i++;
44    test = test / 2;
45  }
46  return i;
47}
48
49/*
50 * Find an index i from G, such that
51 * LT(rside) = x * LT(G[i]) has a solution
52 * or -1 if rside is not in the
53 * ideal of the leading coefficients
54 * of the suitable g from G.
55 */
56int findRing2toMsolver(poly rside, ideal G, ring r) {
57  if (rside == NULL) return -1;
58  int i;
59  int iO2rside = indexOf2(pGetCoeff(rside));
60  for (i = 0; i < IDELEMS(G); i++) {
61    if (indexOf2(pGetCoeff(G->m[i])) <= iO2rside && p_LmDivisibleBy(G->m[i], rside, r)) {
62      return i;
63    }
64  }
65  return -1;
66}
67
68/***************************************************************
69 *
70 * Lcm business
71 *
72 ***************************************************************/
73// get m1 = LCM(LM(p1), LM(p2))/LM(p1)
74//     m2 = LCM(LM(p1), LM(p2))/LM(p2)
75BOOLEAN ring2toM_GetLeadTerms(const poly p1, const poly p2, const ring p_r,
76                               poly &m1, poly &m2, const ring m_r)
77{
78
79  int i;
80  Exponent_t x;
81  m1 = p_Init(m_r);
82  m2 = p_Init(m_r);
83
84  for (i = p_r->N; i; i--)
85  {
86    x = p_GetExpDiff(p1, p2, i, p_r);
87    if (x > 0)
88    {
89      p_SetExp(m2,i,x, m_r);
90      p_SetExp(m1,i,0, m_r);
91    }
92    else
93    {
94      p_SetExp(m1,i,-x, m_r);
95      p_SetExp(m2,i,0, m_r);
96    }
97  }
98  p_Setm(m1, m_r);
99  p_Setm(m2, m_r);
100  long cp1 = (long) pGetCoeff(p1);
101  long cp2 = (long) pGetCoeff(p2);
102  if (cp1 != 0 && cp2 != 0) {
103    while (cp1%2 == 0 && cp2%2 == 0) {
104      cp1 = cp1 / 2;
105      cp2 = cp2 / 2;
106    }
107  }
108  p_SetCoeff(m1, (number) cp2, m_r);
109  p_SetCoeff(m2, (number) cp1, m_r);
110  return TRUE;
111}
112
113void printPolyMsg(char * start, poly f, char * end){
114  PrintS(start);
115  wrp(f);
116  PrintS(end);
117}
118
119poly spolyRing2toM(poly f, poly g, ring r) {
120  poly m1 = NULL;
121  poly m2 = NULL;
122  ring2toM_GetLeadTerms(f, g, r, m1, m2, r);
123  printPolyMsg("spoly: m1=", m1, " | ");
124  printPolyMsg("m2=", m2, "");
125  PrintLn();
126  return pSub(pp_Mult_mm(f, m1, r), pp_Mult_mm(g, m2, r));
127}
128
129poly ringNF(poly f, ideal G, ring r) {
130  // If f = 0, then normal form is also 0
131  if (f == NULL) { return NULL; }
132  poly h = pCopy(f);
133  int i = findRing2toMsolver(h, G, r);
134  int c = 1;
135  while (h != NULL && i >= 0 && c < 20) {
136    Print("%d-step NF - h:", c);
137    wrp(h);
138    PrintS(" ");
139    PrintS("G->m[i]:");
140    wrp(G->m[i]);
141    PrintLn();
142    h = spolyRing2toM(h, G->m[i], r);
143    PrintS("=> h=");
144    wrp(h);
145    PrintLn();
146    i = findRing2toMsolver(h, G, r);
147    c++;
148  }
149  return h;
150}
151
152poly ringRedNF (poly f, ideal G, ring r) {
153  // If f = 0, then normal form is also 0
154  if (f == NULL) { return NULL; }
155  poly h = NULL;
156  poly g = pCopy(f);
157  int c = 0;
158  while (g != NULL && c < 20) {
159    Print("%d-step RedNF - g=", c);
160    wrp(g);
161    PrintS(" | h=");
162    wrp(h);
163    PrintLn();
164    g = ringNF(g, G, r);
165    if (g != NULL) {
166      h = pAdd(h, pHead(g));
167      pLmDelete(&g);
168    }
169    c++;
170  }
171  return h;
172}
Note: See TracBrowser for help on using the repository browser.