My Project
Loading...
Searching...
No Matches
fglmgauss.cc
Go to the documentation of this file.
1// emacs edit mode for this file is -*- C++ -*-
2
3/****************************************
4* Computer Algebra System SINGULAR *
5****************************************/
6/*
7* ABSTRACT - class gaussReducer. Used in fglmzero.cc and fglmhom.cc
8* to find linear dependencies of fglmVectors.
9*/
10
11
12
13
14#include "kernel/mod2.h"
15
16#include "kernel/structs.h"
17#include "coeffs/numbers.h"
19
20#include "fglmvec.h"
21#include "fglmgauss.h"
22
24{
25public:
28 number pdenom;
29 number fac;
30 gaussElem( const fglmVector newv, const fglmVector newp, number & newpdenom, number & newfac ) : v( newv ), p( newp ), pdenom( newpdenom ), fac( newfac )
31 {
32 newpdenom= NULL;
33 newfac= NULL;
34 }
35
36#ifndef HAVE_EXPLICIT_CONSTR
37 gaussElem() : v(), p(), pdenom(NULL), fac(NULL) {}
38
39 void mac_gaussElem( const fglmVector newv, const fglmVector newp, number & newpdenom, number & newfac )
40 {
41 v= newv;
42 p= newp;
43 pdenom=newpdenom;
44 fac=newfac;
45 newpdenom= NULL;
46 newfac= NULL;
47 }
48#endif
49
51 {
52 if (pdenom!=NULL) nDelete( & pdenom );
53 if (fac!=NULL) nDelete( & fac );
54 }
55};
56
58{
59 int k;
60 size= 0;
61 max= dimen;
62#ifndef HAVE_EXPLICIT_CONSTR
63 elems= new gaussElem[ max+1 ];
64#else
65 elems= (gaussElem *)omAlloc( (max+1)*sizeof( gaussElem ) );
66#endif
67 isPivot= (BOOLEAN *)omAlloc( (max+1)*sizeof( BOOLEAN ) );
68 for ( k= max; k > 0; k-- )
69 isPivot[k]= FALSE;
70 perm= (int *)omAlloc( (max+1)*sizeof( int ) );
71}
72
74{
75#ifndef HAVE_EXPLICIT_CONSTR
76 delete [] elems;
77#else
78 int k;
79 for ( k= size; k > 0; k-- )
80 elems[k].~gaussElem();
81 omFreeSize( (ADDRESS)elems, (max+1)*sizeof( gaussElem ) );
82#endif
83
84 omFreeSize( (ADDRESS)isPivot, (max+1)*sizeof( BOOLEAN ) );
85 omFreeSize( (ADDRESS)perm, (max+1)*sizeof( int ) );
86}
87
90{
91 number fac1, fac2;
92 number temp;
93 // Hier ueberlegen, ob thev als referenz, oder wie wann was kopiert usw.
94 v= thev;
95 p= fglmVector( size + 1, size + 1 );
96 // fglmASSERT( pdenom == NULL );
97 pdenom= nInit( 1 );
98 number vdenom = v.clearDenom();
99 if ( ! nIsOne( vdenom ) && ! nIsZero( vdenom ) ) {
100 p.setelem( p.size(), vdenom );
101 }
102 else {
103 nDelete( & vdenom );
104 }
105 number gcd = v.gcd();
106 if ( ! nIsOne( gcd ) && ! nIsZero( gcd ) ) {
107 v /= gcd;
108 number temp= nMult( pdenom, gcd );
109 nDelete( & pdenom );
110 pdenom= temp;
111 }
112 nDelete( & gcd );
113
114 int k;
115 for ( k= 1; k <= size; k++ ) {
116 if ( ! v.elemIsZero( perm[k] ) ) {
117 fac1= elems[k].fac;
118 fac2= nCopy( v.getconstelem( perm[k] ) );
119 v.nihilate( fac1, fac2, elems[k].v );
120 fac1= nMult( fac1, elems[k].pdenom );
121 temp= nMult( fac2, pdenom );
122 nDelete( & fac2 );
123 fac2= temp;
124 p.nihilate( fac1, fac2, elems[k].p );
125 temp= nMult( pdenom, elems[k].pdenom );
126 nDelete( & pdenom );
127 pdenom= temp;
128
129 nDelete( & fac1 );
130 nDelete( & fac2 );
131 number gcd = v.gcd();
132 if ( ! nIsOne( gcd ) && ! nIsZero( gcd ) )
133 {
134 v/= gcd;
135 number temp = nMult( pdenom, gcd );
136 nDelete( & pdenom );
137 pdenom= temp;
138 }
139 nDelete( & gcd );
140 gcd= p.gcd();
141 temp= n_SubringGcd( pdenom, gcd, currRing->cf );
142 nDelete( & gcd );
143 gcd= temp;
144 if ( ! nIsZero( gcd ) && ! nIsOne( gcd ) )
145 {
146 p/= gcd;
147 temp= nDiv( pdenom, gcd );
148 nDelete( & pdenom );
149 pdenom= temp;
151 }
152 nDelete( & gcd );
153 }
154 }
155 return ( v.isZero() );
156}
157
158void
160{
161 // fglmASSERT( size < max );
162 // number fac;
163 // find the pivot-element in v:
164
165 size++;
166 int k= 1;
167 while ( nIsZero(v.getconstelem(k)) || isPivot[k] ) {
168 k++;
169 }
170 // fglmASSERT( k <= dimen, "Error(1) in fglmDdata::pivot-search");
171 number pivot= v.getconstelem( k );
172 int pivotcol = k;
173 k++;
174 while ( k <= max ) {
175 if ( ! nIsZero( v.getconstelem(k) ) && ! isPivot[k] ) {
176 if ( nGreater( v.getconstelem( k ), pivot ) ) {
177 pivot= v.getconstelem( k );
178 pivotcol= k;
179 }
180 }
181 k++;
182 }
183 // fglmASSERT( ! nIsZero( pivot ), "Error(2) fglmDdata::Pivotelement ist Null" );
184 isPivot[ pivotcol ]= TRUE;
185 perm[size]= pivotcol;
186
187 pivot= nCopy( v.getconstelem( pivotcol ) );
188#ifndef HAVE_EXPLICIT_CONSTR
189 elems[size].mac_gaussElem( v, p, pdenom, pivot );
190#else
192#endif
193}
194
197{
198 nDelete( & pdenom );
199 // hier kann p noch gekuerzt werden, je nach Charakteristik
201 p= fglmVector();
202 return ( result );
203}
204// ================================================================================
205
206// ----------------------------------------------------------------------------
207// Local Variables: ***
208// compile-command: "make Singular" ***
209// page-delimiter: "^\\‍(␌\\|//!\\‍)" ***
210// fold-internal-margins: nil ***
211// End: ***
int BOOLEAN
Definition: auxiliary.h:87
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
void * ADDRESS
Definition: auxiliary.h:119
int k
Definition: cfEzgcd.cc:99
number clearDenom()
Definition: fglmvec.cc:502
int size() const
Definition: fglmvec.cc:207
int elemIsZero(int i)
Definition: fglmvec.cc:300
number getconstelem(int i) const
Definition: fglmvec.cc:446
void setelem(int i, number &n)
Definition: fglmvec.cc:451
number gcd() const
Definition: fglmvec.cc:458
void nihilate(const number fac1, const number fac2, const fglmVector v)
Definition: fglmvec.cc:218
int isZero()
Definition: fglmvec.cc:295
number fac
Definition: fglmgauss.cc:29
fglmVector p
Definition: fglmgauss.cc:27
fglmVector v
Definition: fglmgauss.cc:26
~gaussElem()
Definition: fglmgauss.cc:50
number pdenom
Definition: fglmgauss.cc:28
gaussElem(const fglmVector newv, const fglmVector newp, number &newpdenom, number &newfac)
Definition: fglmgauss.cc:30
gaussElem * elems
Definition: fglmgauss.h:21
number pdenom
Definition: fglmgauss.h:26
gaussReducer(int dimen)
Definition: fglmgauss.cc:57
BOOLEAN * isPivot
Definition: fglmgauss.h:22
fglmVector v
Definition: fglmgauss.h:24
BOOLEAN reduce(fglmVector v)
Definition: fglmgauss.cc:89
void store()
Definition: fglmgauss.cc:159
int * perm
Definition: fglmgauss.h:23
fglmVector p
Definition: fglmgauss.h:25
fglmVector getDependence()
Definition: fglmgauss.cc:196
static FORCE_INLINE number n_SubringGcd(number a, number b, const coeffs r)
Definition: coeffs.h:663
return result
Definition: facAbsBiFact.cc:75
bool pivot(const matrix aMat, const int r1, const int r2, const int c1, const int c2, int *bestR, int *bestC, const ring R)
This code computes a score for each non-zero matrix entry in aMat[r1..r2, c1..c2].
#define nDiv(a, b)
Definition: numbers.h:32
#define nDelete(n)
Definition: numbers.h:16
#define nIsZero(n)
Definition: numbers.h:19
#define nCopy(n)
Definition: numbers.h:15
#define nGreater(a, b)
Definition: numbers.h:28
#define nIsOne(n)
Definition: numbers.h:25
#define nNormalize(n)
Definition: numbers.h:30
#define nInit(i)
Definition: numbers.h:24
#define nMult(n1, n2)
Definition: numbers.h:17
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define NULL
Definition: omList.c:12
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
int gcd(int a, int b)
Definition: walkSupport.cc:836