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 < dSEC2TANV < 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); /* sec(ct)^2*tan(ct) */
359  break;
360  case dSEC2TANV:
361  c=cos(ct);
362  if (fabs(c)<ZERO)
363  Error("Division by zero when fixing a variable (diff secant^2*tan)");
364  c=1.0/c*c; /* sec(ct)^2 */
365  v=2*c*tan(ct)+c*c; /* 2*sec(ct)^2*tan(ct)^2+sec(ct)^4 */
366  break;
367  case EXPV:
368  v=exp(ct);
369  break;
370  case PWPV:
371  if (ct<0)
372  v=ct*ct;
373  else
374  v=0.0;
375  break;
376  case PWLV:
377  if (ct<0)
378  v=2.0*ct;
379  else
380  v=0.0;
381  break;
382  case PWCV:
383  if (ct<0)
384  v=2.0;
385  else
386  v=0.0;
387  break;
388  default:
389  Error("Unknown function in FixVariableInVarSet");;
390  }
391  r*=pow(v,vs->power[i]);
392  }
393  else
394  {
395  vs->var_id[k]=vs->var_id[i];
396  vs->power[k]=vs->power[i];
397  vs->fun[k]=vs->fun[i];
398  k++;
399  }
400  }
401  vs->nvars=k;
402  return(r);
403 }
404 
405 double ReplaceVariableInVarSet(unsigned int varid,double ct,unsigned int newID,Tvariable_set *vs)
406 {
407  double r;
408  unsigned int i;
409  Tvariable_set vTmp;
410 
411  InitVarSet(&vTmp);
412  r=1.0;
413  for(i=0;i<vs->nvars;i++)
414  {
415  if ((vs->var_id[i]==varid)&&(ct!=1.0)&&(vs->var_id[i]!=NFUN))
416  Error("Variables in trigonometric expression can not be scaled");
417 
418  r*=pow(ct,vs->power[i]);
419 
420  AddVariable2Set(vs->fun[i],
421  (vs->var_id[i]==varid?newID:vs->var_id[i]),
422  vs->power[i],&vTmp);
423  }
424  DeleteVarSet(vs);
425  CopyVarSet(vs,&vTmp);
426 
427  return(r);
428 }
429 
430 unsigned int VarSetOrder(Tvariable_set *vs)
431 {
432  unsigned int i,o;
433 
434  o=0;
435  for(i=0;i<vs->nvars;i++)
436  o+=vs->power[i];
437 
438 /*
439  o=0;
440  for(i=0;i<vs->nvars;i++)
441  {
442  if (vs->power[i]>o)
443  o=vs->power[i];
444  }
445 */
446  return(o);
447 }
448 
449 inline unsigned int VariableSetSize(Tvariable_set *vs)
450 {
451  return(vs->nvars);
452 }
453 
454 unsigned int GetVariableN(unsigned int n,Tvariable_set *vs)
455 {
456  if (n<vs->nvars)
457  return(vs->var_id[n]);
458  else
459  {
460  Error("Requested an element not included in VarSet");
461  return(0);
462  }
463 }
464 
465 unsigned int *GetVariables(Tvariable_set *vs)
466 {
467  return(vs->var_id);
468 }
469 
470 unsigned int GetVariablePowerN(unsigned int n,Tvariable_set *vs)
471 {
472  if (n<vs->nvars)
473  return(vs->power[n]);
474  else
475  {
476  Error("Requested an element not included in VarSet");
477  return(0);
478  }
479 }
480 
481 unsigned int GetVariableFunctionN(unsigned int n,Tvariable_set *vs)
482 {
483  if (n<vs->nvars)
484  return(vs->fun[n]);
485  else
486  {
487  Error("Requested an element not included in VarSet");
488  return(0);
489  }
490 }
491 
492 unsigned int *GetPowers(Tvariable_set *vs)
493 {
494  return(vs->power);
495 }
496 
497 inline double EvaluateVarSet(double *varValues,Tvariable_set *vs)
498 {
499  double v,f,c;
500  unsigned int i,n;
501 
502  #if (_DEBUG>2)
503  if (vs->nvars==0)
504  Error("Should not evalute empty var sets");
505  #endif
506 
507  f=1.0;
508  for(i=0;i<vs->nvars;i++)
509  {
510  n=vs->var_id[i];
511  v=varValues[n];
512  switch(vs->fun[i])
513  {
514  case NFUN:
515  break;
516  case SINV:
517  v=sin(v);
518  break;
519  case COSV:
520  v=cos(v);
521  break;
522  case TANV:
523  v=tan(v);
524  break;
525  case SEC2V:
526  c=cos(v);
527  if (fabs(c)<ZERO)
528  Error("Division by zero when evaluating a variable (secant^2)");
529  v=1/(c*c);
530  break;
531  case SEC2TANV:
532  c=cos(v);
533  if (fabs(c)<ZERO)
534  Error("Division by zero when evaluating a variable (secant^2*tan)");
535  v=tan(v)/(c*c); /* sec(v)^2*tan(v) */
536  break;
537  case dSEC2TANV:
538  c=cos(v);
539  if (fabs(c)<ZERO)
540  Error("Division by zero when evaluating a variable (diff secant^2*tan)");
541  c=1.0/(c*c); /* sec(v)^2 */
542  v=2*c*tan(v)+c*c; /* 2*sec(v)^2*tan(v)^2+sec(v)^4 */
543  break;
544  case EXPV:
545  v=exp(v);
546  break;
547  case PWPV:
548  if (v<0.0)
549  v=v*v;
550  else
551  v=0.0;
552  break;
553  case PWLV:
554  if (v<0.0)
555  v=2.0*v;
556  else
557  v=0.0;
558  break;
559  case PWCV:
560  if (v<0.0)
561  v=2.0;
562  else
563  v=0.0;
564  break;
565  default:
566  Error("Unknown function in EvaluateVarSet");
567  }
568 
569  if (vs->power[i]==1)
570  f*=v;
571  else
572  f*=pow(v,(double)(vs->power[i]));
573  }
574 
575  return(f);
576 }
577 
579 {
580  unsigned int i,n;
581  Tinterval i_aux,*v;
582 
583  if (vs->nvars==0)
584  Error("Should not evalute empty var sets");
585 
586  NewInterval(1,1,i_out);
587  i=0;
588  while(i<vs->nvars)
589  {
590  n=vs->var_id[i];
591  v=&(varValues[n]);
592  switch(vs->fun[i])
593  {
594  case NFUN:
595  CopyInterval(&i_aux,v);
596  break;
597  case SINV:
598  IntervalSine(v,&i_aux);
599  break;
600  case COSV:
601  IntervalCosine(v,&i_aux);
602  break;
603  case TANV:
604  IntervalTangent(v,&i_aux);
605  break;
606  case SEC2V:
607  IntervalSecant2(v,&i_aux);
608  break;
609  case SEC2TANV:
610  IntervalSecant2Tangent(v,&i_aux);
611  break;
612  case dSEC2TANV:
613  Error("Not implemented yet");
614  break;
615  case EXPV:
616  IntervalExp(v,&i_aux);
617  break;
618  case PWPV:
619  {
620  double l;
621 
622  l=LowerLimit(v);
623  if (l<0.0)
624  {
625  if (UpperLimit(v)>0.0)
626  NewInterval(l*l,0.0,&i_aux);
627  else
628  IntervalPow(v,2,&i_aux);
629  }
630  else
631  NewInterval(0,0,&i_aux);
632  }
633  break;
634  case PWLV:
635  {
636  double l;
637 
638  l=LowerLimit(v);
639  if (l<0.0)
640  {
641  if (UpperLimit(v)>0.0)
642  NewInterval(2*l,0.0,&i_aux);
643  else
644  IntervalScale(v,2,&i_aux);
645  }
646  else
647  NewInterval(0,0,&i_aux);
648  }
649  break;
650  case PWCV:
651  if (LowerLimit(v)<0.0)
652  {
653  if (UpperLimit(v)>0.0)
654  NewInterval(0.0,2.0,&i_aux);
655  else
656  NewInterval(2.0,2.0,&i_aux);
657  }
658  else
659  NewInterval(0,0,&i_aux);
660  break;
661  default:
662  Error("Unknown function in EvaluateVarSetInt");
663  }
664 
665  if (vs->power[i]!=1)
666  IntervalPow(&i_aux,vs->power[i],&i_aux);
667 
668  IntervalProduct(i_out,&i_aux,i_out);
669 
670  i++;
671  }
672 }
673 
674 double DeriveVarSet(unsigned int nv,Tvariable_set *dvs,Tvariable_set *vs)
675 {
676  unsigned int i,p;
677  boolean found;
678  double ct;
679 
680  dvs->maxvars=2*vs->maxvars;
681 
682  NEW(dvs->var_id,dvs->maxvars,unsigned int);
683  NEW(dvs->power,dvs->maxvars,unsigned int);
684  NEW(dvs->fun,dvs->maxvars,unsigned int);
685 
686  dvs->nvars=0;
687  found=FALSE;
688  ct=1.0;
689  for(i=0;i<vs->nvars;i++)
690  {
691  if (vs->var_id[i]==nv)
692  {
693  found=TRUE;
694 
695  p=vs->power[i];
696 
697  /* d ([f(x)]^n)/dx = n [f(x)]^(n-1) * df(x)/dx*/
698 
699  ct*=(double)p;
700  if (p>1)
701  {
702  dvs->var_id[dvs->nvars]=vs->var_id[i];
703  dvs->power[dvs->nvars]=p-1;
704  dvs->fun[dvs->nvars]=vs->fun[i];
705  dvs->nvars++;
706  }
707 
708  switch(vs->fun[i])
709  {
710  case NFUN:
711  break;
712  case SINV:
713  /* d(sin(x))/dx = cos(x) */
714  dvs->fun[dvs->nvars]=COSV;
715  dvs->var_id[dvs->nvars]=vs->var_id[i];
716  dvs->power[dvs->nvars]=1;
717  dvs->nvars++;
718  break;
719  case COSV:
720  /* d(cos(x))/dx = (-1) * sin(x)*/
721  ct=-ct;
722  dvs->fun[dvs->nvars]=SINV;
723  dvs->var_id[dvs->nvars]=vs->var_id[i];
724  dvs->power[dvs->nvars]=1;
725  dvs->nvars++;
726  break;
727  case TANV:
728  /* d(tan(x))/dx = sec^2(x)*/
729  dvs->fun[dvs->nvars]=SEC2V;
730  dvs->var_id[dvs->nvars]=vs->var_id[i];
731  dvs->power[dvs->nvars]=1;
732  dvs->nvars++;
733  break;
734  case SEC2V:
735  /* d(sec^2(x))/dx = 2 * sec^2(x) * tan(x)*/
736  ct*=2;
737  dvs->fun[dvs->nvars]=SEC2TANV;
738  dvs->var_id[dvs->nvars]=vs->var_id[i];
739  dvs->power[dvs->nvars]=1;
740  dvs->nvars++;
741  break;
742  case SEC2TANV:
743  dvs->fun[dvs->nvars]=dSEC2TANV;
744  dvs->var_id[dvs->nvars]=vs->var_id[i];
745  dvs->power[dvs->nvars]=1;
746  dvs->nvars++;
747  break;
748  case EXPV:
749  /* d(exp(x))/dx = exp(x)*/
750  dvs->fun[dvs->nvars]=EXPV;
751  dvs->var_id[dvs->nvars]=vs->var_id[i];
752  dvs->power[dvs->nvars]=1;
753  dvs->nvars++;
754  break;
755  case PWPV:
756  /* d(pwp(x))/dx = pwl(x)*/
757  dvs->fun[dvs->nvars]=PWLV;
758  dvs->var_id[dvs->nvars]=vs->var_id[i];
759  dvs->power[dvs->nvars]=1;
760  dvs->nvars++;
761  break;
762  case PWLV:
763  /* d(pwl(x))/dx = pwc(x)*/
764  dvs->fun[dvs->nvars]=PWCV;
765  dvs->var_id[dvs->nvars]=vs->var_id[i];
766  dvs->power[dvs->nvars]=1;
767  dvs->nvars++;
768  break;
769  case PWCV:
770  /* d(pwc(x))/dx = 0 */
771  ct=0.0;
772  break;
773  default:
774  Error("Unknown function in DeriveVarSet");
775  }
776  }
777  else
778  {
779  dvs->var_id[dvs->nvars]=vs->var_id[i];
780  dvs->power[dvs->nvars]=vs->power[i];
781  dvs->fun[dvs->nvars]=vs->fun[i];
782  dvs->nvars++;
783  }
784  }
785  if ((found)&&(ct!=0.0))
786  return(ct);
787  else
788  {
789  ResetVarSet(dvs);
790  return(0.0);
791  }
792 }
793 
794 void PrintVarSet(FILE *f,char **varNames,Tvariable_set *vs)
795 {
796  unsigned int i;
797  boolean hasFun;
798 
799  if (vs->nvars>0)
800  {
801  for(i=0;i<vs->nvars;i++)
802  {
803  if (i>0)
804  fprintf(f,"*");
805 
806  switch(vs->fun[i])
807  {
808  case NFUN:
809  hasFun=FALSE;
810  break;
811  case SINV:
812  fprintf(f,"sin(");
813  hasFun=TRUE;
814  break;
815  case COSV:
816  fprintf(f,"cos(");
817  hasFun=TRUE;
818  break;
819  case TANV:
820  fprintf(f,"tan(");
821  hasFun=TRUE;
822  break;
823  case SEC2V:
824  fprintf(f,"sec2(");
825  hasFun=TRUE;
826  break;
827  case SEC2TANV:
828  fprintf(f,"sec2_tan(");
829  hasFun=TRUE;
830  break;
831  case dSEC2TANV:
832  fprintf(f,"dsec2_tan(");
833  hasFun=TRUE;
834  break;
835  case EXPV:
836  fprintf(f,"exp(");
837  hasFun=TRUE;
838  break;
839  case PWPV:
840  fprintf(f,"pwp(");
841  hasFun=TRUE;
842  break;
843  case PWLV:
844  fprintf(f,"pwl(");
845  hasFun=TRUE;
846  break;
847  case PWCV:
848  fprintf(f,"pwc(");
849  hasFun=TRUE;
850  break;
851  default:
852  Error("Unknown function in PrintVarSet");
853  }
854 
855  if (varNames!=NULL)
856  {
857  char *n;
858 
859  n=varNames[vs->var_id[i]];
860  PRINT_VARIABLE_NAME(f,n);
861  }
862  else
863  fprintf(f,"v_%u",vs->var_id[i]);
864 
865  if (hasFun)
866  {
867  fprintf(f,")");
868  }
869 
870  if (vs->power[i]>1)
871  fprintf(f,"^%d",vs->power[i]);
872  }
873  }
874 }
875 
877 {
878  free(vs->var_id);
879  free(vs->power);
880  free(vs->fun);
881 }
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:846
#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:674
#define PWCV
Derivative of PWLV.
Definition: variable_set.h:112
#define SEC2TANV
Squared secant per tangent.
Definition: variable_set.h:74
unsigned int * var_id
Definition: variable_set.h:142
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:96
boolean PolynomialVarSet(Tvariable_set *vs)
Identifies polynomial variable sets.
Definition: variable_set.c:153
#define EXPV
Exponential of the variable.
Definition: variable_set.h:88
#define TRUE
TRUE.
Definition: boolean.h:21
void IntervalExp(Tinterval *i, Tinterval *i_out)
Exponentional of an interval.
Definition: interval.c:475
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:430
#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:492
#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:470
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:794
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:405
#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.
#define dSEC2TANV
Derivative of SEC2TANV.
Definition: variable_set.h:81
unsigned int * fun
Definition: variable_set.h:144
unsigned int GetVariableN(unsigned int n, Tvariable_set *vs)
Gets a variable identifier from a variable set.
Definition: variable_set.c:454
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:139
#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:481
unsigned int nvars
Definition: variable_set.h:140
void DeleteVarSet(Tvariable_set *vs)
Destructor.
Definition: variable_set.c:876
#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:143
#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:856
#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:360
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:578
#define PWLV
Derivative of PWPV.
Definition: variable_set.h:104
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:141
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:449
void IntervalProduct(Tinterval *i1, Tinterval *i2, Tinterval *i_out)
Product of two intervals.
Definition: interval.c:389
void IntervalPow(Tinterval *i, unsigned int p, Tinterval *i_out)
Power of a given interval by a integer power factor.
Definition: interval.c:494
double EvaluateVarSet(double *varValues, Tvariable_set *vs)
Evaluates a variable set for a given set of value for the variables.
Definition: variable_set.c:497
void IntervalSine(Tinterval *i, Tinterval *i_out)
Interval sine.
Definition: interval.c:647
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:702
#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:754
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:465