monomial.h File Reference

Detailed Description

Definition of the Tmonomial type and the associated functions.

See Also
Tmonomial, monomial.c.

Definition in file monomial.h.

Data Structures

struct  Tmonomial
 A scaled product of powers of variables. More...
 

Functions

void InitMonomial (Tmonomial *f)
 Constructor. More...
 
void ResetMonomial (Tmonomial *f)
 Reset the monomial information. More...
 
void FixVariableInMonomial (unsigned int nv, double v, Tmonomial *f)
 Replaces a variable by a constant. More...
 
void ReplaceVariableInMonomial (unsigned int nv, double ct, unsigned int nvNew, Tmonomial *f)
 Replaces a variable. More...
 
boolean EmptyMonomial (Tmonomial *f)
 Checks if a monomial is empty. More...
 
boolean CtMonomial (Tmonomial *f)
 Checks if a monomial is constant. More...
 
boolean QuadraticMonomial (Tmonomial *f)
 Checks if a monomial is quadratic: K*x^2, with K a constant. More...
 
boolean BilinearMonomial (Tmonomial *f)
 Checks if a monomial is bilienal: K*x*y, with K a constant. More...
 
boolean LinearMonomial (Tmonomial *f)
 Checks if a monomial is lienal: K*x, with K a constant. More...
 
boolean PolynomialMonomial (Tmonomial *f)
 Identifies monimials not involving any kind of (trigonomitric function). More...
 
unsigned int MonomialOrder (Tmonomial *f)
 Gets the order of a monomial. More...
 
void CopyMonomial (Tmonomial *f_dst, Tmonomial *f_orig)
 Copy constructor. More...
 
unsigned int CmpMonomial (Tmonomial *f1, Tmonomial *f2)
 Monomial comparison. More...
 
void SetMonomialCt (double k, Tmonomial *f)
 Changes the scale factor of a monomial. More...
 
double GetMonomialCt (Tmonomial *f)
 Gets the scale factor of a monomial. More...
 
Tvariable_setGetMonomialVariables (Tmonomial *f)
 Gets the variables of a monomial. More...
 
void AddCt2Monomial (double k, Tmonomial *f)
 Scales a monomial. More...
 
void AddVariable2Monomial (unsigned int fn, unsigned int varid, unsigned int p, Tmonomial *f)
 Adds a power variable to the monomial. More...
 
void MonomialProduct (Tmonomial *f1, Tmonomial *f2, Tmonomial *f)
 Product of two monomials. More...
 
double EvaluateMonomial (double *varValues, Tmonomial *f)
 Evaluates a monomial for a given set of value for the variables. More...
 
void EvaluateMonomialInt (Tinterval *varValues, Tinterval *i_out, Tmonomial *f)
 Evaluates a monomial for a given set of ranges for the variables. More...
 
void DeriveMonomial (unsigned int nv, Tmonomial *df, Tmonomial *f)
 Derives an monomial. More...
 
void PrintMonomial (FILE *file, boolean first, char **varNames, Tmonomial *f)
 Prints a monomial. More...
 
void DeleteMonomial (Tmonomial *f)
 Destructor. More...
 

Function Documentation

void FixVariableInMonomial ( unsigned int  nv,
double  v,
Tmonomial f 
)

Removes a variable from a monomial converting it into a constant. Note, that variables are indexed and that removing a variable shifts down the index of variables with index above the removed variable.

Parameters
nvNumerical identifier of the variable to remove.
vValue for the variable to remove.
fThe monomial to be updated.

Definition at line 31 of file monomial.c.

References Tmonomial::ct, FixVariableInVarSet(), ResetMonomial(), ShiftVarIndexes(), Tmonomial::vars, and ZERO.

Referenced by ReplaceVariableInEquation().

void ReplaceVariableInMonomial ( unsigned int  nv,
double  ct,
unsigned int  nvNew,
Tmonomial f 
)

Replaces a variable from a monomial converting it into a another variable via a linear relation

VarToBeReplaced = a * NewVar + b


Note, that variables are indexed and that removing a variable shifts down the index of variables with index above the removed variable.

Parameters
nvNumerical identifier of the variable to remove.
ctScale factor for the new variable.
nvNewNumerical identifier of the new variable.
fThe monomial to be updated.

Definition at line 42 of file monomial.c.

References Tmonomial::ct, ReplaceVariableInVarSet(), ResetMonomial(), ShiftVarIndexes(), Tmonomial::vars, and ZERO.

boolean EmptyMonomial ( Tmonomial f)

Checks if a monomial is empty.

Parameters
fThe monomial to be checked.
Returns
TRUE if the input monomia is empty.

Definition at line 53 of file monomial.c.

References Tmonomial::empty.

Referenced by AddScaledMonomial().

boolean CtMonomial ( Tmonomial f)

Checks if a monomial is constant.

Parameters
fThe monomial to be checked.
Returns
TRUE if the input monomial is constant.

Definition at line 58 of file monomial.c.

References Tmonomial::empty, VariableSetSize(), and Tmonomial::vars.

Referenced by AddScaledMonomial(), BilinearEquation(), and LinearEquation().

boolean QuadraticMonomial ( Tmonomial f)

Checks if a monomial is quadratic: K*x^2, with K a constant.

Parameters
fThe monomial to be checked.
Returns
TRUE if the input monomial is quadratic.

Definition at line 64 of file monomial.c.

References GetVariablePowerN(), PolynomialVarSet(), VariableSetSize(), and Tmonomial::vars.

Referenced by BilinearEquation(), CircleEquation(), ParabolaEquation(), and SphereEquation().

boolean BilinearMonomial ( Tmonomial f)

Checks if a monomial is bilineal: K*x*y, with K a constant.

Parameters
fThe monomial to be checked.
Returns
TRUE if the input monomial is bilienal.

Definition at line 71 of file monomial.c.

References GetVariablePowerN(), PolynomialVarSet(), VariableSetSize(), and Tmonomial::vars.

Referenced by BilinealMonomialEquation(), BilinearEquation(), and SaddleEquation().

boolean LinearMonomial ( Tmonomial f)

Checks if a monomial is bilineal: K*y, with K a constant.

Parameters
fThe monomial to be checked.
Returns
TRUE if the input monomial is lineal.

Definition at line 79 of file monomial.c.

References GetVariablePowerN(), PolynomialVarSet(), VariableSetSize(), and Tmonomial::vars.

Referenced by BilinearEquation(), LinearEquation(), ParabolaEquation(), and SaddleEquation().

boolean PolynomialMonomial ( Tmonomial f)

Identifies monimials not involving any kind of (trigonomitric function).

Note that mathematically all monomials are polynomials. In this implementation this is not the case since the monomial structrue is used also for the case where variables are affected by (trigonometric) function. To be correct we should not use the term monomial to refer to a product of constants, variables, and functions.

Todo:
Replace the term monomial by factor.
Parameters
fThe monomial to query.
Returns
TRUE if the monomial is purelly polynomial.

Definition at line 86 of file monomial.c.

References PolynomialVarSet(), and Tmonomial::vars.

Referenced by AddScaledMonomial(), and ReplaceVariableInEquation().

unsigned int MonomialOrder ( Tmonomial f)

Gets the order of a monomial. Here the order is the sum of the powers of the variables in the monomial (0 for constant, 1 for lineal, 2 for quadratic and bilineal).

Parameters
fThe monomial to be checked.
Returns
The monomial order as defined above.

Definition at line 91 of file monomial.c.

References Tmonomial::vars, and VarSetOrder().

Referenced by AddScaledMonomial(), and RewriteEquation2Simp().

void CopyMonomial ( Tmonomial f_dst,
Tmonomial f_orig 
)

Copies a constructor copying the data from another monomial.

Parameters
f_dstThe monomial to be created.
f_origThe monomial from where to copy.

Definition at line 96 of file monomial.c.

References CopyVarSet(), Tmonomial::ct, Tmonomial::empty, and Tmonomial::vars.

Referenced by AddScaledMonomial(), ReplaceVariableInEquation(), and VarAccumulateEquations().

unsigned int CmpMonomial ( Tmonomial f1,
Tmonomial f2 
)

Compare two given monomials. Monomials are compared first taking into account the variables and then their scale factor.

Parameters
f1The first monomial to compare.
f2The second monomial to compare.
Returns
1 if f1 is larger than f2, 0 if they are equal and 2 if f2 is larger than f1.
See Also
CmpVarSet

Definition at line 103 of file monomial.c.

References CmpVarSet(), Tmonomial::ct, Tmonomial::empty, and Tmonomial::vars.

Referenced by AddScaledMonomial(), and CmpEquations().

void SetMonomialCt ( double  k,
Tmonomial f 
)

Changes the scale factor of a monomial.

Parameters
kthe new monomial scale factor.
fThe monomial to update.

Definition at line 144 of file monomial.c.

References Tmonomial::ct, Tmonomial::empty, FALSE, ResetMonomial(), and ZERO.

Referenced by AddScaledMonomial(), NormalizeEquation(), RewriteEquation2Orig(), and VarAccumulateEquations().

double GetMonomialCt ( Tmonomial f)
Tvariable_set* GetMonomialVariables ( Tmonomial f)
void MonomialProduct ( Tmonomial f1,
Tmonomial f2,
Tmonomial f 
)

Produces a monomial that is the product of the two other given monomials.

Parameters
f1The firt monomial to product.
f2The second one.
fThe output monomial.

Definition at line 183 of file monomial.c.

References Tmonomial::ct, Tmonomial::empty, InitMonomial(), ProductVarSet(), Tmonomial::vars, and ZERO.

Referenced by ProductEquations().

double EvaluateMonomial ( double *  varValues,
Tmonomial f 
)
inline

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

Parameters
varValuesAn array of doubles with the values for the variables in the problem.
fThe monomial to evaluate.
Returns
The value of the monomial.

Definition at line 197 of file monomial.c.

References Tmonomial::ct, Tmonomial::empty, EvaluateVarSet(), VariableSetSize(), and Tmonomial::vars.

Referenced by EvaluateEquation(), and EvaluateWholeEquation().

void EvaluateMonomialInt ( Tinterval varValues,
Tinterval i_out,
Tmonomial f 
)

Evaluates a monomial 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.
fThe monomial to evaluate.

Definition at line 210 of file monomial.c.

References Tmonomial::ct, Tmonomial::empty, EvaluateVarSetInt(), IntervalProduct(), NewInterval(), VariableSetSize(), Tmonomial::vars, and ZERO.

Referenced by CleanInfEquation(), and EvaluateEquationInt().

void DeriveMonomial ( unsigned int  nv,
Tmonomial df,
Tmonomial f 
)

Derives a monomial with respect to a given variable.

Parameters
nvIdentifier of the variable with respect to the one we have to derive.
dfOutput monomial with the derived monomial.
fThe monomial to derive.

Definition at line 238 of file monomial.c.

References Tmonomial::ct, DeriveVarSet(), Tmonomial::empty, InitMonomial(), VarIncluded(), and Tmonomial::vars.

Referenced by DeriveEquation().

void PrintMonomial ( FILE *  file,
boolean  first,
char **  varNames,
Tmonomial f 
)

Writes a monomial to a given stream.

Parameters
fileThe stream where to print the monomial.
firstTRUE if the monomial is the first one in an equation. This is used to avoid a '+' sign at the beginning of the equation.
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.
fThe monomial to print.

Definition at line 255 of file monomial.c.

References Tmonomial::ct, Tmonomial::empty, EmptyVarSet(), PrintVarSet(), Tmonomial::vars, and ZERO.

Referenced by PrintEquation(), and PrintMonomials().