source: git/kernel/maps/find_perm.cc @ 06abb07

spielwiese
Last change on this file since 06abb07 was 06abb07, checked in by Hans Schoenemann <hannes@…>, 8 years ago
chg: n_...(...,ring) -> n_....(...,coeff) for better debugging
  • Property mode set to 100644
File size: 2.6 KB
Line 
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>
15#include <polys/monomials/p_polys.h>
16#include <kernel/ideals.h>
17#include <polys/monomials/ring.h>
18#include <kernel/maps/find_perm.h>
19
20static 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
70matrix 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
Note: See TracBrowser for help on using the repository browser.