variable_set.h File Reference

Detailed Description

Definition of the Tvariable_set type and the associated functions.

See Also
Tvariable_set, variable_set.c

Definition in file variable_set.h.

Data Structures

struct  Tvariable_set
 A set of variable indexes with powers. More...
 

Macros

#define INIT_NUM_VARIABLES   10
 Initial room for variables. More...
 
#define NFUN   0
 No trigonometric function for the variable. More...
 
#define SINV   1
 Sine of the variable. More...
 
#define COSV   2
 Cosine of the variable. More...
 
#define TANV   3
 Tangent of the variable. More...
 
#define SEC2V   4
 Squared secant of the variable. More...
 
#define SEC2TANV   5
 Squared secant per tangent. More...
 
#define EXPV   6
 Exponential of the variable. More...
 
#define PWPV   7
 Squared of the variable, if it is negative. More...
 
#define PWLV   8
 Derivative of PWPV. More...
 
#define PWCV   9
 Derivative of PWLV. More...
 

Functions

void InitVarSet (Tvariable_set *vs)
 Constructor. More...
 
void ResetVarSet (Tvariable_set *vs)
 Resets the information stored in a variable set. More...
 
void CopyVarSet (Tvariable_set *vs_dst, Tvariable_set *vs_orig)
 Copy constructor. More...
 
void ShiftVarIndexes (unsigned int nv, Tvariable_set *vs)
 Reduces the variable indexes above a given index. More...
 
unsigned int CmpVarSet (Tvariable_set *vs1, Tvariable_set *vs2)
 Variable set comparison. More...
 
boolean PolynomialVarSet (Tvariable_set *vs)
 Identifies polynomial variable sets. More...
 
unsigned int GetPlaceinSet (unsigned int id, Tvariable_set *vs)
 Gets the position of a variable index in a set of variable indexes. More...
 
boolean VarIncluded (unsigned int id, Tvariable_set *vs)
 Checks if a variable index is included in a set of variable indexes. More...
 
boolean Included (unsigned int id, unsigned int f, unsigned int p, Tvariable_set *vs)
 Checks if a variable index is included in a set of variable indexes with a given power. More...
 
boolean EmptyVarSet (Tvariable_set *vs)
 Checks if a variable set is empty. More...
 
void AddVariable2Set (unsigned int f, unsigned int varid, unsigned int p, Tvariable_set *vs)
 Adds an element to a variable set. More...
 
void ProductVarSet (Tvariable_set *vs1, Tvariable_set *vs2, Tvariable_set *v_out)
 Product of two variable sets. More...
 
void RemoveVariableFromSet (unsigned int varid, Tvariable_set *vs)
 Removes an element to a variable set. More...
 
double FixVariableInVarSet (unsigned int varid, double ct, Tvariable_set *vs)
 Replaces a variable by a constant. More...
 
double ReplaceVariableInVarSet (unsigned int varid, double ct, unsigned int newID, Tvariable_set *vs)
 Replaces a variable by another variable. More...
 
unsigned int VarSetOrder (Tvariable_set *vs)
 Gets the order of a variable set. More...
 
unsigned int VariableSetSize (Tvariable_set *vs)
 Gets the number of elements of a variable set. More...
 
unsigned int GetVariableN (unsigned int n, Tvariable_set *vs)
 Gets a variable identifier from a variable set. More...
 
unsigned int * GetVariables (Tvariable_set *vs)
 Gets the variable identifiers stored in a variable set. More...
 
unsigned int GetVariablePowerN (unsigned int n, Tvariable_set *vs)
 Gets a variable power from a variable set. More...
 
unsigned int GetVariableFunctionN (unsigned int n, Tvariable_set *vs)
 Gets a variable function from a variable set. More...
 
unsigned int * GetPowers (Tvariable_set *vs)
 Gets the variable powers stored in a variable set. More...
 
boolean VarSetIntersect (Tvariable_set *vs1, Tvariable_set *vs2)
 Checks if two variable sets have elements in common. More...
 
void UnionVarSet (boolean fun, Tvariable_set *vs_new, Tvariable_set *vs)
 Produces a variable set that is the union of two variable sets. More...
 
double EvaluateVarSet (double *varValues, Tvariable_set *vs)
 Evaluates a variable set for a given set of value for the variables. More...
 
void EvaluateVarSetInt (Tinterval *varValues, Tinterval *i_out, Tvariable_set *vs)
 Evaluates a variable set for a given set of ranges for the variables. More...
 
double DeriveVarSet (unsigned int nv, Tvariable_set *dvs, Tvariable_set *vs)
 Derives an variable set. More...
 
void PrintVarSet (FILE *f, char **varNames, Tvariable_set *vs)
 Prints a variable set. More...
 
void DeleteVarSet (Tvariable_set *vs)
 Destructor. More...
 

Macro Definition Documentation

#define INIT_NUM_VARIABLES   10

Initial room for variables. It will be enlarged if necessary.

See Also
Tvariables

Definition at line 28 of file variable_set.h.

Referenced by InitVariables(), and InitVarSet().

#define SINV   1

Do not use the variable but its sine.

Definition at line 43 of file variable_set.h.

Referenced by DeriveVarSet(), EvaluateVarSet(), EvaluateVarSetInt(), FixVariableInVarSet(), PrintVarSet(), SHTransformVarRx(), SHTransformVarRy(), and SHTransformVarRz().

#define COSV   2

Do not use the variable but its cosine.

Definition at line 50 of file variable_set.h.

Referenced by DeriveVarSet(), EvaluateVarSet(), EvaluateVarSetInt(), FixVariableInVarSet(), PrintVarSet(), SHTransformVarRx(), SHTransformVarRy(), and SHTransformVarRz().

#define TANV   3

Do not use the variable but its tangent.

Definition at line 57 of file variable_set.h.

Referenced by DeriveVarSet(), EvaluateVarSet(), EvaluateVarSetInt(), FixVariableInVarSet(), and PrintVarSet().

#define SEC2V   4

Do not use the variable but its squared secant (1/cos)^2. This only appears in the derivative of a tangent.

Definition at line 65 of file variable_set.h.

Referenced by DeriveVarSet(), EvaluateVarSet(), EvaluateVarSetInt(), FixVariableInVarSet(), and PrintVarSet().

#define SEC2TANV   5

Do not use the variable but its squared secand per tangent. This appears in the derivative of a squared secant (SEC2V), i.e., the second derivative of a tangent (TANV).

Definition at line 74 of file variable_set.h.

Referenced by DeriveVarSet(), EvaluateVarSet(), EvaluateVarSetInt(), FixVariableInVarSet(), and PrintVarSet().

#define EXPV   6

Do not use the variable but its exponential.

Definition at line 81 of file variable_set.h.

Referenced by DeriveVarSet(), EvaluateVarSet(), EvaluateVarSetInt(), FixVariableInVarSet(), and PrintVarSet().

#define PWPV   7

This is a conditional function that evaluates to the squared of the variable if it is negative and to 0 otherwise.

Definition at line 89 of file variable_set.h.

Referenced by DeriveVarSet(), EvaluateVarSet(), EvaluateVarSetInt(), FixVariableInVarSet(), and PrintVarSet().

#define PWLV   8

Derivative of PWPV. This is a line for the negative values and 0 for the positive.

Definition at line 97 of file variable_set.h.

Referenced by DeriveVarSet(), EvaluateVarSet(), EvaluateVarSetInt(), FixVariableInVarSet(), and PrintVarSet().

#define PWCV   9

Derivative of PWLV. This is a constant for the negative values and 0 for the positive.

Definition at line 105 of file variable_set.h.

Referenced by DeriveVarSet(), EvaluateVarSet(), EvaluateVarSetInt(), FixVariableInVarSet(), and PrintVarSet().

Function Documentation

void InitVarSet ( Tvariable_set vs)

Creates an empty set of variable indexes.

Parameters
vsThe variable set to create.

Definition at line 70 of file variable_set.c.

References Tvariable_set::fun, INIT_NUM_VARIABLES, Tvariable_set::maxvars, NEW, Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by CopyEquation(), DeriveEquation(), InitEquation(), InitMonomial(), and ReplaceVariableInVarSet().

void ResetVarSet ( Tvariable_set vs)

Removes the information stored in a variable set (variable identifiers and powers) but not the allocated memory. To re-use a Tvariable_set it is more efficient to reset the variable to re-use instead of deleting it and constructing a new set.

Parameters
vsThe variable set to ber eset.

Definition at line 79 of file variable_set.c.

References Tvariable_set::nvars.

Referenced by AddScaledMonomial(), DeriveVarSet(), ResetEquation(), ResetMonomial(), and VarScaleEquation().

void CopyVarSet ( Tvariable_set vs_dst,
Tvariable_set vs_orig 
)

Creates a set of variable from the informatin stored in another set.

Parameters
vs_dstThe variable set to create.
vs_origThe variable set from where to copy.

Definition at line 84 of file variable_set.c.

References Tvariable_set::fun, Tvariable_set::maxvars, NEW, Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by CopyMonomial(), ProductVarSet(), and ReplaceVariableInVarSet().

void ShiftVarIndexes ( unsigned int  nv,
Tvariable_set vs 
)

When eliminating a variable from a problem, the indexes of the variables with an identifier above the removed varaible need to be decreased by one. This function performs this opearation for a single variable set.

The variable that we are removing from the problem need to be removed before applying this operation. If the variable set still includes the variable to be removed this function triggers and error.

Parameters
nvThe index of the variable we removed from the problem. Variable indexes above it need to be shifted.
vsThe variable set to update.

Definition at line 99 of file variable_set.c.

References Error(), Tvariable_set::nvars, and Tvariable_set::var_id.

Referenced by FixVariableInMonomial(), ReplaceVariableInEquation(), and ReplaceVariableInMonomial().

unsigned int CmpVarSet ( Tvariable_set vs1,
Tvariable_set vs2 
)

Compare two given variable sets. Variable sets are compared first taking into account the numver of indexes they include, then the powers of the variables and, finally, the indexes of the variables.

Parameters
vs1The first set to compare.
vs2The second set to compare.
Returns
1 if vs1 is larger than vs2, 0 if they are equal and 2 if vs2 is larger than vs1.

Definition at line 112 of file variable_set.c.

References Tvariable_set::fun, Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by CmpMonomial(), and FindMonomial().

boolean PolynomialVarSet ( Tvariable_set vs)

Identifies variable sets formed only by products of variables, i.e. without functions in the variables.

Parameters
vsThe variable set to query.
Returns
TRUE for polynomial variable sets.

Definition at line 153 of file variable_set.c.

References FALSE, Tvariable_set::fun, and NFUN.

Referenced by BilinearMonomial(), LinearMonomial(), PolynomialMonomial(), and QuadraticMonomial().

unsigned int GetPlaceinSet ( unsigned int  id,
Tvariable_set vs 
)

Gets the position of a variable index in a set of variable indexes.

Parameters
idThe index of the variable.
vsThe set of variable indexes.
Returns
The position of the variable in the set or NO_UINT if the index is not included in the set.

Definition at line 165 of file variable_set.c.

References FALSE, NO_UINT, and Tvariable_set::var_id.

Referenced by ReplaceVariableInEquation(), and VarIncluded().

boolean VarIncluded ( unsigned int  id,
Tvariable_set vs 
)

Determines if a variable index is included in a set of variable indexes.

Parameters
idThe index of the variable.
vsThe set of variable indexes.
Returns
TRUE if id is included in vs.

Definition at line 183 of file variable_set.c.

References GetPlaceinSet(), and NO_UINT.

Referenced by CSRemoveUnusedVars(), DeriveMonomial(), RemoveEquationsWithVar(), UsedVarInEquations(), and UsedVarInNonDummyEquations().

boolean Included ( unsigned int  id,
unsigned int  f,
unsigned int  p,
Tvariable_set vs 
)

Determines if a variable index is included in a set of variable indexes with a given power and function.

Parameters
idThe index of the variable.
fThe function for the variable (possibly NFUN).
pThe power of the variable.
vsThe set of variables.
Returns
TRUE if id is included in vs with power p.

Definition at line 188 of file variable_set.c.

References FALSE, Tvariable_set::fun, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by VarSetIntersect().

boolean EmptyVarSet ( Tvariable_set vs)

Checks if a variable set is empty.

Parameters
vsThe set of variables.
Returns
TRUE if vs is empty.

Definition at line 148 of file variable_set.c.

References Tvariable_set::nvars.

Referenced by PrintMonomial().

void AddVariable2Set ( unsigned int  f,
unsigned int  varid,
unsigned int  p,
Tvariable_set vs 
)

Adds a variable index with a given power to a variable set.

Parameters
fFunction to apply to the variable (if any).
varidThe index of the variable to be added to the set.
pThe power for this variable
vsThe set of variables to update.

Definition at line 265 of file variable_set.c.

References AddVariableInt(), FALSE, Tvariable_set::fun, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by AddVariable2Monomial(), ProductVarSet(), and ReplaceVariableInVarSet().

void ProductVarSet ( Tvariable_set vs1,
Tvariable_set vs2,
Tvariable_set v_out 
)

Accumulates two variable sets in one. Note that this is different from UnionVarSet since here we keep the sum of the exponentionals (not the maximum one).

Parameters
vs1The first variable set.
vs2The second variable set.
v_outThe resulting set of variables.

Definition at line 282 of file variable_set.c.

References AddVariable2Set(), CopyVarSet(), Tvariable_set::fun, Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by MonomialProduct().

void RemoveVariableFromSet ( unsigned int  varid,
Tvariable_set vs 
)

Removes a variable index from a variable set. This operates indepedently of the function/power applied to the variable.

Parameters
varidThe index of the variable to be removed to the set.
vsThe set of variables to update.

Definition at line 305 of file variable_set.c.

References Tvariable_set::fun, Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

double FixVariableInVarSet ( unsigned int  varid,
double  ct,
Tvariable_set vs 
)

Replaces a variable by a constant.

Parameters
varidThe identifier of the variable to replace.
ctThe constat value.
vsThe variable set to update
Returns
The constant value resulting from the variable substitution.

Definition at line 323 of file variable_set.c.

References COSV, Error(), EXPV, Tvariable_set::fun, NFUN, Tvariable_set::nvars, Tvariable_set::power, PWCV, PWLV, PWPV, SEC2TANV, SEC2V, SINV, TANV, Tvariable_set::var_id, and ZERO.

Referenced by FixVariableInMonomial().

double ReplaceVariableInVarSet ( unsigned int  varid,
double  ct,
unsigned int  newID,
Tvariable_set vs 
)

Replaces a variable by a scaled variable.

Note that variables inside functions can only be replaced with a scale factor set to 1.

Parameters
varidThe identifier of the variable to replace.
ctThe scale factor.
newIDThe identifier of the new variable.
vsThe variable set to update.

Definition at line 398 of file variable_set.c.

References AddVariable2Set(), CopyVarSet(), DeleteVarSet(), Error(), Tvariable_set::fun, InitVarSet(), NFUN, Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by ReplaceVariableInMonomial().

unsigned int VarSetOrder ( Tvariable_set vs)

Returns the order of a variable set: the sum of the powers of the variables in the set.

Parameters
vsThe set of variables to query.
Returns
The variable set order.

Definition at line 423 of file variable_set.c.

References Tvariable_set::nvars, and Tvariable_set::power.

Referenced by MonomialOrder().

unsigned int VariableSetSize ( Tvariable_set vs)
inline

Returns the number of elements of a variable set.

Parameters
vsThe set of variables to query.
Returns
The number of elements of a variable set.

Definition at line 442 of file variable_set.c.

References Tvariable_set::nvars.

Referenced by BilinearMonomial(), CropEquation(), CtMonomial(), DummifyAndAddEquation(), EvaluateMonomial(), EvaluateMonomialInt(), GetBoxMaxSizeVarSet(), GetBoxMinSizeVarSet(), GetEquationNumVariables(), IsSimplificable(), LinearMonomial(), QuadraticMonomial(), ReplaceVariableInEquation(), RewriteEquation2Orig(), RewriteEquation2Simp(), and SetEquationInfo().

unsigned int GetVariableN ( unsigned int  n,
Tvariable_set vs 
)

Returns the identifier for the n-th variable in the set.

If the set has less than n elements this functions triggers an error.

Parameters
nThe position for the index to retrive.
vsThe set of variables to query.
Returns
The index of the variable at position n.

Definition at line 447 of file variable_set.c.

References Error(), and Tvariable_set::var_id.

Referenced by CropEquation(), DummifyAndAddEquation(), ErrorDueToVariable(), GetBoxMaxSizeVarSet(), GetBoxMinSizeVarSet(), GetFirstOrderApproximationToEquation(), IsSimplificable(), LinearEquation2LinearConstraint(), LinearizeBilinealMonomialEquation(), LinearizeCircleEquation(), LinearizeGeneralEquation(), LinearizeParabolaEquation(), LinearizeSaddleEquation(), LinearizeSphereEquation(), RewriteEquation2Orig(), RewriteEquation2Simp(), SetEquationInfo(), and UpdateSplitWeight().

unsigned int* GetVariables ( Tvariable_set vs)

Returns the variable identifiers stored in a variable set.

Parameters
vsThe set of variables to query.
Returns
The a pointer to the array of variable indexes.

Definition at line 458 of file variable_set.c.

References Tvariable_set::var_id.

unsigned int GetVariablePowerN ( unsigned int  n,
Tvariable_set vs 
)

Returns the power for the n-th variable in the set.

If the set has less than n elements this functions triggers an error.

Parameters
nThe position for the variable whose power we want to retrive.
vsThe set of variables to query.
Returns
The power of the variable at position n.

Definition at line 463 of file variable_set.c.

References Error(), and Tvariable_set::power.

Referenced by BilinearMonomial(), DummifyAndAddEquation(), LinearMonomial(), QuadraticMonomial(), ReplaceVariableInEquation(), and RewriteEquation2Orig().

unsigned int GetVariableFunctionN ( unsigned int  n,
Tvariable_set vs 
)

Returns the function applied to the n-th variable in the set.

If the set has less than n elements this functions triggers an error.

Parameters
nThe position for the variable whose function we want to retrive.
vsThe set of variables to query.
Returns
The function of the variable at position n (NFUN if no function is actually applied to the variable).

Definition at line 474 of file variable_set.c.

References Error(), and Tvariable_set::fun.

Referenced by DummifyAndAddEquation(), RewriteEquation2Orig(), and RewriteEquation2Simp().

unsigned int* GetPowers ( Tvariable_set vs)

Returns the variable powers stored in a variable set.

Parameters
vsThe set of variables to query.
Returns
The a pointer to the array of variable powers.

Definition at line 485 of file variable_set.c.

References Tvariable_set::power.

boolean VarSetIntersect ( Tvariable_set vs1,
Tvariable_set vs2 
)

Determines if two variable sets have any element in common. To determine if two variable set elements are the same we take into account bot the variable index, its power, and its associated function (if any).

Parameters
vs1The first set of variables to intersect.
vs2The second set of variables to intersect.
Returns
TRUE if the intersection between the sets is non-empty.

Definition at line 205 of file variable_set.c.

References FALSE, Tvariable_set::fun, Included(), Tvariable_set::power, and Tvariable_set::var_id.

void UnionVarSet ( boolean  fun,
Tvariable_set vs_new,
Tvariable_set vs 
)

Produces a variable set that is the union of two variable sets: i.e., it includes the variables in both sets.

Parameters
funTRUE if the same variable with different functions has to be considered differnt instances. FALSE if the variable indentifier is the only criterion used.
vs_newThe variable set to add to 'vs'
vsThe set of variables to modify.

Definition at line 221 of file variable_set.c.

References AddVariableInt(), FALSE, Tvariable_set::fun, Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by AddScaledMonomial(), and VarScaleEquation().

double EvaluateVarSet ( double *  varValues,
Tvariable_set vs 
)
inline

Evaluates a variable set for a given set of value for the variables.

Parameters
varValuesAn array of doubles with the values for the variables in the problem.
vsThe variable set to evaluate.
Returns
The value of the variable set.

Definition at line 490 of file variable_set.c.

References COSV, Error(), EXPV, Tvariable_set::fun, NFUN, Tvariable_set::nvars, Tvariable_set::power, PWCV, PWLV, PWPV, SEC2TANV, SEC2V, SINV, TANV, Tvariable_set::var_id, and ZERO.

Referenced by EvaluateMonomial().

void EvaluateVarSetInt ( Tinterval varValues,
Tinterval i_out,
Tvariable_set vs 
)

Evaluates a variable set for a given set of ranges for the variables using interval arithmetics.

Parameters
varValuesAn array with the ranges for the variables in the problem.
i_outThe output interval.
vsThe variable set to evaluate.

Definition at line 564 of file variable_set.c.

References CopyInterval(), COSV, Error(), EXPV, Tvariable_set::fun, IntervalCosine(), IntervalExp(), IntervalPow(), IntervalProduct(), IntervalScale(), IntervalSecant2(), IntervalSecant2Tangent(), IntervalSine(), IntervalTangent(), LowerLimit(), NewInterval(), NFUN, Tvariable_set::nvars, Tvariable_set::power, PWCV, PWLV, PWPV, SEC2TANV, SEC2V, SINV, TANV, UpperLimit(), and Tvariable_set::var_id.

Referenced by EvaluateMonomialInt().

double DeriveVarSet ( unsigned int  nv,
Tvariable_set dvs,
Tvariable_set vs 
)

Derives a variable set with respect to a given variable.

Parameters
nvIdentifier of the variable with respect to the one we have to derive.
dvsOutput variable set with the derived variable set.
vsThe variable set to derive.
Returns
The constant term sub-product of the derivation, if any.

Definition at line 657 of file variable_set.c.

References COSV, Error(), EXPV, FALSE, Tvariable_set::fun, Tvariable_set::maxvars, NEW, NFUN, Tvariable_set::nvars, Tvariable_set::power, PWCV, PWLV, PWPV, ResetVarSet(), SEC2TANV, SEC2V, SINV, TANV, TRUE, and Tvariable_set::var_id.

Referenced by DeriveMonomial().

void PrintVarSet ( FILE *  f,
char **  varNames,
Tvariable_set vs 
)

Writes a variable set to a given stream.

Parameters
fThe stream where to print the variable set.
varNamesThe name of the variables. If this parameter is NULL the printed names for the variables are v_X with X the index of the variable.
vsThe variable set to print.

Definition at line 774 of file variable_set.c.

References COSV, Error(), EXPV, FALSE, Tvariable_set::fun, NFUN, Tvariable_set::nvars, Tvariable_set::power, PRINT_VARIABLE_NAME, PWCV, PWLV, PWPV, SEC2TANV, SEC2V, SINV, TANV, TRUE, and Tvariable_set::var_id.

Referenced by PrintMonomial().

void DeleteVarSet ( Tvariable_set vs)

Deletes the information stored in the variable set and frees the allocated memory space.

Parameters
vsThe variable set to be deleted.

Definition at line 852 of file variable_set.c.

References Tvariable_set::fun, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by DeleteEquation(), DeleteMonomial(), and ReplaceVariableInVarSet().