1 | // emacs edit mode for this file is -*- C++ -*- |
---|
2 | /**************************************** |
---|
3 | * Computer Algebra System SINGULAR * |
---|
4 | ****************************************/ |
---|
5 | // $Id$ |
---|
6 | /* |
---|
7 | * ABSTRACT: convert data between Singular and factory |
---|
8 | */ |
---|
9 | |
---|
10 | |
---|
11 | #include "config.h" |
---|
12 | #include <misc/auxiliary.h> |
---|
13 | #ifdef HAVE_FACTORY |
---|
14 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
15 | #include <factory/factory.h> |
---|
16 | |
---|
17 | #include <omalloc/omalloc.h> |
---|
18 | #include <coeffs/coeffs.h> |
---|
19 | #include <polys/monomials/p_polys.h> |
---|
20 | #include <polys/sbuckets.h> |
---|
21 | #include <polys/clapconv.h> |
---|
22 | |
---|
23 | //typedef __mpz_struct lint; |
---|
24 | |
---|
25 | void out_cf(char *s1,const CanonicalForm &f,char *s2); |
---|
26 | |
---|
27 | static void conv_RecPP ( const CanonicalForm & f, int * exp, sBucket_pt result, ring r ); |
---|
28 | |
---|
29 | static number convFactoryNSingAN( const CanonicalForm &f, const ring r); |
---|
30 | |
---|
31 | poly convFactoryPSingP ( const CanonicalForm & f, const ring r ) |
---|
32 | { |
---|
33 | int n = rVar(r)+1; |
---|
34 | /* ASSERT( level( f ) <= pVariables, "illegal number of variables" ); */ |
---|
35 | int * exp = (int*)omAlloc0(n*sizeof(int)); |
---|
36 | sBucket_pt result_bucket=sBucketCreate(r); |
---|
37 | conv_RecPP( f, exp, result_bucket, r ); |
---|
38 | poly result; int dummy; |
---|
39 | sBucketDestroyMerge(result_bucket,&result,&dummy); |
---|
40 | omFreeSize((ADDRESS)exp,n*sizeof(int)); |
---|
41 | return result; |
---|
42 | } |
---|
43 | |
---|
44 | static void conv_RecPP ( const CanonicalForm & f, int * exp, sBucket_pt result, ring r ) |
---|
45 | { |
---|
46 | if (f.isZero()) |
---|
47 | return; |
---|
48 | if ( ! f.inCoeffDomain() ) |
---|
49 | { |
---|
50 | int l = f.level(); |
---|
51 | for ( CFIterator i = f; i.hasTerms(); i++ ) |
---|
52 | { |
---|
53 | exp[l] = i.exp(); |
---|
54 | conv_RecPP( i.coeff(), exp, result, r ); |
---|
55 | } |
---|
56 | exp[l] = 0; |
---|
57 | } |
---|
58 | else |
---|
59 | { |
---|
60 | poly term = p_Init(r); |
---|
61 | pNext( term ) = NULL; |
---|
62 | int varoffset=r->cf->factoryVarOffset; |
---|
63 | for ( int i = 1; i <= r->N; i++ ) |
---|
64 | p_SetExp( term, i-varoffset, exp[i], r); |
---|
65 | pGetCoeff( term )=r->cf->convFactoryNSingN(f, r->cf); |
---|
66 | p_Setm( term, r ); |
---|
67 | if ( n_IsZero(pGetCoeff(term), r->cf) ) |
---|
68 | { |
---|
69 | p_Delete(&term,r); |
---|
70 | } |
---|
71 | else |
---|
72 | { |
---|
73 | sBucket_Merge_p(result,term,1); |
---|
74 | } |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | CanonicalForm convSingPFactoryP( poly p, const ring r ) |
---|
80 | { |
---|
81 | CanonicalForm result = 0; |
---|
82 | int e, n = rVar(r); |
---|
83 | BOOLEAN setChar=TRUE; |
---|
84 | |
---|
85 | while ( p!=NULL ) |
---|
86 | { |
---|
87 | CanonicalForm term; |
---|
88 | term=r->cf->convSingNFactoryN(pGetCoeff( p ),setChar, r->cf); |
---|
89 | if (errorreported) break; |
---|
90 | setChar=FALSE; |
---|
91 | int varoffset=r->cf->factoryVarOffset; |
---|
92 | for ( int i = n; i >0; i-- ) |
---|
93 | { |
---|
94 | if ( (e = p_GetExp( p, i, r)) != 0 ) |
---|
95 | term *= power( Variable( i+varoffset ), e ); |
---|
96 | } |
---|
97 | result += term; |
---|
98 | pIter( p ); |
---|
99 | } |
---|
100 | return result; |
---|
101 | } |
---|
102 | |
---|
103 | CanonicalForm convSingAFactoryA( number pp, Variable a, const coeffs cf ) |
---|
104 | { |
---|
105 | CanonicalForm result = 0; |
---|
106 | int e; |
---|
107 | poly p=(poly)pp; |
---|
108 | BOOLEAN setChar=TRUE; |
---|
109 | |
---|
110 | while ( p!=NULL ) |
---|
111 | { |
---|
112 | CanonicalForm term; |
---|
113 | term=cf->extRing->cf->convSingNFactoryN(pGetCoeff( p ),setChar, cf->extRing->cf); |
---|
114 | if (errorreported) break; |
---|
115 | setChar=FALSE; |
---|
116 | if ( (e = p_GetExp( p, 1, cf->extRing)) != 0 ) |
---|
117 | term *= power( a, e ); |
---|
118 | result += term; |
---|
119 | pIter( p ); |
---|
120 | } |
---|
121 | return result; |
---|
122 | } |
---|
123 | |
---|
124 | number convFactoryASingA ( const CanonicalForm & f, const coeffs cf ) |
---|
125 | { |
---|
126 | poly a=NULL; |
---|
127 | poly t; |
---|
128 | for( CFIterator i=f; i.hasTerms(); i++) |
---|
129 | { |
---|
130 | t=p_New(cf->extRing); |
---|
131 | // pNext( t ) = NULL; //already done by napNew |
---|
132 | pGetCoeff(t)=cf->extRing->cf->convFactoryNSingN( i.coeff(), cf->extRing->cf ); |
---|
133 | if (n_IsZero(p_GetCoeff(t,cf->extRing),cf->extRing->cf)) |
---|
134 | { |
---|
135 | p_Delete(&t,cf->extRing); |
---|
136 | } |
---|
137 | else |
---|
138 | { |
---|
139 | p_SetExp(t,1,i.exp(),cf->extRing); |
---|
140 | a=p_Add_q(a,t,cf->extRing); |
---|
141 | } |
---|
142 | } |
---|
143 | number aa=(number)a; |
---|
144 | n_Normalize(aa,cf); |
---|
145 | return aa; |
---|
146 | } |
---|
147 | |
---|
148 | |
---|
149 | int convFactoryISingI( const CanonicalForm & f) |
---|
150 | { |
---|
151 | if (!f.isImm()) WerrorS("int overflow in det"); |
---|
152 | return f.intval(); |
---|
153 | } |
---|
154 | #endif |
---|