1 | package symexpr
|
---|
2 |
|
---|
3 | import "fmt"
|
---|
4 |
|
---|
5 | func (n *Time) String() string { return "T" }
|
---|
6 | func (t *Time) Serial(sofar []int) []int { return append(sofar, int(TIME)) }
|
---|
7 | func (t *Time) StackSerial(sofar []int) []int { return append(sofar, int(TIME)) }
|
---|
8 | func (t *Time) PrettyPrint(dnames, snames []string, cvals []float64) string { return "T" }
|
---|
9 | func (t *Time) Latex(dnames, snames []string, cvals []float64) string { return "T" }
|
---|
10 | func (t *Time) Javascript(dnames, snames []string, cvals []float64) string { return "T" }
|
---|
11 |
|
---|
12 | func (v *Var) String() string { return "X_" + fmt.Sprint(v.P) }
|
---|
13 | func (v *Var) Serial(sofar []int) []int { return append(sofar, int(v.P)+int(STARTVAR)) }
|
---|
14 | func (v *Var) StackSerial(sofar []int) []int { return append(sofar, int(v.P)+int(STARTVAR)) }
|
---|
15 | func (v *Var) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
16 | if dnames == nil {
|
---|
17 | return v.String()
|
---|
18 | }
|
---|
19 | return dnames[v.P]
|
---|
20 | }
|
---|
21 | func (v *Var) Latex(dnames, snames []string, cvals []float64) string {
|
---|
22 | return v.PrettyPrint(dnames, snames, cvals)
|
---|
23 | }
|
---|
24 | func (v *Var) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
25 | return v.PrettyPrint(dnames, snames, cvals)
|
---|
26 | }
|
---|
27 |
|
---|
28 | func (c *Constant) String() string { return "C_" + fmt.Sprint(c.P) }
|
---|
29 | func (c *Constant) Serial(sofar []int) []int { return append(sofar, int(CONSTANT)) }
|
---|
30 | func (c *Constant) StackSerial(sofar []int) []int {
|
---|
31 | sofar = append(sofar, int(CONSTANT))
|
---|
32 | return append(sofar, c.P)
|
---|
33 | }
|
---|
34 | func (c *Constant) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
35 | if cvals == nil {
|
---|
36 | return c.String()
|
---|
37 | }
|
---|
38 | return fmt.Sprintf("%.6f", cvals[c.P])
|
---|
39 | }
|
---|
40 | func (c *Constant) Latex(dnames, snames []string, cvals []float64) string {
|
---|
41 | return c.PrettyPrint(dnames, snames, cvals)
|
---|
42 | }
|
---|
43 | func (c *Constant) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
44 | return c.PrettyPrint(dnames, snames, cvals)
|
---|
45 | }
|
---|
46 |
|
---|
47 | func (c *ConstantF) String() string { return fmt.Sprintf("%.4e", c.F) }
|
---|
48 | func (c *ConstantF) Serial(sofar []int) []int { return append(sofar, int(CONSTANTF)) } // hmm floats???
|
---|
49 | func (c *ConstantF) StackSerial(sofar []int) []int {
|
---|
50 | sofar = append(sofar, int(CONSTANTF))
|
---|
51 | // fmt.Printf("CF SS: %f\n", c.F)
|
---|
52 | return append(sofar, int(c.F))
|
---|
53 | } // hmm floats???
|
---|
54 | // ( we don't output the index since it is unimportant and can be altered )
|
---|
55 | func (c *ConstantF) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
56 | return c.String()
|
---|
57 | }
|
---|
58 | func (c *ConstantF) Latex(dnames, snames []string, cvals []float64) string {
|
---|
59 | return fmt.Sprintf("%.2f", c.F)
|
---|
60 | }
|
---|
61 | func (c *ConstantF) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
62 | return fmt.Sprintf("%.2f", c.F)
|
---|
63 | }
|
---|
64 |
|
---|
65 | func (s *System) String() string { return "S_" + fmt.Sprint(s.P) }
|
---|
66 | func (s *System) Serial(sofar []int) []int {
|
---|
67 | sofar = append(sofar, int(SYSTEM))
|
---|
68 | return append(sofar, s.P)
|
---|
69 | }
|
---|
70 | func (s *System) StackSerial(sofar []int) []int {
|
---|
71 | sofar = append(sofar, int(SYSTEM))
|
---|
72 | return append(sofar, s.P)
|
---|
73 | }
|
---|
74 | func (s *System) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
75 | if snames == nil {
|
---|
76 | return s.String()
|
---|
77 | }
|
---|
78 | return snames[s.P]
|
---|
79 | }
|
---|
80 | func (s *System) Latex(dnames, snames []string, cvals []float64) string {
|
---|
81 | return s.PrettyPrint(dnames, snames, cvals)
|
---|
82 | }
|
---|
83 | func (s *System) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
84 | return s.PrettyPrint(dnames, snames, cvals)
|
---|
85 | }
|
---|
86 |
|
---|
87 | func (u *Neg) String() string {
|
---|
88 | if u.C == nil {
|
---|
89 | return "-(nil)"
|
---|
90 | }
|
---|
91 | return "-(" + u.C.String() + ")"
|
---|
92 | }
|
---|
93 | func (u *Neg) Serial(sofar []int) []int {
|
---|
94 | sofar = append(sofar, int(NEG))
|
---|
95 | return u.C.Serial(sofar)
|
---|
96 | }
|
---|
97 | func (u *Neg) StackSerial(sofar []int) []int {
|
---|
98 | sofar = u.C.StackSerial(sofar)
|
---|
99 | return append(sofar, int(NEG))
|
---|
100 | }
|
---|
101 | func (u *Neg) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
102 | return "-(" + u.C.PrettyPrint(dnames, snames, cvals) + ")"
|
---|
103 | }
|
---|
104 | func (u *Neg) Latex(dnames, snames []string, cvals []float64) string {
|
---|
105 | return "-(" + u.C.Latex(dnames, snames, cvals) + ")"
|
---|
106 | }
|
---|
107 | func (u *Neg) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
108 | return "-(" + u.C.Javascript(dnames, snames, cvals) + ")"
|
---|
109 | }
|
---|
110 |
|
---|
111 | func (u *Abs) String() string {
|
---|
112 | if u.C == nil {
|
---|
113 | return "abs(nil)"
|
---|
114 | }
|
---|
115 | return "abs(" + u.C.String() + ")"
|
---|
116 | }
|
---|
117 | func (u *Abs) Serial(sofar []int) []int {
|
---|
118 | sofar = append(sofar, int(ABS))
|
---|
119 | return u.C.Serial(sofar)
|
---|
120 | }
|
---|
121 | func (u *Abs) StackSerial(sofar []int) []int {
|
---|
122 | sofar = u.C.StackSerial(sofar)
|
---|
123 | return append(sofar, int(ABS))
|
---|
124 | }
|
---|
125 | func (u *Abs) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
126 | return "abs(" + u.C.PrettyPrint(dnames, snames, cvals) + ")"
|
---|
127 | }
|
---|
128 | func (u *Abs) Latex(dnames, snames []string, cvals []float64) string {
|
---|
129 | return "abs(" + u.C.Latex(dnames, snames, cvals) + ")"
|
---|
130 | }
|
---|
131 | func (u *Abs) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
132 | return "abs(" + u.C.Javascript(dnames, snames, cvals) + ")"
|
---|
133 | }
|
---|
134 |
|
---|
135 | func (u *Sqrt) String() string {
|
---|
136 | if u.C == nil {
|
---|
137 | return "sqrt(nil)"
|
---|
138 | }
|
---|
139 | return "sqrt(" + u.C.String() + ")"
|
---|
140 | }
|
---|
141 | func (u *Sqrt) Serial(sofar []int) []int {
|
---|
142 | sofar = append(sofar, int(SQRT))
|
---|
143 | return u.C.Serial(sofar)
|
---|
144 | }
|
---|
145 | func (u *Sqrt) StackSerial(sofar []int) []int {
|
---|
146 | sofar = u.C.StackSerial(sofar)
|
---|
147 | return append(sofar, int(SQRT))
|
---|
148 | }
|
---|
149 | func (u *Sqrt) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
150 | return "sqrt(" + u.C.PrettyPrint(dnames, snames, cvals) + ")"
|
---|
151 | }
|
---|
152 | func (u *Sqrt) Latex(dnames, snames []string, cvals []float64) string {
|
---|
153 | return "\\sqrt{" + u.C.Latex(dnames, snames, cvals) + "}"
|
---|
154 | }
|
---|
155 | func (u *Sqrt) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
156 | return "sqrt(" + u.C.Javascript(dnames, snames, cvals) + ")"
|
---|
157 | }
|
---|
158 |
|
---|
159 | func (u *Sin) String() string {
|
---|
160 | if u.C == nil {
|
---|
161 | return "sin(nil)"
|
---|
162 | }
|
---|
163 | return "sin(" + u.C.String() + ")"
|
---|
164 | }
|
---|
165 | func (u *Sin) Serial(sofar []int) []int {
|
---|
166 | sofar = u.C.Serial(sofar)
|
---|
167 | return append(sofar, int(SIN))
|
---|
168 | }
|
---|
169 | func (u *Sin) StackSerial(sofar []int) []int {
|
---|
170 | sofar = u.C.StackSerial(sofar)
|
---|
171 | return append(sofar, int(SIN))
|
---|
172 | }
|
---|
173 | func (u *Sin) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
174 | return "sin(" + u.C.PrettyPrint(dnames, snames, cvals) + ")"
|
---|
175 | }
|
---|
176 | func (u *Sin) Latex(dnames, snames []string, cvals []float64) string {
|
---|
177 | return "\\sin(" + u.C.Latex(dnames, snames, cvals) + ")"
|
---|
178 | }
|
---|
179 | func (u *Sin) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
180 | return "sin(" + u.C.Javascript(dnames, snames, cvals) + ")"
|
---|
181 | }
|
---|
182 |
|
---|
183 | func (u *Cos) String() string {
|
---|
184 | if u.C == nil {
|
---|
185 | return "cos(nil)"
|
---|
186 | }
|
---|
187 | return "cos(" + u.C.String() + ")"
|
---|
188 | }
|
---|
189 | func (u *Cos) Serial(sofar []int) []int {
|
---|
190 | sofar = append(sofar, int(COS))
|
---|
191 | return u.C.Serial(sofar)
|
---|
192 | }
|
---|
193 | func (u *Cos) StackSerial(sofar []int) []int {
|
---|
194 | sofar = u.C.StackSerial(sofar)
|
---|
195 | return append(sofar, int(COS))
|
---|
196 | }
|
---|
197 | func (u *Cos) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
198 | return "cos(" + u.C.PrettyPrint(dnames, snames, cvals) + ")"
|
---|
199 | }
|
---|
200 | func (u *Cos) Latex(dnames, snames []string, cvals []float64) string {
|
---|
201 | return "\\cos(" + u.C.Latex(dnames, snames, cvals) + ")"
|
---|
202 | }
|
---|
203 | func (u *Cos) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
204 | return "cos(" + u.C.Javascript(dnames, snames, cvals) + ")"
|
---|
205 | }
|
---|
206 |
|
---|
207 | func (u *Tan) String() string {
|
---|
208 | if u.C == nil {
|
---|
209 | return "tan(nil)"
|
---|
210 | }
|
---|
211 | return "tan(" + u.C.String() + ")"
|
---|
212 | }
|
---|
213 | func (u *Tan) Serial(sofar []int) []int {
|
---|
214 | sofar = append(sofar, int(TAN))
|
---|
215 | return u.C.Serial(sofar)
|
---|
216 | }
|
---|
217 | func (u *Tan) StackSerial(sofar []int) []int {
|
---|
218 | sofar = u.C.StackSerial(sofar)
|
---|
219 | return append(sofar, int(TAN))
|
---|
220 | }
|
---|
221 | func (u *Tan) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
222 | return "tan(" + u.C.PrettyPrint(dnames, snames, cvals) + ")"
|
---|
223 | }
|
---|
224 | func (u *Tan) Latex(dnames, snames []string, cvals []float64) string {
|
---|
225 | return "\\tan(" + u.C.Latex(dnames, snames, cvals) + ")"
|
---|
226 | }
|
---|
227 | func (u *Tan) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
228 | return "tan(" + u.C.Javascript(dnames, snames, cvals) + ")"
|
---|
229 | }
|
---|
230 |
|
---|
231 | func (u *Exp) String() string {
|
---|
232 | if u.C == nil {
|
---|
233 | return "exp(nil)"
|
---|
234 | }
|
---|
235 | return "exp(" + u.C.String() + ")"
|
---|
236 | }
|
---|
237 | func (u *Exp) Serial(sofar []int) []int {
|
---|
238 | sofar = append(sofar, int(EXP))
|
---|
239 | return u.C.Serial(sofar)
|
---|
240 | }
|
---|
241 | func (u *Exp) StackSerial(sofar []int) []int {
|
---|
242 | sofar = u.C.StackSerial(sofar)
|
---|
243 | return append(sofar, int(EXP))
|
---|
244 | }
|
---|
245 | func (u *Exp) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
246 | return "exp(" + u.C.PrettyPrint(dnames, snames, cvals) + ")"
|
---|
247 | }
|
---|
248 | func (u *Exp) Latex(dnames, snames []string, cvals []float64) string {
|
---|
249 | return "\\exp(" + u.C.Latex(dnames, snames, cvals) + ")"
|
---|
250 | }
|
---|
251 | func (u *Exp) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
252 | return "exp(" + u.C.Javascript(dnames, snames, cvals) + ")"
|
---|
253 | }
|
---|
254 |
|
---|
255 | func (u *Log) String() string {
|
---|
256 | if u.C == nil {
|
---|
257 | return "ln(nil)"
|
---|
258 | }
|
---|
259 | return "ln(" + u.C.String() + ")"
|
---|
260 | }
|
---|
261 | func (u *Log) Serial(sofar []int) []int {
|
---|
262 | sofar = append(sofar, int(LOG))
|
---|
263 | return u.C.Serial(sofar)
|
---|
264 | }
|
---|
265 | func (u *Log) StackSerial(sofar []int) []int {
|
---|
266 | sofar = u.C.StackSerial(sofar)
|
---|
267 | return append(sofar, int(LOG))
|
---|
268 | }
|
---|
269 | func (u *Log) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
270 | return "ln(" + u.C.PrettyPrint(dnames, snames, cvals) + ")"
|
---|
271 | }
|
---|
272 | func (u *Log) Latex(dnames, snames []string, cvals []float64) string {
|
---|
273 | return "\\log(" + u.C.Latex(dnames, snames, cvals) + ")"
|
---|
274 | }
|
---|
275 | func (u *Log) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
276 | return "log(" + u.C.Javascript(dnames, snames, cvals) + ")"
|
---|
277 | }
|
---|
278 |
|
---|
279 | func (u *PowI) String() string {
|
---|
280 | if u.Base == nil {
|
---|
281 | return "(nil)^" + fmt.Sprint(u.Power)
|
---|
282 | }
|
---|
283 | return "(" + u.Base.String() + ")^" + fmt.Sprint(u.Power)
|
---|
284 | }
|
---|
285 | func (u *PowI) Serial(sofar []int) []int {
|
---|
286 | sofar = append(sofar, int(POWI))
|
---|
287 | sofar = u.Base.Serial(sofar)
|
---|
288 | return append(sofar, u.Power)
|
---|
289 | }
|
---|
290 | func (u *PowI) StackSerial(sofar []int) []int {
|
---|
291 | sofar = u.Base.StackSerial(sofar)
|
---|
292 | sofar = append(sofar, int(POWI))
|
---|
293 | sofar = append(sofar, u.Power)
|
---|
294 | return sofar
|
---|
295 | }
|
---|
296 | func (u *PowI) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
297 | return "(" + u.Base.PrettyPrint(dnames, snames, cvals) + ")^" + fmt.Sprint(u.Power)
|
---|
298 | }
|
---|
299 | func (u *PowI) Latex(dnames, snames []string, cvals []float64) string {
|
---|
300 | return "(" + u.Base.Latex(dnames, snames, cvals) + ")^{" + fmt.Sprint(u.Power) + "}"
|
---|
301 | }
|
---|
302 | func (u *PowI) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
303 | return "Math.pow(" + u.Base.Javascript(dnames, snames, cvals) + "," + fmt.Sprint(u.Power) + ")"
|
---|
304 | }
|
---|
305 |
|
---|
306 | func (u *PowF) String() string {
|
---|
307 | if u.Base == nil {
|
---|
308 | return "(nil)^" + fmt.Sprint(u.Power)
|
---|
309 | }
|
---|
310 | return "(" + u.Base.String() + ")^" + fmt.Sprint(u.Power)
|
---|
311 | }
|
---|
312 | func (u *PowF) Serial(sofar []int) []int {
|
---|
313 | sofar = append(sofar, int(POWF))
|
---|
314 | return u.Base.Serial(sofar)
|
---|
315 | }
|
---|
316 | func (u *PowF) StackSerial(sofar []int) []int {
|
---|
317 | sofar = u.Base.StackSerial(sofar)
|
---|
318 | // HACK!!!
|
---|
319 | sofar = append(sofar, int(POWI))
|
---|
320 | sofar = append(sofar, int(u.Power))
|
---|
321 | return sofar
|
---|
322 | }
|
---|
323 | func (u *PowF) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
324 | return "(" + u.Base.PrettyPrint(dnames, snames, cvals) + ")^" + fmt.Sprint(u.Power)
|
---|
325 | }
|
---|
326 | func (u *PowF) Latex(dnames, snames []string, cvals []float64) string {
|
---|
327 | return "(" + u.Base.Latex(dnames, snames, cvals) + ")^{" + fmt.Sprint(u.Power) + "}"
|
---|
328 | }
|
---|
329 | func (u *PowF) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
330 | return "Math.pow(" + u.Base.Javascript(dnames, snames, cvals) + "," + fmt.Sprint(u.Power) + ")"
|
---|
331 | }
|
---|
332 |
|
---|
333 | func (n *PowE) String() string {
|
---|
334 | var str string
|
---|
335 | if n.Base == nil {
|
---|
336 | str += "{nil}^"
|
---|
337 | } else {
|
---|
338 | str += "(" + n.Base.String() + ")^"
|
---|
339 | }
|
---|
340 | if n.Power == nil {
|
---|
341 | str += "(nil)"
|
---|
342 | } else {
|
---|
343 | str += "(" + n.Power.String() + ")"
|
---|
344 | }
|
---|
345 | return str
|
---|
346 | }
|
---|
347 | func (n *PowE) Serial(sofar []int) []int {
|
---|
348 | sofar = append(sofar, int(POWE))
|
---|
349 | sofar = n.Base.Serial(sofar)
|
---|
350 | return n.Power.Serial(sofar)
|
---|
351 | }
|
---|
352 | func (n *PowE) StackSerial(sofar []int) []int {
|
---|
353 | sofar = n.Base.StackSerial(sofar)
|
---|
354 | sofar = n.Power.StackSerial(sofar)
|
---|
355 | sofar = append(sofar, int(POWE))
|
---|
356 | return sofar
|
---|
357 | }
|
---|
358 | func (u *PowE) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
359 | return "(" + u.Base.PrettyPrint(dnames, snames, cvals) + ")^{" + u.Power.PrettyPrint(dnames, snames, cvals) + "}"
|
---|
360 | }
|
---|
361 | func (u *PowE) Latex(dnames, snames []string, cvals []float64) string {
|
---|
362 | return "(" + u.Base.Latex(dnames, snames, cvals) + ")^{" + u.Power.Latex(dnames, snames, cvals) + "}"
|
---|
363 | }
|
---|
364 | func (u *PowE) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
365 | return "Math.pow(" + u.Base.Javascript(dnames, snames, cvals) + "," + u.Power.Javascript(dnames, snames, cvals) + ")"
|
---|
366 | }
|
---|
367 |
|
---|
368 | func (n *Div) String() string {
|
---|
369 | nstr, dstr := "nil", "nil"
|
---|
370 | if n.Numer != nil {
|
---|
371 | nstr = n.Numer.String()
|
---|
372 | }
|
---|
373 | if n.Denom != nil {
|
---|
374 | dstr = n.Denom.String()
|
---|
375 | }
|
---|
376 | return "{ " + nstr + " }/{ " + dstr + " }"
|
---|
377 | }
|
---|
378 | func (n *Div) Serial(sofar []int) []int {
|
---|
379 | sofar = append(sofar, int(DIV))
|
---|
380 | if n.Numer == nil {
|
---|
381 | sofar = append(sofar, 0)
|
---|
382 | }
|
---|
383 | sofar = n.Numer.Serial(sofar)
|
---|
384 | if n.Denom == nil {
|
---|
385 | sofar = append(sofar, 0)
|
---|
386 | }
|
---|
387 | sofar = n.Denom.Serial(sofar)
|
---|
388 | return sofar
|
---|
389 | }
|
---|
390 | func (n *Div) StackSerial(sofar []int) []int {
|
---|
391 | sofar = n.Numer.StackSerial(sofar)
|
---|
392 | sofar = n.Denom.StackSerial(sofar)
|
---|
393 | sofar = append(sofar, int(DIV))
|
---|
394 | return sofar
|
---|
395 | }
|
---|
396 | func (n *Div) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
397 | nstr, dstr := "nil", "nil"
|
---|
398 | if n.Numer != nil {
|
---|
399 | nstr = n.Numer.PrettyPrint(dnames, snames, cvals)
|
---|
400 | }
|
---|
401 | if n.Denom != nil {
|
---|
402 | dstr = n.Denom.PrettyPrint(dnames, snames, cvals)
|
---|
403 | }
|
---|
404 | return "{ " + nstr + " }/{ " + dstr + " }"
|
---|
405 | }
|
---|
406 | func (n *Div) Latex(dnames, snames []string, cvals []float64) string {
|
---|
407 | nstr, dstr := "nil", "nil"
|
---|
408 | if n.Numer != nil {
|
---|
409 | nstr = n.Numer.Latex(dnames, snames, cvals)
|
---|
410 | }
|
---|
411 | if n.Denom != nil {
|
---|
412 | dstr = n.Denom.Latex(dnames, snames, cvals)
|
---|
413 | }
|
---|
414 | return "\\\\frac{ " + nstr + " }{ " + dstr + " }"
|
---|
415 | }
|
---|
416 | func (n *Div) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
417 | nstr, dstr := "nil", "nil"
|
---|
418 | if n.Numer != nil {
|
---|
419 | nstr = n.Numer.Javascript(dnames, snames, cvals)
|
---|
420 | }
|
---|
421 | if n.Denom != nil {
|
---|
422 | dstr = n.Denom.Javascript(dnames, snames, cvals)
|
---|
423 | }
|
---|
424 | return "( " + nstr + " )/( " + dstr + " )"
|
---|
425 | }
|
---|
426 |
|
---|
427 | func (n *Add) String() string {
|
---|
428 | str := "( "
|
---|
429 | if len(n.CS) == 0 {
|
---|
430 | str += "[a] )"
|
---|
431 | return str
|
---|
432 | }
|
---|
433 | if n.CS[0] == nil {
|
---|
434 | str += "nil"
|
---|
435 | } else {
|
---|
436 | str += n.CS[0].String()
|
---|
437 | }
|
---|
438 | for i := 1; i < len(n.CS); i++ {
|
---|
439 | if n.CS[i] == nil {
|
---|
440 | str += " + nil"
|
---|
441 | } else {
|
---|
442 | str += " + " + n.CS[i].String()
|
---|
443 | }
|
---|
444 | }
|
---|
445 | str += " )"
|
---|
446 | return str
|
---|
447 | }
|
---|
448 | func (n *Add) Serial(sofar []int) []int {
|
---|
449 | sofar = append(sofar, int(ADD))
|
---|
450 | sofar = append(sofar, len(n.CS))
|
---|
451 | pos := len(sofar) - 1
|
---|
452 | for _, E := range n.CS {
|
---|
453 | if E == nil {
|
---|
454 | sofar[pos]--
|
---|
455 | continue
|
---|
456 | }
|
---|
457 | sofar = E.Serial(sofar)
|
---|
458 | }
|
---|
459 | return sofar
|
---|
460 | }
|
---|
461 | func (n *Add) StackSerial(sofar []int) []int {
|
---|
462 | sofar = n.CS[0].StackSerial(sofar)
|
---|
463 | for i := 1; i < len(n.CS); i++ {
|
---|
464 | E := n.CS[i]
|
---|
465 | if E == nil {
|
---|
466 | continue
|
---|
467 | }
|
---|
468 | sofar = E.StackSerial(sofar)
|
---|
469 | sofar = append(sofar, int(ADD))
|
---|
470 | }
|
---|
471 | return sofar
|
---|
472 | }
|
---|
473 | func (n *Add) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
474 | str := "( " + n.CS[0].PrettyPrint(dnames, snames, cvals)
|
---|
475 | for i := 1; i < len(n.CS); i++ {
|
---|
476 | if n.CS[i] == nil {
|
---|
477 | continue
|
---|
478 | }
|
---|
479 | str += " + " + n.CS[i].PrettyPrint(dnames, snames, cvals)
|
---|
480 | }
|
---|
481 | str += " )"
|
---|
482 | return str
|
---|
483 | }
|
---|
484 | func (n *Add) Latex(dnames, snames []string, cvals []float64) string {
|
---|
485 | str := "( " + n.CS[0].Latex(dnames, snames, cvals)
|
---|
486 | for i := 1; i < len(n.CS); i++ {
|
---|
487 | if n.CS[i] == nil {
|
---|
488 | continue
|
---|
489 | }
|
---|
490 | str += " + " + n.CS[i].Latex(dnames, snames, cvals)
|
---|
491 | }
|
---|
492 | str += " )"
|
---|
493 | return str
|
---|
494 | }
|
---|
495 | func (n *Add) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
496 | str := "( " + n.CS[0].Javascript(dnames, snames, cvals)
|
---|
497 | for i := 1; i < len(n.CS); i++ {
|
---|
498 | if n.CS[i] == nil {
|
---|
499 | continue
|
---|
500 | }
|
---|
501 | str += " + " + n.CS[i].Javascript(dnames, snames, cvals)
|
---|
502 | }
|
---|
503 | str += " )"
|
---|
504 | return str
|
---|
505 | }
|
---|
506 |
|
---|
507 | func (n *Mul) String() string {
|
---|
508 | var str string
|
---|
509 | if len(n.CS) == 0 {
|
---|
510 | return "[m]"
|
---|
511 | }
|
---|
512 | if n.CS[0] == nil {
|
---|
513 | str += "nil"
|
---|
514 | } else {
|
---|
515 | str += n.CS[0].String()
|
---|
516 | }
|
---|
517 | for i := 1; i < len(n.CS); i++ {
|
---|
518 | if n.CS[i] == nil {
|
---|
519 | str += " + nil"
|
---|
520 | } else {
|
---|
521 | str += "*" + n.CS[i].String()
|
---|
522 | }
|
---|
523 | }
|
---|
524 | return str
|
---|
525 | }
|
---|
526 | func (n *Mul) Serial(sofar []int) []int {
|
---|
527 | sofar = append(sofar, int(MUL))
|
---|
528 | sofar = append(sofar, len(n.CS))
|
---|
529 | pos := len(sofar) - 1
|
---|
530 | for _, E := range n.CS {
|
---|
531 | if E == nil {
|
---|
532 | sofar[pos]--
|
---|
533 | continue
|
---|
534 | }
|
---|
535 | sofar = E.Serial(sofar)
|
---|
536 | }
|
---|
537 | return sofar
|
---|
538 | }
|
---|
539 | func (n *Mul) StackSerial(sofar []int) []int {
|
---|
540 | sofar = n.CS[0].StackSerial(sofar)
|
---|
541 | for i := 1; i < len(n.CS); i++ {
|
---|
542 | E := n.CS[i]
|
---|
543 | if E == nil {
|
---|
544 | continue
|
---|
545 | }
|
---|
546 | sofar = E.StackSerial(sofar)
|
---|
547 | sofar = append(sofar, int(MUL))
|
---|
548 | }
|
---|
549 | return sofar
|
---|
550 | }
|
---|
551 | func (n *Mul) PrettyPrint(dnames, snames []string, cvals []float64) string {
|
---|
552 | str := n.CS[0].PrettyPrint(dnames, snames, cvals)
|
---|
553 | for i := 1; i < len(n.CS); i++ {
|
---|
554 | if n.CS[i] == nil {
|
---|
555 | continue
|
---|
556 | }
|
---|
557 | str += "*" + n.CS[i].PrettyPrint(dnames, snames, cvals)
|
---|
558 | }
|
---|
559 | return str
|
---|
560 | }
|
---|
561 | func (n *Mul) Latex(dnames, snames []string, cvals []float64) string {
|
---|
562 | str := n.CS[0].Latex(dnames, snames, cvals)
|
---|
563 | for i := 1; i < len(n.CS); i++ {
|
---|
564 | if n.CS[i] == nil {
|
---|
565 | continue
|
---|
566 | }
|
---|
567 | str += "*" + n.CS[i].Latex(dnames, snames, cvals)
|
---|
568 | }
|
---|
569 | return str
|
---|
570 | }
|
---|
571 | func (n *Mul) Javascript(dnames, snames []string, cvals []float64) string {
|
---|
572 | str := n.CS[0].Javascript(dnames, snames, cvals)
|
---|
573 | for i := 1; i < len(n.CS); i++ {
|
---|
574 | if n.CS[i] == nil {
|
---|
575 | continue
|
---|
576 | }
|
---|
577 | str += "*" + n.CS[i].Javascript(dnames, snames, cvals)
|
---|
578 | }
|
---|
579 | return str
|
---|
580 | }
|
---|