equation.c File Reference

Detailed Description

Implementation of the functions operating on Tequation.

See Also
Tequation, equation.h,

Definition in file equation.c.

Functions

void ResetEquationMonomials (Tequation *eq)
 Resets the information about monomials stored in the equation. More...
 
void PurgeEquation (Tequation *eq)
 Removes monomial with small constant. More...
 
void InitEquation (Tequation *eq)
 Constructor. More...
 
void EquationFromLinearConstraint (TLinearConstraint *lc, Tequation *eq)
 Defines a new equation from a linear constraint. More...
 
void EquationFromLinearConstraintProduct (TLinearConstraint *lc1, TLinearConstraint *lc2, Tequation *eq)
 Defines a new equation from the product of two linear constraints. More...
 
void CopyEquation (Tequation *eq_dst, Tequation *eq_orig)
 Copy constructor. More...
 
void RewriteEquation2Simp (double epsilon, Tmapping *map, Tequation *eqOut, Tequation *eq)
 Applies the simplification mapping to an equation. More...
 
void RewriteEquation2Orig (Tmapping *map, Tequation *eqOut, Tequation *eq)
 Applies the un-simplification mapping to an equation. More...
 
void AccumulateEquations (Tequation *eqn, double ct, Tequation *eq)
 Adds a scaled equation to another equation. More...
 
void VarAccumulateEquations (Tequation *eqn, unsigned int v, Tequation *eq)
 Adds an equation scaled with a variable to another equation. More...
 
void ProductEquations (Tequation *eq1, Tequation *eq2, Tequation *eqOut)
 Product of two equations. More...
 
void ResetEquation (Tequation *eq)
 Reset equation information. More...
 
unsigned int FixVariableInEquation (double epsilon, unsigned int nv, double b, Tequation *eq)
 Turns a variable into a constant. More...
 
unsigned int ReplaceVariableInEquation (double epsilon, unsigned int nv, TLinearConstraint *lc, Tequation *eq)
 Replaces a variable. More...
 
void CtScaleEquation (double ct, Tequation *eq)
 Scales an equation by a constant factor. More...
 
void VarScaleEquation (unsigned int v, Tequation *eq)
 Scales an equation with a variable factor. More...
 
void NormalizeEquation (Tequation *eq)
 Normalizes an equation. More...
 
boolean CleanInfEquation (Tequation *eq_in, Tinterval *varValues, boolean *changed, Tequation *eq_out)
 Removes the monomials that evaluate to inf. More...
 
boolean IsSimplificable (unsigned int simpLevel, unsigned int nTerms, boolean *systemVars, Tbox *cb, unsigned int *v, TLinearConstraint *lc, Tequation *eq)
 Identify equations than can trigger variable simplifications. More...
 
void SetEquationType (unsigned int type, Tequation *eq)
 Changes the type of the equation (SYSTEM_EQ, CARTESIAN_EQ, DUMMY_EQ, DERIVED_EQ). More...
 
void SetEquationCmp (unsigned int cmp, Tequation *eq)
 Changes the relational operator (LEQ, GEQ, EQU) of the equation. More...
 
void SetEquationValue (double v, Tequation *eq)
 Changes the right-hand value of the equation. More...
 
boolean EmptyEquation (Tequation *eq)
 Identify empty equations. More...
 
boolean LinearEquation (Tequation *eq)
 Identify linear equations. More...
 
boolean BilinearEquation (Tequation *eq)
 Identify bilinear equations. More...
 
boolean CircleEquation (Tequation *eq)
 Identify circle equations. More...
 
boolean SphereEquation (Tequation *eq)
 Identify sphere equations. More...
 
boolean SaddleEquation (Tequation *eq)
 Identify scaled saddle equations. More...
 
boolean BilinealMonomialEquation (Tequation *eq)
 Identify single bilineal monomial equations. More...
 
boolean ParabolaEquation (Tequation *eq)
 Identify scaled parabola equations. More...
 
boolean PolynomialEquation (Tequation *eq)
 Idetify polynomial equations. More...
 
unsigned int GetEquationCmp (Tequation *eq)
 Gets the type of relational operator of the equation. More...
 
unsigned int GetEquationType (Tequation *eq)
 Gets the equation type. More...
 
double GetEquationValue (Tequation *eq)
 Gets the right-hand value of the equation. More...
 
void GetEquationBounds (Tinterval *bounds, Tequation *eq)
 Returns the right-hand side of the equation in the form of an interval. More...
 
unsigned int GetEquationOrder (Tequation *eq)
 Gets the equation order. More...
 
Tvariable_setGetEquationVariables (Tequation *eq)
 Gets the set of variables equation used in the equation. More...
 
unsigned int GetEquationNumVariables (Tequation *eq)
 Gets the number of variables equation used in the equation. More...
 
unsigned int CmpEquations (Tequation *eq1, Tequation *eq2)
 Equation comparison. More...
 
void AddScaledMonomial (double sc, Tmonomial *f, Tequation *eq)
 Adds a new scaled monomial to the equation. More...
 
void AddMonomial (Tmonomial *f, Tequation *eq)
 Adds a new monomial to the equation. More...
 
void GenerateParabolaEquation (unsigned int vx, unsigned int vy, Tequation *eq)
 Construtor. Generates a parabola equation. More...
 
void GenerateScaledParabolaEquation (double s, unsigned int vx, unsigned int vy, Tequation *eq)
 Construtor. Generates a scaled parabola equation. More...
 
void GenerateSaddleEquation (unsigned int vx, unsigned int vy, unsigned int vz, Tequation *eq)
 Construtor. Generates a saddle equation. More...
 
void GenerateScaledSaddleEquation (double s, unsigned int vx, unsigned int vy, unsigned int vz, Tequation *eq)
 Construtor. Generates a scaled saddle equation. More...
 
void GenerateNormEquation (unsigned int vx, unsigned int vy, unsigned int vz, double n, Tequation *eq)
 Construtor. Generates an equation that is the norm of a 3d vector. More...
 
void GenerateGeneralNormEquation (unsigned int nv, unsigned int *v, double n, Tequation *eq)
 Construtor. Generates an equation that is the norm of a vector. More...
 
void GenerateCrossProductEquations (unsigned int v1x, unsigned int v1y, unsigned int v1z, unsigned int v2x, unsigned int v2y, unsigned int v2z, unsigned int v3x, unsigned int v3y, unsigned int v3z, unsigned int vs, double s, Tequation *eq)
 Construtor. Generates the three equations of the cross product of two unitary vectors. More...
 
void GenerateDotProductEquation (unsigned int v1x, unsigned int v1y, unsigned int v1z, unsigned int v2x, unsigned int v2y, unsigned int v2z, unsigned int vc, double c, Tequation *eq)
 Construtor. Generates the equation of the dot product of two unitary vectors. More...
 
unsigned int FindMonomial (Tmonomial *f, Tequation *eq)
 Searches for a given monomial in the equation. More...
 
TmonomialGetMonomial (unsigned int i, Tequation *eq)
 Gets a monomial from an equation. More...
 
unsigned int GetNumMonomials (Tequation *eq)
 Number of monomials in an equation. More...
 
void LinearEquation2LinearConstraint (TLinearConstraint *lc, Tequation *eq)
 Converts a linear equation into a linear constraint. More...
 
double EvaluateWholeEquation (double *varValues, Tequation *eq)
 Evaluates an equation in a given point. More...
 
double EvaluateEquation (double *varValues, Tequation *eq)
 Evaluates an equation in a given point. More...
 
void EvaluateEquationInt (Tinterval *varValues, Tinterval *i_out, Tequation *eq)
 Interval evaluation of an equation. More...
 
void DeriveEquation (unsigned int nv, Tequation *d, Tequation *eq)
 Derives an equation. More...
 
void PrintMonomials (FILE *f, char **varNames, Tequation *eq)
 Prints an equation as a set if monomials. More...
 
void PrintEquation (FILE *f, char **varNames, Tequation *eq)
 Prints an equation. More...
 
void DeleteEquation (Tequation *eq)
 Destructor. More...
 

Function Documentation

void ResetEquationMonomials ( Tequation eq)

Removes the information about monomials stored in the equation.

Parameters
eqThe equation to be reseted.

Definition at line 35 of file equation.c.

References DeleteMonomial(), Tequation::monomials, Tequation::nMonomials, Tequation::polynomial, and TRUE.

Referenced by DeleteEquation(), and ResetEquation().

void PurgeEquation ( Tequation eq)
void EquationFromLinearConstraint ( TLinearConstraint lc,
Tequation eq 
)

Defines a new equation from a linear constraint. Only linear constraint with a constant right-hand term can be converted to equations. For other linear constraints this funtion triggers an error.

Parameters
lcThe linear constraint to convert to an equation.
eqThe new equation

Definition at line 106 of file equation.c.

References AddCt2Monomial(), AddMonomial(), AddVariable2Monomial(), Tequation::cmp, DeleteMonomial(), EQU, Error(), GEQ, GetLinearConstraintCoefficient(), GetLinearConstraintError(), GetLinearConstraintVariable(), GetNumTermsInLinearConstraint(), INF, InitEquation(), InitMonomial(), IntervalCenter(), IntervalSize(), LEQ, LowerLimit(), NFUN, UpperLimit(), and Tequation::value.

Referenced by RewriteEquation2Simp().

void EquationFromLinearConstraintProduct ( TLinearConstraint lc1,
TLinearConstraint lc2,
Tequation eq 
)

Defines a new equation from the product of two linear constraint. Only linear constraint with a constant right-hand term are considered. For other linear constraints this funtion triggers an error.

Parameters
lc1The first linear constraint to multiply.
lc2The second linear constraint to multiply.
eqThe new equation

Definition at line 156 of file equation.c.

References AddCt2Monomial(), AddMonomial(), AddVariable2Monomial(), DeleteMonomial(), Error(), GetLinearConstraintCoefficient(), GetLinearConstraintError(), GetLinearConstraintVariable(), GetNumTermsInLinearConstraint(), InitEquation(), InitMonomial(), IntervalCenter(), IntervalSize(), and NFUN.

Referenced by RewriteEquation2Simp().

void RewriteEquation2Simp ( double  epsilon,
Tmapping map,
Tequation eqOut,
Tequation eq 
)

Transform an equation expressed in a given set of variables into an equation in the simplified set of variables. The relation between the two sets of variables is given by a mapping.

Parameters
epsilonWhen replacing variables, monomials with a constant value below epsilon are removed.
mapThe mapping relating the two sets of variables.
eqOutThe output of the re-write (The simplified equation).
eqThe equation in the original system.
See Also
Tmapping

Definition at line 237 of file equation.c.

References AccumulateEquations(), AddMonomial(), Tequation::cmp, CopyEquation(), DeleteEquation(), DeleteLinearConstraint(), EquationFromLinearConstraint(), EquationFromLinearConstraintProduct(), Error(), GetMonomialCt(), GetMonomialVariables(), GetOriginalVarRelation(), GetVariableFunctionN(), GetVariableN(), InitEquation(), MonomialOrder(), Tequation::monomials, NFUN, Tequation::nMonomials, Tequation::polynomial, PurgeEquation(), Tequation::type, Tequation::value, and VariableSetSize().

Referenced by UpdateCuikSystem().

void RewriteEquation2Orig ( Tmapping map,
Tequation eqOut,
Tequation eq 
)

Transform an equation expressed in a simplified set of variables into an equation in the original set of variables. The relation between the two sets of variables is given by a mapping.

Parameters
mapThe mapping relating the two sets of variables.
eqOutThe output of the re-write (the un-simplified equation).
eqThe equation in the simplified system.
See Also
Tmapping

Definition at line 321 of file equation.c.

References AddMonomial(), AddVariable2Monomial(), Tequation::cmp, CopyEquation(), DeleteEquation(), DeleteMonomial(), Error(), GetMonomialCt(), GetMonomialVariables(), GetVariableFunctionN(), GetVariableN(), GetVariablePowerN(), GetVarIDInOriginal(), InitEquation(), InitMonomial(), Tequation::monomials, Tequation::nMonomials, NO_UINT, Tequation::polynomial, ResetMonomial(), SetMonomialCt(), Tequation::type, Tequation::value, and VariableSetSize().

Referenced by AddSimplifiedJacobianEquations().

void VarAccumulateEquations ( Tequation eqn,
unsigned int  v,
Tequation eq 
)

Adds a scaled equation to another equation. This is like AccumulateEquations but here the scale is with a variable and not with a constnat

Parameters
eqnThe equation to scale and add.
vThe variable scale factor.
eqThe equation where to add the result.

Definition at line 377 of file equation.c.

References AddMonomial(), AddVariable2Monomial(), CopyMonomial(), DeleteMonomial(), InitMonomial(), Tequation::monomials, NFUN, Tequation::nMonomials, PurgeEquation(), SetMonomialCt(), and Tequation::value.

Referenced by ApplyLinkRotVar(), and VarAccumulateEqVectors().

void ProductEquations ( Tequation eq1,
Tequation eq2,
Tequation eqOut 
)

Generates an equations that is the product of two given equations.

Parameters
eq1The first equation to operate.
eq2The second equation to operate.
eqOutThe resulting equation.

Definition at line 398 of file equation.c.

References AccumulateEquations(), AddMonomial(), Tequation::cmp, CopyEquation(), DeleteEquation(), DeleteMonomial(), Error(), InitEquation(), MonomialProduct(), Tequation::monomials, NEW, Tequation::nMonomials, PurgeEquation(), Tequation::type, and Tequation::value.

Referenced by CrossProductEqVectors(), DotProductEqVectors(), and SHTransformProduct().

void ResetEquation ( Tequation eq)

Removes the information stored in the equation, but does not frees the memory. It is more efficient to use ResetEquation instead of DeleteEquation plus InitEquation again.

Parameters
eqThe equation to reset.

Definition at line 442 of file equation.c.

References Tequation::cmp, NOCMP, NOTYPE_EQ, Tequation::order, Tequation::polynomial, ResetEquationMonomials(), ResetVarSet(), TRUE, Tequation::type, Tequation::value, and Tequation::vars.

Referenced by GenerateJointRangeSingularityEquations(), and UpdateCuikSystem().

unsigned int FixVariableInEquation ( double  epsilon,
unsigned int  nv,
double  b,
Tequation eq 
)

Removes a variable from an equation 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
epsilonMonomials with a constant value below epsilon are removed.
nvNumerical identifier of the variable to remove.
bValue for the variable to remove.
eqThe equation from where to remove the variable.

Definition at line 461 of file equation.c.

References AddCt2LinearConstraint(), DeleteLinearConstraint(), InitLinearConstraint(), and ReplaceVariableInEquation().

Referenced by RemoveEquationsWithVar().

unsigned int ReplaceVariableInEquation ( double  epsilon,
unsigned int  nv,
TLinearConstraint lc,
Tequation eq 
)

Replaces a variable from an equation converting it to a linear combination of variables.

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

Parameters
epsilonMonomials with a constant value below epsilon are removed.
nvNumerical identifier of the variable to remove.
lcThe linear constraint that replaces the equation.
eqThe equation from where to remove the variable.

Definition at line 481 of file equation.c.

References AddCt2Monomial(), AddMonomial(), AddVariable2Monomial(), Tequation::cmp, CopyEquation(), CopyMonomial(), DeleteEquation(), DeleteMonomial(), EQU, Error(), FixVariableInMonomial(), GEQ, GetEquationCmp(), GetEquationType(), GetEquationValue(), GetLinearConstraintCoefficient(), GetLinearConstraintError(), GetLinearConstraintVariable(), GetMonomialVariables(), GetNumTermsInLinearConstraint(), GetPlaceinSet(), GetVariablePowerN(), InitEquation(), IntervalCenter(), IntervalSize(), LEQ, Tequation::monomials, NFUN, Tequation::nMonomials, NO_UINT, NormalizeEquation(), Tequation::polynomial, PolynomialMonomial(), SetEquationCmp(), SetEquationType(), SetEquationValue(), ShiftVarIndexes(), TRUE, Tequation::value, VariableSetSize(), and ZERO.

Referenced by FixVariableInEquation(), and ReplaceVariableInEquations().

void CtScaleEquation ( double  ct,
Tequation eq 
)

Scales the equation by a constant factor.

Only equalities are scaled and if the scale factor is 0 this function triggers an error.

Parameters
ctThe factor to use as a scale factor.
eqThe equation to scale.

Definition at line 652 of file equation.c.

References AddCt2Monomial(), Tequation::cmp, EQU, Error(), Tequation::monomials, Tequation::nMonomials, Tequation::value, and ZERO.

Referenced by CrossProductVectorEqVector(), DotProductVectorEqVector(), and ScaleEqVector().

void VarScaleEquation ( unsigned int  v,
Tequation eq 
)

Scales the equation by a variable factor.

Only equalities are scaled.

Parameters
vThe variable to use as a scale factor.
eqThe equation to scale.

Definition at line 669 of file equation.c.

References AddCt2Monomial(), AddMonomial(), AddVariable2Monomial(), Tequation::cmp, DeleteMonomial(), EQU, Error(), FALSE, GetMonomialVariables(), InitMonomial(), Tequation::monomials, NFUN, Tequation::nMonomials, ResetVarSet(), UnionVarSet(), Tequation::value, and Tequation::vars.

Referenced by AddJacobianEquationsInt(), GetSCpSystem(), and VarScaleEqVector().

void NormalizeEquation ( Tequation eq)

Simple form of normalization to avoid numerical inestabilities. If all monomials have the same ct (up to ZERO) we make them all equal to one. This helps in many cases when we replace variables to avoid transforming, for instance, a circle equation into a scaled circle equation (that is not identified as a circle!)

Parameters
eqThe equation to be normalized.

Definition at line 703 of file equation.c.

References AddCt2Monomial(), Tequation::cmp, EQU, GetMonomialCt(), Tequation::monomials, Tequation::nMonomials, PurgeEquation(), SetMonomialCt(), TRUE, Tequation::value, and ZERO.

Referenced by AddEquation(), and ReplaceVariableInEquation().

boolean CleanInfEquation ( Tequation eq_in,
Tinterval varValues,
boolean changed,
Tequation eq_out 
)

Evaluates each one of the monomials in the equation and moves those evaluating to inf to the right hand side of the equation. Note that this can transform EQU to LEQ or GEQ. In the extreme case, the right hand side of the equation becomes unbounded (-inf,inf). In this case the equation does not constrain anything.

Parameters
eq_inThe equation to process.
varValuesRanges for the variables.
changedIs set to TRUE if the equation actually changes.
eq_outThe resulting equation.
Returns
TRUE if the right-hand side is bounded (not (-inf.inf)).

Definition at line 752 of file equation.c.

References AddMonomial(), Tequation::cmp, EvaluateMonomialInt(), FALSE, GEQ, INF, InitEquation(), IntervalOffset(), IntervalSize(), IntervalSubstract(), LEQ, LowerLimit(), Tequation::monomials, NewInterval(), Tequation::nMonomials, PrintInterval(), TRUE, Tequation::type, UpperLimit(), and Tequation::value.

Referenced by AddEquation2Simplex().

boolean IsSimplificable ( unsigned int  simpLevel,
unsigned int  nTerms,
boolean systemVars,
Tbox cb,
unsigned int *  v,
TLinearConstraint lc,
Tequation eq 
)

Checks if a given variable can be remove from the system and replaced by a linear combination of the surving variables.

The output variables (v and lc) are only initilized if some simplification is possible (i.e., if the return is TRUE).

Parameters
simpLevelAgressiveness of the simplification process:
  • 0 No simplification is applied.
  • 1 Only equations of the form $x=a$ or $x^2=0$ are considered (with x a variable and a a constant).
  • 2 Equations of the form $x + a y=b$ are also considered (with x and y variables and a and b constants).
  • 3 Equations of the form $a x + b y=c$ are also considered (with x and y variables and a and b constants).
The more the simplification the more the chances to get numerical problems.
nTermsNumber of terms (i.e., variables) in the linear constraint to use in the simplification.
systemVarsArray of booleans marking the main variables. We first try to remove the non-system variables (i.e., to put them in function of the system ones). If this is not possible we proceed to remove system variables.
cbBox with the current ranges for the variables.
vOutput. The variable to eliminate from the system.
lcOutput. The linear constraint to use to replace the eliminated variable.
eqThe equation.
Returns
TRUE if some variable can be eliminated.

Definition at line 840 of file equation.c.

References AddCt2LinearConstraint(), AddTerm2LinearConstraint(), Tequation::cmp, EQU, FALSE, GetBoxInterval(), GetEquationOrder(), GetMonomialCt(), GetMonomialVariables(), GetVariableN(), INF, InitLinearConstraint(), InvertLinearConstraint(), LowerLimit(), MAX_TERMS_SIMP, Tequation::monomials, Tequation::nMonomials, NO_UINT, Tequation::polynomial, ScaleLinearConstraint(), TRUE, UpperLimit(), Tequation::value, VariableSetSize(), and Tequation::vars.

Referenced by CSRemoveLCVars().

boolean EmptyEquation ( Tequation eq)

Identify empty equations: equatoins with no monomias and with left value 0 (i.e., basically a 0=0 equation).

Parameters
eqThe equation.
Returns
TRUE if the given equation is empty.

Definition at line 1031 of file equation.c.

References Tequation::nMonomials, Tequation::value, and ZERO.

Referenced by CacheScalarEQUInfo().

boolean LinearEquation ( Tequation eq)

Identify linear equations.

Parameters
eqThe equation.
Returns
TRUE if the given equation is linear.

Definition at line 1036 of file equation.c.

References CtMonomial(), LinearMonomial(), Tequation::monomials, and Tequation::polynomial.

Referenced by DummifyAndAddEquation(), and SetEquationInfo().

boolean BilinearEquation ( Tequation eq)

Identify bilinear equations.

Parameters
eqThe equation.
Returns
TRUE if the given equation is bilinear.

Definition at line 1049 of file equation.c.

References BilinearMonomial(), CtMonomial(), LinearMonomial(), Tequation::monomials, Tequation::polynomial, and QuadraticMonomial().

boolean CircleEquation ( Tequation eq)

Identify circle equations (with arbitrary radius).

$x^2 + y^2 + z^2=r^2$.

Parameters
eqThe equation.
Returns
TRUE if the given equation define a circle.

Definition at line 1068 of file equation.c.

References FALSE, GetMonomialCt(), Tequation::monomials, Tequation::nMonomials, Tequation::polynomial, QuadraticMonomial(), TRUE, and Tequation::value.

Referenced by DummifyAndAddEquation(), and SetEquationInfo().

boolean SphereEquation ( Tequation eq)

Identify sphere equations (with arbitrary radius).

$x^2 + y^2 =r^2$.

Parameters
eqThe equation.
Returns
TRUE if the given equation define a sphere.

Definition at line 1082 of file equation.c.

References FALSE, GetMonomialCt(), Tequation::monomials, Tequation::nMonomials, Tequation::polynomial, QuadraticMonomial(), TRUE, and Tequation::value.

Referenced by DummifyAndAddEquation(), and SetEquationInfo().

boolean SaddleEquation ( Tequation eq)

Identify scaled saddle equations, i.e., equations of the form $x y + \alpha z =\beta$.

Parameters
eqThe equation.
Returns
TRUE if the given equation define a saddle.

Definition at line 1096 of file equation.c.

References BilinearMonomial(), Tequation::cmp, EQU, FALSE, GetMonomialCt(), LinearMonomial(), Tequation::monomials, Tequation::nMonomials, Tequation::polynomial, and TRUE.

Referenced by DummifyAndAddEquation(), and SetEquationInfo().

boolean BilinealMonomialEquation ( Tequation eq)

Identify equations formed by a single bilineal monomial. $x y =\beta$.

These equations typically appear after simplifications or when including lineal combinations of Jacobian equations and its worth to dectect and linearize them in a special way.

Single quadratic monimial equations $x^2 =\beta$ do not need a special treatment since they are treated in the crop. Moreover, they result in single variable lineal constraints with a single variable that are processed by SimplifyLinearConstraint and not added to the Simplex.

Parameters
eqThe equation.
Returns
TRUE if the given equation define a saddle.

Definition at line 1109 of file equation.c.

References BilinearMonomial(), Tequation::cmp, EQU, FALSE, GetMonomialCt(), Tequation::monomials, Tequation::nMonomials, Tequation::polynomial, and TRUE.

Referenced by SetEquationInfo().

boolean ParabolaEquation ( Tequation eq)

Identify parabola equations, i.e., equations of the form $x^2 + \alpha z =\beta$.

Parameters
eqThe equation.
Returns
TRUE if the given equation define a parabola.

Definition at line 1121 of file equation.c.

References Tequation::cmp, EQU, FALSE, GetMonomialCt(), LinearMonomial(), Tequation::monomials, Tequation::nMonomials, Tequation::polynomial, QuadraticMonomial(), and TRUE.

Referenced by DummifyAndAddEquation(), and SetEquationInfo().

boolean PolynomialEquation ( Tequation eq)

Identify equations formed only by polynomial monomials (i.e. not including trionometric functions).

Parameters
eqThe equation.
Returns
TRUE if the given equation is polynomial.

Definition at line 1134 of file equation.c.

References Tequation::polynomial.

Referenced by AddEquationInt(), and CropEquation().

unsigned int GetEquationCmp ( Tequation eq)
inline
unsigned int GetEquationType ( Tequation eq)
inline
void GetEquationBounds ( Tinterval bounds,
Tequation eq 
)

Returns the right-hand side of the equation in the form of an interval. For EQU equations this is [value,value], for LEQ is [-inf,value], and for GEQ is [value,inf].

Parameters
boundsThe output interval.
eqThe equation to query.

Definition at line 1154 of file equation.c.

References Tequation::cmp, EQU, Error(), GEQ, INF, LEQ, NewInterval(), NOCMP, and Tequation::value.

Referenced by CropEquation().

unsigned int GetEquationOrder ( Tequation eq)

Gets the equation order: 1 for lineal, 2 for bilinear and quadratic.

Parameters
eqThe equation.
Returns
The equation order.

Definition at line 1173 of file equation.c.

References Tequation::order.

Referenced by CmpEquations(), DummifyAndAddEquation(), IsSimplificable(), and LinearEquation2LinearConstraint().

Tvariable_set* GetEquationVariables ( Tequation eq)

Gets the set of variables equation used in the equation. Note, we return a pointer to the interval equation structures so be careful what you do with the pointer.

Parameters
eqThe equation.
Returns
The equation variable set.

Definition at line 1178 of file equation.c.

References Tequation::vars.

Referenced by AddEquation2Simplex(), CropEquation(), CSRemoveUnusedVars(), DummifyAndAddEquation(), ErrorDueToVariable(), GetEquationNumVariables(), GetFirstOrderApproximationToEquation(), LinearizeCircleEquation(), LinearizeGeneralEquation(), LinearizeGeneralEquationInt(), LinearizeSphereEquation(), RemoveEquationsWithVar(), SetEquationInfo(), UpdateSplitWeight(), UsedVarInEquations(), and UsedVarInNonDummyEquations().

unsigned int GetEquationNumVariables ( Tequation eq)

Gets the number of variables equation used in the equation.

Parameters
eqThe equation.
Returns
The number of variables in the equation.

Definition at line 1183 of file equation.c.

References GetEquationVariables(), and VariableSetSize().

Referenced by GaussianElimination().

unsigned int CmpEquations ( Tequation eq1,
Tequation eq2 
)

Returns 1 if eq1<eq2, 0 if eq1=eq2 or 2 if eq1>eq2. Equations are sorted according to

  • type
  • order
  • relational operator
  • number of monomials
Parameters
eq1The first equation to compare.
eq2The second equation compare.
Returns
The relative order between the equations.

Definition at line 1188 of file equation.c.

References Tequation::cmp, CmpMonomial(), GetEquationOrder(), Tequation::monomials, Tequation::nMonomials, Tequation::polynomial, Tequation::type, and Tequation::value.

Referenced by AddEquation(), and HasEquation().

void AddScaledMonomial ( double  sc,
Tmonomial f,
Tequation eq 
)

Adds a new scaled monomial to the equation.

When the scale factor (sc) is 1 this is exactly the same as AddMonomial.

Parameters
scThe scale factor.
fThe monomial to add.
eqThe equation.
See Also
CmpMonomial

Definition at line 1263 of file equation.c.

References AddCt2Monomial(), CmpMonomial(), CopyMonomial(), CtMonomial(), DeleteMonomial(), EmptyMonomial(), Error(), FALSE, FindMonomial(), GetMonomialCt(), GetMonomialVariables(), Tequation::maxMonomials, MEM_DUP, MonomialOrder(), Tequation::monomials, NEW, Tequation::nMonomials, NO_UINT, Tequation::order, Tequation::polynomial, PolynomialMonomial(), ResetVarSet(), SetMonomialCt(), TRUE, UnionVarSet(), Tequation::value, Tequation::vars, and ZERO.

Referenced by AccumulateEquations(), and AddMonomial().

void GenerateParabolaEquation ( unsigned int  vx,
unsigned int  vy,
Tequation eq 
)

Generates a parabola equation vx^2-vy=0.

Parameters
vxIdentifier of the x variable.
vyIdentifier of the y variable.
eqThe equation to generate.

Definition at line 1361 of file equation.c.

References GenerateScaledParabolaEquation().

void GenerateScaledParabolaEquation ( double  s,
unsigned int  vx,
unsigned int  vy,
Tequation eq 
)

Generates a parabola equation s*vx^2-vy=0.

Parameters
sThe scale to apply.
vxIdentifier of the x variable.
vyIdentifier of the y variable.
eqThe equation to generate.

Definition at line 1366 of file equation.c.

References AddCt2Monomial(), AddMonomial(), AddVariable2Monomial(), DeleteMonomial(), DUMMY_EQ, EQU, Error(), InitEquation(), InitMonomial(), NFUN, ResetMonomial(), SetEquationCmp(), SetEquationType(), and SetEquationValue().

Referenced by GenerateParabolaEquation(), and GenerateScaledSaddleEquation().

void GenerateSaddleEquation ( unsigned int  vx,
unsigned int  vy,
unsigned int  vz,
Tequation eq 
)

Generates a saddle equation vx*vy-vz=0.

If vx is the same as vy a parabola equation is generated.

Parameters
vxIdentifier of the x variable.
vyIdentifier of the y variable.
vzIdentifier of the z variable.
eqThe equation to generate.

Definition at line 1392 of file equation.c.

References GenerateScaledSaddleEquation().

Referenced by GenerateJointEquations(), and GenerateLinkRotQLinks().

void GenerateScaledSaddleEquation ( double  s,
unsigned int  vx,
unsigned int  vy,
unsigned int  vz,
Tequation eq 
)

Generates a saddle equation s*vx*vy-vz=0.

If vx is the same as vy a scaled parabola equation is generated.

Parameters
sThe scale to apply.
vxIdentifier of the x variable.
vyIdentifier of the y variable.
vzIdentifier of the z variable.
eqThe equation to generate.

Definition at line 1398 of file equation.c.

References AddCt2Monomial(), AddMonomial(), AddVariable2Monomial(), DeleteMonomial(), DUMMY_EQ, EQU, Error(), GenerateScaledParabolaEquation(), InitEquation(), InitMonomial(), NFUN, ResetMonomial(), SetEquationCmp(), SetEquationType(), and SetEquationValue().

Referenced by GenerateLinkRotLinks(), and GenerateSaddleEquation().

void GenerateNormEquation ( unsigned int  vx,
unsigned int  vy,
unsigned int  vz,
double  n,
Tequation eq 
)

This is a special case of GenerateGeneralNormEquation where the vector has only 3 variables.

Parameters
vxThe first variable of the 3d vector.
vyThe second variable of the 3d vector.
vzThe third variable of the 3d vector.
nThe value for the norm.
eqThe equation.

Definition at line 1431 of file equation.c.

References GenerateGeneralNormEquation().

Referenced by AdjustBioWorldGeometry(), GenerateJointEquations(), GenerateLinkRotFLinks(), and GenerateLinkRotLinks().

void GenerateGeneralNormEquation ( unsigned int  nv,
unsigned int *  v,
double  n,
Tequation eq 
)

Generates an equation that is the norm of a vector with nv variables n. Thus, the equation created is

$\sum_{i=1}^{nv}v_i^2=n$
Parameters
nvNumber of variables.
vArray with the index of the variables to use.
nThe value for the norm.
eqThe equation.

Definition at line 1443 of file equation.c.

References AddMonomial(), AddVariable2Monomial(), DeleteMonomial(), EQU, InitEquation(), InitMonomial(), NFUN, ResetMonomial(), SetEquationCmp(), SetEquationType(), SetEquationValue(), and SYSTEM_EQ.

Referenced by AddJacobianEquationsInt(), GenerateNormEquation(), and GetSCpSystem().

void GenerateCrossProductEquations ( unsigned int  v1x,
unsigned int  v1y,
unsigned int  v1z,
unsigned int  v2x,
unsigned int  v2y,
unsigned int  v2z,
unsigned int  v3x,
unsigned int  v3y,
unsigned int  v3z,
unsigned int  vs,
double  s,
Tequation eq 
)

Generates the three equations of the cross product of two unitary vectors that give as a result a third vector (orthogonal to the two operated vectors) scaled by the sinus of the angle between these two vectors.
The equations result from

(v1x,v1y,v1z) X (v2x,v2y,v2z) =sin(v1,v2) * (v3x,v3y,v3z)


The sinus is given as a constant (parameter s) or as another variable (parameter vs).
The input vectors are assumed to be unitary (i.e., it is assumed that other equations already included in the system ensure they have norm one).
This function can be seen as a constructor of three equations at a time.

Parameters
v1xThe first variable of the first vector.
v1yThe second variable of the first vector.
v1zThe third variable of the first vector.
v2xThe first variable of the second vector.
v2yThe second variable of the second vector.
v2zThe third variable of the second vector.
v3xThe first variable of the third vector.
v3yThe second variable of the third vector.
v3zThe third variable of the third vector.
vsVariable representing the sinus of the angle between v1 and v2. NO_UINT if this sinus is constant (given by parameter s).
sConstant sinus between v1 and v2. Not used if vs is different from NO_UINT.
eqArray of three equations to be created.
See Also
GenerateNormEquation

Definition at line 1464 of file equation.c.

References AddCt2Monomial(), AddMonomial(), AddVariable2Monomial(), DeleteMonomial(), EQU, InitEquation(), InitMonomial(), NFUN, NO_UINT, ResetMonomial(), SetEquationCmp(), SetEquationType(), SetEquationValue(), and SYSTEM_EQ.

Referenced by GenerateLinkRotFLinks().

void GenerateDotProductEquation ( unsigned int  v1x,
unsigned int  v1y,
unsigned int  v1z,
unsigned int  v2x,
unsigned int  v2y,
unsigned int  v2z,
unsigned int  vc,
double  c,
Tequation eq 
)

Generates the equation corresponding to the dot product of two unitary vectors that give as a result the cosinus of the angle between these two vectors.
The equation result from

(v1x,v1y,v1z) * (v2x,v2y,v2z) =cos(v1,v2)


The cosinus is given as a constant (parameter c) or as another variable (parameter vc).
The input vectors are assumed to be unitary (i.e., it is assumed that other equations already included in the system ensure they have norm one)..
This function can be seen as an equation constructor.

Parameters
v1xThe first variable of the first vector.
v1yThe second variable of the first vector.
v1zThe third variable of the first vector.
v2xThe first variable of the second vector.
v2yThe second variable of the second vector.
v2zThe third variable of the second vector.
vcVariable representing the cosinus of the angle between v1 and v2. NO_UINT if this cosinus is constant (given by parameter s).
cConstant cosinus between v1 and v2. Not used if vc is different from NO_UINT.
eqThe equation to be created.
See Also
GenerateNormEquation

Definition at line 1526 of file equation.c.

References AddCt2Monomial(), AddMonomial(), AddVariable2Monomial(), DeleteMonomial(), EQU, InitEquation(), InitMonomial(), NFUN, NO_UINT, ResetMonomial(), SetEquationCmp(), SetEquationType(), SetEquationValue(), and SYSTEM_EQ.

Referenced by AdjustBioWorldGeometry(), GenerateJointEquations(), GenerateJointRangeEquations(), GenerateLinkRotFLinks(), and GenerateLinkRotLinks().

unsigned int FindMonomial ( Tmonomial f,
Tequation eq 
)

Searches for a given monomial in the equation.
In this functions, monomials are compare equal taking into account only the variables they involve.

Parameters
fThe monomial to look for.
eqThe equation where to look for.
Returns
The identifier of the monomial in the equation of NO_UINT if the given monomial is not present in the equation.

Definition at line 1561 of file equation.c.

References CmpVarSet(), FALSE, GetMonomialVariables(), Tequation::monomials, NO_UINT, and TRUE.

Referenced by AddScaledMonomial(), and GaussianElimination().

Tmonomial* GetMonomial ( unsigned int  i,
Tequation eq 
)

Gets a monomial from an equation.

Parameters
iThe identifier of the monimial to retrive.
eqThe equation.
Returns
A pointer to the i-th monomial in the equation or NULL if the equation has less than i monomials.

Definition at line 1584 of file equation.c.

References Tequation::monomials.

Referenced by CropEquation(), DummifyAndAddEquation(), GaussianElimination(), LinearizeBilinealMonomialEquation(), LinearizeParabolaEquation(), LinearizeSaddleEquation(), and SetEquationInfo().

unsigned int GetNumMonomials ( Tequation eq)

Returns the number of monomials in an equation.

Parameters
eqThe equation.
Returns
The number of monomials in an equation.

Definition at line 1592 of file equation.c.

References Tequation::nMonomials.

Referenced by AddEquation(), CropEquation(), DummifyAndAddEquation(), GaussianElimination(), SetEquationInfo(), and UpdateCuikSystem().

void LinearEquation2LinearConstraint ( TLinearConstraint lc,
Tequation eq 
)

Converts a linear equation into a linear constraint.

A linear constraint is just a particular case of equation. We implemented the linear constraints as a different type just for convenience (i.e., to facilitate the simplex implementation).

If the input equation is not linear, the output is empty. To approximate a general equation with a linear constraint use GetFirstOrderApproximationToEquation.

Parameters
lcThe resulting linear constraint.
eqThe equation to convert.

Definition at line 1597 of file equation.c.

References AddCt2LinearConstraint(), AddTerm2LinearConstraint(), GetEquationOrder(), GetMonomialCt(), GetMonomialVariables(), GetVariableN(), InitLinearConstraint(), Tequation::monomials, Tequation::nMonomials, Tequation::polynomial, and Tequation::value.

double EvaluateWholeEquation ( double *  varValues,
Tequation eq 
)
inline

Evaluates an equation in a given point including its right-hand side. This is like a combination of EvaluateEquation and GetEquationValue into a single function.

Parameters
varValuesValues defining the point where to evaluate the equation. The array must include values for all the variables in the system (from where the function selects the values for the variables included in the equation).
eqThe equation.
Returns
The value of the equation including the right-hand side.

Definition at line 1615 of file equation.c.

References Tequation::cmp, Error(), EvaluateMonomial(), Tequation::monomials, Tequation::nMonomials, NOCMP, and Tequation::value.

Referenced by EvaluateCSCost(), EvaluateEqMin(), EvaluateEqualityEquations(), EvaluateEqualitySparseEquations(), EvaluateEqVector(), EvaluateSubSetEqualityEquations(), EvaluateSubSetEqualitySparseEquations(), and SHTransformEvaluate().

double EvaluateEquation ( double *  varValues,
Tequation eq 
)

Evaluates an equation in a given point.

NOTE: The right-hand side value of the equation is not used in the evaluation.

Parameters
varValuesValues defining the point where to evaluate the equation. The array must include values for all the variables in the system (from where the function selects the values for the variables included in the equation).
eqThe equation.
Returns
The value of the equation.

Definition at line 1633 of file equation.c.

References Tequation::cmp, Error(), EvaluateMonomial(), Tequation::monomials, Tequation::nMonomials, and NOCMP.

Referenced by EvaluateInequalityEquations().

void EvaluateEquationInt ( Tinterval varValues,
Tinterval i_out,
Tequation eq 
)

Evaluates an equation for a given ranges of the variables using interval arithmetics.
NOTE: The right-hand side value of the equation is not used in the evaluation.

Parameters
varValuesIntervals for the variables in the system of equations. This function only uses the ranges for the variables in the equation.
i_outThe result of the evalution.
eqThe equation.

Definition at line 1649 of file equation.c.

References Tequation::cmp, Error(), EvaluateMonomialInt(), IntervalAdd(), Tequation::monomials, NewInterval(), Tequation::nMonomials, and NOCMP.

Referenced by AddEquation2Simplex(), CropEquation(), ErrorDueToVariable(), EvaluateEqMin(), EvaluateEqVectorInt(), and GetFirstOrderApproximationToEquation().

void DeriveEquation ( unsigned int  nv,
Tequation d,
Tequation eq 
)

Derives an equation with respect to a given variable.

Parameters
nvIdentifier of the variable with respect to the one we have to derive.
dOutput equation with the derivative.
eqThe equation to derive.

Definition at line 1665 of file equation.c.

References AddMonomial(), Tequation::cmp, DeleteMonomial(), DERIVED_EQ, DeriveMonomial(), EQU, InitVarSet(), Tequation::maxMonomials, Tequation::monomials, NEW, Tequation::nMonomials, Tequation::order, Tequation::polynomial, TRUE, Tequation::type, Tequation::value, and Tequation::vars.

Referenced by DeriveEqualityEquations(), and SetEquationInfo().

void PrintMonomials ( FILE *  f,
char **  varNames,
Tequation eq 
)

Writes an equation to a given stream as a sequence of monomials, i.e., without the equality and with the right-hand side at the left side.

This only works if the equation is a equality. Inequalities are always printed as a normal equations

Parameters
fThe stream where to print 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.
eqThe equation with the monomials to print.
See Also
PrintEquation

Definition at line 1692 of file equation.c.

References Tequation::cmp, EQU, Tequation::monomials, Tequation::nMonomials, PrintEquation(), PrintMonomial(), Tequation::value, and ZERO.

Referenced by PrintCuikSystem(), PrintCuikSystemWithSimplification(), and SHTransformPrint().

void PrintEquation ( FILE *  f,
char **  varNames,
Tequation eq 
)

Writes an equation to a given stream.

Parameters
fThe stream where to print 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.
eqThe equation to print.
See Also
PrintMonomial PrintVarSet

Definition at line 1714 of file equation.c.

References Tequation::cmp, EQU, Error(), GEQ, LEQ, Tequation::monomials, Tequation::nMonomials, NOCMP, PrintMonomial(), and Tequation::value.

Referenced by AddEquation2Simplex(), AddSimplifiedJacobianEquations(), CropEquation(), GaussianElimination(), PrintEquations(), and PrintMonomials().