source: git/misc/lt2.cc @ 25fe907

spielwiese
Last change on this file since 25fe907 was 075bc5, checked in by Hans Schoenemann <hannes@…>, 5 years ago
format
  • Property mode set to 100644
File size: 1.9 KB
Line 
1#include "Singular/libsingular.h"
2// same_lt: search an ideal for entries with the same lead term
3// cf_at: the coefficient of the term given: cf_at(x+2y+3z,y) is 2
4
5BOOLEAN same_lt2(leftv res, leftv arg)
6{
7  if ((currRing!=NULL) && (arg!=NULL) && (arg->Typ()==IDEAL_CMD))
8  {
9    ideal I=(ideal)arg->Data();
10    int i,j;
11    lists L=(lists)omAllocBin(slists_bin);
12    L->Init();
13    res->rtyp=LIST_CMD;
14    res->data=L;
15    for (i=0;i<IDELEMS(I)-1;i++)
16    {
17      if (I->m[i]!=NULL)
18      {
19        for(j=IDELEMS(I)-1;j>i;j--)
20        {
21          if (I->m[j]!=NULL)
22          {
23            if (p_LmCmp(I->m[i],I->m[j],currRing)==0)
24            {
25              L->Init(2);
26              L->m[0].rtyp=INT_CMD; L->m[0].data=(void*)(long)(i+1);
27              L->m[1].rtyp=INT_CMD; L->m[1].data=(void*)(long)(j+1);
28              return FALSE;
29            }
30          }
31        }
32      }
33    }
34    return FALSE; /* not found */
35  }
36  WerrorS("same_lt(ideal)");
37  return TRUE;
38}
39
40BOOLEAN cf_at(leftv res, leftv arg)
41{
42  const short t[]={2,POLY_CMD,POLY_CMD};
43  if ((currRing!=NULL) && iiCheckTypes(arg,t,1))
44  {
45    poly p=(poly)arg->Data();
46    poly m=(poly)arg->next->Data();
47    if (m==NULL) return TRUE;
48    while(p!=NULL)
49    {
50      int c=p_LmCmp(p,m,currRing);
51      if (c==-1) // p after m in ordering
52      {
53        p=NULL;
54        break;
55      }
56      else if (c==0)
57        break;
58      else
59        pIter(p);
60    }
61    res->rtyp=NUMBER_CMD;
62    if (p==NULL)
63      res->data=n_Init(0,currRing->cf);
64    else
65      res->data=n_Copy(pGetCoeff(p),currRing->cf);
66    return FALSE;
67  }
68  WerrorS("expected cf_at(`poly`,`poly`)");
69  return TRUE;
70}
71
72extern "C" int mod_init(SModulFunctions* psModulFunctions)
73{
74  psModulFunctions->iiAddCproc((currPack->libname? currPack->libname: ""),"same_lt2",FALSE,same_lt2);
75  psModulFunctions->iiAddCproc((currPack->libname? currPack->libname: ""),"cf_at",FALSE,cf_at);
76  return MAX_TOK;
77}
Note: See TracBrowser for help on using the repository browser.