-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpolynomial.cpp
More file actions
137 lines (111 loc) · 3.66 KB
/
Copy pathpolynomial.cpp
File metadata and controls
137 lines (111 loc) · 3.66 KB
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
#include <iostream>
#include "polynomial.h"
quintuple_poly::quintuple_poly() { a.clear(); b.clear(); c.clear(); d.clear(); e.clear(); f.clear();}
quintuple_poly::quintuple_poly(const F &aa, const F &bb, const F &cc, const F &dd, const F &ee, const F &ff) {
a = aa;
b = bb;
c = cc;
d = dd;
e = ee;
f = ff;
}
quintuple_poly quintuple_poly::operator + (const quintuple_poly &x) const {
return quintuple_poly(a + x.a, b + x.b, c + x.c, d + x.d, e + x.e, f + x.f);
}
F quintuple_poly::eval(const F &x) const {
return (((((a * x) + b) * x + c) * x + d) * x + e) * x + f;
}
void quintuple_poly::clear() {
a.clear(); b.clear(); c.clear(); d.clear(); e.clear(); f.clear();
}
quadruple_poly::quadruple_poly() {a.clear(); b.clear(); c.clear(); d.clear(); e.clear();}
quadruple_poly::quadruple_poly(const F &aa, const F &bb, const F &cc, const F &dd, const F &ee) {
a = aa;
b = bb;
c = cc;
d = dd;
e = ee;
}
quadruple_poly quadruple_poly::operator + (const quadruple_poly &x) const {
return quadruple_poly(a + x.a, b + x.b, c + x.c, d + x.d, e + x.e);
}
F quadruple_poly::eval(const F &x) const {
return ((((a * x) + b) * x + c) * x + d) * x + e;
}
void quadruple_poly::clear() {
a.clear(); b.clear(); c.clear(); d.clear(); e.clear();
}
cubic_poly::cubic_poly() {a.clear(); b.clear(); c.clear(); d.clear();}
cubic_poly::cubic_poly(const F &aa, const F &bb, const F &cc, const F &dd) {
a = aa;
b = bb;
c = cc;
d = dd;
}
cubic_poly cubic_poly::operator + (const cubic_poly &x) const {
return cubic_poly(a + x.a, b + x.b, c + x.c, d + x.d);
}
F cubic_poly::eval(const F &x) const {
return (((a * x) + b) * x + c) * x + d;
}
quadratic_poly::quadratic_poly() {a.clear(); b.clear(); c.clear();}
quadratic_poly::quadratic_poly(const F &aa, const F &bb, const F &cc) {
a = aa;
b = bb;
c = cc;
}
quadratic_poly quadratic_poly::operator + (const quadratic_poly &x) const {
return quadratic_poly(a + x.a, b + x.b, c + x.c);
}
quadratic_poly quadratic_poly::operator+(const linear_poly &x) const {
return quadratic_poly(a, b + x.a, c + x.b);
}
cubic_poly quadratic_poly::operator * (const linear_poly &x) const {
return cubic_poly(a * x.a, a * x.b + b * x.a, b * x.b + c * x.a, c * x.b);
}
cubic_poly cubic_poly::operator * (const F &x) const {
return cubic_poly(a * x, b * x, c * x, d * x);
}
void cubic_poly::clear() {
a.clear(); b.clear(); c.clear(); d.clear();
}
quadratic_poly quadratic_poly::operator*(const F &x) const {
return quadratic_poly(a * x, b * x, c * x);
}
F quadratic_poly::eval(const F &x) const {
return ((a * x) + b) * x + c;
}
void quadratic_poly::clear() {
a.clear(); b.clear(); c.clear();
}
linear_poly::linear_poly() {a.clear(); b.clear();}
linear_poly::linear_poly(const F &aa, const F &bb) {
a = aa;
b = bb;
}
linear_poly::linear_poly(const F &x) {
a.clear();
b = x;
}
linear_poly linear_poly::operator + (const linear_poly &x) const {
return linear_poly(a + x.a, b + x.b);
}
quadratic_poly linear_poly::operator * (const linear_poly &x) const
{
if(x.a.isZero())
return quadratic_poly(F_ZERO, a * x.b, b * x.b);
else if(x.b.isZero())
return quadratic_poly(a * x.a, b * x.a, F_ZERO);
else
return quadratic_poly(a * x.a, a * x.b + b * x.a, b * x.b);
}
linear_poly linear_poly::operator*(const F &x) const {
return linear_poly(a * x, b * x);
}
F linear_poly::eval(const F &x) const
{
return x.isZero() ? b :a * x + b;
}
void linear_poly::clear() {
a.clear(); b.clear();
}