source: git/Singular/dyn_modules/gfanlib/witness.cc @ 9c0326

spielwiese
Last change on this file since 9c0326 was 9c0326, checked in by Yue Ren <ren@…>, 10 years ago
chg: status update 12.09.
  • Property mode set to 100644
File size: 3.4 KB
Line 
1#include <kernel/GBEngine/kstd1.h>
2#include <Singular/lists.h>
3#include <libpolys/polys/monomials/p_polys.h>
4#include <callgfanlib_conversion.h>
5#include <initial.h>
6#include <tropicalStrategy.h>
7#include <utility>
8
9/***
10 * Given f and G={g1,...,gk}, computes Q=(q1,...,qk) such that
11 * f = q1*g1+...+qk*gk
12 * is a determinate division with remainder with respect to the
13 * ordering active in r.
14 * Returns an error if this is not possible.
15 **/
16matrix divisionDiscardingRemainder(const poly f, const ideal G, const ring r)
17{
18  ring origin = currRing;
19  if (origin != r) rChangeCurrRing(r);
20  ideal F = idInit(1); F->m[0]=f;
21  ideal m = idLift(G,F);
22  F->m[0]=NULL; id_Delete(&F, currRing);
23  matrix Q = id_Module2formatedMatrix(m,IDELEMS(G),1,currRing);
24  if (origin != r) rChangeCurrRing(origin);
25  return Q;
26}
27
28/**
29 * Given F[0],...,F[l] and G[0],...,G[k],
30 * computes Q[i,j] for i=0,..,k and j=0,...,l such that
31 * F[j] = Q[0,j]*G[0]+...+Q[k,j]*G[k].
32 */
33matrix divisionDiscardingRemainder(const ideal F, const ideal G, const ring r)
34{
35  ring origin = currRing;
36  if (origin != r) rChangeCurrRing(r);
37  ideal m = idLift(G,F);
38  matrix Q = id_Module2formatedMatrix(m,IDELEMS(G),1,currRing);
39  if (origin != r) rChangeCurrRing(origin);
40  return Q;
41}
42
43#ifndef NDEBUG
44BOOLEAN dwr0(leftv res, leftv args)
45{
46  leftv u = args;
47  leftv v = u->next;
48  poly f = (poly) u->CopyD();
49  ideal G = (ideal) v->CopyD();
50  omUpdateInfo();
51  Print("usedBytesBefore=%ld\n",om_Info.UsedBytes);
52  matrix Q = divisionDiscardingRemainder(f,G,currRing);
53  p_Delete(&f,currRing);
54  id_Delete(&G,currRing);
55  res->rtyp = MATRIX_CMD;
56  res->data = (char*) Q;
57  return FALSE;
58}
59#endif
60
61/***
62 * Let w be the uppermost weight vector in the matrix defining the ordering on r.
63 * Let I be a Groebner basis of an ideal in r, inI its initial form with respect w.
64 * Given an w-homogeneous element m of inI, computes a witness g of m in I,
65 * i.e. g in I such that in_w(g)=m.
66 **/
67poly witness(const poly m, const ideal I, const ideal inI, const ring r)
68{
69  assume(idSize(I)==idSize(inI));
70  matrix Q = divisionDiscardingRemainder(m,inI,r);
71
72  int k = idSize(I);
73  poly f = p_Mult_q(p_Copy(I->m[0],r),Q->m[0],r);
74  Q->m[0] = NULL;
75  for (int i=1; i<k; i++)
76  {
77    f = p_Add_q(f,p_Mult_q(p_Copy(I->m[i],r),Q->m[i],r),r);
78    Q->m[i] = NULL;
79  }
80  mp_Delete(&Q,r);
81
82  return f;
83}
84
85#ifndef NDEBUG
86BOOLEAN witness0(leftv res, leftv args)
87{
88  leftv u = args;
89  leftv v = u->next;
90  leftv w = v->next;
91  poly m = (poly) u->CopyD();
92  ideal G = (ideal) v->CopyD();
93  ideal inG = (ideal) w->CopyD();
94  omUpdateInfo();
95  Print("usedBytesBefore=%ld\n",om_Info.UsedBytes);
96  poly f = witness(m,G,inG,currRing);
97  p_Delete(&m,currRing);
98  id_Delete(&G,currRing);
99  id_Delete(&inG,currRing);
100  res->rtyp = POLY_CMD;
101  res->data = (char*) f;
102  return FALSE;
103}
104#endif
105
106/***
107 * Let w be the uppermost weight vector in the matrix defining the ordering on r.
108 * Let I be a Groebner basis of an ideal in r, inI its initial form with respect w.
109 * Given an w-homogeneous element m of inI, computes a witness g of m in I,
110 * i.e. g in I such that in_w(g)=m.
111 **/
112ideal witness(const ideal inI, const ideal J, const ring r)
113{
114  ring origin = currRing;
115  if (origin!=r)
116    rChangeCurrRing(r);
117  ideal NFinI = kNF(J,r->qideal,inI);
118  if (origin!=r)
119    rChangeCurrRing(origin);
120
121  int k = idSize(inI);
122  ideal I = idInit(k);
123  for (int i=0; i<k; i++)
124  {
125    I->m[i] = p_Add_q(p_Copy(inI->m[i],r),p_Neg(NFinI->m[i],r),r);
126    NFinI->m[i] = NULL;
127  }
128
129  return I;
130}
Note: See TracBrowser for help on using the repository browser.