Epstein Zeta Library 0.6.2
Calculates the Epstein Zeta function
Loading...
Searching...
No Matches
tools.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 Andreas Buchheit <buchheit@num.uni-sb.de>
2// SPDX-FileCopyrightText: 2024-2026 Jonathan Busse <jonathan@jbusse.de>
3// SPDX-FileCopyrightText: 2024 Ruben Gutendorf
4// <ruben.gutendorf@uni-saarland.de>
5//
6// SPDX-License-Identifier: AGPL-3.0-only
7
13#ifndef EPSTEIN_TOOLS
14#define EPSTEIN_TOOLS
15#include <complex.h>
16#include <stdbool.h>
17
25static inline double real_int_pow(double base, unsigned int exp) {
26 double b2;
27 switch (exp) {
28 case 0:
29 return 1.0;
30 case 1:
31 return base;
32 case 2:
33 return base * base;
34 case 3:
35 return base * base * base;
36 case 4:
37 b2 = base * base;
38 return b2 * b2;
39 case 5:
40 b2 = base * base;
41 return b2 * b2 * base;
42 case 6:
43 b2 = base * base;
44 return b2 * b2 * b2;
45 case 7:
46 b2 = base * base;
47 return b2 * b2 * b2 * base;
48 case 8:
49 b2 = base * base;
50 b2 = b2 * b2;
51 return b2 * b2;
52 default:
53 break;
54 }
55 double res = 1.0;
56 while (1) {
57 if (exp & 1) {
58 res *= base;
59 }
60 exp >>= 1;
61 if (!exp) {
62 break;
63 }
64 base *= base;
65 }
66 return res;
67}
68
75static inline double complex inverse_imaginary_int_pow(unsigned int exp) {
76 static const double complex powers[4] = {1.0, -I, -1.0, I};
77 return powers[exp & 3];
78}
79
86static inline double negative_one_pow(unsigned int exp) {
87 if (exp & 1) {
88 return -1.;
89 }
90 return 1.;
91}
92
100unsigned int mult_abs(unsigned int dim, const unsigned int *alpha);
101
108unsigned long long binom(unsigned long long n, unsigned long long k);
109
116static inline void kahan_add_c(double complex *restrict sum,
117 double complex *restrict epsilon, double complex x) {
118 double complex y = x - *epsilon;
119 double complex t = *sum + y;
120 *epsilon = (t - *sum) - y;
121 *sum = t;
122}
123
130static inline void kahan_add_r(double *restrict sum, double *restrict epsilon,
131 double x) {
132 double y = x - *epsilon;
133 double t = *sum + y;
134 *epsilon = (t - *sum) - y;
135 *sum = t;
136}
137
145static inline double dot(unsigned int dim, const double *v1, const double *v2) {
146 double r = 0;
147 for (int i = 0; i < dim; i++) {
148 r += v1[i] * v2[i];
149 }
150 return r;
151}
152
161static inline void matrix_intVector(unsigned int dim, const double *m, const int *v,
162 double *res, bool diag) {
163 if (diag) {
164 for (int i = 0; i < dim; i++) {
165 res[i] = m[(i * dim) + i] * v[i];
166 }
167 } else {
168 for (int i = 0; i < dim; i++) {
169 res[i] = 0;
170 for (int j = 0; j < dim; j++) {
171 res[i] += m[(i * dim) + j] * v[j];
172 }
173 }
174 }
175}
176
182void transpose(unsigned int dim, double *m);
183
191bool equals(unsigned int dim, const double *v1, const double *v2);
192
200void invert(unsigned int dim, double *m, int *p, double *r);
201
207double inf_norm(unsigned int dim, const double *m);
208
218double *vectorProj(unsigned int dim, const double *m, const double *m_invt,
219 const double *v);
220#endif
double inf_norm(unsigned int dim, const double *m)
Compute infinity norm (maximum sum row norm).
Definition tools.c:124
void transpose(unsigned int dim, double *m)
square matrix transpose.
Definition tools.c:29
double * vectorProj(unsigned int dim, const double *m, const double *m_invt, const double *v)
calculate projection of vector to elementary lattice cell.
Definition tools.c:183
bool equals(unsigned int dim, const double *v1, const double *v2)
check if two vectors are equal.
Definition tools.c:47
void invert(unsigned int dim, double *m, int *p, double *r)
Invert matrix.
Definition tools.c:65
unsigned long long binom(unsigned long long n, unsigned long long k)
Compute the binomial coefficient bionm(n,k).
Definition tools.c:162
unsigned int mult_abs(unsigned int dim, const unsigned int *alpha)
Compute absolute value of multi-index, that is the sum of its components.
Definition tools.c:148