Loading...
Searching...
No Matches
Number.h
Go to the documentation of this file.
#ifndef NUMBERCPP_HEADER
#define NUMBERCPP_HEADER
#include <boost/intrusive_ptr.hpp>
#include "kernel/mod2.h"
#include "coeffs/numbers.h"
#include "kernel/polys.h"
#include "polys/monomials/ring.h"
using namespace boost;
inline void intrusive_ptr_add_ref(ring r)
{
r->ref++;
//Print("ref count after add: %d", r->ref);
}
inline void intrusive_ptr_release(ring r)
{
if (r->ref<=0) rDelete(r);
else
{
r->ref--;
}
//Print("ref count after release: %d", r->ref);
}
enum poly_variant
{
POLY_VARIANT_RING,
POLY_VARIANT_MODUL
};
template<poly_variant,class,class> class PolyBase;
class Poly;
//class TrivialErrorHandler;
class Vector;
class Number
{
public:
friend Number operator+(const Number& n1, const Number& n2);
friend Number operator-(const Number& n1, const Number& n2);
friend Number operator/(const Number& n1, const Number& n2);
friend Number operator*(const Number& n1, const Number& n2);
friend bool operator==(const Number& n1, const Number& n2);
friend Number operator+(const Number& n1, int n2);
friend Number operator-(const Number& n1, int n2);
friend Number operator/(const Number& n1, int n2);
friend Number operator*(const Number& n1, int n2);
friend bool operator==(const Number& n1, int n2);
friend Number operator+(int n1, const Number& n2);
friend Number operator-(int n1, const Number& n2);
friend Number operator/(int n1, const Number& n2);
friend Number operator*(int n1, const Number& n2);
friend bool operator==(int n1, const Number& n2);
friend class Poly;
friend class Vector;
//friend class PolyBase<POLY_VARIANT_RING,Poly,TrivialErrorHandler>;
// friend class PolyBase <poly_variant variant,
// class create_type_input,
// class error_handle_traits>;
template <poly_variant,class,class> friend class PolyBase;
friend class PolyImpl;
number as_number() const
{
return n_Copy(n,r.get()->cf);
}
Number& operator=(const Number& n2)
{
//durch Reihenfolge Selbstzuweisungen berücksichtigt
number nc=n_Copy(n2.n,n2.r.get()->cf);
n_Delete(&n,r.get()->cf);
r=n2.r;
n=nc;
return *this;
}
Number operator-()
{
Number t(*this);
//t.n=n_Copy(n,r);
t.n=n_InpNeg(t.n,r.get()->cf);
return t;
}
Number& operator+=(const Number & n2)
{
if (r!=n2.r)
{
WerrorS("not the same ring");
return *this;
}
number nv=n_Add(n,n2.n,r.get()->cf);
n_Delete(&n,r.get()->cf);
n=nv;
return *this;
}
Number& operator*=(const Number & n2)
{
if (r!=n2.r)
{
WerrorS("not the same ring");
return *this;
}
number nv=n_Mult(n,n2.n,r.get()->cf);
n_Delete(&n,r.get()->cf);
n=nv;
return *this;
}
Number& operator-=(const Number & n2)
{
if (r!=n2.r)
{
WerrorS("not the same ring");
return *this;
}
number nv=n_Sub(n,n2.n,r.get()->cf);
n_Delete(&n,r.get()->cf);
n=nv;
return *this;
}
Number& operator/=(const Number & n2)
{
if (r!=n2.r)
{
WerrorS("not the same ring");
return *this;
}
number nv=n_Div(n,n2.n,r.get()->cf);
n_Delete(&n,r.get()->cf);
n=nv;
return *this;
}
Number& operator=(int n2)
{
n_Delete(&n,r.get()->cf);
n=n_Init(n2,r.get()->cf);
return *this;
}
Number& operator+=(int n2)
{
number n2n=n_Init(n2,r.get()->cf);
number nv=n_Add(n,n2n,r.get()->cf);
n_Delete(&n,r.get()->cf);
n_Delete(&n2n,r.get()->cf);
n=nv;
return *this;
}
Number& operator*=(int n2)
{
number n2n=n_Init(n2,r.get()->cf);
number nv=n_Mult(n,n2n,r.get()->cf);
n_Delete(&n,r.get()->cf);
n_Delete(&n2n,r.get()->cf);
n=nv;
return *this;
}
Number& operator-=(int n2)
{
number n2n=n_Init(n2,r.get()->cf);
number nv=n_Sub(n,n2n,r.get()->cf);
n_Delete(&n,r.get()->cf);
n_Delete(&n2n,r.get()->cf);
n=nv;
return *this;
}
Number& operator/=(int n2)
{
number n2n=n_Init(n2,r.get()->cf);
number nv=n_Div(n,n2n,r.get()->cf);
n_Delete(&n,r.get()->cf);
n_Delete(&n2n,r.get()->cf);
n=nv;
return *this;
}
Number()
{
r=currRing;
if (r.get()!=NULL)
n=n_Init(0,r.get()->cf);
else
n=(number) NULL;
}
Number(const Number & n)
{
r=n.r;
this->n=n_Copy(n.n,r.get()->cf);
}
Number(number n, ring r)
{
this->n=n_Copy(n,r->cf);
this->r=r;
}
Number(int n, ring r)
{
this->r=r;
this->n=n_Init(n,r->cf);
}
Number(int n, intrusive_ptr<ip_sring> r)
{
this->r=r;
this->n=n_Init(n,r.get()->cf);
}
explicit Number(int n)
{
r=currRing;
this->n=n_Init(n,r.get()->cf);
}
void write() const
{
number towrite=n;
n_Write(towrite,r.get()->cf);
}
~Number()
{
if (r!=NULL)
n_Delete(&n,r.get()->cf);
}
ring getRing() const
{
return r.get();
}
protected:
number n;
intrusive_ptr<ip_sring> r;
};
inline Number operator+(const Number &n1, const Number& n2)
{
Number erg(n1);
erg+=n2;
return erg;
}
inline Number operator*(const Number &n1, const Number& n2)
{
Number erg(n1);
erg*=n2;
return erg;
}
inline Number operator-(const Number &n1, const Number& n2)
{
Number erg(n1);
erg-=n2;
return erg;
}
inline Number operator/(const Number &n1, const Number& n2)
{
Number erg(n1);
erg/=n2;
return erg;
}
inline bool operator==(const Number &n1, const Number& n2)
{
if(n1.r!=n2.r)
return false;
return n_Equal(n1.n,n2.n,n1.r.get()->cf);
}
inline Number operator+(const Number &n1, int n2)
{
Number erg(n1);
erg+=Number(n2,n1.r);
return erg;
}
inline Number operator*(const Number &n1, int n2)
{
Number erg(n1);
erg*=Number(n2,n1.r);
return erg;
}
inline Number operator-(const Number &n1, int n2)
{
Number erg(n1);
erg-=Number(n2,n1.r);
return erg;
}
inline Number operator/(const Number &n1, int n2)
{
Number erg(n1);
erg/=Number(n2,n1.r);
return erg;
}
inline bool operator==(const Number &n1, int n2)
{
return n_Equal(n1.n,Number(n2,n1.r).n,n1.r.get()->cf);
}
inline Number operator+(int n1, const Number& n2)
{
Number erg(n2);
return erg+=Number(n1,n2.r);
}
inline Number operator-(int n1, const Number& n2)
{
Number erg(n1,n2.r);
return erg-=n2;
}
inline Number operator/(int n1, const Number& n2)
{
Number erg(n1,n2.r);
return erg/=n2;
}
inline Number operator*(int n1, const Number& n2)
{
Number erg(n2);
return erg*=Number(n1,n2.r);
}
inline bool operator==(int n1, const Number& n2)
{
return n2==Number(n1,n2.r);
}
#endif
operator-
Number operator-(const Number &n1, const Number &n2)
Definition Number.h:233
poly_variant
poly_variant
Definition Number.h:25
POLY_VARIANT_MODUL
@ POLY_VARIANT_MODUL
Definition Number.h:27
POLY_VARIANT_RING
@ POLY_VARIANT_RING
Definition Number.h:26
operator==
bool operator==(const Number &n1, const Number &n2)
Definition Number.h:245
intrusive_ptr_add_ref
void intrusive_ptr_add_ref(ring r)
Definition Number.h:9
operator+
Number operator+(const Number &n1, const Number &n2)
Definition Number.h:221
operator*
Number operator*(const Number &n1, const Number &n2)
Definition Number.h:227
operator/
Number operator/(const Number &n1, const Number &n2)
Definition Number.h:239
intrusive_ptr_release
void intrusive_ptr_release(ring r)
Definition Number.h:14
Number::operator*=
Number & operator*=(int n2)
Definition Number.h:142
Number::Number
Number(const Number &n)
Definition Number.h:177
Number::PolyBase
friend class PolyBase
Definition Number.h:57
Number::Number
Number(int n)
Definition Number.h:197
Number::getRing
ring getRing() const
Definition Number.h:212
Number::~Number
~Number()
Definition Number.h:207
Number::Number
Number()
Definition Number.h:169
Number::operator/=
Number & operator/=(int n2)
Definition Number.h:160
Number::operator==
friend bool operator==(const Number &n1, const Number &n2)
Definition Number.h:245
Number::Number
Number(int n, ring r)
Definition Number.h:187
Number::operator+
friend Number operator+(const Number &n1, const Number &n2)
Definition Number.h:221
Number::write
void write() const
Definition Number.h:202
Number::Vector
friend class Vector
Definition Number.h:52
Number::operator-
Number operator-()
Definition Number.h:72
Number::operator-=
Number & operator-=(const Number &n2)
Definition Number.h:103
Number::operator*
friend Number operator*(const Number &n1, const Number &n2)
Definition Number.h:227
Number::r
intrusive_ptr< ip_sring > r
Definition Number.h:218
Number::operator=
Number & operator=(const Number &n2)
Definition Number.h:63
Number::operator+=
Number & operator+=(int n2)
Definition Number.h:133
Number::PolyImpl
friend class PolyImpl
Definition Number.h:58
Number::operator/
friend Number operator/(const Number &n1, const Number &n2)
Definition Number.h:239
Number::operator+=
Number & operator+=(const Number &n2)
Definition Number.h:79
Number::operator*=
Number & operator*=(const Number &n2)
Definition Number.h:91
Number::Number
Number(number n, ring r)
Definition Number.h:182
Number::Poly
friend class Poly
Definition Number.h:51
Number::operator-=
Number & operator-=(int n2)
Definition Number.h:151
Number::operator=
Number & operator=(int n2)
Definition Number.h:127
Number::Number
Number(int n, intrusive_ptr< ip_sring > r)
Definition Number.h:192
Number::operator/=
Number & operator/=(const Number &n2)
Definition Number.h:115
Number::as_number
number as_number() const
Definition Number.h:59
Number::n
number n
Definition Number.h:217
PolyBase
Definition Poly.h:330
Vector
Definition Poly.h:509
n_Mult
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
Definition coeffs.h:639
n_Copy
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition coeffs.h:457
n_Add
static FORCE_INLINE number n_Add(number a, number b, const coeffs r)
return the sum of 'a' and 'b', i.e., a+b
Definition coeffs.h:653
n_InpNeg
static FORCE_INLINE number n_InpNeg(number n, const coeffs r)
in-place negation of n MUST BE USED: n = n_InpNeg(n) (no copy is returned)
Definition coeffs.h:560
n_Div
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition coeffs.h:618
n_Sub
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of 'a' and 'b', i.e., a-b
Definition coeffs.h:658
n_Delete
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:461
n_Write
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition coeffs.h:594
n_Init
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition coeffs.h:541
n_Equal
static FORCE_INLINE BOOLEAN n_Equal(number a, number b, const coeffs r)
TRUE iff 'a' and 'b' represent the same number; they may have different representations.
Definition coeffs.h:466
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
mod2.h
numbers.h
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
polys.h
Compatibility layer for legacy polynomial operations (over currRing).
rDelete
void rDelete(ring r)
unconditionally deletes fields in r
Definition ring.cc:454
ring.h
Poly
Definition janet.h:15