My Project  debian-1:4.1.1-p2+ds-4build3
find_perm.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /***************************************************************
5  * File: find_perm.cc
6  * Purpose: is a map a permuation ?
7  * Author: hannes
8  * Created: 16/01
9  *******************************************************************/
10 
11 
12 
13 #include "kernel/mod2.h"
14 #include "omalloc/omalloc.h"
16 #include "kernel/ideals.h"
17 #include "polys/monomials/ring.h"
18 #include "kernel/maps/find_perm.h"
19 
20 static int* find_perm_for_map(const ring preimage_r, const ring image_r, const ideal image)
21 {
22  int i;
23  int *perm=(int *)omAlloc0((preimage_r->N+1)*sizeof(int));
24  for (i=si_min(IDELEMS(image),preimage_r->N)-1; i>=0; i--)
25  {
26  if (image->m[i]!=NULL)
27  {
28  if((pNext(image->m[i])==NULL)
29  && (n_IsOne(pGetCoeff(image->m[i]),image_r->cf)))
30  {
31  int v=p_IsUnivariate(image->m[i],image_r);
32  if (v<=0) /*not univariate */
33  {
34  omFreeSize(perm,(preimage_r->N+1)*sizeof(int));
35  return NULL;
36  }
37  else if (v>0) /* image is univaritate */
38  {
39  if (p_GetExp(image->m[i],v,image_r)==1)
40  {
41  perm[i+1]=v; /* and of exp 1 */
42  }
43  else
44  {
45  omFreeSize(perm,(preimage_r->N+1)*sizeof(int));
46  return NULL;
47  }
48  }
49  }
50  else /* image is not a monomial */
51  {
52  omFreeSize(perm,(preimage_r->N+1)*sizeof(int));
53  return NULL;
54  }
55  }
56  }
57  //Print("elms:%d, N:%d\n",IDELEMS(image),preimage_r->N);
58  //iiWriteMatrix((matrix)image,"_",1,image_r,0);
59  //PrintS("\npreimage:\n");rWrite(preimage_r);
60  //PrintS("image:\n");rWrite(image_r);
61  //PrintS("\nperm:");
62  //for (i=1; i<=preimage_r->N; i++)
63  //{
64  // Print(" %d",perm[i]);
65  //}
66  //PrintLn();
67  return perm;
68 }
69 
70 matrix ma_ApplyPermForMap(const matrix to_map, const ring preimage_r,
71  const ideal image, const ring image_r, const nMapFunc nMap)
72 {
73  if ((rPar(preimage_r)>0)||(rPar(image_r)>0)) return NULL; /* not applicable */
74  int *perm=find_perm_for_map(preimage_r,image_r,image);
75  if (perm==NULL) return NULL; /* could not find permutation */
76  int C=to_map->cols();
77  int R=to_map->rows();
78  matrix m=mpNew(R,C);
79  for (int i=R*C-1;i>=0;i--)
80  {
81  if (to_map->m[i]!=NULL)
82  {
83  m->m[i]=p_PermPoly(to_map->m[i],perm,preimage_r,image_r, nMap,NULL,0);
84  p_Test(m->m[i],image_r);
85  }
86  }
87  ideal ii=(ideal)m;
88  ii->rank=((ideal)to_map)->rank;
89  omFreeSize(perm,(preimage_r->N+1)*sizeof(int));
90  return m;
91 }
92 
si_min
static int si_min(const int a, const int b)
Definition: auxiliary.h:139
omalloc.h
ip_smatrix
Definition: matpol.h:15
p_GetExp
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition: p_polys.h:469
ma_ApplyPermForMap
matrix ma_ApplyPermForMap(const matrix to_map, const ring preimage_r, const ideal image, const ring image_r, const nMapFunc nMap)
helper function for maMapIdeal mapping ideal/matrix/module for the case of a permutation: maps the id...
Definition: find_perm.cc:70
find_perm_for_map
static int * find_perm_for_map(const ring preimage_r, const ring image_r, const ideal image)
Definition: find_perm.cc:20
p_IsUnivariate
int p_IsUnivariate(poly p, const ring r)
return i, if poly depends only on var(i)
Definition: p_polys.cc:1239
ip_smatrix::cols
int & cols()
Definition: matpol.h:26
p_Test
#define p_Test(p, r)
Definition: p_polys.h:163
n_IsOne
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition: coeffs.h:469
i
int i
Definition: cfEzgcd.cc:125
p_PermPoly
poly p_PermPoly(poly p, const int *perm, const ring oldRing, const ring dst, nMapFunc nMap, const int *par_perm, int OldPar, BOOLEAN use_mult)
Definition: p_polys.cc:4014
ip_smatrix::rows
int & rows()
Definition: matpol.h:25
nMapFunc
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:74
omFreeSize
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
mod2.h
ip_smatrix::m
poly * m
Definition: matpol.h:20
p_polys.h
rPar
static int rPar(const ring r)
(r->cf->P)
Definition: ring.h:590
find_perm.h
mpNew
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition: matpol.cc:36
ring.h
m
int m
Definition: cfEzgcd.cc:121
NULL
#define NULL
Definition: omList.c:10
ideals.h
R
#define R
Definition: sirandom.c:26
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
IDELEMS
#define IDELEMS(i)
Definition: simpleideals.h:26
pGetCoeff
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:51
pNext
#define pNext(p)
Definition: monomials.h:43
omAlloc0
#define omAlloc0(size)
Definition: omAllocDecl.h:211