source: git/kernel/algmap.cc @ 35aab3

spielwiese
Last change on this file since 35aab3 was 35aab3, checked in by Hans Schönemann <hannes@…>, 21 years ago
This commit was generated by cvs2svn to compensate for changes in r6879, which included commits to RCS files with non-trunk default branches. git-svn-id: file:///usr/local/Singular/svn/trunk@6880 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.2 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: algmap.cc,v 1.1.1.1 2003-10-06 12:15:50 Singular Exp $ */
5/*
6* ABSTRACT - the mapping of polynomials from rings with
7* 'alg' numbers
8*/
9
10#include "mod2.h"
11#include "omalloc.h"
12#include "polys.h"
13#include "numbers.h"
14#include "longalg.h"
15#include "ring.h"
16#include "febase.h"
17#include "maps.h"
18#include "algmap.h"
19
20
21static poly maLongalg1Fetch(poly res, poly p0, ring r0, int n,
22                            int t, BOOLEAN *nom)
23{
24  napoly a0, b0;
25  poly q0, q1 = NULL;
26  int i, j, m = r0->N;
27
28  if (naGetDenom0(pGetCoeff(p0)) != NULL)
29  {
30    *nom = TRUE;
31    return res;
32  }
33  a0 = naGetNom0(pGetCoeff(p0));
34  do
35  {
36    q0 = pInit();
37    pSetComp(q0,p_GetComp(p0, r0));
38    if (t!=0)
39    {
40      pGetCoeff(q0) = (number)omAlloc0Bin(rnumber_bin);
41      b0 = naGetNom0(pGetCoeff(q0)) = napNew();
42      napGetCoeff(b0) = nacCopy(napGetCoeff(a0));
43      for (i=1; i<=t; i++)
44      {
45        napSetExp(b0,i,napGetExpFrom(a0,i,r0));
46      }
47    }
48    else
49    {
50      pGetCoeff(q0) = nCopy(napGetCoeff(a0));
51    }
52    for (i=m; i>0; i--)
53    {
54      pSetExp(q0,i, p_GetExp( p0,i,r0));
55    }
56    j = t;
57    for (i=m+1; i<=n; i++)
58    {
59      j++;
60      pSetExp(q0,i, napGetExpFrom(a0,j,r0));
61    }
62    pSetm(q0);
63    q1 = pAdd(q1, q0);
64    a0 = napNext(a0);
65  }
66  while (a0 != NULL);
67  return pAdd(res, q1);
68}
69
70static poly maLongalg2Fetch(poly res, poly p0, ring r0, int n, int s,
71                            int t, BOOLEAN *nom)
72{
73  poly q0;
74  int i, j;
75  napoly b0;
76  napoly a0 = NULL, b1 = NULL;
77
78  if (s!=0)
79  {
80    if (naGetDenom0(pGetCoeff(p0)) != NULL)
81    {
82      *nom = TRUE;
83      return res;
84    }
85    a0 = naGetNom0(pGetCoeff(p0));
86  }
87  q0 = pInit();
88  pSetComp(q0,p_GetComp(p0, r0));
89  for (i=n; i>0; i--)
90  {
91    pSetExp(q0,i, p_GetExp(p0,i,r0));
92  }
93  pSetm(q0);
94  do
95  {
96    b0 = napNew();
97    if (s!=0)
98    {
99      napGetCoeff(b0) = nacCopy(napGetCoeff(a0));
100      for (i=1; i<=s; i++)
101      {
102        napSetExp(b0,i, napGetExp(a0,i));
103      }
104    }
105    else
106    {
107      napGetCoeff(b0) = nacCopy(pGetCoeff(p0));
108    }
109    j = n;
110    for (i=s+1; i<=t; i++)
111    {
112      j++;
113      napSetExp(b0,i, p_GetExp(p0,j,r0));
114    }
115    if (s==0)
116    {
117      pGetCoeff(q0)=(number)omAlloc0Bin(rnumber_bin);
118      naGetNom0(pGetCoeff(q0)) = b0;
119      return pAdd(res, q0);
120    }
121    b1 = napAdd(b1, b0);
122    a0 = napNext(a0);
123  }
124  while (a0 != NULL);
125  if (pGetCoeff(q0)==NULL)
126    pGetCoeff(q0) = (number)omAlloc0Bin(rnumber_bin);
127  naGetNom0(pGetCoeff(q0)) = b1;
128  return pAdd(res, q0);
129}
130
131/*2
132* return Fe(preimage)
133* Fe : k(y(1),..,y(s))[x(1),..,x(m)] -> k(y(1),..,y(t))[x(1),..,x(n)]
134*      with:
135*      s+m = t+n,
136*      Fe(y(i)) = y(i), i = 1,..,min(s,t),
137*      Fe(x(i)) = x(i), i = 1,..,min(m,n),
138*      and
139*      1. for s>t: Fe(y(i)) = x(i+n-t), i = t+1,..,s
140*      2. for m>n: Fe(x(i)) = y(i+t-n), i = n+1,..,m
141*/
142poly maAlgpolyFetch(ring R, poly preimage)
143{
144  BOOLEAN nom=FALSE;
145  int m, n, s, t;
146  poly p0, result=NULL;
147
148  if (preimage == NULL)
149  {
150    return NULL;
151  }
152  m = R->N;
153  n = currRing->N;
154  s = rPar(R);
155  t = rPar(currRing);
156  if ((m+s) != (n+t))
157  {
158    WerrorS("no algfetch possible");
159    return NULL;
160  }
161  if (n == m)
162  {
163    return pCopy(preimage);
164  }
165  p0 = preimage;
166  if (s > t)
167  {
168    while (p0!=NULL)
169    {
170      result = maLongalg1Fetch(result, p0, R, n, t, &nom);
171      if (nom)
172      {
173        goto err_algfetch;
174      }
175      pIter(p0);
176    }
177  }
178  else
179  {
180    while (p0!=NULL)
181    {
182      result = maLongalg2Fetch(result, p0, R, n, s, t, &nom);
183      if (nom)
184      {
185        goto err_algfetch;
186      }
187      pIter(p0);
188    }
189  }
190  return result;
191
192err_algfetch:
193  pDelete(&result);
194  WerrorS("denominator in algnumber");
195  return NULL;
196}
197
198static poly maLongalgMap(poly res, ring r, poly p0, int s, int t,
199                         BOOLEAN *nom, poly monpart, ideal F)
200{
201  number cc;
202  napoly a0, b0;
203  poly q, q0, q1 = NULL;
204  int i;
205
206  if (s == 0)
207  {
208    if (t!=0)
209    {
210      nNew(&cc);
211      b0 = napNew();
212      napGetCoeff(b0) = pGetCoeff(p0);
213      naGetNom0(cc) = b0;
214      pMult_nn(monpart,cc);
215      napGetCoeff(b0) = NULL;
216      nDelete(&cc);
217    }
218    else
219    {
220      pMult_nn(monpart,pGetCoeff(p0));
221    }
222    pSetCompP(monpart, p_GetComp(p0,r));
223    return pAdd(res, monpart);
224  }
225  if (naGetDenom0(pGetCoeff(p0)) != NULL)
226  {
227    *nom = TRUE;
228    WerrorS("denominator in algnumber");
229    pDelete(&monpart);
230    pDelete(&res);
231    return NULL;
232  }
233  a0 = naGetNom0(pGetCoeff(p0));
234  do
235  {
236    q = pInit();
237    if (t!=0)
238    {
239      pGetCoeff(q) = (number)omAlloc0Bin(rnumber_bin);
240      b0 = naGetNom0(pGetCoeff(q)) = napNew();
241      napGetCoeff(b0) = nacCopy(napGetCoeff(a0));
242    }
243    else
244    {
245      pGetCoeff(q) = nCopy(napGetCoeff(a0));
246    }
247    for(i=0; i<s; i++)
248    {
249      if (napGetExpFrom(a0,i+1,r) != 0)
250      {
251        if (F->m[i]!=NULL)
252        {
253          q0 = pPower(pCopy(F->m[i]),napGetExpFrom(a0,i+1,r));
254          q = pMult(q, q0);
255        }
256        else
257        {
258          pDelete(&q);
259          break;
260        }
261      }
262    }
263    q1 = pAdd(q1, q);
264    a0 = napNext(a0);
265  }
266  while (a0 != NULL);
267  q1 = pMult(q1,monpart);
268  pSetCompP(q1,p_GetComp(p0,r));
269  return pAdd(res, q1);
270}
271
272number maNumberOne(number x)
273{
274  return nInit(1);
275}
276
277/*2
278* return Ma(preimage)
279* Ma : k(y(1),..,y(s))[x(1),..,x(m)] -> k(y(1),..,y(t))[z(1),..,z(n)]
280* the ideals F = f_1,..,f_s and G = g_1,..,g_m in k(y(1),..,y(t))[z(1),..,z(n)]
281* are as follows:
282* f_i = Ma(y(i)), g_i = Ma(x(i))
283*/
284poly maAlgpolyMap(ring R, poly preimage, ideal F, ideal G)
285{
286  BOOLEAN nom=FALSE;
287  int m, s, t;
288  poly p0, monpart, result = NULL;
289
290  if (preimage == NULL)
291  {
292    return NULL;
293  }
294  m = R->N;
295  if (m != IDELEMS(G))
296  {
297    WerrorS("error 1 in algmap");
298    return NULL;
299  }
300  s = rPar(R);
301  if ((s!=0) && (s != IDELEMS(F)))
302  {
303    WerrorS("error 2 in algmap");
304    return NULL;
305  }
306  t = rPar(currRing);
307  p0 = preimage;
308  poly pr=NULL;
309  while (p0!=NULL)
310  {
311    poly pr=pNext(p0);
312    p0->next=NULL;
313    monpart = maEval((map)G, p0, R, maNumberOne);
314    result = maLongalgMap(result, R, p0, s, t, &nom, monpart, F);
315    pTest(result);
316    if (nom)
317    {
318      return NULL;
319    }
320    p0->next = pr;
321    p0=pr;
322  }
323  return result;
324}
Note: See TracBrowser for help on using the repository browser.