-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
45 lines (36 loc) · 906 Bytes
/
main.cpp
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
#include <cstdio>
#include <ctime>
#include "include/tree.h"
#include "include/parser.h"
#include "include/dump.h"
#include "include/differentiator.h"
#include "include/optimizer.h"
#include "include/tex.h"
int
main()
{
size_t derivative_order = 0;
Tree **trees = nullptr;
printf("Derivative order: ");
scanf("%zu", &derivative_order);
trees = (Tree **)calloc(derivative_order + 1, sizeof(Tree *));
assert(trees);
trees[0] = get_expression_tree();
tex(trees[0], 0);
optimize(trees[0]);
tex(trees[0], 0);
for (size_t i = 1; i <= derivative_order; i++)
{
trees[i] = differentiate(trees[i - 1]);
optimize(trees[i]);
tex(trees[i], i);
}
show_texfile();
for (size_t i = 0; i < derivative_order + 1; i++)
{
tree_dump(trees[i]);
tree_destruct(trees[i]);
}
free(trees);
return 0;
}