Loading...
Searching...
No Matches
ntupel.cc
Go to the documentation of this file.
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
/*
* ABSTRACT: n-tupel of coefficients
*/
#include "misc/auxiliary.h"
#include "misc/mylimits.h"
#include "reporter/reporter.h"
#include "coeffs/numbers.h"
#include "coeffs/coeffs.h"
#include "coeffs/mpr_complex.h"
#include "coeffs/ntupel.h"
#include "coeffs/modulop.h"
#include "coeffs/longrat.h"
typedef coeffs *coeffs_array;
typedef number *number_array;
static void nnCoeffWrite(const coeffs r, BOOLEAN b)
{
int i=0;
coeffs_array d=(coeffs_array)r->data;
loop
{
d[i]->cfCoeffWrite(d[i],b);
i++;
if (d[i]==NULL) break;
PrintS(" x ");
}
}
static BOOLEAN nnGreaterZero (number k, const coeffs r)
{
int i=0;
coeffs_array d=(coeffs_array)r->data;
loop
{
if (d[i]->type==n_R) return d[i]->cfGreaterZero(k,d[i]);
if (d[i]->type==n_long_R) return d[i]->cfGreaterZero(k,d[i]);
i++;
if (d[i]==NULL) return d[i-1]->cfGreaterZero(k,d[i-1]);
}
}
static number nnMult (number a,number b, const coeffs r)
{
number_array A=(number_array)a;
number_array B=(number_array)b;
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
i++;
if (d[i]==NULL) break;
}
number *C=(number*)omAlloc(i*sizeof(number));
i=0;
loop
{
C[i]=d[i]->cfMult(A[i],B[i],d[i]);
i++;
if (d[i]==NULL) return (number)C;
}
}
static void nnInpMult (number &a,number b, const coeffs r)
{
number_array A=(number_array)a;
number_array B=(number_array)b;
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
d[i]->cfInpMult(A[i],B[i],d[i]);
i++;
if (d[i]==NULL) return;
}
}
/*2
* create a number from int
*/
static number nnInit (long l, const coeffs r)
{
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
i++;
if (d[i]==NULL) break;
}
number *C=(number*)omAlloc(i*sizeof(number));
i=0;
loop
{
C[i]=d[i]->cfInit(l,d[i]);
i++;
if (d[i]==NULL) return (number)C;
}
}
/*2
* convert a number to int
*/
static long nnInt(number &n, const coeffs r)
{
int i=0;
coeffs_array d=(coeffs_array)r->data;
loop
{
if (d[i]->type==n_R) return d[i]->cfInt(n,d[i]);
if (d[i]->type==n_long_R) return d[i]->cfInt(n,d[i]);
i++;
if (d[i]==NULL) return d[i-1]->cfInt(n,d[i-1]);
}
}
static int nnSize(number n, const coeffs r)
{
int s=0;
int i=0;
coeffs_array d=(coeffs_array)r->data;
loop
{
if (d[i]->type==n_R) s+=d[i]->cfSize(n,d[i]);
else if (d[i]->type==n_long_R) s+=d[i]->cfSize(n,d[i]);
i++;
if (d[i]==NULL)
{
if (s==0) return d[i-1]->cfSize(n,d[i-1]);
else return s;
}
}
}
static number nnCopy (number a, const coeffs r)
{
number_array A=(number_array)a;
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
i++;
if (d[i]==NULL) break;
}
number *C=(number*)omAlloc(i*sizeof(number));
i=0;
loop
{
C[i]=d[i]->cfCopy(A[i],d[i]);
i++;
if (d[i]==NULL) return (number)C;
}
}
static number nnAdd (number a, number b, const coeffs r)
{
number_array A=(number_array)a;
number_array B=(number_array)b;
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
i++;
if (d[i]==NULL) break;
}
number *C=(number*)omAlloc(i*sizeof(number));
i=0;
loop
{
C[i]=d[i]->cfAdd(A[i],B[i],d[i]);
i++;
if (d[i]==NULL) return (number)C;
}
}
static void nnInpAdd (number &a, number b, const coeffs r)
{
number_array A=(number_array)a;
number_array B=(number_array)b;
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
d[i]->cfInpAdd(A[i],B[i],d[i]);
i++;
if (d[i]==NULL) return;
}
}
static number nnSub (number a, number b, const coeffs r)
{
number_array A=(number_array)a;
number_array B=(number_array)b;
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
i++;
if (d[i]==NULL) break;
}
number *C=(number*)omAlloc(i*sizeof(number));
i=0;
loop
{
C[i]=d[i]->cfSub(A[i],B[i],d[i]);
i++;
if (d[i]==NULL) return (number)C;
}
}
static BOOLEAN nnIsZero (number a, const coeffs r)
{
number_array A=(number_array)a;
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
if (!d[i]->cfIsZero(A[i],d[i])) return FALSE;
i++;
if (d[i]==NULL) return TRUE;
}
}
static BOOLEAN nnIsOne (number a, const coeffs r)
{
int i=0;
number_array A=(number_array)a;
coeffs_array d=(coeffs_array)r->data;
loop
{
if (!d[i]->cfIsOne(A[i],d[i])) return FALSE;
i++;
if (d[i]==NULL) return TRUE;
}
}
static BOOLEAN nnIsMOne (number a, const coeffs r)
{
int i=0;
number_array A=(number_array)a;
coeffs_array d=(coeffs_array)r->data;
loop
{
if (!d[i]->cfIsMOne(A[i],d[i])) return FALSE;
i++;
if (d[i]==NULL) return TRUE;
}
}
static number nnDiv (number a,number b, const coeffs r)
{
if (nnIsZero(b,r))
{
WerrorS(nDivBy0);
return nnInit(0,r);
}
number_array A=(number_array)a;
number_array B=(number_array)b;
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
i++;
if (d[i]==NULL) break;
}
number *C=(number*)omAlloc(i*sizeof(number));
i=0;
loop
{
C[i]=d[i]->cfDiv(A[i],B[i],d[i]);
i++;
if (d[i]==NULL) return (number)C;
}
}
static number nnInvers (number a, const coeffs r)
{
if (nnIsZero(a,r))
{
WerrorS(nDivBy0);
return nnInit(0,r);
}
number_array A=(number_array)a;
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
i++;
if (d[i]==NULL) break;
}
number *C=(number*)omAlloc(i*sizeof(number));
i=0;
loop
{
C[i]=d[i]->cfInvers(A[i],d[i]);
i++;
if (d[i]==NULL) return (number)C;
}
}
static number nnInpNeg (number a, const coeffs r)
{
number_array A=(number_array)a;
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
i++;
if (d[i]==NULL) break;
}
i=0;
loop
{
A[i]=d[i]->cfInpNeg(A[i],d[i]);
i++;
if (d[i]==NULL) return (number)A;
}
}
static BOOLEAN nnGreater (number a,number b, const coeffs r)
{
number_array A=(number_array)a;
number_array B=(number_array)b;
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
if (d[i]->type==n_R) return d[i]->cfGreater(A[i],B[i],d[i]);
else if (d[i]->type==n_long_R) return d[i]->cfGreater(A[i],B[i],d[i]);
i++;
if (d[i]==NULL)
{
return d[i-1]->cfGreater(A[i],B[i],d[i-1]);
}
}
}
static BOOLEAN nnEqual (number a,number b, const coeffs r)
{
int i=0;
number_array A=(number_array)a;
number_array B=(number_array)b;
coeffs_array d=(coeffs_array)r->data;
loop
{
if (!d[i]->cfEqual(A[i],B[i],d[i])) return FALSE;
i++;
if (d[i]==NULL) return TRUE;
}
}
static void nnWriteShort (number a, const coeffs r)
{
number_array A=(number_array)a;
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
if (d[i]->type==n_R) { d[i]->cfWriteLong(A[i],d[i]); return; }
else if (d[i]->type==n_long_R) {d[i]->cfWriteLong(A[i],d[i]); return; }
i++;
if (d[i]==NULL) { d[i-1]->cfWriteLong(A[i-1],d[i-1]); return; }
}
}
static void nnWriteLong (number a, const coeffs r)
{
number_array A=(number_array)a;
coeffs_array d=(coeffs_array)r->data;
int i=0;
StringSetS("(");
loop
{
d[i]->cfWriteLong(A[i],d[i]);
i++;
if (d[i]==NULL) {StringAppendS(")"); return; }
else StringAppendS(",");
}
}
#if 0
static void nrPower (number a, int i, number * result, const coeffs r)
{
assume( getCoeffType(r) == n_R );
if (i==0)
{
*result = nf(nf(1.0).F()).N();
return;
}
if (i==1)
{
*result = nf(nf(a).F()).N();
return;
}
nrPower(a,i-1,result,r);
*result = nf(nf(a).F() * nf(*result).F()).N();
}
#endif
static const char * nnRead (const char *s, number *a, const coeffs r)
{
// reading R/longR part, setting everything else to random
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
i++;
if (d[i]==NULL) break;
}
number *C=(number*)omAlloc0(i*sizeof(number));
*a=(number)C;
int is_zero=2; /*1: read 0, 2: read <> 0 */
int reader=-1;
i=0;
loop
{
if ((d[i]->type==n_R)
|| (d[i]->type==n_long_R))
{
s=d[i]->cfRead(s,&(C[i]),d[i]);
is_zero=d[i]->cfIsZero(C[i],d[i]);
reader=i;
break;
}
i++;
if (d[i]==NULL)
{
s=d[i-1]->cfRead(s,&(C[i-1]),d[i-1]);
is_zero=d[i-1]->cfIsZero(C[i-1],d[i-1]);
reader=i-1;
break;
}
}
if (is_zero==0)
{ // setting random values!=0 for Z/p
i=0;
loop
{
if (i!=reader)
{
if (d[i]->type==n_Zp)
{
int l=0;
do
{
l=siRand();
} while(l%(d[i]->ch)==0);
C[i]=d[i]->cfInit(l,d[i]);
}
else if ((d[i]->type==n_R)
|| (d[i]->type==n_long_R))
{
nMapFunc nMap=d[i]->cfSetMap(d[reader],d[i]);
C[i]=nMap(C[reader],d[reader],d[i]);
}
else
{
WerrorS("reading is not suppiorted for such compinations of coeffs");
break;
}
}
i++;
if (d[i]==NULL) break;
}
}
else if (is_zero==1)
{ // read a zero
i=0;
loop
{
C[i]=d[i]->cfInit(0,d[i]);
i++;
if (d[i]==NULL) break;
}
}
else if (reader==-1)/* not R or long_R*/
{
s=d[0]->cfRead(s,&(C[0]),d[0]);
i=1;
loop
{
if (d[i]==NULL) break;
i++;
{
nMapFunc nMap=d[i]->cfSetMap(d[0],d[i]);
C[i]=nMap(C[0],d[0],d[i]);
}
}
}
else
{
WerrorS("nnRead: should not happen");
}
return s;
}
#ifdef LDEBUG
/*2
* test valid numbers: not implemented yet
*/
static BOOLEAN nnDBTest(number a, const char *f, const int l, const coeffs r)
{
BOOLEAN bo=FALSE;
number_array A=(number_array)a;
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
bo&=d[i]->cfDBTest(A[i],f,l,d[i]);
i++;
if (d[i]==NULL) return bo;
}
}
#endif
static number nnMap(number from, const coeffs aRing, const coeffs r)
{
coeffs_array d=(coeffs_array)r->data;
int i=0;
loop
{
i++;
if (d[i]==NULL) break;
}
number *C=(number*)omAlloc(i*sizeof(number));
nMapFunc nMap;
i=0;
loop
{
nMap=d[i]->cfSetMap(aRing,d[i]);
if (nMap==NULL) Werror("no map for component %d",i);
else C[i]=nMap(from,aRing,d[i]);
i++;
if (d[i]==NULL) return (number)C;
}
}
static nMapFunc nnSetMap(const coeffs, const coeffs)
{
return nnMap;
}
static char* nnCoeffString(const coeffs r)
{
#define SI_BUF_SIZE 1024
char buf[SI_BUF_SIZE];
coeffs_array d=(coeffs_array)r->data;
int i=0;
buf[0]='\0';
loop
{
char *s=d[i]->cfCoeffName(d[i]);
strncat(buf,s, SI_BUF_SIZE-strlen(buf)-strlen(s)-1);
i++;
if (d[i]==NULL) break;
strncat(buf," x ", SI_BUF_SIZE-strlen(buf)-4);
}
return omStrDup(buf);
}
typedef char si_char_SI_BUF_SIZE[SI_BUF_SIZE];
STATIC_VAR si_char_SI_BUF_SIZE nnCoeffName_buf;
static char* nnCoeffName(const coeffs r)
{
coeffs_array d=(coeffs_array)r->data;
int i=0;
nnCoeffName_buf[0]='\0';
loop
{
char *s=d[i]->cfCoeffName(d[i]);
strncat(nnCoeffName_buf,s, SI_BUF_SIZE-strlen(nnCoeffName_buf)-strlen(s)-1);
i++;
if (d[i]==NULL) break;
strncat(nnCoeffName_buf," x ", SI_BUF_SIZE-strlen(nnCoeffName_buf)-4);
}
return nnCoeffName_buf;
}
static void nnDelete (number * a, const coeffs r)
{
if (*a!=NULL)
{
coeffs_array d=(coeffs_array)r->data;
number_array A=(number_array)(*a);
int i=0;
loop
{
d[i]->cfDelete(&(A[i]),d[i]);
i++;
if (d[i]==NULL) break;
}
omFreeSize(d,i*sizeof(number));
*a=NULL;
}
}
static number nnChineseRemainder(number *, number *,int , BOOLEAN , CFArray &,const coeffs )
{
WerrorS("not yet");
return NULL;
}
BOOLEAN nnInitChar(coeffs n, void* p)
{
n->data=p;
n->type=n_nTupel;
n->is_field=TRUE;
n->is_domain=TRUE;
n->ch = 0;
n->cfCoeffString = nnCoeffString;
n->cfCoeffName = nnCoeffName;
n->cfInit = nnInit;
n->cfDelete = nnDelete;
n->cfInt = nnInt;
n->cfAdd = nnAdd;
n->cfInpAdd = nnInpAdd;
n->cfSub = nnSub;
n->cfMult = nnMult;
n->cfInpMult = nnInpMult;
n->cfDiv = nnDiv;
n->cfExactDiv= nnDiv;
n->cfInpNeg = nnInpNeg;
n->cfInvers= nnInvers;
n->cfCopy = nnCopy;
n->cfGreater = nnGreater;
n->cfEqual = nnEqual;
n->cfIsZero = nnIsZero;
n->cfIsOne = nnIsOne;
n->cfIsMOne = nnIsMOne;
n->cfGreaterZero = nnGreaterZero;
n->cfWriteShort = nnWriteShort;
n->cfWriteLong = nnWriteLong;
n->cfRead = nnRead;
//n->cfPower = nnPower;
n->cfSetMap = nnSetMap;
n->cfCoeffWrite = nnCoeffWrite;
n->cfChineseRemainder=nnChineseRemainder;
n->cfSize = nnSize;
#ifdef LDEBUG
n->cfDBTest=nnDBTest;
#endif
//n->nCoeffIsEqual = ndCoeffIsEqual;
return FALSE;
}
auxiliary.h
All the auxiliary stuff.
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
CFArray
Array< CanonicalForm > CFArray
Definition canonicalform.h:397
l
int l
Definition cfEzgcd.cc:100
i
int i
Definition cfEzgcd.cc:132
k
int k
Definition cfEzgcd.cc:99
p
int p
Definition cfModGcd.cc:4086
b
CanonicalForm b
Definition cfModGcd.cc:4111
f
FILE * f
Definition checklibs.c:9
coeffs.h
Coefficient rings, fields and other domains suitable for Singular polynomials.
n_R
@ n_R
single prescision (6,6) real numbers
Definition coeffs.h:31
n_long_R
@ n_long_R
real floating point (GMP) numbers
Definition coeffs.h:33
n_Zp
@ n_Zp
\F{p < 2^31}
Definition coeffs.h:29
n_nTupel
@ n_nTupel
n-tupel of cf: ZZ/p1,... ZZ/pn, R, long_R
Definition coeffs.h:42
getCoeffType
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition coeffs.h:431
nMapFunc
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:80
result
return result
Definition facAbsBiFact.cc:76
s
const CanonicalForm int s
Definition facAbsFact.cc:51
B
b *CanonicalForm B
Definition facBivar.cc:52
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
STATIC_VAR
#define STATIC_VAR
Definition globaldefs.h:7
longrat.h
assume
#define assume(x)
Definition mod2.h:389
modulop.h
mpr_complex.h
mylimits.h
coeffs
The main handler for Singular numbers which are suitable for Singular polynomials.
nnMap
static number nnMap(number from, const coeffs aRing, const coeffs r)
Definition ntupel.cc:527
nnIsZero
static BOOLEAN nnIsZero(number a, const coeffs r)
Definition ntupel.cc:221
nnCoeffName
static char * nnCoeffName(const coeffs r)
Definition ntupel.cc:574
nnDBTest
static BOOLEAN nnDBTest(number a, const char *f, const int l, const coeffs r)
Definition ntupel.cc:512
coeffs_array
coeffs * coeffs_array
Definition ntupel.cc:24
nnIsMOne
static BOOLEAN nnIsMOne(number a, const coeffs r)
Definition ntupel.cc:247
nnCoeffName_buf
STATIC_VAR si_char_SI_BUF_SIZE nnCoeffName_buf
Definition ntupel.cc:573
nnCopy
static number nnCopy(number a, const coeffs r)
Definition ntupel.cc:145
nnDiv
static number nnDiv(number a, number b, const coeffs r)
Definition ntupel.cc:260
nnAdd
static number nnAdd(number a, number b, const coeffs r)
Definition ntupel.cc:165
SI_BUF_SIZE
#define SI_BUF_SIZE
nnDelete
static void nnDelete(number *a, const coeffs r)
Definition ntupel.cc:590
number_array
number * number_array
Definition ntupel.cc:25
nnInpNeg
static number nnInpNeg(number a, const coeffs r)
Definition ntupel.cc:311
nnWriteShort
static void nnWriteShort(number a, const coeffs r)
Definition ntupel.cc:362
nnEqual
static BOOLEAN nnEqual(number a, number b, const coeffs r)
Definition ntupel.cc:348
nnInit
static number nnInit(long l, const coeffs r)
Definition ntupel.cc:92
nnInt
static long nnInt(number &n, const coeffs r)
Definition ntupel.cc:114
nnMult
static number nnMult(number a, number b, const coeffs r)
Definition ntupel.cc:54
nnGreaterZero
static BOOLEAN nnGreaterZero(number k, const coeffs r)
Definition ntupel.cc:41
nnInitChar
BOOLEAN nnInitChar(coeffs n, void *p)
Initialize r.
Definition ntupel.cc:616
nnRead
static const char * nnRead(const char *s, number *a, const coeffs r)
Definition ntupel.cc:411
nnGreater
static BOOLEAN nnGreater(number a, number b, const coeffs r)
Definition ntupel.cc:330
nnSetMap
static nMapFunc nnSetMap(const coeffs, const coeffs)
Definition ntupel.cc:549
nnInvers
static number nnInvers(number a, const coeffs r)
Definition ntupel.cc:286
nnSub
static number nnSub(number a, number b, const coeffs r)
Definition ntupel.cc:200
nnCoeffWrite
static void nnCoeffWrite(const coeffs r, BOOLEAN b)
Definition ntupel.cc:27
nnIsOne
static BOOLEAN nnIsOne(number a, const coeffs r)
Definition ntupel.cc:234
nnSize
static int nnSize(number n, const coeffs r)
Definition ntupel.cc:127
si_char_SI_BUF_SIZE
char si_char_SI_BUF_SIZE[SI_BUF_SIZE]
Definition ntupel.cc:572
nnChineseRemainder
static number nnChineseRemainder(number *, number *, int, BOOLEAN, CFArray &, const coeffs)
Definition ntupel.cc:609
nnInpAdd
static void nnInpAdd(number &a, number b, const coeffs r)
Definition ntupel.cc:186
nnWriteLong
static void nnWriteLong(number a, const coeffs r)
Definition ntupel.cc:376
nnInpMult
static void nnInpMult(number &a, number b, const coeffs r)
Definition ntupel.cc:75
nnCoeffString
static char * nnCoeffString(const coeffs r)
Definition ntupel.cc:554
ntupel.h
numbers.h
nDivBy0
const char *const nDivBy0
Definition numbers.h:90
omStrDup
#define omStrDup(s)
Definition omAllocDecl.h:263
omFreeSize
#define omFreeSize(addr, size)
Definition omAllocDecl.h:260
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210
omAlloc0
#define omAlloc0(size)
Definition omAllocDecl.h:211
NULL
#define NULL
Definition omList.c:12
StringSetS
void StringSetS(const char *st)
Definition reporter.cc:128
StringAppendS
void StringAppendS(const char *st)
Definition reporter.cc:107
PrintS
void PrintS(const char *s)
Definition reporter.cc:288
Werror
void Werror(const char *fmt,...)
Definition reporter.cc:189
reporter.h
buf
int status int void * buf
Definition si_signals.h:69
siRand
int siRand()
Definition sirandom.c:42
A
#define A
Definition sirandom.c:24
loop
#define loop
Definition structs.h:71
nf
Definition gnumpfl.cc:25
nf::F
SI_FLOAT F() const
Definition gnumpfl.cc:30
nf::N
number N() const
Definition gnumpfl.cc:31