source: git/misc/std_demo.cc @ b6c5b9e

spielwiese
Last change on this file since b6c5b9e was b6c5b9e, checked in by Hans Schoenemann <hannes@…>, 9 years ago
small misc, Singular modules
  • Property mode set to 100644
File size: 3.9 KB
Line 
1#include <Singular/libsingular.h>
2
3// example of a routine which changes nothing
4static BOOLEAN display_sp(kStrategy strat)
5{
6  // will be call each time a new s-poly is computed (strat->P)
7  // the algorithm assures that strat->P.p!=NULL, in currRing
8  // if strat->P.t_p==NULL: strat->P.p->next is in currRing
9  // otherwise: strat->P.t_p->next==strat->P.p->next, in strat->tailRing
10  // must return TRUE, if strat->P is changed, FALSE otherwise
11  PrintS("a new s-poly found: ");
12  p_Write(strat->P.p,currRing,strat->tailRing);
13  return FALSE;
14}
15static BOOLEAN std_with_display(leftv res, leftv args)
16{
17  if (args!=NULL)
18  {
19    if (args->Typ()==IDEAL_CMD)
20    {
21      ideal I=(ideal)args->Data();
22      I=kStd(I,currRing->qideal,testHomog,NULL,NULL,0,0,NULL,display_sp);
23      idSkipZeroes(I);
24      res->data=(char*)I;
25      res->rtyp=IDEAL_CMD;
26      return FALSE;
27    }
28  }
29  WerrorS("expected: std_with_display(`idea;`)");
30  return TRUE;
31}
32//------------------------------------------------------------------------
33// example of a routine which divides by the i-th variable
34static BOOLEAN divide_sp(kStrategy strat)
35{
36  bool b = false;
37  int *mm=(int*)omAlloc((1+rVar(currRing))*sizeof(int));
38  int *m0=(int*)omAlloc((1+rVar(currRing))*sizeof(int));
39  if (strat->P.t_p==NULL)
40  {
41    poly p=strat->P.p;
42    p_GetExpV(p,mm,currRing);
43    int m_null=0;
44    while(p!=NULL)
45    {
46      m_null=0;
47      p_GetExpV(p,m0,currRing);
48      for(int i=1;i<=rVar(currRing);i++)
49      {
50        mm[i]=si_min(mm[i],m0[i]);
51        if (mm[i]>0) m_null++;
52      }
53      if (m_null==0) break;
54      pIter(p);
55    }
56    if (m_null>0)
57    {
58      //Print("dividing the following with respect to variable %d and power %ld: ",var_to_divide,m);
59      p_Write(strat->P.p,currRing,strat->tailRing);
60      PrintS(" -> ");
61      p=p_Copy(strat->P.p,currRing);
62      strat->P.p=p;
63      while(p!=NULL)
64      {
65        for(int i=1;i<=rVar(currRing);i++)
66          p_SubExp(p,i,mm[i],currRing);
67        p_Setm(p,currRing);
68        pIter(p);
69      }
70      p_Write(strat->P.p,currRing,strat->tailRing);
71      b = true;
72    }
73  }
74  else
75  {
76    poly p=strat->P.t_p;
77    p_GetExpV(p,mm,strat->tailRing);
78    int m_null=0;
79    while(p!=NULL)
80    {
81      m_null=0;
82      p_GetExpV(p,m0,strat->tailRing);
83      for(int i=1;i<=rVar(currRing);i++)
84      {
85        mm[i]=si_min(mm[i],m0[i]);
86        if (mm[i]>0) m_null++;
87      }
88      if (m_null==0) break;
89      pIter(p);
90    }
91    if (m_null>0)
92    {
93      //Print("dividing the following with respect to variable %d and power %ld: ",var_to_divide,m);
94      p_Write(strat->P.t_p,strat->tailRing,strat->tailRing);
95      PrintS(" -> ");
96      p=p_Copy(strat->P.t_p,strat->tailRing);
97      strat->P.t_p=p;
98      strat->P.p=NULL;
99      while(p!=NULL)
100      {
101        for(int i=1;i<=rVar(currRing);i++)
102          p_SubExp(p,i,mm[i],strat->tailRing);
103        p_Setm(p,strat->tailRing);
104        pIter(p);
105      }
106      strat->P.GetP();
107      Print("result: ");
108      p_Write(strat->P.p,currRing,strat->tailRing);
109      b = true;
110    }
111  }
112  omFree(mm);
113  omFree(m0);
114  return b;// return TRUE if sp was changed, FALSE if not
115}
116static BOOLEAN std_with_divide(leftv res, leftv args)
117{
118  if (args!=NULL)
119  {
120    if ((args->Typ()==IDEAL_CMD) && (args->next==NULL))
121    {
122      ideal I=(ideal)args->Data();
123      I=kStd(I,currRing->qideal,testHomog,NULL,NULL,0,0,NULL,divide_sp);
124      idSkipZeroes(I);
125      res->data=(char*)I;
126      res->rtyp=IDEAL_CMD;
127      return FALSE;
128    }
129  }
130  WerrorS("expected: std_with_divide(`idea;`,`int`)");
131  return TRUE;
132}
133//------------------------------------------------------------------------
134// initialisation of the module
135extern "C" int SI_MOD_INIT(std_demo)(SModulFunctions* p)
136{
137  p->iiAddCproc("std_demo","std_with_display",FALSE,std_with_display);
138  p->iiAddCproc("std_demo","std_with_divide",FALSE,std_with_divide);
139  PrintS("init of std_demo - type `listvar(Std_demo);` to its contents\n");
140  return (MAX_TOK);
141}
142
Note: See TracBrowser for help on using the repository browser.