source: git/Singular/algmap.cc @ 6f2edc

spielwiese
Last change on this file since 6f2edc was da97958, checked in by Hans Schönemann <hannes@…>, 27 years ago
* hannes: changed Werror to WerroS at same places, corrected bugs found by christian gorzel (ring definition, vector[intvec], etc) changed output: -1x to -x git-svn-id: file:///usr/local/Singular/svn/trunk@150 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.0 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: algmap.cc,v 1.4 1997-04-12 16:04:33 Singular Exp $ */
5/*
6* ABSTRACT - the mapping of polynomials from rings with
7* 'alg' numbers
8*/
9
10#include "mod2.h"
11#include "polys.h"
12#include "numbers.h"
13#include "longalg.h"
14#include "ipid.h"
15#include "ring.h"
16#include "mmemory.h"
17#include "febase.h"
18#include "maps.h"
19#include "algmap.h"
20
21
22static poly maLongalg1Fetch(poly res, poly p0, int m, int n,
23                            int t, BOOLEAN *nom)
24{
25  napoly a0, b0;
26  poly q0, q1 = NULL;
27  int i, j;
28
29  if (naGetDenom(pGetCoeff(p0)) != NULL)
30  {
31    *nom = TRUE;
32    return res;
33  }
34  a0 = naGetNom(pGetCoeff(p0));
35  do
36  {
37    q0 = pInit();
38    pSetComp(q0,pGetComp(p0));
39    if (t!=0)
40    {
41      pGetCoeff(q0) = (number)Alloc0(sizeof(rnumber));
42      b0 = naGetNom(pGetCoeff(q0)) = napNew();
43      napGetCoeff(b0) = nacCopy(napGetCoeff(a0));
44      for (i=1; i<=t; i++)
45      {
46        napGetExp(b0,i) = napGetExp(a0,i);
47      }
48    }
49    else
50    {
51      pGetCoeff(q0) = nCopy(napGetCoeff(a0));
52    }
53    for (i=m; i>0; i--)
54    {
55      pGetExp(q0,i) = pGetExp(p0,i);
56    }
57    j = t;
58    for (i=m+1; i<=n; i++)
59    {
60      j++;
61      pGetExp(q0,i) = napGetExp(a0,j);
62    }
63    pSetm(q0);
64    q1 = pAdd(q1, q0);
65    a0 = napNext(a0);
66  }
67  while (a0 != NULL);
68  return pAdd(res, q1);
69}
70
71static poly maLongalg2Fetch(poly res, poly p0, int n, int s,
72                            int t, BOOLEAN *nom)
73{
74  poly q0;
75  int i, j;
76  napoly b0;
77  napoly a0 = NULL, b1 = NULL;
78
79  if (s!=0)
80  {
81    if (naGetDenom(pGetCoeff(p0)) != NULL)
82    {
83      *nom = TRUE;
84      return res;
85    }
86    a0 = naGetNom(pGetCoeff(p0));
87  }
88  q0 = pInit();
89  pSetComp(q0,pGetComp(p0));
90  for (i=n; i>0; i--)
91  {
92    pGetExp(q0,i) = pGetExp(p0,i);
93  }
94  pSetm(q0);
95  do
96  {
97    b0 = napNew();
98    if (s!=0)
99    {
100      napGetCoeff(b0) = nacCopy(napGetCoeff(a0));
101      for (i=1; i<=s; i++)
102      {
103        napGetExp(b0,i) = napGetExp(a0,i);
104      }
105    }
106    else
107    {
108      napGetCoeff(b0) = nacCopy(pGetCoeff(p0));
109    }
110    j = n;
111    for (i=s+1; i<=t; i++)
112    {
113      j++;
114      napGetExp(b0,i) = pGetExp(p0,j);
115    }
116    if (s==0)
117    {
118      naGetNom(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)Alloc0(sizeof(rnumber));
127  naGetNom(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, m, 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, 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, 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      naGetNom(cc) = b0;
214      pMultN(monpart,cc);
215      napGetCoeff(b0) = NULL;
216      nDelete(&cc);
217    }
218    else
219    {
220      pMultN(monpart,pGetCoeff(p0));
221    }
222    pSetCompP(monpart, pGetComp(p0));
223    return pAdd(res, monpart);
224  }
225  if (naGetDenom(pGetCoeff(p0)) != NULL)
226  {
227    *nom = TRUE;
228    WerrorS("denominator in algnumber");
229    pDelete(&monpart);
230    pDelete(&res);
231    return NULL;
232  }
233  a0 = naGetNom(pGetCoeff(p0));
234  do
235  {
236    q = pInit();
237    if (t!=0)
238    {
239      pGetCoeff(q) = (number)Alloc0(sizeof(rnumber));
240      b0 = naGetNom(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 (napGetExp(a0,i+1) != 0)
250      {
251        if (F->m[i]!=NULL)
252        {
253          q0 = pPower(pCopy(F->m[i]),napGetExp(a0,i+1));
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,pGetComp(p0));
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  nMap=maNumberOne;
310  while (p0!=NULL)
311  {
312    poly pr=pNext(p0);
313    p0->next=NULL;
314    monpart = maEval((map)G, p0, m);
315    result = maLongalgMap(result, p0, s, t, &nom, monpart, F);
316    if (nom)
317    {
318      return NULL;
319    }
320    p0=pr;
321  }
322  return result;
323}
Note: See TracBrowser for help on using the repository browser.