My Project
Loading...
Searching...
No Matches
pCoeff.cc
Go to the documentation of this file.
1// emacs edit mode for this file is -*- C++ -*-
2/****************************************
3* Computer Algebra System SINGULAR *
4****************************************/
5/*
6* ABSTRACT: accces single (coeffs of) monoms
7*/
8
9#include "misc/auxiliary.h"
10
11#include "coeffs/coeffs.h"
12
13#include "coeffs/longrat.h" // snumber is necessary
14
16#include "polys/pCoeff.h"
17
18#include "simpleideals.h"
19
20/// find coeff of (polynomial) m in polynomial p
21/// find coeff of (vector) m in vector p
22number p_CoeffTerm(poly p, poly m, const ring r)
23{
24 if (m!=NULL)
25 {
26 while (p!=NULL)
27 {
28 if (p_LmCmp(p,m,r)==0)
29 {
30 return n_Copy(p_GetCoeff(p,r),r->cf);
31 }
32 pIter(p);
33 }
34 }
35 return n_Init(0,r->cf);
36}
37
38/// find vector of coeffs of (polynomial) m in vector v
39poly p_CoeffTermV(poly v, poly m, const ring r)
40{
41 poly res=NULL;
42 if (m!=NULL)
43 {
44 while (v!=NULL)
45 {
46 p_SetComp(m,p_GetComp(v,r),r);
47 if (p_LmCmp(v,m,r)==0)
48 {
49 p_SetComp(m,0,r);
50 poly p=p_Init(r);
52 p_SetComp(p,p_GetComp(v,r),r);
53 res=p_Add_q(res,p,r);
54 }
55 pIter(v);
56 }
57 }
58 return res;
59}
60
61/// find coeffs of (polynomial) m in all polynomials from I
62/// find coeffs of (vector) m in all vectors from I
63ideal id_CoeffTerm(ideal I, poly m, const ring r)
64{
65 ideal res=idInit(IDELEMS(I),I->rank);
66 for(int i=IDELEMS(I)-1;i>=0;i--)
67 {
68 number n=p_CoeffTerm(I->m[i],m,r);
69 res->m[i]=p_NSet(n,r);
70 }
71 return res;
72}
73
74/// find coeffs of (polynomial) m in all vectors from I
75ideal id_CoeffTermV(ideal M, poly m, const ring r)
76{
77 ideal res=idInit(IDELEMS(M),M->rank);
78 for(int i=IDELEMS(M)-1;i>=0;i--)
79 {
80 res->m[i]=p_CoeffTermV(M->m[i],m,r);
81 }
82 return res;
83}
84
85/// find coeffs of a vector of a list of given monomials, n>=max_comp(v)
86poly p_CoeffTermId(poly v, ideal m, int n, const ring r)
87{
88 if ((n<=0)||(v==NULL)) return NULL;
89 poly q;
90 poly u=NULL;
91 int dummy;
92 const int ncols_m=IDELEMS(m);
93 v=p_Copy(v,r);
94 for(int i=1;i<=n;i++)
95 {
96 p_TakeOutComp(&v,i,&q,&dummy,r);
97 for(int j=0;j<ncols_m;j++)
98 {
99 number n=p_CoeffTerm(q,m->m[j],r);
100 poly uu=p_NSet(n,r);
101 if (uu!=NULL)
102 {
103 p_SetComp(uu,(i-1)*ncols_m+j+1,r);
104 u=p_Add_q(u,uu,r);
105 }
106 }
107 if (v==NULL) break;
108 }
109 return u;
110}
111
112/// find coeffs of a vector of a matrix(module) of given monomials, n>=max_comp(v)
113poly p_CoeffTermMo(poly v, ideal m, int n, const ring r)
114{
115 poly res=NULL;
116 int to_shift=0;
117 poly q;
118 int dummy;
119 v=p_Copy(v,r);
120 for(int i=0;i<IDELEMS(m);i++)
121 {
122 if (v==NULL) break;
123 p_TakeOutComp(&v,i+1,&q,&dummy,r);
124 ideal mm=id_Vec2Ideal(m->m[i],r);
125 p_SetCompP(q,1,r);
126 poly tmp=p_CoeffTermId(q,mm,1,r);
127 if (i>0)
128 {
129 to_shift+=p_MaxComp(m->m[i-1],r);
130 p_Shift(&tmp,to_shift,r);
131 res=p_Add_q(res,tmp,r);
132 }
133 else
134 res=tmp;
135 }
136 return res;
137}
All the auxiliary stuff.
int m
Definition: cfEzgcd.cc:128
int i
Definition: cfEzgcd.cc:132
int p
Definition: cfModGcd.cc:4078
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition: coeffs.h:448
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:535
CanonicalForm res
Definition: facAbsFact.cc:60
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39
int j
Definition: facHensel.cc:110
void p_TakeOutComp(poly *p, long comp, poly *q, int *lq, const ring r)
Definition: p_polys.cc:3496
#define p_SetCoeff0(p, n, r)
Definition: monomials.h:60
#define p_GetComp(p, r)
Definition: monomials.h:64
#define pIter(p)
Definition: monomials.h:37
#define p_GetCoeff(p, r)
Definition: monomials.h:50
#define NULL
Definition: omList.c:12
poly p_CoeffTermMo(poly v, ideal m, int n, const ring r)
find coeffs of a vector of a matrix(module) of given monomials, n>=max_comp(v)
Definition: pCoeff.cc:113
poly p_CoeffTermId(poly v, ideal m, int n, const ring r)
find coeffs of a vector of a list of given monomials, n>=max_comp(v)
Definition: pCoeff.cc:86
number p_CoeffTerm(poly p, poly m, const ring r)
find coeff of (polynomial) m in polynomial p find coeff of (vector) m in vector p
Definition: pCoeff.cc:22
ideal id_CoeffTermV(ideal M, poly m, const ring r)
find coeffs of (polynomial) m in all vectors from I
Definition: pCoeff.cc:75
ideal id_CoeffTerm(ideal I, poly m, const ring r)
find coeffs of (polynomial) m in all polynomials from I find coeffs of (vector) m in all vectors from...
Definition: pCoeff.cc:63
poly p_CoeffTermV(poly v, poly m, const ring r)
find vector of coeffs of (polynomial) m in vector v
Definition: pCoeff.cc:39
void p_Shift(poly *p, int i, const ring r)
shifts components of the vector p by i
Definition: p_polys.cc:4706
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition: p_polys.cc:1473
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:934
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:252
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:245
static int p_LmCmp(poly p, poly q, const ring r)
Definition: p_polys.h:1578
static long p_MaxComp(poly p, ring lmRing, ring tailRing)
Definition: p_polys.h:290
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1318
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:844
ideal id_Vec2Ideal(poly vec, const ring R)
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:35
#define IDELEMS(i)
Definition: simpleideals.h:23
#define M
Definition: sirandom.c:25