equation.c
Go to the documentation of this file.
1 #include "equation.h"
2 
3 #include "defines.h"
4 
5 #include <string.h>
6 #include <math.h>
7 
25 
33 void PurgeEquation(Tequation *eq);
34 
36 {
37  unsigned int i;
38 
39  eq->polynomial=TRUE;
40 
41  for(i=0;i<eq->nMonomials;i++)
42  {
43  DeleteMonomial(eq->monomials[i]);
44  free(eq->monomials[i]);
45  eq->monomials[i]=NULL;
46  }
47 
48  eq->nMonomials=0;
49 }
50 
52 {
53  Tequation eq1;
54  unsigned int i;
55  boolean changed;
56 
57  InitEquation(&eq1);
58 
59  eq1.cmp=eq->cmp;
60  eq1.type=eq->type;
61 
62  changed=FALSE;
63  if (fabs(eq->value)<=ZERO)
64  {
65  eq1.value=0.0;
66  changed=(eq->value!=0.0);
67  }
68  else
69  eq1.value=eq->value;
70 
71  for(i=0;i<eq->nMonomials;i++)
72  {
73  if (fabs(GetMonomialCt(eq->monomials[i]))>ZERO)
74  AddMonomial(eq->monomials[i],&eq1);
75  else
76  changed=TRUE;
77  }
78  if (changed)
79  {
80  DeleteEquation(eq);
81  CopyEquation(eq,&eq1);
82  }
83  DeleteEquation(&eq1);
84 }
85 
87 {
88  unsigned int i;
89 
90  eq->cmp=NOCMP;
91  eq->type=NOTYPE_EQ;
92  eq->polynomial=TRUE;
93  eq->order=0;
94  eq->value=0.0;
95 
97  eq->nMonomials=0;
99 
100  for(i=0;i<eq->maxMonomials;i++)
101  eq->monomials[i]=NULL;
102 
103  InitVarSet(&(eq->vars));
104 }
105 
107 {
108  Tinterval error;
109  double ct=0;
110  unsigned int cmp=EQU;
111  Tmonomial m;
112  unsigned int i,n;
113 
114  InitEquation(eq);
115 
116  GetLinearConstraintError(&error,lc);
117  if (IntervalSize(&error)==0)
118  {
119  ct=IntervalCenter(&error);
120  cmp=EQU;
121  }
122  else
123  {
124  if (LowerLimit(&error)==-INF)
125  {
126  ct=UpperLimit(&error);
127  cmp=LEQ;
128  }
129  else
130  {
131  if (UpperLimit(&error)==INF)
132  {
133  ct=LowerLimit(&error);
134  cmp=GEQ;
135  }
136  else
137  Error("The input linear constraint can not be converted into a single equation");
138  }
139  }
140  eq->cmp=cmp;
141  eq->value=ct;
142 
144  for(i=0;i<n;i++)
145  {
146  InitMonomial(&m);
149 
150  AddMonomial(&m,eq);
151  DeleteMonomial(&m);
152  }
153 }
154 
155 
157 {
158  Tinterval error1,error2;
159  double ct1,ct2;
160  Tmonomial m;
161  unsigned int i,j,n1,n2;
162 
163  InitEquation(eq);
164 
165  GetLinearConstraintError(&error1,lc1);
166  if (IntervalSize(&error1)==0)
167  ct1=IntervalCenter(&error1);
168  else
169  Error("The input linear constraint can not be converted into an equation");
170 
171  GetLinearConstraintError(&error2,lc2);
172  if (IntervalSize(&error2)==0)
173  ct2=IntervalCenter(&error2);
174  else
175  Error("The input linear constraint can not be converted into an equation");
176 
179  for(i=0;i<n1;i++)
180  {
181  for(j=0;j<n2;j++)
182  {
183  InitMonomial(&m);
186 
189 
190  AddMonomial(&m,eq);
191  DeleteMonomial(&m);
192  }
193  }
194 
195  for(i=0;i<n1;i++)
196  {
197  InitMonomial(&m);
198  AddCt2Monomial(ct2,&m);
201  AddMonomial(&m,eq);
202  DeleteMonomial(&m);
203  }
204 
205  for(j=0;j<n2;j++)
206  {
207  InitMonomial(&m);
208  AddCt2Monomial(ct1,&m);
211  AddMonomial(&m,eq);
212  DeleteMonomial(&m);
213  }
214 }
215 
216 void CopyEquation(Tequation *eq_dst,Tequation *eq_orig)
217 {
218  unsigned int i;
219 
220  eq_dst->cmp=eq_orig->cmp;
221  eq_dst->type=eq_orig->type;
222  eq_dst->polynomial=eq_orig->polynomial;
223  eq_dst->value=eq_orig->value;
224 
225  eq_dst->maxMonomials=eq_orig->maxMonomials;
226  eq_dst->nMonomials=0;
227  NEW(eq_dst->monomials,eq_dst->maxMonomials,Tmonomial*);
228 
229  InitVarSet(&(eq_dst->vars));
230  eq_dst->order=0;
231 
232 
233  for(i=0;i<eq_orig->nMonomials;i++)
234  AddMonomial(eq_orig->monomials[i],eq_dst);
235 }
236 
237 void RewriteEquation2Simp(double epsilon,Tmapping *map,Tequation *eqOut,Tequation *eq)
238 {
239  unsigned int i,nv,o;
240  double ct;
241  unsigned int v,v1,v2;
242  TLinearConstraint lc,lc1,lc2;
243  Tvariable_set *vars;
244  Tequation eqTmp,eqRw;
245 
246  InitEquation(&eqRw);
247  eqRw.cmp=eq->cmp;
248  eqRw.polynomial=eq->polynomial;
249  eqRw.type=eq->type;
250  eqRw.value=eq->value;
251 
252  for(i=0;i<eq->nMonomials;i++)
253  {
254  vars=GetMonomialVariables(eq->monomials[i]);
255  nv=VariableSetSize(vars);
256  switch (nv)
257  {
258  case 0:
259  AddMonomial(eq->monomials[i],&eqRw);
260  break;
261 
262  case 1:
263  if (GetVariableFunctionN(0,vars)!=NFUN)
264  AddMonomial(eq->monomials[i],&eqRw);
265  else
266  {
267  v=GetVariableN(0,vars);
268  GetOriginalVarRelation(v,&lc,map);
269  o=MonomialOrder(eq->monomials[i]);
270 
271  if (o==1)
272  EquationFromLinearConstraint(&lc,&eqTmp);
273  else
274  {
275  if (o==2)
276  EquationFromLinearConstraintProduct(&lc,&lc,&eqTmp);
277  else
278  Error("Cubic factor in a equation");
279  }
280  ct=GetMonomialCt(eq->monomials[i]);
281  AccumulateEquations(&eqTmp,ct,&eqRw);
282 
284  DeleteEquation(&eqTmp);
285  }
286  break;
287 
288  case 2:
289  if ((GetVariableFunctionN(0,vars)!=NFUN)||
290  (GetVariableFunctionN(1,vars)!=NFUN))
291  AddMonomial(eq->monomials[i],&eqRw);
292  else
293  {
294  v1=GetVariableN(0,vars);
295  GetOriginalVarRelation(v1,&lc1,map);
296 
297  v2=GetVariableN(1,vars);
298  GetOriginalVarRelation(v2,&lc2,map);
299 
300  EquationFromLinearConstraintProduct(&lc1,&lc2,&eqTmp);
301  ct=GetMonomialCt(eq->monomials[i]);
302  AccumulateEquations(&eqTmp,ct,&eqRw);
303 
306  DeleteEquation(&eqTmp);
307  }
308  break;
309 
310  default:
311  Error("Only constant, linear or bilinear monomials are allowed");
312  }
313  }
314  PurgeEquation(&eqRw);
315  if (eq==eqOut)
316  DeleteEquation(eq);
317  CopyEquation(eqOut,&eqRw);
318  DeleteEquation(&eqRw);
319 }
320 
322 {
323  unsigned int i,j,nv,vID;
324  Tmonomial f;
325  Tvariable_set *vars;
326  Tequation eqRw;
327 
328  /*
329  All the variables in the simplified system are also in the original one
330  and thus, we only need to replace variable the identifiers for all the monomials
331  in the equation.
332  */
333  InitEquation(&eqRw);
334  eqRw.cmp=eq->cmp;
335  eqRw.type=eq->type;
336  eqRw.polynomial=eq->polynomial;
337  eqRw.value=eq->value;
338 
339  InitMonomial(&f);
340 
341  for(i=0;i<eq->nMonomials;i++)
342  {
343  vars=GetMonomialVariables(eq->monomials[i]);
344  nv=VariableSetSize(vars);
345  for(j=0;j<nv;j++)
346  {
347  vID=GetVarIDInOriginal(GetVariableN(j,vars),map);
348  if (vID==NO_UINT)
349  Error("Simplied var is not in original (RewriteEquation2Orig)");
351  GetVariablePowerN(j,vars),&f);
352  }
353 
354 
356  AddMonomial(&f,&eqRw);
357  ResetMonomial(&f);
358  }
359  DeleteMonomial(&f);
360  if (eq==eqOut)
361  DeleteEquation(eq);
362  CopyEquation(eqOut,&eqRw);
363  DeleteEquation(&eqRw);
364 }
365 
366 void AccumulateEquations(Tequation *eqn,double ct,Tequation *eq)
367 {
368  unsigned int i;
369 
370  for(i=0;i<eqn->nMonomials;i++)
371  AddScaledMonomial(ct,eqn->monomials[i],eq);
372 
373  eq->value+=(ct*eqn->value);
374  PurgeEquation(eq);
375 }
376 
377 void VarAccumulateEquations(Tequation *eqn,unsigned int v,Tequation *eq)
378 {
379  unsigned int i;
380  Tmonomial fnew;
381 
382  for(i=0;i<eqn->nMonomials;i++)
383  {
384  CopyMonomial(&fnew,eqn->monomials[i]);
385  AddVariable2Monomial(NFUN,v,1,&fnew);
386  AddMonomial(&fnew,eq);
387  DeleteMonomial(&fnew);
388  }
389  InitMonomial(&fnew);
390  SetMonomialCt(eqn->value,&fnew);
391  AddVariable2Monomial(NFUN,v,1,&fnew);
392  AddMonomial(&fnew,eq);
393  DeleteMonomial(&fnew);
394 
395  PurgeEquation(eq);
396 }
397 
399 {
400  unsigned int i,j;
401  Tmonomial fnew;
402  Tequation *eq;
403 
404  if ((eq1->cmp!=eq2->cmp)||(eq1->type!=eq2->type))
405  Error("Product of equations of different type in ProductEquations");
406 
407  if ((eqOut==eq1)||(eqOut==eq2))
408  NEW(eq,1,Tequation)
409  else
410  eq=eqOut;
411 
412  InitEquation(eq);
413  eq->cmp=eq->cmp;
414  eq->type=eq->type;
415 
416  for(i=0;i<eq1->nMonomials;i++)
417  {
418  for(j=0;j<eq2->nMonomials;j++)
419  {
420  MonomialProduct(eq1->monomials[i],eq2->monomials[j],&fnew);
421  AddMonomial(&fnew,eq);
422  DeleteMonomial(&fnew);
423  }
424  }
425 
426  AccumulateEquations(eq1,-eq2->value,eq);
427  AccumulateEquations(eq2,-eq1->value,eq);
428 
429  eq->value+=(eq1->value*eq2->value);
430 
431  PurgeEquation(eq);
432 
433  if ((eqOut==eq1)||(eqOut==eq2))
434  {
435  DeleteEquation(eqOut);
436  CopyEquation(eqOut,eq);
437  DeleteEquation(eq);
438  free(eq);
439  }
440 }
441 
443 {
444  eq->cmp=NOCMP;
445  eq->type=NOTYPE_EQ;
446  eq->polynomial=TRUE;
447  eq->value=0.0;
448  eq->order=0;
449 
451 
452  ResetVarSet(&(eq->vars));
453 }
454 
455 /*
456  Returns
457  0: normal case
458  1: the equation becomes constant and it holds
459  2 the equation becomes constant and it does not hold
460 */
461 unsigned int FixVariableInEquation(double epsilon,unsigned int nv,double b,Tequation *eq)
462 {
464  unsigned int r;
465 
467 
468  AddCt2LinearConstraint(b,&lc);
469  r=ReplaceVariableInEquation(epsilon,nv,&lc,eq);
471 
472  return(r);
473 }
474 
475 /*
476  Returns
477  0: normal case
478  1: the equation becomes constant and it holds
479  2 the equation becomes constant and it does not hold
480 */
481 unsigned int ReplaceVariableInEquation(double epsilon,unsigned int nv,
483 {
484  unsigned int n;
485 
487 
488  if ((n<2)||(eq->polynomial))
489  {
490  /* We are either in the case x=ct or x=y or dealing with a monomial without
491  (trigonometric) functions. */
492  unsigned int i,j,k;
493  Tequation eqNew;
494  Tmonomial m;
495  unsigned int np;
496  unsigned int p;
497  Tvariable_set *vm;
498  Tinterval error;
499  double a,a1,ct;
500  unsigned int ind,ind1;
501  unsigned int nvNew;
502 
503  if ((!eq->polynomial)&&(n==1))
504  {
505  nvNew=GetLinearConstraintVariable(0,lc);
506  if (fabs(GetLinearConstraintCoefficient(0,lc)-1.0)>ZERO)
507  Error("For non-polynomial equations only x=ct of x=y replacements are possible");
508  }
509  else
510  nvNew=NO_UINT;
511 
512  InitEquation(&eqNew);
513  SetEquationCmp(GetEquationCmp(eq),(&eqNew));
514  SetEquationType(GetEquationType(eq),(&eqNew));
515  SetEquationValue(GetEquationValue(eq),(&eqNew));
516 
517  GetLinearConstraintError(&error,lc);
518  if (IntervalSize(&error)>ZERO)
519  Error("Only linear constraints with constant offset can be used in simplification");
520  ct=-IntervalCenter(&error);
521 
522  i=0;
523  while(i<eq->nMonomials)
524  {
525  vm=GetMonomialVariables(eq->monomials[i]);
526  np=GetPlaceinSet(nv,vm);
527  if (np!=NO_UINT)
528  {
529  /*The variable is in the monomial */
530  if (!PolynomialMonomial(eq->monomials[i]))
531  {
532  CopyMonomial(&m,eq->monomials[i]);
533  if (nvNew==NO_UINT)
534  FixVariableInMonomial(nv,ct,&m); /* Replace var=ct */
535  else
536  ReplaceVariableInMonomial(nv,1.0,nvNew,&m); /* Replace x=y */
537  AddMonomial(&m,&eqNew);
538  DeleteMonomial(&m);
539  }
540  else
541  {
542  /* Replace var=linear_constraint inside a polynomial monomial */
543  p=GetVariablePowerN(np,vm);
544  if (p==1)
545  {
546  for(k=0;k<n;k++)
547  {
549  ind=GetLinearConstraintVariable(k,lc);
550 
551  CopyMonomial(&m,eq->monomials[i]);
552  AddVariable2Monomial(NFUN,ind,1,&m);
553  FixVariableInMonomial(nv,1,&m);
554  AddCt2Monomial(a,&m);
555  AddMonomial(&m,&eqNew);
556  DeleteMonomial(&m);
557  }
558 
559  CopyMonomial(&m,eq->monomials[i]);
560  FixVariableInMonomial(nv,1,&m);
561  AddCt2Monomial(ct,&m);
562  AddMonomial(&m,&eqNew);
563  DeleteMonomial(&m);
564  }
565  else
566  {
567  /* if we fix a variable (n==0) we do not care about the degree (p).
568  In this case, we do not enter the loop below and we have to take
569  into account that the degree can be larger than 2 */
570  if ((n>0)&&
571  ((p>2)||(VariableSetSize(vm)>1)))
572  Error("Monomials should be lineal, bilineal or quadratic");
573  /* here we have a monomial of the form c*x^2 and we need to
574  apply a subtitution x=a*y+b that gives
575  c*(a*y+b)^2=c*(a^2*y^2+2*a*y*b+b^2)=c*(a*y)^2+c*(2*a*b*y)+c*(b^2)
576  */
577 
578  for(k=0;k<n;k++)
579  {
581  ind=GetLinearConstraintVariable(k,lc);
582 
583  for(j=0;j<n;j++)
584  {
586  ind1=GetLinearConstraintVariable(j,lc);
587 
588  CopyMonomial(&m,eq->monomials[i]);
589  AddVariable2Monomial(NFUN,ind,1,&m);
590  AddVariable2Monomial(NFUN,ind1,1,&m);
591  FixVariableInMonomial(nv,1,&m);
592  AddCt2Monomial(a*a1,&m);
593  AddMonomial(&m,&eqNew);
594  DeleteMonomial(&m);
595  }
596 
597  CopyMonomial(&m,eq->monomials[i]);
598  AddVariable2Monomial(NFUN,ind,1,&m);
599  FixVariableInMonomial(nv,1,&m);
600  AddCt2Monomial(2*a*ct,&m);
601  AddMonomial(&m,&eqNew);
602  DeleteMonomial(&m);
603  }
604 
605  /* Take into account the constant term (the only term if
606  the variable is replaced by a ct) */
607  CopyMonomial(&m,eq->monomials[i]);
608  FixVariableInMonomial(nv,1,&m);
609  AddCt2Monomial(pow(ct,(double)p),&m);
610  AddMonomial(&m,&eqNew);
611  DeleteMonomial(&m);
612  }
613  }
614  }
615  else
616  {
617  CopyMonomial(&m,eq->monomials[i]);
619  AddMonomial(&m,&eqNew);
620  DeleteMonomial(&m);
621  }
622  i++;
623  }
624 
625  DeleteEquation(eq);
626  CopyEquation(eq,&eqNew);
627  DeleteEquation(&eqNew);
628 
629  NormalizeEquation(eq);
630 
631  if (eq->nMonomials>0)
632  return(0);
633  else
634  {
635  boolean hold=TRUE;
636 
637  switch (eq->cmp)
638  {
639  case EQU:
640  hold=(fabs(eq->value)<=epsilon);
641  break;
642  case LEQ:
643  hold=(-epsilon<=eq->value);
644  break;
645  case GEQ:
646  hold=( epsilon>=eq->value);
647  break;
648  }
649 
650  if (!hold)
651  {
652  printf("Ct equation does not hold: %g\n",eq->value);
653  return(2);
654  }
655  else
656  return(1);
657  }
658  }
659  else
660  return(1); /* No replacement */
661 }
662 
663 void CtScaleEquation(double ct,Tequation *eq)
664 {
665  if (eq->cmp==EQU)
666  {
667  unsigned int i;
668 
669  if (fabs(ct)<ZERO)
670  Error("Scaling an equation by 0");
671 
672  for(i=0;i<eq->nMonomials;i++)
673  AddCt2Monomial(ct,eq->monomials[i]);
674  eq->value*=ct;
675  }
676  else
677  Error("CtScaleEquation for non-equalities is not implemented yet");
678 }
679 
680 void VarScaleEquation(unsigned int v,Tequation *eq)
681 {
682  if (eq->cmp==EQU)
683  {
684  unsigned int i;
685  Tmonomial m;
686 
687  ResetVarSet(&(eq->vars));
688  for(i=0;i<eq->nMonomials;i++)
689  {
690  AddVariable2Monomial(NFUN,v,1,eq->monomials[i]);
692  }
693 
694  InitMonomial(&m);
695  AddCt2Monomial(-eq->value,&m);
696  AddVariable2Monomial(NFUN,v,1,&m);
697  AddMonomial(&m,eq);
698  DeleteMonomial(&m);
699 
700  eq->value=0;
701  }
702  else
703  Error("VarScaleEquation for non-equalities is not implemented yet");
704 }
705 
706 /*
707  Simple form of normalization to avoid numerical inestabilities
708  If all monomials have the same ct (up to ZERO) we make them
709  all equal to one.
710  This helps in many cases when we replace variables to avoid
711  transforming a circle equation into a scaled circle equation
712  (that is not identified as a circle!)
713 */
715 {
716  boolean equal;
717  unsigned int i;
718  double s,s1;
719 
720  PurgeEquation(eq);
721  if ((eq->nMonomials>0)&&(eq->cmp==EQU))
722  {
723  /*first monomial is set to possitive*/
724  s=GetMonomialCt(eq->monomials[0]);
725  s=(s<0?-1.0:1.0);
726  for(i=0;i<eq->nMonomials;i++)
727  AddCt2Monomial(s,eq->monomials[i]);
728  eq->value*=s;
729 
730  /* if all constants in the momomials are "almost" the same
731  we set all them to 1 (or -1)*/
732  equal=TRUE;
733  s=GetMonomialCt(eq->monomials[0]); /* s is possitive !! */
734  for(i=1;((equal)&&(i<eq->nMonomials));i++)
735  {
736  s1=GetMonomialCt(eq->monomials[i]);
737  equal=((fabs(s-s1)<=ZERO)||(fabs(s+s1)<=ZERO));
738  }
739 
740  if (equal)
741  {
742  if (fabs(eq->value-s)<=ZERO)
743  eq->value=1;
744  else
745  {
746  if (fabs(eq->value+s)<=ZERO)
747  eq->value=-1;
748  else
749  eq->value/=s;
750  }
751  for(i=0;i<eq->nMonomials;i++)
752  {
753  s1=GetMonomialCt(eq->monomials[i]);
754  if (s1>0)
755  SetMonomialCt(+1,eq->monomials[i]);
756  else
757  SetMonomialCt(-1,eq->monomials[i]);
758  }
759  }
760  }
761 }
762 
763 boolean CleanInfEquation(Tequation *eq_in,Tinterval *varValues,boolean *changed,Tequation *eq_out)
764 {
765  Tinterval m,rhs;
766  boolean bounded;
767  unsigned int i;
768 
769  #if (_DEBUG>6)
770  printf(" Cleaning equation inf\n");
771  #endif
772  InitEquation(eq_out);
773 
774  NewInterval(0,0,&rhs);
775  *changed=FALSE;
776  for(i=0;i<eq_in->nMonomials;i++)
777  {
778  EvaluateMonomialInt(varValues,&m,eq_in->monomials[i]);
779  if (IntervalSize(&m)==INF)
780  {
781  IntervalSubstract(&rhs,&m,&rhs);
782  *changed=TRUE;
783  }
784  else
785  AddMonomial(eq_in->monomials[i],eq_out);
786 
787  #if (_DEBUG>6)
788  printf(" Monomial %u ",i);
789  PrintInterval(stdout,&m);
790  printf(" ->");
791  PrintInterval(stdout,&rhs);
792  printf("\n");
793  #endif
794  }
795 
796  if (*changed)
797  {
798  #if (_DEBUG>6)
799  printf(" Changing equation to rhs ");
800  PrintInterval(stdout,&rhs);
801  printf("\n");
802  #endif
803  if ((LowerLimit(&rhs)==-INF)&&(UpperLimit(&rhs)==+INF))
804  {
805  bounded=FALSE;
806  #if (_DEBUG>6)
807  printf(" Unbounded\n");
808  #endif
809  }
810  else
811  {
812  /* Only one of the extremes of rhs is INF */
813  bounded=TRUE;
814  IntervalOffset(&rhs,eq_in->value,&rhs);
815  #if (_DEBUG>6)
816  printf(" rhs arter offset ");
817  PrintInterval(stdout,&rhs);
818  printf("\n");
819  #endif
820  if (LowerLimit(&rhs)==-INF)
821  {
822  /* upper limit is finite -> <= */
823  eq_out->value=UpperLimit(&rhs);
824  eq_out->cmp=LEQ;
825  #if (_DEBUG>6)
826  printf(" Changing to LEQ %f\n",eq_out->value);
827  #endif
828  }
829  else
830  {
831  /* lower limit is finite -> >= */
832  eq_out->value=UpperLimit(&rhs);
833  eq_out->cmp=GEQ;
834  #if (_DEBUG>6)
835  printf(" Changing to GEQ %f\n",eq_out->value);
836  #endif
837  }
838  }
839  }
840  else
841  {
842  eq_out->cmp=eq_in->cmp;
843  eq_out->type=eq_in->type;
844  eq_out->value=eq_in->value;
845  bounded=TRUE;
846  }
847 
848  return((bounded)&&(eq_out->nMonomials>0));
849 }
850 
851 boolean IsSimplificable(unsigned int simpLevel,unsigned int nTerms,boolean polynomial,
852  boolean *systemVars,Tbox *cb,
853  unsigned int *v,TLinearConstraint *lc,
854  Tequation *eq)
855 {
856  boolean s;
857 
858  s=FALSE;
859  *v=NO_UINT;
860 
861  if ((eq->polynomial)&&
862  (eq->cmp==EQU)&&
863  (simpLevel>0)&&
864  (((simpLevel==1)&&(nTerms==0))||
865  ((simpLevel==2)&&(nTerms<=MAX_TERMS_SIMP))||
866  ((simpLevel==3)&&(nTerms<=MAX_TERMS_SIMP))
867  ))
868  {
869  unsigned int o,nveq,j,l,r;
870  signed int i;
871  double ct;
872  boolean found;
873 
874  o=GetEquationOrder(eq);
875  nveq=VariableSetSize(&(eq->vars));
876 
877  switch(o)
878  {
879  case 1:
880  if (nveq==(nTerms+1))
881  {
882  if (simpLevel<3) /*simpLevel=1,2 -> nTerms = 0,1 -> nveq=1,2*/
883  {
884  /* x=ct */
885  /* x + a * y = ct */
886 
887  found=FALSE;
888  /* two loops, in the first one we try to find a non-system variable
889  we can put in function of other (including system) variables.
890  If this is not possible, we try, as a last resort, to put remove
891  system variables (to put them in function of other variables, possibly
892  non system ones) */
893  for(r=0;((!found)&&(r<2));r++)
894  {
895  /* The loop is tail to head just to get nice results in a particular
896  example. It can be also head to tail without any problem. */
897  i=eq->nMonomials-1;
898  while((!found)&&(i>=0))
899  {
901 
902  if (((r==0)&&(!systemVars[l]))||
903  ((r==1)&&(systemVars[l])))
904  {
905  ct=GetMonomialCt(eq->monomials[i]);
906 
907  if ((ct==1)||(ct==-1))
908  found=TRUE;
909  else
910  i--;
911  }
912  else
913  i--;
914  }
915  }
916  /* When we have matrix or trigonometric equations we are more strict in the variable
917  replacements and only x=ct and x=y are allowed*/
918  if ((found)&&(!polynomial)&&(nveq==2))
919  {
920  double a,b;
921 
922  /* in the case x + a y = ct ensure that we actually have x - y = 0 (or -x + y =0) -> x=y */
923  a=GetMonomialCt(eq->monomials[i]);
924  b=GetMonomialCt(eq->monomials[(i==0?1:0)]);
925  found=(((b==1.0)||(b==-1.0))&&(a!=b)&&(eq->value==0.0));
926  }
927  }
928  else
929  {
930  /*simpLevel=3 -> nTerms=2*/
931  /*General case: a*x+b*y=ct*/
932  unsigned int k;
933  double d,d1,d2,ct1,dm;
934 
935  found=FALSE;
936  /* two loops, in the first one we try to find a non-system variable
937  we can put in function of other (including system) variables.
938  If this is not possible, we try, as a last resort, to put remove
939  system variables (to put them in function of other variables, possibly
940  non system ones) */
941  for(r=0;((!found)&&(r<2));r++)
942  {
943  dm=INF;
944  for(k=0;((!found)&&(k<eq->nMonomials));k++)
945  {
947 
948  if (((r==0)&&(!systemVars[l]))||
949  ((r==1)&&(systemVars[l])))
950  {
951  ct1=GetMonomialCt(eq->monomials[k]);
952  d1=fabs(ct1-1);
953  d2=fabs(ct1+1);
954  d=(d1<d2?d1:d2);
955  if (d<dm)
956  {
957  found=TRUE;
958  i=k;
959  ct=ct1;
960  dm=d;
961  }
962  }
963  }
964  }
965  }
966 
967  if (found)
968  {
971  s=TRUE;
972  for(j=0;j<eq->nMonomials;j++)
973  {
974  if (j!=i)
975  {
977  -GetMonomialCt(eq->monomials[j]),
978  lc
979  );
980  }
981  }
983  if (ct!=1)
984  {
985  if (ct==-1)
987  else
988  ScaleLinearConstraint(1/ct,lc);
989  }
990  }
991  }
992  break;
993  case 2:
994  /* if nveq==1 -> the equation can only have one monomial */
995  if ((nveq==1)&&(nTerms==0))
996  {
997  if (eq->value==0)
998  {
999  /* a x^2 =0 -> x=0 */
1000  s=TRUE;
1001 
1004  }
1005  else
1006  {
1007  if (simpLevel>1)
1008  {
1009  /* a x^2 = b with x in [c,d] c>0 or d<0 -> unique solution */
1011 
1012  if (LowerLimit(GetBoxInterval(*v,cb))>=0)
1013  {
1014  s=TRUE;
1016  AddCt2LinearConstraint(sqrt(eq->value/GetMonomialCt(eq->monomials[0])),lc);
1017  }
1018  else
1019  {
1020  if (UpperLimit(GetBoxInterval(*v,cb))<=0)
1021  {
1022  s=TRUE;
1024  AddCt2LinearConstraint(-sqrt((eq->value/GetMonomialCt(eq->monomials[0]))),lc);
1025  }
1026  }
1027  }
1028  }
1029  }
1030  else
1031  {
1032  if ((nveq==2)&&(eq->nMonomials==1)&&(eq->value==0))
1033  {
1034  Tinterval *range;
1035  unsigned int n;
1036 
1037 
1038  /* a x y = 0 */
1040  range=GetBoxInterval(n,cb);
1041  if (!IsInside(0.0,0.0,range))
1042  {
1043  /* x can not be zero -> y must be zero*/
1045  range=GetBoxInterval(*v,cb);
1046  if (!IsInside(0.0,0.0,range))
1047  Error("Inconsistent input system"); /* y can not be 0 either?? */
1049  s=TRUE;
1050  }
1051  else
1052  {
1054  range=GetBoxInterval(n,cb);
1055  if (!IsInside(0.0,0.0,range))
1056  {
1057  /* y can not be zero -> x must be zero*/
1059  range=GetBoxInterval(*v,cb);
1060  if (!IsInside(0.0,0.0,range))
1061  Error("Inconsistent input system"); /* x can not be 0 either?? */
1063  s=TRUE;
1064  }
1065  }
1066  }
1067  }
1068  break;
1069  }
1070  }
1071 
1072  return(s);
1073 }
1074 
1075 
1076 void SetEquationType(unsigned int type,Tequation *eq)
1077 {
1078  eq->type=type;
1079 }
1080 
1081 void SetEquationCmp(unsigned int cmp,Tequation *eq)
1082 {
1083  if ((cmp!=EQU)&&(cmp!=LEQ)&&(cmp!=GEQ))
1084  Error("Unknow equation cmp");
1085 
1086  eq->cmp=cmp;
1087 }
1088 
1089 void SetEquationValue(double v,Tequation *eq)
1090 {
1091  eq->value=v;
1092 }
1093 
1095 {
1096  return((eq->nMonomials==0)&&(fabs(eq->value)<ZERO));
1097 }
1098 
1100 {
1101  boolean l;
1102  unsigned int i;
1103 
1104  l=eq->polynomial;
1105  for(i=0;((l)&&(i<eq->nMonomials));i++)
1106  {
1107  l=((CtMonomial(eq->monomials[i]))||(LinearMonomial(eq->monomials[i])));
1108  }
1109  return(l);
1110 }
1111 
1113 {
1114  /* A polynomial equation with monomial of order at most two (quadratic or involving
1115  at most two variables) */
1116 
1117  boolean b;
1118  unsigned int i;
1119 
1120  b=eq->polynomial;
1121  for(i=0;((b)&&(i<eq->nMonomials));i++)
1122  {
1123  b=((CtMonomial(eq->monomials[i]))||
1124  (LinearMonomial(eq->monomials[i]))||
1125  (QuadraticMonomial(eq->monomials[i]))||
1126  (BilinearMonomial(eq->monomials[i])));
1127  }
1128  return(b);
1129 }
1130 
1132 {
1133  /* x^2 + y^2 = r^2 */
1134 
1135  boolean c=FALSE;
1136 
1137  if ((eq->polynomial)&&(eq->nMonomials==2)&&(eq->value>0.0)&&
1138  (GetMonomialCt(eq->monomials[0])==1.0)&&(QuadraticMonomial(eq->monomials[0]))&&
1139  (GetMonomialCt(eq->monomials[1])==1.0)&&(QuadraticMonomial(eq->monomials[1])))
1140  c=TRUE;
1141 
1142  return(c);
1143 }
1144 
1146 {
1147  /* x^2 + y^2 + z^2 = r^2 */
1148  boolean s=FALSE;
1149 
1150  if ((eq->polynomial)&&(eq->nMonomials==3)&&(eq->value>0.0)&&
1151  (GetMonomialCt(eq->monomials[0])==1.0)&&(QuadraticMonomial(eq->monomials[0]))&&
1152  (GetMonomialCt(eq->monomials[1])==1.0)&&(QuadraticMonomial(eq->monomials[1]))&&
1153  (GetMonomialCt(eq->monomials[2])==1.0)&&(QuadraticMonomial(eq->monomials[2])))
1154  s=TRUE;
1155 
1156  return(s);
1157 }
1158 
1160 {
1161  /* x*y + \alpha*z = \beta */
1162  boolean s=FALSE;
1163 
1164  if ((eq->polynomial)&&(eq->nMonomials==2)&&(eq->cmp==EQU)&&
1165  (GetMonomialCt(eq->monomials[0])==1.0)&&(BilinearMonomial(eq->monomials[0]))&&
1166  (LinearMonomial(eq->monomials[1])))
1167  s=TRUE;
1168 
1169  return(s);
1170 }
1171 
1173 {
1174  /* x*y = \beta */
1175  boolean s=FALSE;
1176 
1177  if ((eq->polynomial)&&(eq->nMonomials==1)&&(eq->cmp==EQU)&&
1178  (GetMonomialCt(eq->monomials[0])==1.0)&&(BilinearMonomial(eq->monomials[0])))
1179  s=TRUE;
1180 
1181  return(s);
1182 }
1183 
1185 {
1186  /* x^2 + \alpha*y = \beta */
1187  boolean s=FALSE;
1188 
1189  if ((eq->polynomial)&&(eq->nMonomials==2)&&(eq->cmp==EQU)&&
1190  (GetMonomialCt(eq->monomials[0])==1.0)&&(QuadraticMonomial(eq->monomials[0]))&&
1191  (LinearMonomial(eq->monomials[1])))
1192  s=TRUE;
1193 
1194  return(s);
1195 }
1196 
1198 {
1199  return(eq->polynomial);
1200 }
1201 
1202 inline unsigned int GetEquationCmp(Tequation *eq)
1203 {
1204  return(eq->cmp);
1205 }
1206 
1207 inline unsigned int GetEquationType(Tequation *eq)
1208 {
1209  return(eq->type);
1210 }
1211 
1212 inline double GetEquationValue(Tequation *eq)
1213 {
1214  return(eq->value);
1215 }
1216 
1218 {
1219  switch(eq->cmp)
1220  {
1221  case EQU:
1222  NewInterval(eq->value,eq->value,bounds);
1223  break;
1224  case GEQ:
1225  NewInterval(eq->value,+INF,bounds);
1226  break;
1227  case LEQ:
1228  NewInterval(-INF,eq->value,bounds);
1229  break;
1230  case NOCMP:
1231  Error("Undefined equation cmp in GetEquationBounds");
1232  break;
1233  }
1234 }
1235 
1236 unsigned int GetEquationOrder(Tequation *eq)
1237 {
1238  return(eq->order);
1239 }
1240 
1242 {
1243  return(&(eq->vars));
1244 }
1245 
1247 {
1249 }
1250 
1251 unsigned int CmpEquations(Tequation *eq1,Tequation *eq2)
1252 {
1253 
1254  unsigned int r;
1255 
1256  if (eq1->polynomial<eq2->polynomial)
1257  r=2;
1258  else
1259  if (eq2->polynomial<eq1->polynomial)
1260  r=1;
1261  else
1262  {
1263  if (eq1->type<eq2->type)
1264  r=2;
1265  else
1266  {
1267  if (eq2->type<eq1->type)
1268  r=1;
1269  else
1270  {
1271  /* Here both equations are of the same type */
1272  unsigned int o1,o2;
1273 
1274  o1=GetEquationOrder(eq1);
1275  o2=GetEquationOrder(eq2);
1276 
1277  if ((eq1->cmp>eq2->cmp)||
1278  ((eq1->cmp==eq2->cmp)&&(o1>o2))||
1279  ((eq1->cmp==eq2->cmp)&&(o1==o2)&&(eq1->nMonomials>eq2->nMonomials)))
1280  r=1;
1281  else
1282  {
1283  if ((eq2->cmp>eq1->cmp)||
1284  ((eq1->cmp==eq2->cmp)&&(o2>o1))||
1285  ((eq1->cmp==eq2->cmp)&&(o1==o2)&&(eq2->nMonomials>eq1->nMonomials)))
1286  r=2;
1287  else
1288  {
1289  /*the two equations have the same cmp, order, and number of monomials*/
1290  unsigned int i;
1291 
1292  i=0;
1293  r=0;
1294  while ((i<eq1->nMonomials)&&(r==0))
1295  {
1296  r=CmpMonomial(eq1->monomials[i],eq2->monomials[i]);
1297  if (r==0)
1298  i++;
1299  }
1300 
1301  if (r==0)
1302  {
1303  /*the 2 equations have the same order and the same
1304  set of monomials. We compare the value*/
1305  if (eq1->value>eq2->value)
1306  r=1;
1307  else
1308  {
1309  if (eq2->value>eq1->value)
1310  r=2;
1311  else
1312  r=0;
1313  }
1314  }
1315  }
1316  }
1317  }
1318  }
1319  }
1320  if (r!=0)
1321  return(2);
1322  else
1323  return(r);
1324 }
1325 
1326 void AddScaledMonomial(double sc,Tmonomial* f,Tequation *eq)
1327 {
1328  double ct;
1329 
1330  ct=sc*GetMonomialCt(f);
1331 
1332  /* Ensure that we are not adding an empty monomial */
1333  if ((!EmptyMonomial(f))&&(fabs(ct)>ZERO))
1334  {
1335  if (CtMonomial(f))
1336  eq->value-=ct;
1337  else
1338  {
1339  unsigned int j;
1340 
1341  j=FindMonomial(f,eq);
1342 
1343  if (j!=NO_UINT)
1344  {
1345  /* The equation already has a monomial with the same equations as the
1346  one we are adding -> just add the constants*/
1347  SetMonomialCt(GetMonomialCt(eq->monomials[j])+ct,eq->monomials[j]);
1348 
1349  if (CtMonomial(eq->monomials[j]))
1350  {
1351  unsigned int n,o;
1352 
1353  /* A non-constant monomial can only become constant if it
1354  becomes 0 */
1355  if (fabs(GetMonomialCt(eq->monomials[j]))>ZERO)
1356  Error("Non Zero constant monomial");
1357 
1358  /*If the monomial becomes ct (i.e., 0) we have to compact the
1359  monomials and recompute the varset for the equation*/
1360 
1361  /*Remove the Zeroed monomial from the equation*/
1362  DeleteMonomial(eq->monomials[j]);
1363  free(eq->monomials[j]);
1364 
1365  for(n=j+1;n<eq->nMonomials;n++)
1366  eq->monomials[n-1]=eq->monomials[n];
1367  eq->nMonomials--;
1368  eq->monomials[eq->nMonomials]=NULL;
1369 
1370  /*Recompute the variables in the equation, the monomial flag, and the order */
1371  ResetVarSet(&(eq->vars));
1372  eq->polynomial=TRUE;
1373  eq->order=0;
1374  for(n=0;n<eq->nMonomials;n++)
1375  {
1377  eq->polynomial=((eq->polynomial)&&(PolynomialMonomial(eq->monomials[n])));
1378  o=MonomialOrder(f);
1379  if (o>eq->order)
1380  eq->order=o;
1381  }
1382  }
1383  }
1384  else
1385  {
1386  /* A new (not null) monomial -> add it to the equation */
1387  unsigned int o,j;
1388  Tmonomial *s;
1389 
1390  if (eq->nMonomials==eq->maxMonomials)
1392 
1393  NEW(eq->monomials[eq->nMonomials],1,Tmonomial);
1394  CopyMonomial(eq->monomials[eq->nMonomials],f);
1395  AddCt2Monomial(sc,eq->monomials[eq->nMonomials]);
1396  eq->nMonomials++;
1397 
1398  o=MonomialOrder(f);
1399  if (eq->order<o)
1400  eq->order=o;
1401 
1403 
1404  j=eq->nMonomials-1;
1405  while((j>0)&&(CmpMonomial(eq->monomials[j-1],eq->monomials[j])==1))
1406  {
1407  s=eq->monomials[j-1];
1408  eq->monomials[j-1]=eq->monomials[j];
1409  eq->monomials[j]=s;
1410 
1411  j--;
1412  }
1413  eq->polynomial=((eq->polynomial)&&(PolynomialMonomial(f)));
1414  }
1415  }
1416  }
1417 }
1418 
1419 inline void AddMonomial(Tmonomial* f,Tequation *eq)
1420 {
1421  AddScaledMonomial(1.0,f,eq);
1422 }
1423 
1424 void GenerateParabolaEquation(unsigned int vx,unsigned int vy,Tequation *eq)
1425 {
1426  GenerateScaledParabolaEquation(1,vx,vy,eq);
1427 }
1428 
1430  unsigned int vx,unsigned int vy,Tequation *eq)
1431 {
1432  Tmonomial f;
1433 
1434  if (s==0)
1435  Error("Defining a scaled parabola equation with scale equal to 0.");
1436 
1437  InitEquation(eq);
1438  InitMonomial(&f);
1439 
1440  AddVariable2Monomial(NFUN,vx,2,&f);
1441  AddMonomial(&f,eq);
1442  ResetMonomial(&f);
1443 
1444  AddVariable2Monomial(NFUN,vy,1,&f);
1445  AddCt2Monomial(-s,&f);
1446  AddMonomial(&f,eq);
1447 
1448  DeleteMonomial(&f);
1449 
1450  SetEquationCmp(EQU,eq);
1451  SetEquationValue(0,eq);
1453 }
1454 
1455 void GenerateSaddleEquation(unsigned int vx,unsigned int vy,unsigned int vz,
1456  Tequation *eq)
1457 {
1458  GenerateScaledSaddleEquation(1,vx,vy,vz,eq);
1459 }
1460 
1462  unsigned int vx,unsigned int vy,unsigned int vz,
1463  Tequation *eq)
1464 {
1465  if (s==0)
1466  Error("Defining a scaled saddle equation with scale equal to 0.");
1467 
1468  if (vx==vy)
1469  GenerateScaledParabolaEquation(s,vx,vz,eq);
1470  else
1471  {
1472  Tmonomial f;
1473 
1474  InitEquation(eq);
1475  InitMonomial(&f);
1476 
1477  AddVariable2Monomial(NFUN,vx,1,&f);
1478  AddVariable2Monomial(NFUN,vy,1,&f);
1479  AddMonomial(&f,eq);
1480  ResetMonomial(&f);
1481 
1482  AddVariable2Monomial(NFUN,vz,1,&f);
1483  AddCt2Monomial(-s,&f);
1484  AddMonomial(&f,eq);
1485 
1486  DeleteMonomial(&f);
1487 
1488  SetEquationCmp(EQU,eq);
1489  SetEquationValue(0,eq);
1491  }
1492 }
1493 
1494 void GenerateNormEquation(unsigned int vx,unsigned int vy,unsigned int vz,
1495  double n,
1496  Tequation *eq)
1497 {
1498  unsigned int v[3];
1499 
1500  v[0]=vx;
1501  v[1]=vy;
1502  v[2]=vz;
1503  GenerateGeneralNormEquation(3,v,n,eq);
1504 }
1505 
1506 void GenerateGeneralNormEquation(unsigned int nv,unsigned int *v,double n,Tequation *eq)
1507 {
1508  Tmonomial f;
1509  unsigned int i;
1510 
1511  InitEquation(eq);
1512 
1513  InitMonomial(&f);
1514  for(i=0;i<nv;i++)
1515  {
1516  AddVariable2Monomial(NFUN,v[i],2,&f);
1517  AddMonomial(&f,eq);
1518  ResetMonomial(&f);
1519  }
1520  DeleteMonomial(&f);
1521 
1522  SetEquationCmp(EQU,eq);
1523  SetEquationValue(n,eq);
1525 }
1526 
1527 void GenerateCrossProductEquations(unsigned int v1x,unsigned int v1y,unsigned int v1z,
1528  unsigned int v2x,unsigned int v2y,unsigned int v2z,
1529  unsigned int v3x,unsigned int v3y,unsigned int v3z,
1530  unsigned int vs,
1531  double s,
1532  Tequation *eq)
1533 {
1534  Tmonomial f;
1535  unsigned int i;
1536 
1537  for(i=0;i<3;i++)
1538  InitEquation(&(eq[i]));
1539 
1540  InitMonomial(&f);
1541 
1542  AddCt2Monomial(+1.0,&f);AddVariable2Monomial(NFUN,v1y,1,&f);AddVariable2Monomial(NFUN,v2z,1,&f);
1543  AddMonomial(&f,&(eq[0]));ResetMonomial(&f);
1544  AddCt2Monomial(-1.0,&f);AddVariable2Monomial(NFUN,v1z,1,&f);AddVariable2Monomial(NFUN,v2y,1,&f);
1545  AddMonomial(&f,&(eq[0]));ResetMonomial(&f);
1546  AddCt2Monomial(-1,&f);
1547  if (vs==NO_UINT)
1548  AddCt2Monomial(s,&f);
1549  else
1550  AddVariable2Monomial(NFUN,vs,1,&f);
1551  AddVariable2Monomial(NFUN,v3x,1,&f);
1552  AddMonomial(&f,&(eq[0]));ResetMonomial(&f);
1553 
1554  AddCt2Monomial(+1.0,&f);AddVariable2Monomial(NFUN,v1z,1,&f);AddVariable2Monomial(NFUN,v2x,1,&f);
1555  AddMonomial(&f,&(eq[1]));ResetMonomial(&f);
1556  AddCt2Monomial(-1.0,&f);AddVariable2Monomial(NFUN,v1x,1,&f);AddVariable2Monomial(NFUN,v2z,1,&f);
1557  AddMonomial(&f,&(eq[1]));ResetMonomial(&f);
1558  AddCt2Monomial(-1,&f);
1559  if (vs==NO_UINT)
1560  AddCt2Monomial(s,&f);
1561  else
1562  AddVariable2Monomial(NFUN,vs,1,&f);
1563  AddVariable2Monomial(NFUN,v3y,1,&f);
1564  AddMonomial(&f,&(eq[1]));ResetMonomial(&f);
1565 
1566  AddCt2Monomial(+1.0,&f);AddVariable2Monomial(NFUN,v1x,1,&f);AddVariable2Monomial(NFUN,v2y,1,&f);
1567  AddMonomial(&f,&(eq[2]));ResetMonomial(&f);
1568  AddCt2Monomial(-1.0,&f);AddVariable2Monomial(NFUN,v1y,1,&f);AddVariable2Monomial(NFUN,v2x,1,&f);
1569  AddMonomial(&f,&(eq[2]));ResetMonomial(&f);
1570  AddCt2Monomial(-1,&f);
1571  if (vs==NO_UINT)
1572  AddCt2Monomial(s,&f);
1573  else
1574  AddVariable2Monomial(NFUN,vs,1,&f);
1575  AddVariable2Monomial(NFUN,v3z,1,&f);
1576  AddMonomial(&f,&(eq[2]));
1577 
1578  DeleteMonomial(&f);
1579 
1580  for(i=0;i<3;i++)
1581  {
1582  SetEquationCmp(EQU,&(eq[i]));
1583  SetEquationValue(0.0,&(eq[i]));
1584  SetEquationType(SYSTEM_EQ,&(eq[i]));
1585  }
1586 }
1587 
1588 void GenerateDotProductEquation(unsigned int v1x,unsigned int v1y,unsigned int v1z,
1589  unsigned int v2x,unsigned int v2y,unsigned int v2z,
1590  unsigned int vc,
1591  double c,
1592  Tequation *eq)
1593 {
1594  Tmonomial f;
1595 
1596  InitEquation(eq);
1597 
1598  InitMonomial(&f);
1599 
1600  AddCt2Monomial(+1.0,&f);AddVariable2Monomial(NFUN,v1x,1,&f);AddVariable2Monomial(NFUN,v2x,1,&f);
1601  AddMonomial(&f,eq);ResetMonomial(&f);
1602  AddCt2Monomial(+1.0,&f);AddVariable2Monomial(NFUN,v1y,1,&f);AddVariable2Monomial(NFUN,v2y,1,&f);
1603  AddMonomial(&f,eq);ResetMonomial(&f);
1604  AddCt2Monomial(+1.0,&f);AddVariable2Monomial(NFUN,v1z,1,&f);AddVariable2Monomial(NFUN,v2z,1,&f);
1605  AddMonomial(&f,eq);ResetMonomial(&f);
1606 
1607  if (vc!=NO_UINT)
1608  {
1609  AddCt2Monomial(-1.0,&f);AddVariable2Monomial(NFUN,vc,1,&f);
1610  AddMonomial(&f,eq);ResetMonomial(&f);
1611  SetEquationValue(0.0,eq);
1612  }
1613  else
1614  SetEquationValue(c,eq);
1615 
1616  DeleteMonomial(&f);
1617 
1618  SetEquationCmp(EQU,eq);
1620 
1621 }
1622 
1623 void GenerateDistanceEquation(unsigned int v1x,unsigned int v1y,unsigned int v1z,
1624  unsigned int v2x,unsigned int v2y,unsigned int v2z,
1625  unsigned int vc,
1626  double c,
1627  Tequation *eq)
1628 {
1629  Tmonomial f;
1630 
1631  InitEquation(eq);
1632 
1633  InitMonomial(&f);
1634 
1635  /* (a-b)^2=a^2-2*a*b+b^2 added for X, Y, and Z*/
1636  AddVariable2Monomial(NFUN,v1x,2,&f);
1637  AddMonomial(&f,eq);ResetMonomial(&f);
1638  AddCt2Monomial(-2.0,&f);AddVariable2Monomial(NFUN,v1x,1,&f);AddVariable2Monomial(NFUN,v2x,1,&f);
1639  AddMonomial(&f,eq);ResetMonomial(&f);
1640  AddVariable2Monomial(NFUN,v2x,2,&f);
1641  AddMonomial(&f,eq);ResetMonomial(&f);
1642 
1643  AddVariable2Monomial(NFUN,v1y,2,&f);
1644  AddMonomial(&f,eq);ResetMonomial(&f);
1645  AddCt2Monomial(-2.0,&f);AddVariable2Monomial(NFUN,v1y,1,&f);AddVariable2Monomial(NFUN,v2y,1,&f);
1646  AddMonomial(&f,eq);ResetMonomial(&f);
1647  AddVariable2Monomial(NFUN,v2y,2,&f);
1648  AddMonomial(&f,eq);ResetMonomial(&f);
1649 
1650  AddVariable2Monomial(NFUN,v1z,2,&f);
1651  AddMonomial(&f,eq);ResetMonomial(&f);
1652  AddCt2Monomial(-2.0,&f);AddVariable2Monomial(NFUN,v1z,1,&f);AddVariable2Monomial(NFUN,v2z,1,&f);
1653  AddMonomial(&f,eq);ResetMonomial(&f);
1654  AddVariable2Monomial(NFUN,v2z,2,&f);
1655  AddMonomial(&f,eq);ResetMonomial(&f);
1656 
1657  if (vc!=NO_UINT)
1658  {
1659  AddCt2Monomial(-1.0,&f);AddVariable2Monomial(NFUN,vc,1,&f);
1660  AddMonomial(&f,eq);ResetMonomial(&f);
1661  SetEquationValue(0.0,eq);
1662  }
1663  else
1664  SetEquationValue(c,eq);
1665 
1666  DeleteMonomial(&f);
1667 
1668  SetEquationCmp(EQU,eq);
1670 }
1671 
1672 unsigned int FindMonomial(Tmonomial *f,Tequation *eq)
1673 {
1674  unsigned int j;
1675  boolean found;
1676  Tvariable_set *vf;
1677 
1678  vf=GetMonomialVariables(f);
1679 
1680  found=FALSE;
1681  j=0;
1682  while((j<eq->nMonomials)&&(!found))
1683  {
1684  if (CmpVarSet(vf,GetMonomialVariables(eq->monomials[j]))==0)
1685  found=TRUE;
1686  else
1687  j++;
1688  }
1689  if (found)
1690  return(j);
1691  else
1692  return(NO_UINT);
1693 }
1694 
1695 Tmonomial *GetMonomial(unsigned int i,Tequation *eq)
1696 {
1697  if (i<eq->nMonomials)
1698  return(eq->monomials[i]);
1699  else
1700  return(NULL);
1701 }
1702 
1703 unsigned int GetNumMonomials(Tequation *eq)
1704 {
1705  return(eq->nMonomials);
1706 }
1707 
1709 {
1711  if ((eq->polynomial)&&(GetEquationOrder(eq)<2))
1712  {
1713  unsigned int i,v;
1714  double ct;
1715 
1716  for(i=0;i<eq->nMonomials;i++)
1717  {
1719  ct=GetMonomialCt(eq->monomials[i]);
1720  AddTerm2LinearConstraint(v,ct,lc);
1721  }
1722  AddCt2LinearConstraint(-eq->value,lc);
1723  }
1724 }
1725 
1726 inline double EvaluateWholeEquation(double *varValues,Tequation *eq)
1727 {
1728  double v;
1729  unsigned int i;
1730 
1731  #if (_DEBUG>2)
1732  if (eq->cmp==NOCMP)
1733  Error("Evaluation of an undefined equation");
1734  #endif
1735 
1736  v=-eq->value;
1737 
1738  for(i=0;i<eq->nMonomials;i++)
1739  v+=EvaluateMonomial(varValues,eq->monomials[i]);
1740 
1741  return(v);
1742 }
1743 
1744 double EvaluateEquation(double *varValues,Tequation *eq)
1745 {
1746  double v;
1747  unsigned int i;
1748 
1749  if (eq->cmp==NOCMP)
1750  Error("Evaluation of an undefined equation");
1751 
1752  v=0.0;
1753 
1754  for(i=0;i<eq->nMonomials;i++)
1755  v+=EvaluateMonomial(varValues,eq->monomials[i]);
1756 
1757  return(v);
1758 }
1759 
1761 {
1762  unsigned int i;
1763  Tinterval i_aux;
1764 
1765  if (eq->cmp==NOCMP)
1766  Error("Evaluation of an undefined equation");
1767 
1768  NewInterval(0,0,i_out);
1769  for(i=0;i<eq->nMonomials;i++)
1770  {
1771  EvaluateMonomialInt(varValues,&i_aux,eq->monomials[i]);
1772  IntervalAdd(i_out,&i_aux,i_out);
1773  }
1774 }
1775 
1776 void DeriveEquation(unsigned int nv,Tequation *d,Tequation *eq)
1777 {
1778  Tmonomial f;
1779  unsigned int i;
1780 
1781  d->cmp=EQU;
1782  d->type=DERIVED_EQ;
1783  d->polynomial=TRUE;
1784  d->order=0.0;
1785  d->value=0.0;
1786 
1787  d->maxMonomials=eq->maxMonomials;
1788  d->nMonomials=0;
1790 
1791  for(i=0;i<d->maxMonomials;i++)
1792  d->monomials[i]=NULL;
1793  InitVarSet(&(d->vars));
1794 
1795  for(i=0;i<eq->nMonomials;i++)
1796  {
1797  DeriveMonomial(nv,&f,eq->monomials[i]);
1798  AddMonomial(&f,d);
1799  DeleteMonomial(&f);
1800  }
1801 }
1802 
1803 void PrintMonomials(FILE *f,char **varNames,Tequation *eq)
1804 {
1805  unsigned int i;
1806 
1807  if (eq->cmp!=EQU)
1808  PrintEquation(f,varNames,eq);
1809  else
1810  {
1811  for(i=0;i<eq->nMonomials;i++)
1812  PrintMonomial(f,(i==0),varNames,eq->monomials[i]);
1813 
1814  if (fabs(eq->value)>ZERO)
1815  fprintf(f,"%+.12g",-eq->value);
1816  else
1817  {
1818  if (eq->nMonomials==0)
1819  fprintf(f,"0");
1820  }
1821  fprintf(f,"\n");
1822  }
1823 }
1824 
1825 void PrintEquation(FILE *f,char **varNames,Tequation *eq)
1826 {
1827  unsigned int i;
1828  double s;
1829 
1830  fprintf(f," ");
1831  for(i=0;i<eq->nMonomials;i++)
1832  PrintMonomial(f,(i==0),varNames,eq->monomials[i]);
1833 
1834  if (eq->nMonomials>0)
1835  {
1836  switch(eq->cmp)
1837  {
1838  case EQU:
1839  fprintf(f," = ");
1840  break;
1841  case GEQ:
1842  fprintf(f," >= ");
1843  break;
1844  case LEQ:
1845  fprintf(f," <= ");
1846  break;
1847  case NOCMP:
1848  fprintf(f,"??\n");
1849  Error("Unkown equation type in PrintEquation");
1850  break;
1851  }
1852  s=1.0;
1853  }
1854  else
1855  s=-1.0;
1856  fprintf(f,"%.12g;\n",s*eq->value);
1857 }
1858 
1860 {
1862  free(eq->monomials);
1863 
1864  DeleteVarSet(&(eq->vars));
1865 }
void DeleteVarSet(Tvariable_set *vs)
Destructor.
Definition: variable_set.c:876
Definition of the Tequation type and the associated functions.
void DeleteLinearConstraint(TLinearConstraint *lc)
Destructor.
void RewriteEquation2Simp(double epsilon, Tmapping *map, Tequation *eqOut, Tequation *eq)
Applies the simplification mapping to an equation.
Definition: equation.c:237
Tinterval * GetBoxInterval(unsigned int n, Tbox *b)
Returns a pointer to one of the intervals defining the box.
Definition: box.c:270
double EvaluateWholeEquation(double *varValues, Tequation *eq)
Evaluates an equation in a given point.
Definition: equation.c:1726
#define SYSTEM_EQ
One of the possible type of equations.
Definition: equation.h:146
Tmonomial * GetMonomial(unsigned int i, Tequation *eq)
Gets a monomial from an equation.
Definition: equation.c:1695
void DeriveEquation(unsigned int nv, Tequation *d, Tequation *eq)
Derives an equation.
Definition: equation.c:1776
#define FALSE
FALSE.
Definition: boolean.h:30
void GenerateSaddleEquation(unsigned int vx, unsigned int vy, unsigned int vz, Tequation *eq)
Construtor. Generates a saddle equation.
Definition: equation.c:1455
void DeriveMonomial(unsigned int nv, Tmonomial *df, Tmonomial *f)
Derives an monomial.
Definition: monomial.c:238
boolean BilinealMonomialEquation(Tequation *eq)
Identify single bilineal monomial equations.
Definition: equation.c:1172
void SetMonomialCt(double k, Tmonomial *f)
Changes the scale factor of a monomial.
Definition: monomial.c:144
void SetEquationType(unsigned int type, Tequation *eq)
Changes the type of the equation (SYSTEM_EQ, CARTESIAN_EQ, DUMMY_EQ, DERIVED_EQ). ...
Definition: equation.c:1076
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.
Definition: equation.c:1527
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
void MonomialProduct(Tmonomial *f1, Tmonomial *f2, Tmonomial *f)
Product of two monomials.
Definition: monomial.c:183
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.
Definition: equation.c:1494
boolean LinearMonomial(Tmonomial *f)
Checks if a monomial is lienal: K*x, with K a constant.
Definition: monomial.c:79
void EvaluateEquationInt(Tinterval *varValues, Tinterval *i_out, Tequation *eq)
Interval evaluation of an equation.
Definition: equation.c:1760
A linear constraint with an associated error.
void DeleteEquation(Tequation *eq)
Destructor.
Definition: equation.c:1859
unsigned int GetVarIDInOriginal(unsigned int v, Tmapping *m)
Gets the original identifier of a simplified variable.
Definition: csmapping.c:135
void AddScaledMonomial(double sc, Tmonomial *f, Tequation *eq)
Adds a new scaled monomial to the equation.
Definition: equation.c:1326
boolean CtMonomial(Tmonomial *f)
Checks if a monomial is constant.
Definition: monomial.c:58
void LinearEquation2LinearConstraint(TLinearConstraint *lc, Tequation *eq)
Converts a linear equation into a linear constraint.
Definition: equation.c:1708
void IntervalAdd(Tinterval *i1, Tinterval *i2, Tinterval *i_out)
Addition of two intervals.
Definition: interval.c:423
unsigned int GetEquationNumVariables(Tequation *eq)
Gets the number of variables equation used in the equation.
Definition: equation.c:1246
double EvaluateEquation(double *varValues, Tequation *eq)
Evaluates an equation in a given point.
Definition: equation.c:1744
void CopyEquation(Tequation *eq_dst, Tequation *eq_orig)
Copy constructor.
Definition: equation.c:216
#define EQU
In a Tequation, the equation relational operator is equal.
Definition: equation.h:202
#define DUMMY_EQ
One of the possible type of equations.
Definition: equation.h:164
void InitLinearConstraint(TLinearConstraint *lc)
Constructor.
unsigned int maxMonomials
Definition: equation.h:246
void UnionVarSet(boolean fun, Tvariable_set *vs_new, Tvariable_set *vs)
Produces a variable set that is the union of two variable sets.
Definition: variable_set.c:221
boolean EmptyMonomial(Tmonomial *f)
Checks if a monomial is empty.
Definition: monomial.c:53
void GenerateParabolaEquation(unsigned int vx, unsigned int vy, Tequation *eq)
Construtor. Generates a parabola equation.
Definition: equation.c:1424
unsigned int ReplaceVariableInEquation(double epsilon, unsigned int nv, TLinearConstraint *lc, Tequation *eq)
Replaces a variable.
Definition: equation.c:481
unsigned int GetLinearConstraintVariable(unsigned int i, TLinearConstraint *lc)
Gets the a particular variable index.
#define INIT_NUM_MONOMIALS
Initial room for monomials.
Definition: equation.h:40
#define TRUE
TRUE.
Definition: boolean.h:21
Mapping between the sets of variables in two different cuiksystems.
Definition: csmapping.h:53
#define LEQ
In a Tequation, the equation relational operator is less equal.
Definition: equation.h:196
void ResetEquationMonomials(Tequation *eq)
Resets the information about monomials stored in the equation.
Definition: equation.c:35
unsigned int CmpEquations(Tequation *eq1, Tequation *eq2)
Equation comparison.
Definition: equation.c:1251
unsigned int nMonomials
Definition: equation.h:247
void InitEquation(Tequation *eq)
Constructor.
Definition: equation.c:86
Tmonomial ** monomials
Definition: equation.h:248
void Error(const char *s)
General error function.
Definition: error.c:80
#define NFUN
No trigonometric function for the variable.
Definition: variable_set.h:36
void InvertLinearConstraint(TLinearConstraint *lc)
Changes the sign of a linear constraint.
#define NOCMP
In a Tequation, the equation relational operator is not defined yet.
Definition: equation.h:208
void ResetVarSet(Tvariable_set *vs)
Resets the information stored in a variable set.
Definition: variable_set.c:79
void FixVariableInMonomial(unsigned int nv, double v, Tmonomial *f)
Replaces a variable by a constant.
Definition: monomial.c:31
double EvaluateMonomial(double *varValues, Tmonomial *f)
Evaluates a monomial for a given set of value for the variables.
Definition: monomial.c:197
#define ZERO
Floating point operations giving a value below this constant (in absolute value) are considered 0...
Definition: defines.h:37
void AddTerm2LinearConstraint(unsigned int ind, double val, TLinearConstraint *lc)
Adds a scaled variable to the linear constraint.
unsigned int CmpVarSet(Tvariable_set *vs1, Tvariable_set *vs2)
Variable set comparison.
Definition: variable_set.c:112
void SetEquationValue(double v, Tequation *eq)
Changes the right-hand value of the equation.
Definition: equation.c:1089
unsigned int GetPlaceinSet(unsigned int id, Tvariable_set *vs)
Gets the position of a variable index in a set of variable indexes.
Definition: variable_set.c:165
Tvariable_set vars
Definition: equation.h:250
void AddMonomial(Tmonomial *f, Tequation *eq)
Adds a new monomial to the equation.
Definition: equation.c:1419
unsigned int cmp
Definition: equation.h:242
unsigned int GetVariableFunctionN(unsigned int n, Tvariable_set *vs)
Gets a variable function from a variable set.
Definition: variable_set.c:481
#define GEQ
In a Tequation, the equation relational operator is great equal.
Definition: equation.h:190
boolean IsSimplificable(unsigned int simpLevel, unsigned int nTerms, boolean polynomial, boolean *systemVars, Tbox *cb, unsigned int *v, TLinearConstraint *lc, Tequation *eq)
Identify equations than can trigger variable simplifications.
Definition: equation.c:851
unsigned int GetVariableN(unsigned int n, Tvariable_set *vs)
Gets a variable identifier from a variable set.
Definition: variable_set.c:454
void CtScaleEquation(double ct, Tequation *eq)
Scales an equation by a constant factor.
Definition: equation.c:663
boolean BilinearMonomial(Tmonomial *f)
Checks if a monomial is bilienal: K*x*y, with K a constant.
Definition: monomial.c:71
boolean polynomial
Definition: equation.h:240
void PrintEquation(FILE *f, char **varNames, Tequation *eq)
Prints an equation.
Definition: equation.c:1825
void SetEquationCmp(unsigned int cmp, Tequation *eq)
Changes the relational operator (LEQ, GEQ, EQU) of the equation.
Definition: equation.c:1081
#define NOTYPE_EQ
One of the possible type of equations.
Definition: equation.h:182
void EquationFromLinearConstraintProduct(TLinearConstraint *lc1, TLinearConstraint *lc2, Tequation *eq)
Defines a new equation from the product of two linear constraints.
Definition: equation.c:156
void ResetMonomial(Tmonomial *f)
Reset the monomial information.
Definition: monomial.c:24
double LowerLimit(Tinterval *i)
Gets the lower limit.
Definition: interval.c:79
unsigned int GetVariablePowerN(unsigned int n, Tvariable_set *vs)
Gets a variable power from a variable set.
Definition: variable_set.c:470
void GenerateGeneralNormEquation(unsigned int nv, unsigned int *v, double n, Tequation *eq)
Construtor. Generates an equation that is the norm of a vector.
Definition: equation.c:1506
boolean PolynomialMonomial(Tmonomial *f)
Identifies monimials not involving any kind of (trigonomitric function).
Definition: monomial.c:86
unsigned int CmpMonomial(Tmonomial *f1, Tmonomial *f2)
Monomial comparison.
Definition: monomial.c:103
unsigned int order
Definition: equation.h:243
void VarScaleEquation(unsigned int v, Tequation *eq)
Scales an equation with a variable factor.
Definition: equation.c:680
An equation.
Definition: equation.h:237
Definitions of constants and macros used in several parts of the cuik library.
void IntervalSubstract(Tinterval *i1, Tinterval *i2, Tinterval *i_out)
Substraction of two intervals.
Definition: interval.c:442
void ShiftVarIndexes(unsigned int nv, Tvariable_set *vs)
Reduces the variable indexes above a given index.
Definition: variable_set.c:99
boolean ParabolaEquation(Tequation *eq)
Identify scaled parabola equations.
Definition: equation.c:1184
boolean EmptyEquation(Tequation *eq)
Identify empty equations.
Definition: equation.c:1094
void ScaleLinearConstraint(double a, TLinearConstraint *lc)
Scales a linear constraint.
A set of variable indexes with powers.
Definition: variable_set.h:139
Tvariable_set * GetMonomialVariables(Tmonomial *f)
Gets the variables of a monomial.
Definition: monomial.c:153
A scaled product of powers of variables.
Definition: monomial.h:32
double UpperLimit(Tinterval *i)
Gets the uppser limit.
Definition: interval.c:87
void GenerateScaledParabolaEquation(double s, unsigned int vx, unsigned int vy, Tequation *eq)
Construtor. Generates a scaled parabola equation.
Definition: equation.c:1429
unsigned int GetNumTermsInLinearConstraint(TLinearConstraint *lc)
Number of variables in a linear constraint.
void ResetEquation(Tequation *eq)
Reset equation information.
Definition: equation.c:442
void GetEquationBounds(Tinterval *bounds, Tequation *eq)
Returns the right-hand side of the equation in the form of an interval.
Definition: equation.c:1217
void GenerateScaledSaddleEquation(double s, unsigned int vx, unsigned int vy, unsigned int vz, Tequation *eq)
Construtor. Generates a scaled saddle equation.
Definition: equation.c:1461
unsigned int VariableSetSize(Tvariable_set *vs)
Gets the number of elements of a variable set.
Definition: variable_set.c:449
A box.
Definition: box.h:83
double GetEquationValue(Tequation *eq)
Gets the right-hand value of the equation.
Definition: equation.c:1212
unsigned int FixVariableInEquation(double epsilon, unsigned int nv, double b, Tequation *eq)
Turns a variable into a constant.
Definition: equation.c:461
void VarAccumulateEquations(Tequation *eqn, unsigned int v, Tequation *eq)
Adds an equation scaled with a variable to another equation.
Definition: equation.c:377
void GetLinearConstraintError(Tinterval *error, TLinearConstraint *lc)
Gets the right-hand side interval for the linear constraint.
#define MEM_DUP(_var, _n, _type)
Duplicates a previously allocated memory space.
Definition: defines.h:414
void PrintInterval(FILE *f, Tinterval *i)
Prints an interval.
Definition: interval.c:1006
#define NO_UINT
Used to denote an identifier that has not been initialized.
Definition: defines.h:435
void AddVariable2Monomial(unsigned int fn, unsigned int varid, unsigned int p, Tmonomial *f)
Adds a power variable to the monomial.
Definition: monomial.c:171
double IntervalCenter(Tinterval *i)
Gets the interval center.
Definition: interval.c:129
boolean CleanInfEquation(Tequation *eq_in, Tinterval *varValues, boolean *changed, Tequation *eq_out)
Removes the monomials that evaluate to inf.
Definition: equation.c:763
boolean CircleEquation(Tequation *eq)
Identify circle equations.
Definition: equation.c:1131
void AddCt2LinearConstraint(double ct, TLinearConstraint *lc)
Adds a constant term to the linear constraint.
unsigned int FindMonomial(Tmonomial *f, Tequation *eq)
Searches for a given monomial in the equation.
Definition: equation.c:1672
void EquationFromLinearConstraint(TLinearConstraint *lc, Tequation *eq)
Defines a new equation from a linear constraint.
Definition: equation.c:106
unsigned int type
Definition: equation.h:238
double GetMonomialCt(Tmonomial *f)
Gets the scale factor of a monomial.
Definition: monomial.c:136
boolean IsInside(double p, double tol, Tinterval *i)
Checks if a value is inside an interval.
Definition: interval.c:348
unsigned int MonomialOrder(Tmonomial *f)
Gets the order of a monomial.
Definition: monomial.c:91
void PrintMonomials(FILE *f, char **varNames, Tequation *eq)
Prints an equation as a set if monomials.
Definition: equation.c:1803
boolean BilinearEquation(Tequation *eq)
Identify bilinear equations.
Definition: equation.c:1112
void EvaluateMonomialInt(Tinterval *varValues, Tinterval *i_out, Tmonomial *f)
Evaluates a monomial for a given set of ranges for the variables.
Definition: monomial.c:210
#define MAX_TERMS_SIMP
Maximum number of terms to be used in the simplifications.
Definition: equation.h:31
boolean SphereEquation(Tequation *eq)
Identify sphere equations.
Definition: equation.c:1145
void NewInterval(double lower, double upper, Tinterval *i)
Constructor.
Definition: interval.c:47
#define DERIVED_EQ
One of the possible type of equations.
Definition: equation.h:174
#define INF
Infinite.
Definition: defines.h:70
void PrintMonomial(FILE *file, boolean first, char **varNames, Tmonomial *f)
Prints a monomial.
Definition: monomial.c:255
double GetLinearConstraintCoefficient(unsigned int i, TLinearConstraint *lc)
Gets the a particular linear constraint coefficient.
void AddCt2Monomial(double k, Tmonomial *f)
Scales a monomial.
Definition: monomial.c:158
void GetOriginalVarRelation(unsigned int nvo, TLinearConstraint *lc, Tmapping *m)
Gets the relation for a variable in the original set with the variables in the simple set...
Definition: csmapping.c:112
void ProductEquations(Tequation *eq1, Tequation *eq2, Tequation *eqOut)
Product of two equations.
Definition: equation.c:398
boolean PolynomialEquation(Tequation *eq)
Idetify polynomial equations.
Definition: equation.c:1197
Defines a interval.
Definition: interval.h:33
void GenerateDistanceEquation(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 distance between two points.
Definition: equation.c:1623
void CopyMonomial(Tmonomial *f_dst, Tmonomial *f_orig)
Copy constructor.
Definition: monomial.c:96
void InitMonomial(Tmonomial *f)
Constructor.
Definition: monomial.c:17
double IntervalSize(Tinterval *i)
Gets the uppser limit.
Definition: interval.c:96
void RewriteEquation2Orig(Tmapping *map, Tequation *eqOut, Tequation *eq)
Applies the un-simplification mapping to an equation.
Definition: equation.c:321
void PurgeEquation(Tequation *eq)
Removes monomial with small constant.
Definition: equation.c:51
void AccumulateEquations(Tequation *eqn, double ct, Tequation *eq)
Adds a scaled equation to another equation.
Definition: equation.c:366
unsigned int GetNumMonomials(Tequation *eq)
Number of monomials in an equation.
Definition: equation.c:1703
double value
Definition: equation.h:244
unsigned int GetEquationType(Tequation *eq)
Gets the equation type.
Definition: equation.c:1207
boolean QuadraticMonomial(Tmonomial *f)
Checks if a monomial is quadratic: K*x^2, with K a constant.
Definition: monomial.c:64
void NormalizeEquation(Tequation *eq)
Normalizes an equation.
Definition: equation.c:714
Tvariable_set * GetEquationVariables(Tequation *eq)
Gets the set of variables equation used in the equation.
Definition: equation.c:1241
unsigned int GetEquationOrder(Tequation *eq)
Gets the equation order.
Definition: equation.c:1236
void DeleteMonomial(Tmonomial *f)
Destructor.
Definition: monomial.c:289
boolean LinearEquation(Tequation *eq)
Identify linear equations.
Definition: equation.c:1099
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.
Definition: equation.c:1588
void ReplaceVariableInMonomial(unsigned int nv, double ct, unsigned int nvNew, Tmonomial *f)
Replaces a variable.
Definition: monomial.c:42
unsigned int GetEquationCmp(Tequation *eq)
Gets the type of relational operator of the equation.
Definition: equation.c:1202
void IntervalOffset(Tinterval *i, double offset, Tinterval *i_out)
Interval offset.
Definition: interval.c:627
void InitVarSet(Tvariable_set *vs)
Constructor.
Definition: variable_set.c:70
boolean SaddleEquation(Tequation *eq)
Identify scaled saddle equations.
Definition: equation.c:1159