Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit ac01107

Browse files
committed
bibase class
1 parent 80e08ad commit ac01107

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

hypercomplex.hpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,108 @@ namespace hypercomplex {
119119
return os;
120120
}
121121
};
122+
123+
class bibase {
124+
private:
125+
bibase self() { return bibase(e); }
126+
127+
Cpair<bibase, bibase> split(bibase q) {
128+
int m = q.e.size() / 2;
129+
130+
bibase a = bibase({});
131+
bibase b = bibase({});
132+
for(int l = 0; l < q.e.size(); l++) {
133+
if (l < m) {
134+
a.e.push_back(q.e[l]);
135+
} else {
136+
b.e.push_back(q.e[l]);
137+
}
138+
}
139+
return {a, b};
140+
}
141+
142+
bibase conj(bibase other) {
143+
bibase xstar = bibase({});
144+
for(auto a : other.e) {
145+
xstar.e.push_back(a*-1.0);
146+
}
147+
xstar.e[0] *= -1;
148+
return xstar;
149+
}
150+
public:
151+
std::vector<float> e;
152+
153+
bibase(int dim) {
154+
assert(!valid_dim(dim));
155+
for(int x = 0; x < dim; x++) {
156+
e.push_back(0);
157+
}
158+
}
159+
bibase(std::vector<float> data) {
160+
assert(valid_dim(data.size()));
161+
e = data;
162+
};
163+
bibase(std::vector<float> data, int dim) {
164+
assert(valid_dim(data.size()) && dim == data.size());
165+
e = data;
166+
};
167+
168+
bibase operator+(bibase const& other) {
169+
assert(e.size() == other.e.size());
170+
std::vector<float> E;
171+
for(int x = 0; x < e.size(); x++) {
172+
E.push_back(e[x] + other.e[x]);
173+
}
174+
return bibase(E);
175+
}
176+
bibase operator-(bibase const& other) {
177+
assert(e.size() == other.e.size());
178+
std::vector<float> E;
179+
for(int x = 0; x < e.size(); x++) {
180+
E.push_back(e[x] - other.e[x]);
181+
}
182+
return bibase(E);
183+
}
184+
void operator+=(bibase const& other) {
185+
assert(e.size() == other.e.size());
186+
for(int x = 0; x < e.size(); x++)
187+
e[x] += other.e[x];
188+
}
189+
void operator-=(bibase const& other) {
190+
assert(e.size() == other.e.size());
191+
for(int x = 0; x < e.size(); x++)
192+
e[x] -= other.e[x];
193+
}
194+
195+
bibase operator*(bibase y) {
196+
assert(e.size() == y.e.size());
197+
if(e.size() == 1)
198+
return bibase(std::vector<float>({e[0]*y.e[0]}));
199+
200+
Cpair<bibase, bibase> p1 = split(self());
201+
Cpair<bibase, bibase> p2 = split(y);
202+
203+
bibase qp1 = bibase((p1.a1*p2.a1 - conj(p2.a2)*p1.a2).e);
204+
bibase qp2 = bibase((p2.a2*p1.a1 + p1.a2*conj(p2.a1)).e);
205+
206+
bibase q = bibase({});
207+
208+
for(auto qp : qp1.e)
209+
q.e.push_back(qp);
210+
211+
for(auto qp : qp2.e)
212+
q.e.push_back(qp);
213+
214+
return q;
215+
}
216+
217+
friend std::ostream& operator<<(std::ostream& os, bibase other) {
218+
for(int x = 0; x < other.e.size(); x++){
219+
os << (other.e[x] > 0 ? '+' : '-') << fabs(other.e[x]) << "e" << x+1;
220+
}
221+
return os;
222+
}
223+
};
122224
}
123225

124226
struct complex: hypercomplex::base {

0 commit comments

Comments
 (0)