variable_set.c
Go to the documentation of this file.
1 #include "variable_set.h"
2 
3 #include "defines.h"
4 
5 #include <string.h>
6 #include <math.h>
7 
8 
19 /*private function of adding a var to vs*/
20 
33 void AddVariableInt(unsigned int f,unsigned int varid,unsigned int p,
34  Tvariable_set *vs);
35 
36 void AddVariableInt(unsigned int f,unsigned int varid,unsigned int p,
37  Tvariable_set *vs)
38 {
39  signed int j;
40  unsigned int s;
41 
42  if (vs->nvars==vs->maxvars)
43  {
44  MEM_DUP(vs->var_id,vs->maxvars,unsigned int);
45  MEM_EXPAND(vs->power,vs->maxvars,unsigned int);
46  MEM_EXPAND(vs->fun,vs->maxvars,unsigned int);
47  }
48 
49  vs->var_id[vs->nvars]=varid;
50  vs->power[vs->nvars]=p;
51  vs->fun[vs->nvars]=f;
52  vs->nvars++;
53 
54  /* Keep variables in order from lower to upper ID. For
55  all functions applied to the same variable, keep
56  an order from lower to upper (function ID
57  NFUN < SINV < COSV < TANV < SEC2V < SEC2TANV < EXPV < PWPV < PWLV < PWCV */
58  j=vs->nvars-1;
59  while((j>0)&&
60  ((vs->var_id[j-1]>vs->var_id[j])||
61  ((vs->var_id[j-1]==vs->var_id[j])&&(vs->fun[j-1]>vs->fun[j]))))
62  {
63  SWAP(vs->var_id[j],vs->var_id[j-1],s);
64  SWAP(vs->power[j],vs->power[j-1],s);
65  SWAP(vs->fun[j],vs->fun[j-1],s);
66  j--;
67  }
68 }
69 
71 {
72  vs->nvars=0;
74  NEW(vs->var_id,vs->maxvars,unsigned int);
75  NEW(vs->power,vs->maxvars,unsigned int);
76  NEW(vs->fun,vs->maxvars,unsigned int);
77 }
78 
80 {
81  vs->nvars=0;
82 }
83 
84 void CopyVarSet(Tvariable_set *vs_dst,Tvariable_set *vs_orig)
85 {
86  vs_dst->nvars=vs_orig->nvars;
87 
88  vs_dst->maxvars=vs_orig->maxvars;
89 
90  NEW(vs_dst->var_id,vs_dst->maxvars,unsigned int);
91  NEW(vs_dst->power,vs_dst->maxvars,unsigned int);
92  NEW(vs_dst->fun,vs_dst->maxvars,unsigned int);
93 
94  memcpy(vs_dst->var_id,vs_orig->var_id,vs_dst->nvars*sizeof(unsigned int));
95  memcpy(vs_dst->power,vs_orig->power,vs_dst->nvars*sizeof(unsigned int));
96  memcpy(vs_dst->fun,vs_orig->fun,vs_dst->nvars*sizeof(unsigned int));
97 }
98 
99 void ShiftVarIndexes(unsigned int nv,Tvariable_set *vs)
100 {
101  unsigned int i;
102 
103  for(i=0;i<vs->nvars;i++)
104  {
105  if (vs->var_id[i]==nv)
106  Error("Remove the variable before shifting the var indexes for the remaining vars");
107  if (vs->var_id[i]>nv)
108  vs->var_id[i]--;
109  }
110 }
111 
112 unsigned int CmpVarSet(Tvariable_set *vs1,Tvariable_set *vs2)
113 {
114  unsigned int r;
115  unsigned int i;
116 
117  if (vs1->nvars>vs2->nvars)
118  r=2;
119  else
120  {
121  if (vs2->nvars>vs1->nvars)
122  r=1;
123  else
124  {
125  i=0;
126  while((i<vs1->nvars)&&
127  (vs1->var_id[i]==vs2->var_id[i])&&
128  (vs1->power[i]==vs2->power[i])&&
129  (vs1->fun[i]==vs2->fun[i]))
130  i++;
131 
132  if (i==vs1->nvars)
133  r=0;
134  else
135  {
136  if((vs1->fun[i]>vs2->fun[i])||
137  (vs1->power[i]>vs2->power[i])||
138  (vs2->var_id[i]>vs1->var_id[i]))
139  r=2;
140  else
141  r=1;
142  }
143  }
144  }
145  return(r);
146 }
147 
149 {
150  return(vs->nvars==0);
151 }
152 
154 {
155  boolean found;
156  unsigned int i;
157 
158  found=FALSE;
159  for(i=0;((!found)&&(i<vs->nvars));i++)
160  found=(vs->fun[i]!=NFUN);
161 
162  return(!found);
163 }
164 
165 unsigned int GetPlaceinSet(unsigned int id,Tvariable_set *vs)
166 {
167  boolean found=FALSE;
168  unsigned int i;
169 
170  i=0;
171  while((i<vs->nvars)&&(!found))
172  {
173  found=(id==vs->var_id[i]);
174  if (!found) i++;
175  }
176 
177  if (found)
178  return(i);
179  else
180  return(NO_UINT);
181 }
182 
183 boolean VarIncluded(unsigned int id,Tvariable_set *vs)
184 {
185  return((boolean)(GetPlaceinSet(id,vs)!=NO_UINT));
186 }
187 
188 boolean Included(unsigned int f,unsigned int id,
189  unsigned int p,Tvariable_set *vs)
190 {
191  boolean found=FALSE;
192  unsigned int i;
193 
194  i=0;
195  while((i<vs->nvars)&&(!found))
196  {
197  found=((id==vs->var_id[i])&&(f==vs->fun[i])&&(p==vs->power[i]));
198  if (!found) i++;
199  }
200 
201  return(found);
202 }
203 
204 /*True if they share a variable with the SAME exponent and function */
206 {
207  boolean found=FALSE;
208  unsigned int i;
209 
210  i=0;
211  while((i<vs1->nvars)&&(!found))
212  {
213  found=Included(vs1->fun[i],vs1->var_id[i],vs1->power[i],vs2);
214  if (!found) i++;
215  }
216  return(found);
217 }
218 
219 /*result of v1+v2 : we want to keep all the variables and the maximum of the exponents
220  in v1,v2 */
221 void UnionVarSet(boolean fun,Tvariable_set *vs_new,Tvariable_set *vs)
222 {
223  unsigned int i,j,n,id;
224  boolean found;
225 
226  for(i=0;i<vs_new->nvars;i++)
227  {
228  /* Size of 'vs' changes as we add variables (and the order
229  of variables in 'vs' change!!) */
230  n=vs->nvars;
231 
232  id=vs_new->var_id[i];
233  found=FALSE;
234  j=0;
235  if (fun)
236  {
237  while((j<n)&&(!found)&&(vs->var_id[j]<=id))
238  {
239  found=((vs->var_id[j]==id)&&
240  (vs_new->fun[j]==vs->fun[i]));
241  if (!found)
242  j++;
243  }
244  }
245  else
246  {
247  while((j<n)&&(!found)&&(vs->var_id[j]<=id))
248  {
249  found=(vs->var_id[j]==id);
250  if (!found)
251  j++;
252  }
253  }
254  if (found)
255  {
256  if (vs_new->power[i]>vs->power[j])
257  vs->power[j]=vs_new->power[i]; /*we keep the maximum order for this variable*/
258  }
259  else
260  AddVariableInt(vs_new->fun[i],id,vs_new->power[i],vs);
261  }
262 }
263 
264 /*If already in the set, we just increse the exponent. We implement: (var_set)*x^p */
265 void AddVariable2Set(unsigned int f,unsigned int varid,unsigned int p,Tvariable_set *vs)
266 {
267  boolean found=FALSE;
268  unsigned int i;
269 
270  i=0;
271  while((i<vs->nvars)&&(!found))
272  {
273  found=((varid==vs->var_id[i])&&(f==vs->fun[i]));
274  if (!found) i++;
275  }
276  if (found)
277  vs->power[i]+=p;
278  else
279  AddVariableInt(f,varid,p,vs);
280 }
281 
283 {
284  Tvariable_set *v1,*v2;
285  unsigned int i;
286 
287  if ((vs1->nvars>vs2->nvars)||(vs1==v_out))
288  {
289  v1=vs1;
290  v2=vs2;
291  }
292  else
293  {
294  v1=vs2;
295  v2=vs1;
296  }
297 
298  if (v1!=v_out)
299  CopyVarSet(v_out,v1);
300  for(i=0;i<v2->nvars;i++)
301  AddVariable2Set(v2->fun[i],v2->var_id[i],v2->power[i],v_out);
302 }
303 
304 /*Independent of the exponent and function*/
305 void RemoveVariableFromSet(unsigned int varid,Tvariable_set *vs)
306 {
307  unsigned int i,k;
308 
309  k=0;
310  for(i=0;i<vs->nvars;i++)
311  {
312  if (vs->var_id[i]!=varid)
313  {
314  vs->var_id[k]=vs->var_id[i];
315  vs->power[k]=vs->power[i];
316  vs->fun[k]=vs->fun[i];
317  k++;
318  }
319  }
320  vs->nvars=k;
321 }
322 
323 double FixVariableInVarSet(unsigned int varid,double ct,Tvariable_set *vs)
324 {
325  double r,v,c;
326  unsigned int i,k;
327 
328  r=1.0;
329  k=0;
330  for(i=0;i<vs->nvars;i++)
331  {
332  if (vs->var_id[i]==varid)
333  {
334  switch(vs->fun[i])
335  {
336  case NFUN:
337  v=ct;
338  break;
339  case SINV:
340  v=sin(ct);
341  break;
342  case COSV:
343  v=cos(ct);
344  break;
345  case TANV:
346  v=tan(ct);
347  break;
348  case SEC2V:
349  c=cos(ct);
350  if (fabs(c)<ZERO)
351  Error("Division by zero when fixing a variable (secant^2)");
352  v=1/(c*c);
353  break;
354  case SEC2TANV:
355  c=cos(ct);
356  if (fabs(c)<ZERO)
357  Error("Division by zero when fixing a variable (secant^2*tan)");
358  v=tan(ct)/(c*c);
359  break;
360  case EXPV:
361  v=exp(ct);
362  break;
363  case PWPV:
364  if (ct<0)
365  v=ct*ct;
366  else
367  v=0.0;
368  break;
369  case PWLV:
370  if (ct<0)
371  v=2.0*ct;
372  else
373  v=0.0;
374  break;
375  case PWCV:
376  if (ct<0)
377  v=2.0;
378  else
379  v=0.0;
380  break;
381  default:
382  Error("Unknown function in FixVariableInVarSet");;
383  }
384  r*=pow(v,vs->power[i]);
385  }
386  else
387  {
388  vs->var_id[k]=vs->var_id[i];
389  vs->power[k]=vs->power[i];
390  vs->fun[k]=vs->fun[i];
391  k++;
392  }
393  }
394  vs->nvars=k;
395  return(r);
396 }
397 
398 double ReplaceVariableInVarSet(unsigned int varid,double ct,unsigned int newID,Tvariable_set *vs)
399 {
400  double r;
401  unsigned int i;
402  Tvariable_set vTmp;
403 
404  InitVarSet(&vTmp);
405  r=1.0;
406  for(i=0;i<vs->nvars;i++)
407  {
408  if ((vs->var_id[i]==varid)&&(ct!=1.0)&&(vs->var_id[i]!=NFUN))
409  Error("Variables in trigonometric expression can not be scaled");
410 
411  r*=pow(ct,vs->power[i]);
412 
413  AddVariable2Set(vs->fun[i],
414  (vs->var_id[i]==varid?newID:vs->var_id[i]),
415  vs->power[i],&vTmp);
416  }
417  DeleteVarSet(vs);
418  CopyVarSet(vs,&vTmp);
419 
420  return(r);
421 }
422 
423 unsigned int VarSetOrder(Tvariable_set *vs)
424 {
425  unsigned int i,o;
426 
427  o=0;
428  for(i=0;i<vs->nvars;i++)
429  o+=vs->power[i];
430 
431 /*
432  o=0;
433  for(i=0;i<vs->nvars;i++)
434  {
435  if (vs->power[i]>o)
436  o=vs->power[i];
437  }
438 */
439  return(o);
440 }
441 
442 inline unsigned int VariableSetSize(Tvariable_set *vs)
443 {
444  return(vs->nvars);
445 }
446 
447 unsigned int GetVariableN(unsigned int n,Tvariable_set *vs)
448 {
449  if (n<vs->nvars)
450  return(vs->var_id[n]);
451  else
452  {
453  Error("Requested an element not included in VarSet");
454  return(0);
455  }
456 }
457 
458 unsigned int *GetVariables(Tvariable_set *vs)
459 {
460  return(vs->var_id);
461 }
462 
463 unsigned int GetVariablePowerN(unsigned int n,Tvariable_set *vs)
464 {
465  if (n<vs->nvars)
466  return(vs->power[n]);
467  else
468  {
469  Error("Requested an element not included in VarSet");
470  return(0);
471  }
472 }
473 
474 unsigned int GetVariableFunctionN(unsigned int n,Tvariable_set *vs)
475 {
476  if (n<vs->nvars)
477  return(vs->fun[n]);
478  else
479  {
480  Error("Requested an element not included in VarSet");
481  return(0);
482  }
483 }
484 
485 unsigned int *GetPowers(Tvariable_set *vs)
486 {
487  return(vs->power);
488 }
489 
490 inline double EvaluateVarSet(double *varValues,Tvariable_set *vs)
491 {
492  double v,f,c;
493  unsigned int i,n;
494 
495  #if (_DEBUG>2)
496  if (vs->nvars==0)
497  Error("Should not evalute empty var sets");
498  #endif
499 
500  f=1.0;
501  for(i=0;i<vs->nvars;i++)
502  {
503  n=vs->var_id[i];
504  v=varValues[n];
505  switch(vs->fun[i])
506  {
507  case NFUN:
508  break;
509  case SINV:
510  v=sin(v);
511  break;
512  case COSV:
513  v=cos(v);
514  break;
515  case TANV:
516  v=tan(v);
517  break;
518  case SEC2V:
519  c=cos(v);
520  if (fabs(c)<ZERO)
521  Error("Division by zero when evaluating a variable (secant^2)");
522  v=1/(c*c);
523  break;
524  case SEC2TANV:
525  c=cos(v);
526  if (fabs(c)<ZERO)
527  Error("Division by zero when evaluating a variable (secant^2*tan)");
528  v=tan(v)/(c*c);
529  break;
530  case EXPV:
531  v=exp(v);
532  break;
533  case PWPV:
534  if (v<0.0)
535  v=v*v;
536  else
537  v=0.0;
538  break;
539  case PWLV:
540  if (v<0.0)
541  v=2.0*v;
542  else
543  v=0.0;
544  break;
545  case PWCV:
546  if (v<0.0)
547  v=2.0;
548  else
549  v=0.0;
550  break;
551  default:
552  Error("Unknown function in EvaluateVarSet");
553  }
554 
555  if (vs->power[i]==1)
556  f*=v;
557  else
558  f*=pow(v,(double)(vs->power[i]));
559  }
560 
561  return(f);
562 }
563 
565 {
566  unsigned int i,n;
567  Tinterval i_aux,*v;
568 
569  if (vs->nvars==0)
570  Error("Should not evalute empty var sets");
571 
572  NewInterval(1,1,i_out);
573  i=0;
574  while(i<vs->nvars)
575  {
576  n=vs->var_id[i];
577  v=&(varValues[n]);
578  switch(vs->fun[i])
579  {
580  case NFUN:
581  CopyInterval(&i_aux,v);
582  break;
583  case SINV:
584  IntervalSine(v,&i_aux);
585  break;
586  case COSV:
587  IntervalCosine(v,&i_aux);
588  break;
589  case TANV:
590  IntervalTangent(v,&i_aux);
591  break;
592  case SEC2V:
593  IntervalSecant2(v,&i_aux);
594  break;
595  case SEC2TANV:
596  IntervalSecant2Tangent(v,&i_aux);
597  break;
598  case EXPV:
599  IntervalExp(v,&i_aux);
600  break;
601  case PWPV:
602  {
603  double l;
604 
605  l=LowerLimit(v);
606  if (l<0.0)
607  {
608  if (UpperLimit(v)>0.0)
609  NewInterval(l*l,0.0,&i_aux);
610  else
611  IntervalPow(v,2,&i_aux);
612  }
613  else
614  NewInterval(0,0,&i_aux);
615  }
616  break;
617  case PWLV:
618  {
619  double l;
620 
621  l=LowerLimit(v);
622  if (l<0.0)
623  {
624  if (UpperLimit(v)>0.0)
625  NewInterval(2*l,0.0,&i_aux);
626  else
627  IntervalScale(v,2,&i_aux);
628  }
629  else
630  NewInterval(0,0,&i_aux);
631  }
632  break;
633  case PWCV:
634  if (LowerLimit(v)<0.0)
635  {
636  if (UpperLimit(v)>0.0)
637  NewInterval(0.0,2.0,&i_aux);
638  else
639  NewInterval(2.0,2.0,&i_aux);
640  }
641  else
642  NewInterval(0,0,&i_aux);
643  break;
644  default:
645  Error("Unknown function in EvaluateVarSetInt");
646  }
647 
648  if (vs->power[i]!=1)
649  IntervalPow(&i_aux,vs->power[i],&i_aux);
650 
651  IntervalProduct(i_out,&i_aux,i_out);
652 
653  i++;
654  }
655 }
656 
657 double DeriveVarSet(unsigned int nv,Tvariable_set *dvs,Tvariable_set *vs)
658 {
659  unsigned int i,p;
660  boolean found;
661  double ct;
662 
663  dvs->maxvars=2*vs->maxvars;
664 
665  NEW(dvs->var_id,dvs->maxvars,unsigned int);
666  NEW(dvs->power,dvs->maxvars,unsigned int);
667  NEW(dvs->fun,dvs->maxvars,unsigned int);
668 
669  dvs->nvars=0;
670  found=FALSE;
671  ct=1.0;
672  for(i=0;i<vs->nvars;i++)
673  {
674  if (vs->var_id[i]==nv)
675  {
676  found=TRUE;
677 
678  p=vs->power[i];
679 
680  /* d ([f(x)]^n)/dx = n [f(x)]^(n-1) * df(x)/dx*/
681 
682  ct*=(double)p;
683  if (p>1)
684  {
685  dvs->var_id[dvs->nvars]=vs->var_id[i];
686  dvs->power[dvs->nvars]=p-1;
687  dvs->fun[dvs->nvars]=vs->fun[i];
688  dvs->nvars++;
689  }
690 
691  switch(vs->fun[i])
692  {
693  case NFUN:
694  break;
695  case SINV:
696  /* d(sin(x))/dx = cos(x) */
697  dvs->fun[dvs->nvars]=COSV;
698  dvs->var_id[dvs->nvars]=vs->var_id[i];
699  dvs->power[dvs->nvars]=1;
700  dvs->nvars++;
701  break;
702  case COSV:
703  /* d(cos(x))/dx = (-1) * sin(x)*/
704  ct=-ct;
705  dvs->fun[dvs->nvars]=SINV;
706  dvs->var_id[dvs->nvars]=vs->var_id[i];
707  dvs->power[dvs->nvars]=1;
708  dvs->nvars++;
709  break;
710  case TANV:
711  /* d(tan(x))/dx = sec^2(x)*/
712  dvs->fun[dvs->nvars]=SEC2V;
713  dvs->var_id[dvs->nvars]=vs->var_id[i];
714  dvs->power[dvs->nvars]=1;
715  dvs->nvars++;
716  break;
717  case SEC2V:
718  /* d(sec^2(x))/dx = 2 * sec^2(x) * tan(x)*/
719  ct*=2;
720  dvs->fun[dvs->nvars]=SEC2TANV;
721  dvs->var_id[dvs->nvars]=vs->var_id[i];
722  dvs->power[dvs->nvars]=1;
723  dvs->nvars++;
724  break;
725  case SEC2TANV:
726  Error("Sec^2*Tan can not be derived");
727  break;
728  case EXPV:
729  /* d(exp(x))/dx = exp(x)*/
730  dvs->fun[dvs->nvars]=EXPV;
731  dvs->var_id[dvs->nvars]=vs->var_id[i];
732  dvs->power[dvs->nvars]=1;
733  dvs->nvars++;
734  break;
735  case PWPV:
736  /* d(pwp(x))/dx = pwl(x)*/
737  dvs->fun[dvs->nvars]=PWLV;
738  dvs->var_id[dvs->nvars]=vs->var_id[i];
739  dvs->power[dvs->nvars]=1;
740  dvs->nvars++;
741  break;
742  case PWLV:
743  /* d(pwl(x))/dx = pwc(x)*/
744  dvs->fun[dvs->nvars]=PWCV;
745  dvs->var_id[dvs->nvars]=vs->var_id[i];
746  dvs->power[dvs->nvars]=1;
747  dvs->nvars++;
748  break;
749  case PWCV:
750  /* d(pwc(x))/dx = 0 */
751  ct=0.0;
752  break;
753  default:
754  Error("Unknown function in DeriveVarSet");
755  }
756  }
757  else
758  {
759  dvs->var_id[dvs->nvars]=vs->var_id[i];
760  dvs->power[dvs->nvars]=vs->power[i];
761  dvs->fun[dvs->nvars]=vs->fun[i];
762  dvs->nvars++;
763  }
764  }
765  if ((found)&&(ct!=0.0))
766  return(ct);
767  else
768  {
769  ResetVarSet(dvs);
770  return(0.0);
771  }
772 }
773 
774 void PrintVarSet(FILE *f,char **varNames,Tvariable_set *vs)
775 {
776  unsigned int i;
777  boolean hasFun;
778 
779  if (vs->nvars>0)
780  {
781  for(i=0;i<vs->nvars;i++)
782  {
783  if (i>0)
784  fprintf(f,"*");
785 
786  switch(vs->fun[i])
787  {
788  case NFUN:
789  hasFun=FALSE;
790  break;
791  case SINV:
792  fprintf(f,"sin(");
793  hasFun=TRUE;
794  break;
795  case COSV:
796  fprintf(f,"cos(");
797  hasFun=TRUE;
798  break;
799  case TANV:
800  fprintf(f,"tan(");
801  hasFun=TRUE;
802  break;
803  case SEC2V:
804  fprintf(f,"sec2(");
805  hasFun=TRUE;
806  break;
807  case SEC2TANV:
808  fprintf(f,"sec2_tan(");
809  hasFun=TRUE;
810  break;
811  case EXPV:
812  fprintf(f,"exp(");
813  hasFun=TRUE;
814  break;
815  case PWPV:
816  fprintf(f,"pwp(");
817  hasFun=TRUE;
818  break;
819  case PWLV:
820  fprintf(f,"pwl(");
821  hasFun=TRUE;
822  break;
823  case PWCV:
824  fprintf(f,"pwc(");
825  hasFun=TRUE;
826  break;
827  default:
828  Error("Unknown function in PrintVarSet");
829  }
830 
831  if (varNames!=NULL)
832  {
833  char *n;
834 
835  n=varNames[vs->var_id[i]];
836  PRINT_VARIABLE_NAME(f,n);
837  }
838  else
839  fprintf(f,"v_%u",vs->var_id[i]);
840 
841  if (hasFun)
842  {
843  fprintf(f,")");
844  }
845 
846  if (vs->power[i]>1)
847  fprintf(f,"^%d",vs->power[i]);
848  }
849  }
850 }
851 
853 {
854  free(vs->var_id);
855  free(vs->power);
856  free(vs->fun);
857 }
Definition of the Tvariable_set type and the associated functions.
#define FALSE
FALSE.
Definition: boolean.h:30
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
void IntervalSecant2(Tinterval *i, Tinterval *i_out)
Interval squared secant.
Definition: interval.c:841
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
double DeriveVarSet(unsigned int nv, Tvariable_set *dvs, Tvariable_set *vs)
Derives an variable set.
Definition: variable_set.c:657
#define PWCV
Derivative of PWLV.
Definition: variable_set.h:105
#define SEC2TANV
Squared secant per tangent.
Definition: variable_set.h:74
unsigned int * var_id
Definition: variable_set.h:134
boolean VarSetIntersect(Tvariable_set *vs1, Tvariable_set *vs2)
Checks if two variable sets have elements in common.
Definition: variable_set.c:205
#define PWPV
Squared of the variable, if it is negative.
Definition: variable_set.h:89
boolean PolynomialVarSet(Tvariable_set *vs)
Identifies polynomial variable sets.
Definition: variable_set.c:153
#define EXPV
Exponential of the variable.
Definition: variable_set.h:81
#define TRUE
TRUE.
Definition: boolean.h:21
void IntervalExp(Tinterval *i, Tinterval *i_out)
Exponentional of an interval.
Definition: interval.c:470
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
unsigned int VarSetOrder(Tvariable_set *vs)
Gets the order of a variable set.
Definition: variable_set.c:423
#define COSV
Cosine of the variable.
Definition: variable_set.h:50
#define ZERO
Floating point operations giving a value below this constant (in absolute value) are considered 0...
Definition: defines.h:37
void CopyInterval(Tinterval *i_dst, Tinterval *i_org)
Copy constructor.
Definition: interval.c:59
void RemoveVariableFromSet(unsigned int varid, Tvariable_set *vs)
Removes an element to a variable set.
Definition: variable_set.c:305
unsigned int * GetPowers(Tvariable_set *vs)
Gets the variable powers stored in a variable set.
Definition: variable_set.c:485
#define SINV
Sine of the variable.
Definition: variable_set.h:43
unsigned int GetVariablePowerN(unsigned int n, Tvariable_set *vs)
Gets a variable power from a variable set.
Definition: variable_set.c:463
void AddVariable2Set(unsigned int f, unsigned int varid, unsigned int p, Tvariable_set *vs)
Adds an element to a variable set.
Definition: variable_set.c:265
void PrintVarSet(FILE *f, char **varNames, Tvariable_set *vs)
Prints a variable set.
Definition: variable_set.c:774
double LowerLimit(Tinterval *i)
Gets the lower limit.
Definition: interval.c:79
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
unsigned int CmpVarSet(Tvariable_set *vs1, Tvariable_set *vs2)
Variable set comparison.
Definition: variable_set.c:112
double ReplaceVariableInVarSet(unsigned int varid, double ct, unsigned int newID, Tvariable_set *vs)
Replaces a variable by another variable.
Definition: variable_set.c:398
#define PRINT_VARIABLE_NAME(f, name)
Prints a variable name into a file.
Definition: defines.h:427
Definitions of constants and macros used in several parts of the cuik library.
unsigned int * fun
Definition: variable_set.h:136
unsigned int GetVariableN(unsigned int n, Tvariable_set *vs)
Gets a variable identifier from a variable set.
Definition: variable_set.c:447
boolean EmptyVarSet(Tvariable_set *vs)
Checks if a variable set is empty.
Definition: variable_set.c:148
double FixVariableInVarSet(unsigned int varid, double ct, Tvariable_set *vs)
Replaces a variable by a constant.
Definition: variable_set.c:323
A set of variable indexes with powers.
Definition: variable_set.h:131
#define TANV
Tangent of the variable.
Definition: variable_set.h:57
void InitVarSet(Tvariable_set *vs)
Constructor.
Definition: variable_set.c:70
double UpperLimit(Tinterval *i)
Gets the uppser limit.
Definition: interval.c:87
unsigned int GetVariableFunctionN(unsigned int n, Tvariable_set *vs)
Gets a variable function from a variable set.
Definition: variable_set.c:474
unsigned int nvars
Definition: variable_set.h:132
void DeleteVarSet(Tvariable_set *vs)
Destructor.
Definition: variable_set.c:852
#define INIT_NUM_VARIABLES
Initial room for variables.
Definition: variable_set.h:28
boolean Included(unsigned int f, unsigned int id, unsigned int p, Tvariable_set *vs)
Checks if a variable index is included in a set of variable indexes with a given power.
Definition: variable_set.c:188
#define SEC2V
Squared secant of the variable.
Definition: variable_set.h:65
unsigned int * power
Definition: variable_set.h:135
#define MEM_DUP(_var, _n, _type)
Duplicates a previously allocated memory space.
Definition: defines.h:414
void IntervalSecant2Tangent(Tinterval *i, Tinterval *i_out)
Interval squared secant per tangent.
Definition: interval.c:851
#define NO_UINT
Used to denote an identifier that has not been initialized.
Definition: defines.h:435
void IntervalScale(Tinterval *i1, double e, Tinterval *i_out)
Scales an interval.
Definition: interval.c:355
void EvaluateVarSetInt(Tinterval *varValues, Tinterval *i_out, Tvariable_set *vs)
Evaluates a variable set for a given set of ranges for the variables.
Definition: variable_set.c:564
#define PWLV
Derivative of PWPV.
Definition: variable_set.h:97
void ResetVarSet(Tvariable_set *vs)
Resets the information stored in a variable set.
Definition: variable_set.c:79
void ProductVarSet(Tvariable_set *vs1, Tvariable_set *vs2, Tvariable_set *v_out)
Product of two variable sets.
Definition: variable_set.c:282
void ShiftVarIndexes(unsigned int nv, Tvariable_set *vs)
Reduces the variable indexes above a given index.
Definition: variable_set.c:99
void CopyVarSet(Tvariable_set *vs_dst, Tvariable_set *vs_orig)
Copy constructor.
Definition: variable_set.c:84
unsigned int maxvars
Definition: variable_set.h:133
boolean VarIncluded(unsigned int id, Tvariable_set *vs)
Checks if a variable index is included in a set of variable indexes.
Definition: variable_set.c:183
#define MEM_EXPAND(_var, _n, _type)
Expands a previously allocated memory space.
Definition: defines.h:404
unsigned int VariableSetSize(Tvariable_set *vs)
Gets the number of elements of a variable set.
Definition: variable_set.c:442
void IntervalProduct(Tinterval *i1, Tinterval *i2, Tinterval *i_out)
Product of two intervals.
Definition: interval.c:384
void IntervalPow(Tinterval *i, unsigned int p, Tinterval *i_out)
Power of a given interval by a integer power factor.
Definition: interval.c:489
double EvaluateVarSet(double *varValues, Tvariable_set *vs)
Evaluates a variable set for a given set of value for the variables.
Definition: variable_set.c:490
void IntervalSine(Tinterval *i, Tinterval *i_out)
Interval sine.
Definition: interval.c:642
void NewInterval(double lower, double upper, Tinterval *i)
Constructor.
Definition: interval.c:47
void IntervalCosine(Tinterval *i, Tinterval *i_out)
Interval cosine.
Definition: interval.c:697
#define SWAP(a, b, c)
Swaps two values.
Definition: defines.h:161
Defines a interval.
Definition: interval.h:33
void IntervalTangent(Tinterval *i, Tinterval *i_out)
Interval tangent.
Definition: interval.c:749
void AddVariableInt(unsigned int f, unsigned int varid, unsigned int p, Tvariable_set *vs)
Adds an element to a variable set.
Definition: variable_set.c:36
unsigned int * GetVariables(Tvariable_set *vs)
Gets the variable identifiers stored in a variable set.
Definition: variable_set.c:458