source: git/libpolys/polys/flintconv.cc @ 9ccaaf

spielwiese
Last change on this file since 9ccaaf was fb24e81, checked in by Hans Schoenemann <hannes@…>, 8 years ago
system("LLL_flint",,,)
  • Property mode set to 100644
File size: 3.6 KB
Line 
1// emacs edit mode for this file is -*- C++ -*-
2/****************************************
3*  Computer Algebra System SINGULAR     *
4****************************************/
5/*
6* ABSTRACT: convert data between Singular and Flint
7*/
8
9
10
11#include <misc/auxiliary.h>
12#include "flintconv.h"
13
14#ifdef HAVE_FLINT
15#if __FLINT_RELEASE >= 20500
16#include <coeffs/coeffs.h>
17#include <polys/monomials/p_polys.h>
18
19#include <omalloc/omalloc.h>
20// #include <coeffs/longrat.h>
21// #include <coeffs/modulop.h>
22#include <polys/sbuckets.h>
23#include <polys/clapconv.h>
24
25#include "simpleideals.h"
26
27
28int convFlintISingI (fmpz_t f)
29{
30  int res;
31  res = fmpz_get_si(f);
32  return res;
33}
34
35void convSingIFlintI(fmpz_t f, int p)
36{
37  fmpz_init(f);
38  fmpz_set_si(f,p);
39  return;
40}
41
42void convFlintNSingN (mpz_t z, fmpz_t f)
43{
44  mpz_init(z);
45  fmpz_get_mpz(z,f);
46}
47
48void convSingNFlintN(fmpz_t f, mpz_t z)
49{
50  fmpz_init(f);
51  fmpz_set_mpz(f,z);
52}
53
54
55bigintmat* singflint_LLL(bigintmat*  m, bigintmat* T)
56{
57  int r=m->rows();
58  int c=m->cols();
59  bigintmat* res=new bigintmat(r,c,m->basecoeffs());
60  fmpz_mat_t M, Transf;
61  fmpz_mat_init(M, r, c);
62  if(T != NULL)
63  {
64    fmpz_mat_init(Transf, T->rows(), T->rows());
65  }
66  fmpz_t dummy;
67  mpz_t n;
68  int i,j;
69  for(i=r;i>0;i--)
70  {
71    for(j=c;j>0;j--)
72    {
73      n_MPZ(n, BIMATELEM(*m, i, j),m->basecoeffs());
74      convSingNFlintN(dummy,n);
75      mpz_clear(n);
76      fmpz_set(fmpz_mat_entry(M, i-1, j-1), dummy);
77      fmpz_clear(dummy);
78    }
79  }
80  if(T != NULL)
81  {
82    for(i=T->rows();i>0;i--)
83    {
84      for(j=T->rows();j>0;j--)
85      {
86        n_MPZ(n, BIMATELEM(*T, i, j),T->basecoeffs());
87        convSingNFlintN(dummy,n);
88        mpz_clear(n);
89        fmpz_set(fmpz_mat_entry(Transf, i-1, j-1), dummy);
90        fmpz_clear(dummy);
91      }
92    }
93  }
94  fmpz_lll_t fl;
95  fmpz_lll_context_init_default(fl);
96  if(T != NULL)
97    fmpz_lll(M, Transf, fl);
98  else
99    fmpz_lll(M, NULL, fl);
100  for(i=r;i>0;i--)
101  {
102    for(j=c;j>0;j--)
103    {
104      convFlintNSingN(n, fmpz_mat_entry(M, i-1, j-1));
105      n_Delete(&(BIMATELEM(*res,i,j)),res->basecoeffs());
106      BIMATELEM(*res,i,j)=n_InitMPZ(n,res->basecoeffs());
107      mpz_clear(n);
108    }
109  }
110  if(T != NULL)
111  {
112    for(i=T->rows();i>0;i--)
113    {
114      for(j=T->cols();j>0;j--)
115      {
116        convFlintNSingN(n, fmpz_mat_entry(Transf, i-1, j-1));
117        n_Delete(&(BIMATELEM(*T,i,j)),T->basecoeffs());
118        BIMATELEM(*T,i,j)=n_InitMPZ(n,T->basecoeffs());
119        mpz_clear(n);
120      }
121    }
122  }
123  return res;
124}
125
126intvec* singflint_LLL(intvec*  m, intvec* T)
127{
128  int r=m->rows();
129  int c=m->cols();
130  intvec* res = new intvec(r,c,(int)0);
131  fmpz_mat_t M,Transf;
132  fmpz_mat_init(M, r, c);
133  if(T != NULL)
134    fmpz_mat_init(Transf, r, r);
135  fmpz_t dummy;
136  int i,j;
137  for(i=r;i>0;i--)
138  {
139    for(j=c;j>0;j--)
140    {
141      convSingIFlintI(dummy,IMATELEM(*m,i,j));
142      fmpz_set(fmpz_mat_entry(M, i-1, j-1), dummy);
143      fmpz_clear(dummy);
144    }
145  }
146  if(T != NULL)
147  {
148    for(i=T->rows();i>0;i--)
149    {
150      for(j=T->rows();j>0;j--)
151      {
152        convSingIFlintI(dummy,IMATELEM(*T,i,j));
153        fmpz_set(fmpz_mat_entry(Transf, i-1, j-1), dummy);
154        fmpz_clear(dummy);
155      }
156    }
157  }
158  fmpz_lll_t fl;
159  fmpz_lll_context_init_default(fl);
160  if(T != NULL)
161    fmpz_lll(M, Transf, fl);
162  else
163    fmpz_lll(M, NULL, fl);
164  for(i=r;i>0;i--)
165  {
166    for(j=c;j>0;j--)
167    {
168      IMATELEM(*res,i,j)=convFlintISingI(fmpz_mat_entry(M, i-1, j-1));
169    }
170  }
171  if(T != NULL)
172  {
173    for(i=Transf->r;i>0;i--)
174    {
175      for(j=Transf->r;j>0;j--)
176      {
177        IMATELEM(*T,i,j)=convFlintISingI(fmpz_mat_entry(Transf, i-1, j-1));
178      }
179    }
180  }
181  return res;
182}
183#endif
184#endif
Note: See TracBrowser for help on using the repository browser.