kalc 0.7.4

a complex numbers, 2d/3d graphing, arbitrary precision, vector, cli calculator with real-time output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
use std::{thread, thread::JoinHandle, time::Instant};
use gnuplot::{AxesCommon, Caption, Color, Figure, Fix, PointSymbol};
use rug::Complex;
use crate::{
    complex::{
        NumStr,
        NumStr::{Num, Str, Vector},
    },
    math::do_math,
    Options,
};
pub fn graph(input:Vec<String>, func:Vec<Vec<NumStr>>, options:Options, deg:u8, prec:u32, watch:Option<Instant>) -> JoinHandle<()>
{
    thread::spawn(move || {
        let mut fg = Figure::new();
        fg.set_enhanced_text(false);
        let re1col = "#ff5555";
        let re2col = "#55ff55";
        let re3col = "#ffff55";
        let re4col = "#5555ff";
        let re5col = "#ff55ff";
        let re6col = "#55ffff";
        let im1col = "#aa0000";
        let im2col = "#00aa00";
        let im3col = "#aaaa00";
        let im4col = "#0000aa";
        let im5col = "#aa00aa";
        let im6col = "#00aaaa";
        let xticks = Some((Fix((options.xr[1] - options.xr[0]) / 20.0), 1));
        let yticks = Some((Fix((options.yr[1] - options.yr[0]) / 20.0), 1));
        let mut re_cap:[String; 6] = Default::default();
        let mut im_cap:[String; 6] = Default::default();
        if !input[0].contains('x')
        {
            let mut re = Vec::new();
            for (i, f) in func.iter().enumerate()
            {
                re.push(match do_math(f.to_vec(), deg, prec).unwrap()
                  {
                      Vector(n) => n,
                      Num(n) => vec![Complex::with_val(prec, n.real()), Complex::with_val(prec, n.imag())],
                      _ => return,
                  });
                re_cap[i] = input[i].to_owned() + ":re";
                im_cap[i] = input[i].to_owned() + ":im";
            }
            if re[0].len() == 2
            {
                let z = vec![Complex::with_val(prec, 0); 2];
                for _ in 0..6 - func.len()
                {
                    re.push(z.clone());
                }
                fg.axes2d()
                  .set_x_ticks(xticks, &[], &[])
                  .set_y_ticks(yticks, &[], &[])
                  .set_y_range(Fix(options.yr[0]), Fix(options.yr[1]))
                  .set_x_range(Fix(options.xr[0]), Fix(options.xr[1]))
                  .lines([0.0, re[0][0].real().to_f64()], [0.0, re[0][1].real().to_f64()], &[Caption(&re_cap[0]), Color(re1col)])
                  .lines([0.0, re[1][0].real().to_f64()], [0.0, re[1][1].real().to_f64()], &[Caption(&re_cap[1]), Color(re2col)])
                  .lines([0.0, re[2][0].real().to_f64()], [0.0, re[2][1].real().to_f64()], &[Caption(&re_cap[2]), Color(re3col)])
                  .lines([0.0, re[3][0].real().to_f64()], [0.0, re[3][1].real().to_f64()], &[Caption(&re_cap[3]), Color(re4col)])
                  .lines([0.0, re[4][0].real().to_f64()], [0.0, re[4][1].real().to_f64()], &[Caption(&re_cap[4]), Color(re5col)])
                  .lines([0.0, re[5][0].real().to_f64()], [0.0, re[5][1].real().to_f64()], &[Caption(&re_cap[5]), Color(re6col)])
                  .lines([0.0, re[0][0].imag().to_f64()], [0.0, re[0][1].imag().to_f64()], &[Caption(&im_cap[0]), Color(im1col)])
                  .lines([0.0, re[1][0].imag().to_f64()], [0.0, re[1][1].imag().to_f64()], &[Caption(&im_cap[1]), Color(im2col)])
                  .lines([0.0, re[2][0].imag().to_f64()], [0.0, re[2][1].imag().to_f64()], &[Caption(&im_cap[2]), Color(im3col)])
                  .lines([0.0, re[3][0].imag().to_f64()], [0.0, re[3][1].imag().to_f64()], &[Caption(&im_cap[3]), Color(im4col)])
                  .lines([0.0, re[4][0].imag().to_f64()], [0.0, re[4][1].imag().to_f64()], &[Caption(&im_cap[4]), Color(im5col)])
                  .lines([0.0, re[5][0].imag().to_f64()], [0.0, re[5][1].imag().to_f64()], &[Caption(&im_cap[5]), Color(im6col)]);
            }
            else if re[0].len() == 3
            {
                let z = vec![Complex::with_val(prec, 0); 3];
                for _ in 0..6 - func.len()
                {
                    re.push(z.clone());
                }
                let zticks = Some((Fix((options.zr[1] - options.zr[0]) / 20.0), 1));
                fg.axes3d()
                  .set_x_ticks(xticks, &[], &[])
                  .set_y_ticks(yticks, &[], &[])
                  .set_z_ticks(zticks, &[], &[])
                  .set_x_range(Fix(options.xr[0]), Fix(options.xr[1]))
                  .set_y_range(Fix(options.yr[0]), Fix(options.yr[1]))
                  .set_z_range(Fix(options.zr[0]), Fix(options.zr[1]))
                  .set_z_label("z", &[])
                  .set_y_label("y", &[])
                  .set_x_label("x", &[])
                  .lines([0.0, re[0][0].real().to_f64()], [0.0, re[0][1].real().to_f64()], [0.0, re[0][2].real().to_f64()], &[Caption(&re_cap
                                                                                                                                          [0]),
                                                                                                                              Color(re1col)])
                  .lines([0.0, re[1][0].real().to_f64()], [0.0, re[1][1].real().to_f64()], [0.0, re[1][2].real().to_f64()], &[Caption(&re_cap
                                                                                                                                          [1]),
                                                                                                                              Color(re2col)])
                  .lines([0.0, re[2][0].real().to_f64()], [0.0, re[2][1].real().to_f64()], [0.0, re[2][2].real().to_f64()], &[Caption(&re_cap
                                                                                                                                          [2]),
                                                                                                                              Color(re3col)])
                  .lines([0.0, re[3][0].real().to_f64()], [0.0, re[3][1].real().to_f64()], [0.0, re[3][2].real().to_f64()], &[Caption(&re_cap
                                                                                                                                          [3]),
                                                                                                                              Color(re4col)])
                  .lines([0.0, re[4][0].real().to_f64()], [0.0, re[4][1].real().to_f64()], [0.0, re[4][2].real().to_f64()], &[Caption(&re_cap
                                                                                                                                          [4]),
                                                                                                                              Color(re5col)])
                  .lines([0.0, re[5][0].real().to_f64()], [0.0, re[5][1].real().to_f64()], [0.0, re[5][2].real().to_f64()], &[Caption(&re_cap
                                                                                                                                          [5]),
                                                                                                                              Color(re6col)])
                  .lines([0.0, re[0][0].imag().to_f64()], [0.0, re[0][1].imag().to_f64()], [0.0, re[0][2].imag().to_f64()], &[Caption(&im_cap
                                                                                                                                          [0]),
                                                                                                                              Color(im1col)])
                  .lines([0.0, re[1][0].imag().to_f64()], [0.0, re[1][1].imag().to_f64()], [0.0, re[1][2].imag().to_f64()], &[Caption(&im_cap
                                                                                                                                          [1]),
                                                                                                                              Color(im2col)])
                  .lines([0.0, re[2][0].imag().to_f64()], [0.0, re[2][1].imag().to_f64()], [0.0, re[2][2].imag().to_f64()], &[Caption(&im_cap
                                                                                                                                          [2]),
                                                                                                                              Color(im3col)])
                  .lines([0.0, re[3][0].imag().to_f64()], [0.0, re[3][1].imag().to_f64()], [0.0, re[3][2].imag().to_f64()], &[Caption(&im_cap
                                                                                                                                          [3]),
                                                                                                                              Color(im4col)])
                  .lines([0.0, re[4][0].imag().to_f64()], [0.0, re[4][1].imag().to_f64()], [0.0, re[4][2].imag().to_f64()], &[Caption(&im_cap
                                                                                                                                          [4]),
                                                                                                                              Color(im5col)])
                  .lines([0.0, re[5][0].imag().to_f64()], [0.0, re[5][1].imag().to_f64()], [0.0, re[5][2].imag().to_f64()], &[Caption(&im_cap
                                                                                                                                          [5]),
                                                                                                                              Color(im6col)]);
            }
        }
        else if input[0].contains('y')
        {
            let zticks = Some((Fix((options.zr[1] - options.zr[0]) / 20.0), 1));
            let mut re = vec![Vec::new(); 6];
            let mut im = vec![Vec::new(); 6];
            let (mut re2, mut im2);
            for (i, f) in func.iter().enumerate()
            {
                (re2, im2) = get_list_3d(f, options, deg, prec);
                if re2.iter().map(|i| ((i[2] * 1e15).round() / 1e15) == 0.0).all(|i| i)
                {
                    re2.clear();
                }
                else
                {
                    re_cap[i] = input[i].to_owned() + ":re";
                }
                if im2.iter().map(|i| ((i[2] * 1e15).round() / 1e15) == 0.0).all(|i| i)
                {
                    im2.clear();
                }
                else
                {
                    im_cap[i] = input[i].to_owned() + ":im";
                }
                re[i].extend(re2);
                im[i].extend(im2);
            }
            if re.iter().all(|x| x.is_empty()) && im.iter().all(|x| x.is_empty())
            {
                println!("No data to plot");
                return;
            }
            fg.axes3d()
              .set_x_ticks(xticks, &[], &[])
              .set_y_ticks(yticks, &[], &[])
              .set_z_ticks(zticks, &[], &[])
              .set_x_range(Fix(options.xr[0]), Fix(options.xr[1]))
              .set_y_range(Fix(options.yr[0]), Fix(options.yr[1]))
              .set_z_range(Fix(options.zr[0]), Fix(options.zr[1]))
              .set_z_label("z", &[])
              .set_y_label("y", &[])
              .set_x_label("x", &[])
              .lines([0], [0], [0], &[Caption(&re_cap[0]), Color(re1col)])
              .lines([0], [0], [0], &[Caption(&im_cap[0]), Color(im1col)])
              .lines([0], [0], [0], &[Caption(&re_cap[1]), Color(re2col)])
              .lines([0], [0], [0], &[Caption(&im_cap[1]), Color(im2col)])
              .lines([0], [0], [0], &[Caption(&re_cap[2]), Color(re3col)])
              .lines([0], [0], [0], &[Caption(&im_cap[2]), Color(im3col)])
              .lines([0], [0], [0], &[Caption(&re_cap[3]), Color(re4col)])
              .lines([0], [0], [0], &[Caption(&im_cap[3]), Color(im4col)])
              .lines([0], [0], [0], &[Caption(&re_cap[4]), Color(re5col)])
              .lines([0], [0], [0], &[Caption(&im_cap[4]), Color(im5col)])
              .lines([0], [0], [0], &[Caption(&re_cap[5]), Color(re6col)])
              .lines([0], [0], [0], &[Caption(&im_cap[5]), Color(im6col)])
              .points(re[0].iter().map(|i| i[0]), re[0].iter().map(|i| i[1]), re[0].iter().map(|i| i[2]), &[PointSymbol(options.point_style),
                                                                                                            Color(re1col)])
              .points(im[0].iter().map(|i| i[0]), im[0].iter().map(|i| i[1]), im[0].iter().map(|i| i[2]), &[PointSymbol(options.point_style),
                                                                                                            Color(im1col)])
              .points(re[1].iter().map(|i| i[0]), re[1].iter().map(|i| i[1]), re[1].iter().map(|i| i[2]), &[PointSymbol(options.point_style),
                                                                                                            Color(re2col)])
              .points(im[1].iter().map(|i| i[0]), im[1].iter().map(|i| i[1]), im[1].iter().map(|i| i[2]), &[PointSymbol(options.point_style),
                                                                                                            Color(im2col)])
              .points(re[2].iter().map(|i| i[0]), re[2].iter().map(|i| i[1]), re[2].iter().map(|i| i[2]), &[PointSymbol(options.point_style),
                                                                                                            Color(re3col)])
              .points(im[2].iter().map(|i| i[0]), im[2].iter().map(|i| i[1]), im[2].iter().map(|i| i[2]), &[PointSymbol(options.point_style),
                                                                                                            Color(im3col)])
              .points(re[3].iter().map(|i| i[0]), re[3].iter().map(|i| i[1]), re[3].iter().map(|i| i[2]), &[PointSymbol(options.point_style),
                                                                                                            Color(re4col)])
              .points(im[3].iter().map(|i| i[0]), im[3].iter().map(|i| i[1]), im[3].iter().map(|i| i[2]), &[PointSymbol(options.point_style),
                                                                                                            Color(im4col)])
              .points(re[4].iter().map(|i| i[0]), re[4].iter().map(|i| i[1]), re[4].iter().map(|i| i[2]), &[PointSymbol(options.point_style),
                                                                                                            Color(re5col)])
              .points(im[4].iter().map(|i| i[0]), im[4].iter().map(|i| i[1]), im[4].iter().map(|i| i[2]), &[PointSymbol(options.point_style),
                                                                                                            Color(im5col)])
              .points(re[5].iter().map(|i| i[0]), re[5].iter().map(|i| i[1]), re[5].iter().map(|i| i[2]), &[PointSymbol(options.point_style),
                                                                                                            Color(re6col)])
              .points(im[5].iter().map(|i| i[0]), im[5].iter().map(|i| i[1]), im[5].iter().map(|i| i[2]), &[PointSymbol(options.point_style),
                                                                                                            Color(im6col)]);
        }
        else
        {
            let mut re = vec![Vec::new(); 6];
            let mut im = vec![Vec::new(); 6];
            let (mut re2, mut im2);
            for (i, f) in func.iter().enumerate()
            {
                (re2, im2) = get_list_2d(f, options, deg, prec);
                if re2.iter().map(|i| ((i[1] * 1e15).round() / 1e15) == 0.0).all(|i| i)
                {
                    re2.clear();
                }
                else
                {
                    re_cap[i] = input[i].to_owned() + ":re";
                }
                if im2.iter().map(|i| ((i[1] * 1e15).round() / 1e15) == 0.0).all(|i| i)
                {
                    im2.clear();
                }
                else
                {
                    im_cap[i] = input[i].to_owned() + ":im";
                }
                re[i].extend(re2);
                im[i].extend(im2);
            }
            if re.iter().all(|x| x.is_empty()) && im.iter().all(|x| x.is_empty())
            {
                println!("No data to plot");
                return;
            }
            if options.lines
            {
                fg.axes2d()
                  .set_x_ticks(xticks, &[], &[])
                  .set_y_ticks(yticks, &[], &[])
                  .set_y_range(Fix(options.yr[0]), Fix(options.yr[1]))
                  .set_x_range(Fix(options.xr[0]), Fix(options.xr[1]))
                  .lines([0], [0], &[Caption(&re_cap[0]), Color(re1col)])
                  .lines([0], [0], &[Caption(&im_cap[0]), Color(im1col)])
                  .lines([0], [0], &[Caption(&re_cap[1]), Color(re2col)])
                  .lines([0], [0], &[Caption(&im_cap[1]), Color(im2col)])
                  .lines([0], [0], &[Caption(&re_cap[2]), Color(re3col)])
                  .lines([0], [0], &[Caption(&im_cap[2]), Color(im3col)])
                  .lines([0], [0], &[Caption(&re_cap[3]), Color(re4col)])
                  .lines([0], [0], &[Caption(&im_cap[3]), Color(im4col)])
                  .lines([0], [0], &[Caption(&re_cap[4]), Color(re5col)])
                  .lines([0], [0], &[Caption(&im_cap[4]), Color(im5col)])
                  .lines([0], [0], &[Caption(&re_cap[5]), Color(re6col)])
                  .lines([0], [0], &[Caption(&im_cap[5]), Color(im6col)])
                  .lines(re[0].iter().map(|x| x[0]), re[0].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(re1col)])
                  .lines(im[0].iter().map(|x| x[0]), im[0].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(im1col)])
                  .lines(re[1].iter().map(|x| x[0]), re[1].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(re2col)])
                  .lines(im[1].iter().map(|x| x[0]), im[1].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(im2col)])
                  .lines(re[2].iter().map(|x| x[0]), re[2].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(re3col)])
                  .lines(im[2].iter().map(|x| x[0]), im[2].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(im3col)])
                  .lines(re[3].iter().map(|x| x[0]), re[3].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(re4col)])
                  .lines(im[3].iter().map(|x| x[0]), im[3].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(im4col)])
                  .lines(re[4].iter().map(|x| x[0]), re[4].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(re5col)])
                  .lines(im[4].iter().map(|x| x[0]), im[4].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(im5col)])
                  .lines(re[5].iter().map(|x| x[0]), re[5].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(re6col)])
                  .lines(im[5].iter().map(|x| x[0]), im[5].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(im6col)]);
            }
            else
            {
                fg.axes2d()
                  .set_x_ticks(xticks, &[], &[])
                  .set_y_ticks(yticks, &[], &[])
                  .set_y_range(Fix(options.yr[0]), Fix(options.yr[1]))
                  .set_x_range(Fix(options.xr[0]), Fix(options.xr[1]))
                  .lines([0], [0], &[Caption(&re_cap[0]), Color(re1col)])
                  .lines([0], [0], &[Caption(&im_cap[0]), Color(im1col)])
                  .lines([0], [0], &[Caption(&re_cap[1]), Color(re2col)])
                  .lines([0], [0], &[Caption(&im_cap[1]), Color(im2col)])
                  .lines([0], [0], &[Caption(&re_cap[2]), Color(re3col)])
                  .lines([0], [0], &[Caption(&im_cap[2]), Color(im3col)])
                  .lines([0], [0], &[Caption(&re_cap[3]), Color(re4col)])
                  .lines([0], [0], &[Caption(&im_cap[3]), Color(im4col)])
                  .lines([0], [0], &[Caption(&re_cap[4]), Color(re5col)])
                  .lines([0], [0], &[Caption(&im_cap[4]), Color(im5col)])
                  .lines([0], [0], &[Caption(&re_cap[5]), Color(re6col)])
                  .lines([0], [0], &[Caption(&im_cap[5]), Color(im6col)])
                  .points(re[0].iter().map(|x| x[0]), re[0].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(re1col)])
                  .points(im[0].iter().map(|x| x[0]), im[0].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(im1col)])
                  .points(re[1].iter().map(|x| x[0]), re[1].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(re2col)])
                  .points(im[1].iter().map(|x| x[0]), im[1].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(im2col)])
                  .points(re[2].iter().map(|x| x[0]), re[2].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(re3col)])
                  .points(im[2].iter().map(|x| x[0]), im[2].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(im3col)])
                  .points(re[3].iter().map(|x| x[0]), re[3].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(re4col)])
                  .points(im[3].iter().map(|x| x[0]), im[3].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(im4col)])
                  .points(re[4].iter().map(|x| x[0]), re[4].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(re5col)])
                  .points(im[4].iter().map(|x| x[0]), im[4].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(im5col)])
                  .points(re[5].iter().map(|x| x[0]), re[5].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(re6col)])
                  .points(im[5].iter().map(|x| x[0]), im[5].iter().map(|x| x[1]), &[PointSymbol(options.point_style), Color(im6col)]);
            }
        }
        if let Some(time) = watch
        {
            println!("{}ms", time.elapsed().as_millis());
        }
        fg.show().unwrap();
    })
}
pub fn get_list_2d(func:&[NumStr], range:Options, deg:u8, prec:u32) -> (Vec<[f64; 2]>, Vec<[f64; 2]>)
{
    if let Num(n) = &func[0]
    {
        if func.len() == 1 && n.eq0()
        {
            return (Vec::new(), Vec::new());
        }
    }
    let mut re = Vec::new();
    let mut im = Vec::new();
    let min = range.xr[0];
    let max = range.xr[1];
    let den = range.samples_2d;
    let den_range = (max - min) / den;
    let (mut n, mut num);
    for i in 0..=den as i32
    {
        n = min + i as f64 * den_range;
        num = match do_math(func.iter()
                                .map(|i| {
                                    match i
                                    {
                                        Str(s) if s == "x" => Num(Complex::with_val(prec, n)),
                                        _ => i.clone(),
                                    }
                                })
                                .collect(),
                            deg,
                            prec)
        {
            Ok(n) =>
            {
                match n.num()
                {
                    Ok(n) => n,
                    _ => continue,
                }
            }
            Err(_) => continue,
        };
        if num.real().is_finite()
        {
            re.push([n, num.real().to_f64()]);
        }
        if num.imag().is_finite()
        {
            im.push([n, num.imag().to_f64()]);
        }
    }
    (re, im)
}
pub fn get_list_3d(func:&[NumStr], range:Options, deg:u8, prec:u32) -> (Vec<[f64; 3]>, Vec<[f64; 3]>)
{
    if let Num(n) = &func[0]
    {
        if func.len() == 1 && n.eq0()
        {
            return (Vec::new(), Vec::new());
        }
    }
    let mut re = Vec::new();
    let mut im = Vec::new();
    let den = range.samples_3d;
    let min_x = range.xr[0];
    let max_x = range.xr[1];
    let den_x_range = (max_x - min_x) / den;
    let min_y = range.yr[0];
    let max_y = range.yr[1];
    let den_y_range = (max_y - min_y) / den;
    let (mut n, mut f, mut num);
    let mut modified:Vec<NumStr>;
    for i in 0..=den as i32
    {
        n = min_x + i as f64 * den_x_range;
        modified = func.iter()
                       .map(|i| {
                           match i
                           {
                               Str(s) if s == "x" => Num(Complex::with_val(prec, n)),
                               _ => i.clone(),
                           }
                       })
                       .collect();
        for g in 0..=den as i32
        {
            f = min_y + g as f64 * den_y_range;
            num = match do_math(modified.iter()
                                        .map(|j| {
                                            match j
                                            {
                                                Str(s) if s == "y" => Num(Complex::with_val(prec, f)),
                                                _ => j.clone(),
                                            }
                                        })
                                        .collect(),
                                deg,
                                prec)
            {
                Ok(n) =>
                {
                    match n.num()
                    {
                        Ok(n) => n,
                        _ => continue,
                    }
                }
                Err(_) => continue,
            };
            if num.real().is_finite()
            {
                re.push([n, f, num.real().to_f64()]);
            }
            if num.imag().is_finite()
            {
                im.push([n, f, num.imag().to_f64()]);
            }
        }
    }
    (re, im)
}