Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / eqt / eqt_main.c
1 /**************************/
2 /* eqt_main.c */
3 /**************************/
4
5 /**********************************************************************/
6 /* includes */
7 /**********************************************************************/
8
9 #include EQT_H
10 #include "eqt_util.h"
11
12 /**********************************************************************/
13 /* extern variable */
14 /**********************************************************************/
15
16 /**********************************************************************/
17 /* main */
18 /**********************************************************************/
19
20 /* bench for test */
21
22 static char *eqt_bench[] =
23 {
24 "h+i*64+j*128+320-(h+i*64+j*128+64)" ,"256" ,
25 "f*1" ,"f" ,
26 "f*0" ,"0" ,
27 "h+i*64+j*128+64-0+4*k" ,"h+i*64+j*128+k*4+64" ,
28 "(i-1)*4+j" ,"j+(i-1)*4" ,
29 "(-i+j*1024+5119)-(-i+j*1024+1023)" ,"4096" ,
30 "1588211555" ,"1588211555" ,
31 "(-i+j*1024+k*4096+l*524288+1.0496e+06)-(-i+j*1024+k*4096+l*524288+1023)", "1048577",
32 "(i+j+384)-(i+j+640)" ,"-256" ,
33 "(i+j+512)-(i+j+256)" ,"256" ,
34 "i" ,"i" ,
35 0
36 };
37
38 /***** New function from USER ****************************************/
39
40 double trunc (double p)
41 {
42 return (int)(p) ;
43 }
44
45 double sum (double p, double q)
46 {
47 return p + q ;
48 }
49
50
51 double max (double p, double q)
52 {
53 double r ;
54
55 if ( p >= q )
56 r = p ;
57 else
58 r = q ;
59 return r ;
60 }
61
62 double ln (double p)
63 {
64 return log (p);
65 }
66
67 double mycos (double p)
68 {
69 return cos (p);
70 }
71
72 /******** Main function ***********************************/
73 int main (int argc, char **argv)
74 {
75 char *str, *str2;
76 // char *string ;
77 // chain_list *abl ;
78 // chain_list *expr1;
79 // chain_list *expr2;
80 eqt_node *node = NULL ;
81 int doTree, i;
82 eqt_ctx *ecx;
83
84 mbkenv () ;
85
86 ecx=eqt_init (EQT_NB_VARS);
87
88 eqt_addfunction2(ecx, "max", &max) ;
89 eqt_addfunction (ecx, "ln", &ln) ;
90 eqt_addfunction (ecx, "cos", &mycos) ;
91
92 /******* Initialisation des parametres generaux *******/
93
94
95 if (argc > 1)
96 {
97 str = argv[1];
98 if (argc > 2)
99 {
100 str2 = argv[2];
101 doTree = !strcmp(str2,"tree");
102 }
103 else
104 doTree = 0;
105
106 /*- Test arithmetique -*/
107 node = eqt_create(ecx, str) ;
108 if (!node)
109 printf("error empty node!!!\n") ;
110 else
111 {
112 printf("\noriginal\n");
113 eqt_drive(ecx,node);
114 if (doTree)
115 eqt_printTree(ecx,node,0);
116 printf("\ndelmindiv\n");
117 node = eqt_DelMinDiv(ecx,node);
118 eqt_drive(ecx, node);
119 if (doTree)
120 eqt_printTree(ecx,node,0);
121 printf("\nlinearisation\n");
122 eqt_linearise(ecx,node);
123 eqt_drive(ecx,node);
124 if (doTree)
125 eqt_printTree(ecx,node,0);
126 printf("\nadd neutral\n");
127 eqt_addNeutral(ecx,node);
128 eqt_drive(ecx,node);
129 if (doTree)
130 eqt_printTree(ecx,node,0);
131 printf("\nsorting\n");
132 eqt_sortBranch(ecx,node);
133 eqt_drive(ecx,node);
134 if (doTree)
135 eqt_printTree(ecx,node,0);
136 printf("\nassociation\n");
137 node = eqt_associate(ecx,node);
138 eqt_drive(ecx,node);
139 if (doTree)
140 eqt_printTree(ecx,node,0);
141 eqt_assocVar(ecx,node);
142 printf("\nresult\n");
143 eqt_reduce(ecx,node);
144 node = eqt_DelNeutral(ecx,node);
145 if (doTree)
146 eqt_printTree(ecx,node,0);
147 printf("\ndrived\n");
148 eqt_drive(ecx,node);
149 //eqt_print(node) ;
150 eqt_eval (ecx, str,EQTFAST);
151 }
152 // fprintf (stdout, "\n*** Normal = %g ***\n", eqt_eval (str, EQTNORMAL)) ;
153 // fprintf (stdout, "\n*** Fast = %g ***\n", eqt_eval (str, EQTFAST)) ;
154 eqt_freenode(node);
155 eqt_term (ecx);
156
157 str = eqt_getSimpleEquation(str);
158 printf("eqt_getSimpleEquation :\n%s\n",str);
159 mbkfree(str);
160
161 EXIT(0);
162 return 1 ;
163 }
164 else
165 for (i = 0; eqt_bench[i]; i += 2)
166 {
167 fprintf(stdout,"Testing : %s\n",eqt_bench[i]);
168 fprintf(stdout,"-- Expected : %s\n",eqt_bench[i+1]);
169 str = eqt_getSimpleEquation(eqt_bench[i]);
170 fprintf(stdout,"-- Result : %s\n",str);
171 if (strcmp(str,eqt_bench[i+1]))
172 eqt_error(NULL);
173 else
174 fprintf(stdout,"OK\n");
175 mbkfree(str);
176 }
177
178 eqt_term (ecx);
179 EXIT(0) ;
180 }