Loading...
Searching...
No Matches
dirichlet.h
Go to the documentation of this file.
1#pragma once
2
87
88#include <stdbool.h>
89#include <assert.h>
90
91#include <nut/modular_math.h>
92
96typedef struct{
97 int64_t x;
98 int64_t y, yinv;
99 int64_t *buf;
100} nut_Diri;
101
107uint64_t nut_dirichlet_D(uint64_t max, uint64_t m);
108
114uint64_t nut_dirichlet_Sigma(uint64_t max, uint64_t m);
115
124NUT_ATTR_ACCESS(read_only, 3, 1)
125NUT_ATTR_ACCESS(read_write, 4, 1)
126bool nut_euler_sieve_conv_u(int64_t n, int64_t m, const int64_t f_vals[static n+1], int64_t f_conv_u_vals[restrict static n+1]);
127
136NUT_ATTR_ACCESS(read_only, 3, 1)
137NUT_ATTR_ACCESS(read_write, 4, 1)
138bool nut_euler_sieve_conv_N(int64_t n, int64_t m, const int64_t f_vals[static n+1], int64_t f_conv_N_vals[restrict static n+1]);
139
151NUT_ATTR_NONNULL(3, 4, 5)
152NUT_ATTR_ACCESS(read_only, 3, 1)
153NUT_ATTR_ACCESS(read_only, 4, 1)
154NUT_ATTR_ACCESS(read_write, 5, 1)
155bool nut_euler_sieve_conv(int64_t n, int64_t m, const int64_t f_vals[static n+1], const int64_t g_vals[static n+1], int64_t f_conv_g_vals[restrict static n+1]);
156
167NUT_ATTR_ACCESS(write_only, 1)
168bool nut_Diri_init(nut_Diri *self, int64_t x, int64_t y);
169
172NUT_ATTR_ACCESS(read_write, 1)
173NUT_ATTR_ACCESS(read_only, 2)
174void nut_Diri_copy(nut_Diri *restrict dest, const nut_Diri *restrict src);
175
178NUT_ATTR_ACCESS(read_write, 1)
180
183NUT_ATTR_ACCESS(read_only, 1)
184static inline int64_t nut_Diri_get_dense(const nut_Diri *self, int64_t k){
185 assert(k >= 0 && k <= self->y);
186 return self->buf[k];
187}
188
190NUT_ATTR_ACCESS(read_write, 1)
191static inline void nut_Diri_set_dense(nut_Diri *self, int64_t k, int64_t v){
192 assert(k >= 0 && k <= self->y);
193 self->buf[k] = v;
194}
195
198NUT_ATTR_ACCESS(read_only, 1)
199static inline int64_t nut_Diri_get_sparse(const nut_Diri *self, int64_t k){
200 assert(k > 0 && k <= self->yinv);
201 return self->buf[self->y + k];
202}
203
205NUT_ATTR_ACCESS(read_write, 1)
206static inline void nut_Diri_set_sparse(nut_Diri *self, int64_t k, int64_t v){
207 assert(k > 0 && k <= self->yinv);
208 self->buf[self->y + k] = v;
209}
210
215NUT_ATTR_ACCESS(read_write, 1)
217
223NUT_ATTR_ACCESS(read_write, 1)
224void nut_Diri_compute_u(nut_Diri *self, int64_t m);
225
231NUT_ATTR_ACCESS(read_write, 1)
232void nut_Diri_compute_N(nut_Diri *self, int64_t m);
233
240NUT_ATTR_ACCESS(read_write, 1)
241NUT_ATTR_ACCESS(read_only, 3)
242void nut_Diri_compute_mertens(nut_Diri *restrict self, int64_t m, const uint8_t mobius[restrict static self->y/4 + 1]);
243
255NUT_ATTR_NONNULL(1, 4, 5)
256NUT_ATTR_ACCESS(read_write, 1, 4, 5)
257bool nut_Diri_compute_dk(nut_Diri *restrict self, uint64_t k, int64_t m, nut_Diri *restrict f_tbl, nut_Diri *restrict g_tbl);
258
268NUT_ATTR_ACCESS(read_write, 1)
269bool nut_Diri_compute_Nk(nut_Diri *restrict self, uint64_t k, int64_t m);
270
277NUT_ATTR_ACCESS(read_write, 1)
278bool nut_Diri_compute_J(nut_Diri *restrict self, uint64_t p);
279
289bool nut_Diri_compute_Chi_balanced(nut_Diri *restrict self, uint64_t n, int64_t m, const int64_t period_tbl[restrict static n]);
290
297NUT_ATTR_ACCESS(read_write, 1)
298bool nut_Diri_compute_pi(nut_Diri *restrict self);
299
307NUT_ATTR_ACCESS(read_write, 1)
308NUT_ATTR_ACCESS(read_only, 3)
309bool nut_Diri_compute_conv_u(nut_Diri *restrict self, int64_t m, const nut_Diri *restrict f_tbl);
310
318NUT_ATTR_ACCESS(read_write, 1)
319NUT_ATTR_ACCESS(read_only, 3)
320bool nut_Diri_compute_conv_N(nut_Diri *restrict self, int64_t m, const nut_Diri *restrict f_tbl);
321
333NUT_ATTR_NONNULL(1, 3, 4)
334NUT_ATTR_ACCESS(read_write, 1)
335NUT_ATTR_ACCESS(read_only, 3)
336NUT_ATTR_ACCESS(read_only, 4)
337bool nut_Diri_compute_conv(nut_Diri *restrict self, int64_t m, const nut_Diri *f_tbl, const nut_Diri *g_tbl);
338
339
353NUT_ATTR_NONNULL(1, 3, 4)
354NUT_ATTR_ACCESS(read_write, 1, 3, 4)
355bool nut_Diri_convdiv(nut_Diri *restrict self, int64_t m, const nut_Diri *restrict f_tbl, const nut_Diri *restrict g_tbl);
356
void nut_Diri_compute_mertens(nut_Diri *restrict self, int64_t m, const uint8_t mobius[restrict static self->y/4+1])
Compute the value table for the mobius function mu(n) (whose sum is called the Mertens function) Requ...
NUT_ATTR_CONST uint64_t nut_dirichlet_D(uint64_t max, uint64_t m)
Compute the sum of the divisor count function d from 1 to max.
void nut_Diri_copy(nut_Diri *restrict dest, const nut_Diri *restrict src)
Copy the values from one diri table to another, which must be initialized.
bool nut_Diri_init(nut_Diri *self, int64_t x, int64_t y)
Allocate internal buffers for a diri table self->buf will have f(0) through f(y) at indicies 0 throug...
bool nut_euler_sieve_conv(int64_t n, int64_t m, const int64_t f_vals[static n+1], const int64_t g_vals[static n+1], int64_t f_conv_g_vals[restrict static n+1])
Given tables of values of multiplicative functions f and g, compute (f <*> g)(x) for all x from 1 to ...
bool nut_Diri_compute_conv_N(nut_Diri *restrict self, int64_t m, const nut_Diri *restrict f_tbl)
Compute the value table for h = f <*> N, the dirichlet convolution of f and N (the identity function ...
bool nut_Diri_compute_Chi_balanced(nut_Diri *restrict self, uint64_t n, int64_t m, const int64_t period_tbl[restrict static n])
Compute the value table for a given Dirichlet Character Chi, whose total is 0 A dirichlet character i...
void nut_Diri_compute_I(nut_Diri *self)
Just memset's the dense part, then sets index 1 and y + 1 through y + yinv - 1 to 1 (remember the spa...
bool nut_euler_sieve_conv_N(int64_t n, int64_t m, const int64_t f_vals[static n+1], int64_t f_conv_N_vals[restrict static n+1])
Given a table of values of a multiplicative function f, compute (f <*> N)(x) for all x from 1 to n Se...
void nut_Diri_compute_u(nut_Diri *self, int64_t m)
Compute the value table for the unit function u(n) = 1 Fills the dense part of the table with 1s,...
bool nut_Diri_compute_pi(nut_Diri *restrict self)
Compute the value table for the prime counting function, aka prime pi The indicator function for prim...
bool nut_Diri_convdiv(nut_Diri *restrict self, int64_t m, const nut_Diri *restrict f_tbl, const nut_Diri *restrict g_tbl)
Compute the value table for h such that f = g <*> h, aka h = f </> g where the division is in terms o...
bool nut_Diri_compute_dk(nut_Diri *restrict self, uint64_t k, int64_t m, nut_Diri *restrict f_tbl, nut_Diri *restrict g_tbl)
Compute the value table for the kth generalized divisor function dk(n) dk(n) = da(n) <*> db(n) whenev...
bool nut_Diri_compute_conv_u(nut_Diri *restrict self, int64_t m, const nut_Diri *restrict f_tbl)
Compute the value table for h = f <*> u, the dirichlet convolution of f and u (the unit function u(n)...
bool nut_Diri_compute_conv(nut_Diri *restrict self, int64_t m, const nut_Diri *f_tbl, const nut_Diri *g_tbl)
Compute the value table for h = f <*> g, the dirichlet convolution of f and g, given value tables for...
NUT_ATTR_CONST uint64_t nut_dirichlet_Sigma(uint64_t max, uint64_t m)
Compute the sum of the divisor sum function sigma from 1 to max.
bool nut_Diri_compute_J(nut_Diri *restrict self, uint64_t p)
Compute the value table for the Jacobi symbol jacobi(n/p) Currently, p MUST be and odd prime This is ...
void nut_Diri_destroy(nut_Diri *self)
Deallocate internal buffers for a diri table.
bool nut_Diri_compute_Nk(nut_Diri *restrict self, uint64_t k, int64_t m)
Compute the value table for the kth power function N^k(n) N^k(n) = n^k, so we can find the sums using...
void nut_Diri_compute_N(nut_Diri *self, int64_t m)
Compute the value table for the identity function N(n) = n Fills the dense part of the table with inc...
bool nut_euler_sieve_conv_u(int64_t n, int64_t m, const int64_t f_vals[static n+1], int64_t f_conv_u_vals[restrict static n+1])
Given a table of values of a multiplicative function f, compute (f <*> u)(x) for all x from 1 to n Se...
#define NUT_ATTR_ACCESS(...)
Wrapper for gcc's access function annotation - no clang equivalent, and currently disabled because it...
#define NUT_ATTR_NONNULL(...)
Wrapper for gnu::nonnull attr.
#define NUT_ATTR_PURE
Wrapper for gnu::pure attr - similar to const but the function can read non-volatile memory (includin...
#define NUT_ATTR_CONST
Wrapper for gnu::const attr - such a function has no side effects and cannot read memory.
Wrapper to hold values of some multiplicative function.
Definition dirichlet.h:96