@@ -5,7 +5,22 @@ const assert = std.debug.assert;
55
66const internal = @import ("internal_math.zig" );
77
8- // TODO: add doc comment
8+ /// Calculates the $(+, \times)$ convolution in $\mathbb{Z}/p\mathbb{Z}$.
9+ /// Caller must free returned memory.
10+ ///
11+ /// Returns a empty `T[]` if `a` or `b` is empty.
12+ ///
13+ /// # Constraints
14+ ///
15+ /// - $2 \leq m \leq 2 \times 10^9$
16+ /// - `mod` is a prime number.
17+ /// - $\exists c \text{ s.t. } 2^c \mid (m - 1), |a| + |b| - 1 \leq 2^c$
18+ /// - $(0, m] \subseteq$ `T`
19+ ///
20+ /// # Complexity
21+ ///
22+ /// - $O(n \log n + \log m)$ where $n = |a| + |b|$.
23+ ///
924pub fn convolution (comptime mod : u32 , comptime T : type , allocator : Allocator , a : []const T , b : []const T ) ! []T {
1025 const Mint = Modint (mod );
1126 const n = a .len ;
@@ -36,7 +51,22 @@ pub fn convolution(comptime mod: u32, comptime T: type, allocator: Allocator, a:
3651 return out ;
3752}
3853
39- // TODO: add doc comment
54+ /// Calculates the $(+, \times)$ convolution in $\mathbb{Z}/p\mathbb{Z}$.
55+ /// Caller must free returned memory.
56+ ///
57+ /// Returns a empty `T[]` if `a` or `b` is empty.
58+ ///
59+ /// # Constraints
60+ ///
61+ /// - $2 \leq m \leq 2 \times 10^9$
62+ /// - `mod` is a prime number.
63+ /// - $\exists c \text{ s.t. } 2^c \mid (m - 1), |a| + |b| - 1 \leq 2^c$
64+ /// - $(0, m] \subseteq$ `T`
65+ ///
66+ /// # Complexity
67+ ///
68+ /// - $O(n \log n + \log m)$ where $n = |a| + |b|$.
69+ ///
4070pub fn convolutionModint (comptime mod : u32 , allocator : Allocator , a : []const Modint (mod ), b : []const Modint (mod )) ! []Modint (mod ) {
4171 const Mint = Modint (mod );
4272 const n = a .len ;
@@ -78,7 +108,20 @@ pub fn convolutionModint(comptime mod: u32, allocator: Allocator, a: []const Mod
78108 return a_tmp ;
79109}
80110
81- // TODO: add doc comment
111+ /// Calculates the $(+, \times)$ convolution in `i64`.
112+ /// Caller must free returned memory.
113+ ///
114+ /// Returns a empty `Vec` if `a` or `b` is empty.
115+ ///
116+ /// # Constraints
117+ ///
118+ /// - $|a| + |b| - 1 \leq 2^{24}$
119+ /// - All elements of the result are inside of the range of `i64`
120+ ///
121+ /// # Complexity
122+ ///
123+ /// - $O(n \log n)$ where $n = |a| + |b|$.
124+ ///
82125pub fn convolutionI64 (allocator : Allocator , a : []const i64 , b : []const i64 ) ! []i64 {
83126 const n = a .len ;
84127 const m = b .len ;
0 commit comments