polylib 5.22.8
ehrhart.c File Reference
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <polylib/homogenization.h>
#include <polylib/polylib.h>

Go to the source code of this file.

Macros

#define EPRINT_ALL_VALIDITY_CONSTRAINTS
 define this to print all constraints on the validity domains if not defined, only new constraints (not in validity domain given by the user) are printed More...
 
#define REDUCE_DEGREE
 Reduce the degree of resulting polynomials. More...
 
#define ALL_OVERFLOW_WARNINGS
 define this to print one warning message per domain overflow these overflows should no longer happen since version 4.20 More...
 
#define MAXITER   100
 This procedure finds an integer point contained in polyhedron D / first checks for positive values, then for negative values returns TRUE on success. More...
 

Functions

enodenew_enode (enode_type type, int size, int pos)
 EHRHART POLYNOMIAL SYMBOLIC ALGEBRA SYSTEM. More...
 
void free_evalue_refs (evalue *e)
 releases all memory referenced by e. More...
 
enodeecopy (enode *e)
 
void print_evalue (FILE *DST, evalue *e, const char **pname)
 
void print_enode (FILE *DST, enode *p, const char **pname)
 prints the enode to DST More...
 
static int eequal (evalue *e1, evalue *e2)
 
void reduce_evalue (evalue *e)
 
static void emul (evalue *e1, evalue *e2, evalue *res)
 multiplies two evalues and puts the result in res More...
 
void eadd (evalue *e1, evalue *res)
 adds one evalue to evalue 'res. More...
 
void edot (enode *v1, enode *v2, evalue *res)
 computes the inner product of two vectors. More...
 
static void aep_evalue (evalue *e, int *ref)
 local recursive function used in the following ref contains the new position for each old index position More...
 
static void addeliminatedparams_evalue (evalue *e, Matrix *CT)
 Comments. More...
 
int cherche_min (Value *min, Polyhedron *D, int pos)
 
PolyhedronPolyhedron_Preprocess (Polyhedron *D, Value *size, unsigned MAXRAYS)
 This procedure finds the smallest parallelepiped of size 'size[i]' for every dimension i, contained in polyhedron D. More...
 
PolyhedronPolyhedron_Preprocess2 (Polyhedron *D, Value *size, Value *lcm, unsigned MAXRAYS)
 This procedure finds an hypercube of size 'size', containing polyhedron D increases size and lcm if necessary (and not "too big") If this is not possible, an empty polyhedron is returned. More...
 
Polyhedronold_Polyhedron_Preprocess (Polyhedron *D, Value size, unsigned MAXRAYS)
 This procedure adds additional constraints to D so that as each parameter is scanned, it will have a minimum of 'size' points If this is not possible, an empty polyhedron is returned. More...
 
void count_points (int pos, Polyhedron *P, Value *context, Value *res)
 PROCEDURES TO COMPUTE ENUMERATION. More...
 
static enodeP_Enum (Polyhedron *L, Polyhedron *LQ, Value *context, int pos, int nb_param, int dim, Value *lcm, const char **param_name)
 
static void Scan_Vertices (Param_Polyhedron *PP, Param_Domain *Q, Matrix *CT, Value *lcm, int nbp, const char **param_name)
 
EnumerationEnumerate_NoParameters (Polyhedron *P, Polyhedron *C, Matrix *CT, Polyhedron *CEq, unsigned MAXRAYS, const char **param_name)
 Procedure to count points in a non-parameterized polytope. More...
 
EnumerationPolyhedron_Enumerate (Polyhedron *Pi, Polyhedron *C, unsigned MAXRAYS, const char **param_name)
 Procedure to count points in a parameterized polytope. More...
 
void Enumeration_Free (Enumeration *en)
 
void evalue_div (evalue *e, Value n)
 Divides the evalue e by the integer n
recursive function
Warning : modifies e. More...
 
EnumerationEhrhart_Quick_Apx_Full_Dim (Polyhedron *Pi, Polyhedron *C, unsigned MAXRAYS, const char **param_name)
 Ehrhart_Quick_Apx_Full_Dim(P, C, MAXRAYS, param_names) More...
 
EnumerationEhrhart_Quick_Apx (Matrix *M, Matrix *C, Matrix **Validity_Lattice, unsigned maxRays)
 Computes the approximation of the Ehrhart polynomial of a polyhedron (implicit form -> matrix), treating the non-full-dimensional case. More...
 
EnumerationConstraints_EhrhartQuickApx (Matrix const *M, Matrix const *C, Matrix **validityLattice, Matrix **parmEqualities, unsigned int **elimParms, unsigned maxRays)
 Computes the approximation of the Ehrhart polynomial of a polyhedron (implicit form -> matrix), treating the non-full-dimensional case. More...
 
const char ** parmsWithoutElim (char const **parmNames, unsigned int const *elimParms, unsigned int nbParms)
 Returns the array of parameter names after some of them have been eliminated. More...
 
EnumerationEnumeration_zero (unsigned int nbParms, unsigned int maxRays)
 returns a constant Ehrhart polynomial whose value is zero for any value of the parameters. More...
 

Variables

int overflow_warning_flag = 1
 

Macro Definition Documentation

◆ ALL_OVERFLOW_WARNINGS

#define ALL_OVERFLOW_WARNINGS

define this to print one warning message per domain overflow these overflows should no longer happen since version 4.20

Definition at line 70 of file ehrhart.c.

◆ EPRINT_ALL_VALIDITY_CONSTRAINTS

#define EPRINT_ALL_VALIDITY_CONSTRAINTS

define this to print all constraints on the validity domains if not defined, only new constraints (not in validity domain given by the user) are printed

Definition at line 47 of file ehrhart.c.

◆ MAXITER

#define MAXITER   100

This procedure finds an integer point contained in polyhedron D / first checks for positive values, then for negative values returns TRUE on success.

Result is in min. returns FALSE if no integer point is found

This is the maximum number of iterations for a given parameter to find a integer point inside the context. Kind of weird. cherche_min should

Parameters
min
D
pos

Definition at line 623 of file ehrhart.c.

◆ REDUCE_DEGREE

#define REDUCE_DEGREE

Reduce the degree of resulting polynomials.

Definition at line 64 of file ehrhart.c.

Function Documentation

◆ addeliminatedparams_evalue()

static void addeliminatedparams_evalue ( evalue e,
Matrix CT 
)
static

◆ aep_evalue()

static void aep_evalue ( evalue e,
int *  ref 
)
static

local recursive function used in the following ref contains the new position for each old index position

Parameters
epointer to an evalue
reftransformation Matrix

Definition at line 557 of file ehrhart.c.

References aep_evalue(), _enode::arr, _evalue::d, _enode::pos, _enode::size, value_notzero_p, and _evalue::x.

Referenced by addeliminatedparams_evalue(), and aep_evalue().

◆ cherche_min()

◆ Constraints_EhrhartQuickApx()

Enumeration * Constraints_EhrhartQuickApx ( Matrix const *  M,
Matrix const *  C,
Matrix **  validityLattice,
Matrix **  parmEqualities,
unsigned int **  elimParms,
unsigned  maxRays 
)

Computes the approximation of the Ehrhart polynomial of a polyhedron (implicit form -> matrix), treating the non-full-dimensional case.

If there are some equalities involving only parameters, these are used to eliminate useless parameters.

Parameters
Ma polyhedron under implicit form
CM's context under implicit form
validityLatticea pointer to the parameter's validity lattice (returned)
parmsEqualitiesEqualities involving only the parameters
maxRaysthe needed "working space" for other polylib functions used here
elimParamsarray of the indices of the eliminated parameters (returned)

Definition at line 2669 of file ehrhart.c.

References Constraints_Remove_parm_eqs(), Ehrhart_Quick_Apx(), Matrix_Copy(), maxRays, and matrix::NbRows.

◆ count_points()

void count_points ( int  pos,
Polyhedron P,
Value *  context,
Value *  res 
)

PROCEDURES TO COMPUTE ENUMERATION.

recursive procedure, recurse for each imbriquation

Parameters
posindex position of current loop index (1..hdim-1)
Ploop domain
contextcontext values for fixed indices
resthe number of integer points in this polyhedron

Definition at line 1154 of file ehrhart.c.

References count_points(), emptyQ, lower_upper_bounds(), polyhedron::next, P_VALUE_FMT, POL_ENSURE_FACETS, POL_ENSURE_VERTICES, value_add_int, value_addto, value_assign, value_clear, value_increment, value_init, value_le, value_lt, value_notmone_p, value_print, value_set_si, and value_subtract.

Referenced by check_poly(), count_points(), Enumerate_NoParameters(), and P_Enum().

◆ eadd()

void eadd ( evalue e1,
evalue res 
)

adds one evalue to evalue 'res.

result = res + e1

Parameters
e1an evalue
res

Definition at line 385 of file ehrhart.c.

References _enode::arr, _evalue::d, eadd(), ecopy(), free_evalue_refs(), periodic, polynomial, value_addto, value_clear, value_divexact, value_gcd, value_init, value_multiply, value_notone_p, value_notzero_p, value_zero_p, and _evalue::x.

Referenced by eadd(), and edot().

◆ ecopy()

enode * ecopy ( enode e)
Parameters
epointer to an evalue
Returns
description

Definition at line 144 of file ehrhart.c.

References _enode::arr, _evalue::d, ecopy(), new_enode(), _enode::pos, _enode::size, _enode::type, value_assign, value_init, value_zero_p, and _evalue::x.

Referenced by Domain_Enumerate(), eadd(), ecopy(), and new_eadd().

◆ edot()

void edot ( enode v1,
enode v2,
evalue res 
)

computes the inner product of two vectors.

Result = result (evalue) = v1.v2 (dot product)

Parameters
v1an enode (vector)
v2an enode (vector of constants)
resresult (evalue)

Definition at line 514 of file ehrhart.c.

References _enode::arr, _evalue::d, eadd(), emul(), evector, free_evalue_refs(), _enode::size, _enode::type, value_init, value_set_si, and _evalue::x.

Referenced by P_Enum().

◆ eequal()

static int eequal ( evalue e1,
evalue e2 
)
static
Parameters
e1pointers to evalues
e2pointers to evalues
Returns
1 (true) if they are equal, 0 (false) if not

Definition at line 234 of file ehrhart.c.

References _enode::arr, _evalue::d, eequal(), _enode::pos, _enode::size, _enode::type, value_ne, value_notzero_p, and _evalue::x.

Referenced by eequal(), and reduce_evalue().

◆ Ehrhart_Quick_Apx()

Enumeration * Ehrhart_Quick_Apx ( Matrix M,
Matrix C,
Matrix **  Validity_Lattice,
unsigned  maxRays 
)

Computes the approximation of the Ehrhart polynomial of a polyhedron (implicit form -> matrix), treating the non-full-dimensional case.

Parameters
Ma polyhedron under implicit form
CM's context under implicit form
Validity_Latticea pointer to the parameter's validity lattice
MAXRAYSthe needed "working space" for other polylib functions used here
param_namethe names of the parameters,

Definition at line 2627 of file ehrhart.c.

References Constraints2Polyhedron(), Ehrhart_Quick_Apx_Full_Dim(), full_dimensionize(), Matrix_Free(), maxRays, mpolyhedron_compress_last_vars(), matrix::NbColumns, Polyhedron_Free(), and show_matrix.

Referenced by Constraints_EhrhartQuickApx(), and main().

◆ Ehrhart_Quick_Apx_Full_Dim()

Enumeration * Ehrhart_Quick_Apx_Full_Dim ( Polyhedron Pi,
Polyhedron C,
unsigned  MAXRAYS,
const char **  param_name 
)

Ehrhart_Quick_Apx_Full_Dim(P, C, MAXRAYS, param_names)

Procedure to estimate the number of points in a parameterized polytope. Returns a list of validity domains + evalues EP B.M. The most rough and quick approximation by variables expansion Deals with the full-dimensional case.

Parameters
Pi: Polyhedron to enumerate (approximatively)
C: Context Domain
MAXRAYS: size of workspace
param_name: names for the parameters (char strings)

Definition at line 2282 of file ehrhart.c.

References addeliminatedparams_evalue(), assert, CATCH, _Param_Polyhedron::D, _evalue::d, polyhedron::Dimension, _Param_Domain::Domain, Domain_Free(), DomainIntersection(), DomainSimplify(), emptyQ, Enumerate_NoParameters(), _enumeration::EP, evalue_div(), MAXRAYS, polyhedron::NbBid, matrix::NbColumns, polyhedron::NbEq, polyhedron::NbRays, matrix::NbRows, _Param_Polyhedron::nbV, _Param_Domain::next, _enumeration::next, overflow_error, overflow_warning_flag, P_Enum(), P_VALUE_FMT, Param_Polyhedron_Scale_Integer(), Pi, Polyhedron2Param_SimplifiedDomain(), Polyhedron_Free(), Polyhedron_Preimage(), Polyhedron_Preprocess(), Polyhedron_Preprocess2(), Polyhedron_Print(), Polyhedron_Scan(), PolyhedronIncludes(), Print_Domain(), print_evalue(), polyhedron::Ray, reduce_evalue(), TRY, UNCATCH, Universe_Polyhedron(), _enumeration::ValidityDomain, value_clear, value_init, value_multiply, value_notzero_p, value_print, value_set_si, value_zero_p, Vector_Set(), and _evalue::x.

Referenced by Ehrhart_Quick_Apx().

◆ emul()

static void emul ( evalue e1,
evalue e2,
evalue res 
)
static

multiplies two evalues and puts the result in res

Parameters
e1pointer to an evalue
e2pointer to a constant evalue
respointer to result evalue = e1 * e2

Definition at line 344 of file ehrhart.c.

References _enode::arr, _evalue::d, emul(), new_enode(), _enode::pos, _enode::size, _enode::type, value_clear, value_divexact, value_gcd, value_init, value_multiply, value_notone_p, value_notzero_p, value_set_si, value_zero_p, and _evalue::x.

Referenced by edot(), and emul().

◆ Enumerate_NoParameters()

Enumeration * Enumerate_NoParameters ( Polyhedron P,
Polyhedron C,
Matrix CT,
Polyhedron CEq,
unsigned  MAXRAYS,
const char **  param_name 
)

Procedure to count points in a non-parameterized polytope.

Parameters
PPolyhedron to count
CParameter Context domain
CTMatrix to transform context to original
CEqadditionnal equalities in context
MAXRAYSworkspace size
param_nameparameter names

Definition at line 1750 of file ehrhart.c.

References assert, CATCH, count_points(), _evalue::d, polyhedron::Dimension, Domain_Free(), DomainIntersection(), emptyQ, _enumeration::EP, MAXRAYS, polyhedron::NbRays, new_enode(), _enumeration::next, overflow_error, overflow_warning_flag, P_VALUE_FMT, Polyhedron_Free(), Polyhedron_Preimage(), Polyhedron_Print(), Polyhedron_Scan(), polynomial, Print_Domain(), print_evalue(), polyhedron::Ray, TRY, UNCATCH, Universe_Polyhedron(), _enumeration::ValidityDomain, value_clear, value_init, value_notone_p, value_print, value_set_si, value_zero_p, Vector_Set(), and _evalue::x.

Referenced by Ehrhart_Quick_Apx_Full_Dim(), and Polyhedron_Enumerate().

◆ Enumeration_Free()

void Enumeration_Free ( Enumeration en)

◆ Enumeration_zero()

Enumeration * Enumeration_zero ( unsigned int  nbParms,
unsigned int  maxRays 
)

returns a constant Ehrhart polynomial whose value is zero for any value of the parameters.

Parameters
nbParmsthe number of parameters, i.e., the number of arguments to the Ehrhart polynomial

Definition at line 2719 of file ehrhart.c.

References Constraints2Polyhedron(), Matrix_Alloc(), Matrix_Free(), maxRays, matrix::p, Polyhedron_Enumerate(), Polyhedron_Free(), Universe_Polyhedron(), and value_set_si.

Referenced by test_Constraints_fullDimensionize().

◆ evalue_div()

void evalue_div ( evalue e,
Value  n 
)

Divides the evalue e by the integer n
recursive function
Warning : modifies e.

Parameters
ean evalue (to be divided by n)
n

Definition at line 2247 of file ehrhart.c.

References _evalue::d, evalue_div(), n, value_clear, value_divexact, value_gcd, value_init, value_multiply, value_notone_p, value_zero_p, and _evalue::x.

Referenced by Ehrhart_Quick_Apx_Full_Dim(), and evalue_div().

◆ free_evalue_refs()

void free_evalue_refs ( evalue e)

releases all memory referenced by e.

(recursive)

Parameters
epointer to an evalue

Definition at line 115 of file ehrhart.c.

References _enode::arr, _evalue::d, free_evalue_refs(), _enode::size, value_clear, value_notzero_p, and _evalue::x.

Referenced by dehomogenize_evalue(), Domain_Enumerate(), eadd(), edot(), Enumeration_Free(), free_evalue_refs(), main(), P_Enum(), and reduce_evalue().

◆ new_enode()

enode * new_enode ( enode_type  type,
int  size,
int  pos 
)

EHRHART POLYNOMIAL SYMBOLIC ALGEBRA SYSTEM.

The newly allocated enode can be freed with a simple free(x)

Parameters
type: enode type
size: degree+1 for polynomial, period for periodic
pos: 1..nb_param, position of parameter
Returns
a newly allocated enode

Definition at line 90 of file ehrhart.c.

References _enode::arr, _evalue::d, _enode::pos, _enode::size, _enode::type, value_init, value_set_si, and _evalue::x.

Referenced by ecopy(), emul(), Enumerate_NoParameters(), new_eadd(), and P_Enum().

◆ old_Polyhedron_Preprocess()

Polyhedron * old_Polyhedron_Preprocess ( Polyhedron D,
Value  size,
unsigned  MAXRAYS 
)

This procedure adds additional constraints to D so that as each parameter is scanned, it will have a minimum of 'size' points If this is not possible, an empty polyhedron is returned.

Parameters
D
size
MAXRAYS

Definition at line 1060 of file ehrhart.c.

References AddConstraints(), polyhedron::Constraint, polyhedron::Dimension, Matrix_Alloc(), Matrix_Free(), MAXRAYS, polyhedron::NbConstraints, matrix::p, matrix::p_Init, value_absolute, value_addmul, value_assign, value_clear, value_divexact, value_gcd, value_init, value_multiply, value_negz_p, value_notzero_p, value_oppose, value_posz_p, value_set_si, Vector_Combine(), and Vector_Normalize().

◆ P_Enum()

◆ parmsWithoutElim()

const char ** parmsWithoutElim ( char const **  parmNames,
unsigned int const *  elimParms,
unsigned int  nbParms 
)

Returns the array of parameter names after some of them have been eliminated.

Parameters
parmNamesthe initial names of the parameters
elimParmsa list of parameters that have been eliminated from the original parameters. The first element of this array is the number of elements.

Note: does not copy the parameters names themselves.

Parameters
nbParmsthe initial number of parameters

Definition at line 2698 of file ehrhart.c.

◆ Polyhedron_Enumerate()

Enumeration * Polyhedron_Enumerate ( Polyhedron Pi,
Polyhedron C,
unsigned  MAXRAYS,
const char **  param_name 
)

Procedure to count points in a parameterized polytope.

Parameters
PiPolyhedron to enumerate
CContext Domain
MAXRAYSsize of workspace
param_nameparameter names (array of strings), may be NULL
Returns
a list of validity domains + evalues EP

Definition at line 1870 of file ehrhart.c.

References addeliminatedparams_evalue(), assert, CATCH, _Param_Polyhedron::D, _evalue::d, dehomogenize_evalue(), polyhedron::Dimension, _Param_Domain::Domain, Domain_Free(), DomainIntersection(), DomainSimplify(), emptyQ, Enumerate_NoParameters(), _enumeration::EP, _Param_Domain::F, homogenize(), Matrix_Free(), MAXRAYS, polyhedron::NbBid, matrix::NbColumns, polyhedron::NbEq, polyhedron::NbRays, matrix::NbRows, _Param_Domain::next, _enumeration::next, overflow_error, overflow_warning_flag, P_Enum(), P_VALUE_FMT, Param_Polyhedron_Free(), Param_Vertices_Free(), Pi, POL_ENSURE_FACETS, POL_ENSURE_VERTICES, POL_ISSET, POL_NO_DUAL, Polyhedron2Param_SimplifiedDomain(), Polyhedron_Free(), Polyhedron_Preimage(), Polyhedron_Preprocess(), Polyhedron_Preprocess2(), Polyhedron_Print(), Polyhedron_Scan(), PolyhedronIncludes(), Print_Domain(), print_evalue(), polyhedron::Ray, reduce_evalue(), Scan_Vertices(), TRY, UNCATCH, Universe_Polyhedron(), _Param_Polyhedron::V, _enumeration::ValidityDomain, value_addto, value_clear, value_init, value_multiply, value_notzero_p, value_print, value_set_si, value_zero_p, Vector_Set(), and _evalue::x.

Referenced by Domain_Enumerate(), Enumeration_zero(), main(), and test_Constraints_fullDimensionize().

◆ Polyhedron_Preprocess()

Polyhedron * Polyhedron_Preprocess ( Polyhedron D,
Value *  size,
unsigned  MAXRAYS 
)

This procedure finds the smallest parallelepiped of size 'size[i]' for every dimension i, contained in polyhedron D.

If this is not possible, NULL is returned

written by vin100, 2000, for version 4.19
modified 2002, version 5.10

It first finds the coordinates of the lexicographically smallest edge of the hypercube, obtained by transforming the constraints of D (by adding 'size' as many times as there are negative coeficients in each constraint), and finding the lexicographical min of this polyhedron. Then it builds the hypercube and returns it.

Parameters
D
size
MAXRAYS

Definition at line 738 of file ehrhart.c.

References assert, cherche_min(), polyhedron::Constraint, Constraints2Polyhedron(), polyhedron::Dimension, Domain_Free(), emptyQ, Matrix_Alloc(), Matrix_Free(), Matrix_Print(), MAXRAYS, min, polyhedron::NbConstraints, matrix::NbRows, matrix::p, P_VALUE_FMT, Polyhedron_Free(), Polyhedron_Print(), Polyhedron_Scan(), Universe_Polyhedron(), value_addmul, value_addto, value_clear, value_init, value_ne, value_neg_p, value_oppose, value_print, value_set_si, value_sub_int, value_zero_p, and Vector_Copy().

Referenced by Ehrhart_Quick_Apx_Full_Dim(), and Polyhedron_Enumerate().

◆ Polyhedron_Preprocess2()

Polyhedron * Polyhedron_Preprocess2 ( Polyhedron D,
Value *  size,
Value *  lcm,
unsigned  MAXRAYS 
)

This procedure finds an hypercube of size 'size', containing polyhedron D increases size and lcm if necessary (and not "too big") If this is not possible, an empty polyhedron is returned.

 written by vin100, 2001, for version 4.19
Parameters
D
size
lcm
MAXRAYS

Definition at line 891 of file ehrhart.c.

References Constraints2Polyhedron(), polyhedron::Dimension, Matrix_Alloc(), Matrix_Free(), Matrix_Print(), MAXRAYS, n, polyhedron::NbRays, matrix::p, P_VALUE_FMT, polyhedron::Ray, s, value_add_int, value_addto, value_assign, value_clear, value_division, value_gt, value_init, value_le, value_lt, value_multiply, value_oppose, value_print, value_set_si, value_sub_int, value_subtract, and value_zero_p.

Referenced by Ehrhart_Quick_Apx_Full_Dim(), and Polyhedron_Enumerate().

◆ print_enode()

void print_enode ( FILE *  DST,
enode p,
const char **  pname 
)

prints the enode to DST

Parameters
DSTdestination file
ppointer to enode to be printed
pnamearray of strings, name of the parameters

Definition at line 190 of file ehrhart.c.

References _enode::arr, evector, periodic, polynomial, _enode::pos, print_evalue(), _enode::size, and _enode::type.

Referenced by P_Enum(), and print_evalue().

◆ print_evalue()

void print_evalue ( FILE *  DST,
evalue e,
const char **  pname 
)
Parameters
DSTdestination file
epointer to evalue to be printed
pnamearray of strings, name of the parameters

Definition at line 169 of file ehrhart.c.

References _evalue::d, print_enode(), value_notone_p, value_notzero_p, value_print, and _evalue::x.

Referenced by compute_poly(), Ehrhart_Quick_Apx_Full_Dim(), Enumerate_NoParameters(), main(), P_Enum(), Polyhedron_Enumerate(), print_enode(), and test_Constraints_fullDimensionize().

◆ reduce_evalue()

◆ Scan_Vertices()

Variable Documentation

◆ overflow_warning_flag

int overflow_warning_flag = 1