Overview
The Giac polynomial API provides a powerful tensor-based representation for multivariate polynomials with various coefficient types. The core class is tensor<T>, which represents polynomials as sorted lists of monomials.
Core Classes
tensor<T>
The main polynomial class template that represents a multivariate polynomial.
template < class T > class tensor {
public:
int dim; // number of variables
std ::vector < monomial < T > > coord; // sorted list of monomials
bool (* is_strictly_greater )( const index_m & , const index_m & );
// Constructors
tensor (); // default constructor
explicit tensor ( int d ); // dimension d
tensor ( const T & v , int d ); // constant polynomial
tensor ( const monomial < T > & v ); // single monomial
};
Key Members
Number of variables (dimension of the polynomial)
Sorted list of monomials representing the polynomial terms
Comparison function for monomial ordering (lexicographic by default)
Tref_tensor<T>
Reference-counted wrapper for tensor objects.
template < class T > class Tref_tensor {
public:
ref_count_t ref_count;
tensor < T > t;
Tref_tensor < T >( const tensor < T > & P): ref_count ( 1 ), t (P) {}
Tref_tensor < T >( int dim): ref_count ( 1 ), t (dim) {}
};
Degree Operations
degree()
Returns the degree of the polynomial with respect to variable n.
Returns a vector containing the degrees with respect to each variable.
total_degree()
int total_degree () const ;
Returns the total degree (sum of all variable degrees) of the polynomial.
partial_degree()
int partial_degree ( int nvars ) const ;
Returns the total degree with respect to the first nvars variables.
valuation()
int valuation ( int n ) const ;
Returns the minimum degree of variable n across all monomials.
Arithmetic Operations
Addition
void TAdd ( const tensor < T > & other , tensor < T > & result ) const ;
Computes result = this + other. Merges sorted monomial lists efficiently.
tensor < gen > p1 ( 2 ), p2 ( 2 ), result ( 2 );
// ... initialize p1 and p2 ...
p1 . TAdd (p2, result);
Subtraction
void TSub ( const tensor < T > & other , tensor < T > & result ) const ;
Computes result = this - other.
Multiplication
tensor < T > & operator *= ( const T & fact );
Multiplies the polynomial by a scalar coefficient.
Division and Remainder
bool TDivRem ( const tensor < T > & other , tensor < T > & quo , tensor < T > & rem ,
bool allowrational = true ) const ;
Divides this by other, computing quotient and remainder such that this = quo * other + rem.
Whether to allow rational coefficients in the result
Exact Quotient
bool Texactquotient ( const tensor < T > & other , tensor < T > & quo ,
bool allowrational = false ) const ;
Computes exact quotient if this is exactly divisible by other. Returns false if remainder is non-zero.
Pseudo Division
bool TPseudoDivRem ( const tensor < T > & other , tensor < T > & quo ,
tensor < T > & rem , tensor < T > & a ) const ;
Computes pseudo-division: a * this = quo * other + rem, where a is chosen to avoid division.
Evaluation
Horner Evaluation
tensor < T > operator () ( const T & x0 ) const ;
Evaluates the polynomial using Horner’s scheme. For a univariate polynomial, substitutes x0 for the main variable.
Returns the constant term of the polynomial.
shift()
tensor < T > shift ( const index_m & ishift , const T & fois ) const ;
tensor < T > shift ( const T & fois , const index_m & ishift ) const ;
tensor < T > shift ( const index_m & ishift ) const ;
Shifts monomial degrees and optionally multiplies by a coefficient.
Degree Manipulation
tensor < T > multiplydegrees ( int d ) const ; // multiply degrees by d
tensor < T > dividedegrees ( int d ) const ; // divide main degree by d
tensor < T > dividealldegrees ( int d ) const ; // divide all degrees by d
homogeneize()
tensor < T > homogeneize () const ;
Converts the polynomial to homogeneous form by adding an extra variable.
reverse()
Reverses the variable ordering.
reorder()
void reorder ( const std :: vector < int > & permutation );
Reorders variables according to the given permutation.
Calculus Operations
derivative()
tensor < T > derivative () const ;
Computes the derivative with respect to the main variable.
integrate()
tensor < T > integrate () const ;
Computes the integral with respect to the main variable.
Tcoeffs()
void Tcoeffs ( std :: vector < tensor < T > > & v ) const ;
std :: vector < tensor < T > > Tcoeffs () const ;
Extracts coefficients with respect to the main variable, returning them as polynomials in the remaining variables.
coeff()
tensor < T > coeff ( int deg ) const ;
Returns the coefficient of degree deg in the main variable.
Truncation and Projection
untrunc1() / trunc1()
tensor < T > untrunc1 ( int j = 0 ) const ; // add variable
void untruncn ( int j = 0 ); // add variable in-place
tensor < T > trunc1 () const ; // remove first variable
Add or remove variables from the polynomial representation.
Degree Truncation
tensor < T > total_degree_truncate ( int n ) const ;
void high_order_degree_truncate ( int n );
Removes terms above specified degree thresholds.
Utility Functions
norm()
Returns the maximum absolute value of coefficients.
gcddeg()
int gcddeg ( int k ) const ;
index_t gcddeg () const ;
Computes the GCD of all degrees in variable k, or all variables.
Tcontent() / Tppz()
template < class T > T Tcontent ( const tensor < T > & p );
template < class T > T Tppz ( tensor < T > & p , bool divide = true );
Extracts the content (GCD of coefficients) and primitive part.
Conversion Functions
convert()
template < class T , class U >
void convert ( const tensor < T > & p , const index_t & deg ,
std :: vector < T_unsigned < T , U > > & v );
Converts between tensor and hash-based representations for efficient operations.
Power Operations
template < class T >
tensor < T > Tpow ( const tensor < T > & x , int n );
Computes x^n efficiently for non-negative integer n.
Comparison and Testing
template < class T >
bool operator == ( const tensor < T > & p , const tensor < T > & q );
template < class T > bool Tis_one ( const tensor < T > & p );
template < class T > bool Tis_constant ( const tensor < T > & p );
Test for equality, unity, or constant polynomials.
See Also
Factorization Polynomial factorization algorithms
Algebraic Extensions Polynomials over algebraic extensions