Loading...
Searching...
No Matches
fglmgauss.cc
Go to the documentation of this file.
// emacs edit mode for this file is -*- C++ -*-
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
/*
* ABSTRACT - class gaussReducer. Used in fglmzero.cc and fglmhom.cc
* to find linear dependencies of fglmVectors.
*/
#include "kernel/mod2.h"
#include "kernel/structs.h"
#include "coeffs/numbers.h"
#include "polys/monomials/ring.h"
#include "fglmvec.h"
#include "fglmgauss.h"
class gaussElem
{
public:
fglmVector v;
fglmVector p;
number pdenom;
number fac;
gaussElem( const fglmVector newv, const fglmVector newp, number & newpdenom, number & newfac ) : v( newv ), p( newp ), pdenom( newpdenom ), fac( newfac )
{
newpdenom= NULL;
newfac= NULL;
}
#ifndef HAVE_EXPLICIT_CONSTR
gaussElem() : v(), p(), pdenom(NULL), fac(NULL) {}
void mac_gaussElem( const fglmVector newv, const fglmVector newp, number & newpdenom, number & newfac )
{
v= newv;
p= newp;
pdenom=newpdenom;
fac=newfac;
newpdenom= NULL;
newfac= NULL;
}
#endif
~gaussElem()
{
if (pdenom!=NULL) nDelete( & pdenom );
if (fac!=NULL) nDelete( & fac );
}
};
gaussReducer::gaussReducer( int dimen )
{
int k;
size= 0;
max= dimen;
#ifndef HAVE_EXPLICIT_CONSTR
elems= new gaussElem[ max+1 ];
#else
elems= (gaussElem *)omAlloc( (max+1)*sizeof( gaussElem ) );
#endif
isPivot= (BOOLEAN *)omAlloc( (max+1)*sizeof( BOOLEAN ) );
for ( k= max; k > 0; k-- )
isPivot[k]= FALSE;
perm= (int *)omAlloc( (max+1)*sizeof( int ) );
}
gaussReducer::~gaussReducer()
{
#ifndef HAVE_EXPLICIT_CONSTR
delete [] elems;
#else
int k;
for ( k= size; k > 0; k-- )
elems[k].~gaussElem();
omFreeSize( (ADDRESS)elems, (max+1)*sizeof( gaussElem ) );
#endif
omFreeSize( (ADDRESS)isPivot, (max+1)*sizeof( BOOLEAN ) );
omFreeSize( (ADDRESS)perm, (max+1)*sizeof( int ) );
}
BOOLEAN
gaussReducer::reduce( fglmVector thev )
{
number fac1, fac2;
number temp;
// Hier ueberlegen, ob thev als referenz, oder wie wann was kopiert usw.
v= thev;
p= fglmVector( size + 1, size + 1 );
// fglmASSERT( pdenom == NULL );
pdenom= nInit( 1 );
number vdenom = v.clearDenom();
if ( ! nIsOne( vdenom ) && ! nIsZero( vdenom ) ) {
p.setelem( p.size(), vdenom );
}
else {
nDelete( & vdenom );
}
number gcd = v.gcd();
if ( ! nIsOne( gcd ) && ! nIsZero( gcd ) ) {
v /= gcd;
number temp= nMult( pdenom, gcd );
nDelete( & pdenom );
pdenom= temp;
}
nDelete( & gcd );
int k;
for ( k= 1; k <= size; k++ ) {
if ( ! v.elemIsZero( perm[k] ) ) {
fac1= elems[k].fac;
fac2= nCopy( v.getconstelem( perm[k] ) );
v.nihilate( fac1, fac2, elems[k].v );
fac1= nMult( fac1, elems[k].pdenom );
temp= nMult( fac2, pdenom );
nDelete( & fac2 );
fac2= temp;
p.nihilate( fac1, fac2, elems[k].p );
temp= nMult( pdenom, elems[k].pdenom );
nDelete( & pdenom );
pdenom= temp;
nDelete( & fac1 );
nDelete( & fac2 );
number gcd = v.gcd();
if ( ! nIsOne( gcd ) && ! nIsZero( gcd ) )
{
v/= gcd;
number temp = nMult( pdenom, gcd );
nDelete( & pdenom );
pdenom= temp;
}
nDelete( & gcd );
gcd= p.gcd();
temp= n_SubringGcd( pdenom, gcd, currRing->cf );
nDelete( & gcd );
gcd= temp;
if ( ! nIsZero( gcd ) && ! nIsOne( gcd ) )
{
p/= gcd;
temp= nDiv( pdenom, gcd );
nDelete( & pdenom );
pdenom= temp;
nNormalize( pdenom );
}
nDelete( & gcd );
}
}
return ( v.isZero() );
}
void
gaussReducer::store()
{
// fglmASSERT( size < max );
// number fac;
// find the pivot-element in v:
size++;
int k= 1;
while ( nIsZero(v.getconstelem(k)) || isPivot[k] ) {
k++;
}
// fglmASSERT( k <= dimen, "Error(1) in fglmDdata::pivot-search");
number pivot= v.getconstelem( k );
int pivotcol = k;
k++;
while ( k <= max ) {
if ( ! nIsZero( v.getconstelem(k) ) && ! isPivot[k] ) {
if ( nGreater( v.getconstelem( k ), pivot ) ) {
pivot= v.getconstelem( k );
pivotcol= k;
}
}
k++;
}
// fglmASSERT( ! nIsZero( pivot ), "Error(2) fglmDdata::Pivotelement ist Null" );
isPivot[ pivotcol ]= TRUE;
perm[size]= pivotcol;
pivot= nCopy( v.getconstelem( pivotcol ) );
#ifndef HAVE_EXPLICIT_CONSTR
elems[size].mac_gaussElem( v, p, pdenom, pivot );
#else
elems[size].gaussElem( v, p, pdenom, pivot );
#endif
}
fglmVector
gaussReducer::getDependence()
{
nDelete( & pdenom );
// hier kann p noch gekuerzt werden, je nach Charakteristik
fglmVector result = p;
p= fglmVector();
return ( result );
}
// ================================================================================
// ----------------------------------------------------------------------------
// Local Variables: ***
// compile-command: "make Singular" ***
// page-delimiter: "^\\‍(␌\\|//!\\‍)" ***
// fold-internal-margins: nil ***
// End: ***
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
ADDRESS
void * ADDRESS
Definition auxiliary.h:120
k
int k
Definition cfEzgcd.cc:99
p
int p
Definition cfModGcd.cc:4086
fglmVector
Definition fglmvec.h:19
gaussElem
Definition fglmgauss.cc:24
gaussElem::fac
number fac
Definition fglmgauss.cc:29
gaussElem::p
fglmVector p
Definition fglmgauss.cc:27
gaussElem::v
fglmVector v
Definition fglmgauss.cc:26
gaussElem::~gaussElem
~gaussElem()
Definition fglmgauss.cc:50
gaussElem::pdenom
number pdenom
Definition fglmgauss.cc:28
gaussElem::gaussElem
gaussElem(const fglmVector newv, const fglmVector newp, number &newpdenom, number &newfac)
Definition fglmgauss.cc:30
gaussReducer::elems
gaussElem * elems
Definition fglmgauss.h:21
gaussReducer::pdenom
number pdenom
Definition fglmgauss.h:26
gaussReducer::~gaussReducer
~gaussReducer()
Definition fglmgauss.cc:73
gaussReducer::gaussReducer
gaussReducer(int dimen)
Definition fglmgauss.cc:57
gaussReducer::max
int max
Definition fglmgauss.h:28
gaussReducer::isPivot
BOOLEAN * isPivot
Definition fglmgauss.h:22
gaussReducer::v
fglmVector v
Definition fglmgauss.h:24
gaussReducer::size
int size
Definition fglmgauss.h:27
gaussReducer::reduce
BOOLEAN reduce(fglmVector v)
Definition fglmgauss.cc:89
gaussReducer::store
void store()
Definition fglmgauss.cc:159
gaussReducer::perm
int * perm
Definition fglmgauss.h:23
gaussReducer::p
fglmVector p
Definition fglmgauss.h:25
gaussReducer::getDependence
fglmVector getDependence()
Definition fglmgauss.cc:196
n_SubringGcd
static FORCE_INLINE number n_SubringGcd(number a, number b, const coeffs r)
Definition coeffs.h:669
result
return result
Definition facAbsBiFact.cc:76
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
fglmgauss.h
fglmvec.h
pivot
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].
Definition linearAlgebra.cc:68
mod2.h
numbers.h
nDiv
#define nDiv(a, b)
Definition numbers.h:32
nDelete
#define nDelete(n)
Definition numbers.h:16
nIsZero
#define nIsZero(n)
Definition numbers.h:19
nCopy
#define nCopy(n)
Definition numbers.h:15
nGreater
#define nGreater(a, b)
Definition numbers.h:28
nIsOne
#define nIsOne(n)
Definition numbers.h:25
nNormalize
#define nNormalize(n)
Definition numbers.h:30
nInit
#define nInit(i)
Definition numbers.h:24
nMult
#define nMult(n1, n2)
Definition numbers.h:17
omFreeSize
#define omFreeSize(addr, size)
Definition omAllocDecl.h:260
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210
NULL
#define NULL
Definition omList.c:12
currRing
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
ring.h
structs.h
gcd
int gcd(int a, int b)
Definition walkSupport.cc:836