Skip to content

Commit 9e9cfe2

Browse files
committed
Refactor
1 parent ce40f15 commit 9e9cfe2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+129
-113
lines changed

cp-algo/all

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace cp_algo {
99
using namespace data_structures;
1010
using namespace geometry;
11-
using namespace algebra;
11+
using namespace math;
1212
using namespace linalg;
1313
using namespace random;
1414
}

cp-algo/data_structures/segtree/metas/affine.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#ifndef CP_ALGO_DATA_STRUCTURES_SEGMENT_TREE_METAS_AFFINE_HPP
22
#define CP_ALGO_DATA_STRUCTURES_SEGMENT_TREE_METAS_AFFINE_HPP
33
#include "base.hpp"
4-
#include "../../../algebra/affine.hpp"
4+
#include "../../../math/affine.hpp"
55
namespace cp_algo::data_structures::segtree::metas {
66
template<typename base>
77
struct affine_meta: base_meta<affine_meta<base>> {
88
using meta = affine_meta;
9-
using lin = algebra::lin<base>;
9+
using lin = math::lin<base>;
1010

1111
base sum = 0;
1212
lin to_push = {};

cp-algo/data_structures/treap/metas/reverse.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#ifndef CP_ALGO_DATA_STRUCTURES_TREAP_METAS_REVERSE_HPP
22
#define CP_ALGO_DATA_STRUCTURES_TREAP_METAS_REVERSE_HPP
33
#include "base.hpp"
4-
#include "../../../algebra/affine.hpp"
4+
#include "../../../math/affine.hpp"
55
#include <algorithm>
66
namespace cp_algo::data_structures::treap::metas {
77
template<typename base>
88
struct reverse_meta: base_meta {
9-
using lin = algebra::lin<base>;
9+
using lin = math::lin<base>;
1010
base val;
1111
size_t sz = 1;
1212
bool reverse = false;

cp-algo/linalg/frobenius.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#ifndef CP_ALGO_LINALG_FROBENIUS_HPP
22
#define CP_ALGO_LINALG_FROBENIUS_HPP
3+
#include "../math/poly.hpp"
34
#include "matrix.hpp"
4-
#include "../algebra/poly.hpp"
55
#include <algorithm>
66
#include <vector>
7-
namespace cp_algo::linalg {
7+
namespace cp_algo::math::linalg {
88
enum frobenius_mode {blocks, full};
99
template<frobenius_mode mode = blocks>
1010
auto frobenius_form(auto const& A) {
1111
using matrix = std::decay_t<decltype(A)>;
1212
using base = matrix::base;
13-
using polyn = algebra::poly_t<base>;
13+
using polyn = math::poly_t<base>;
1414
assert(A.n() == A.m());
1515
size_t n = A.n();
1616
std::vector<polyn> charps;
@@ -76,7 +76,7 @@ namespace cp_algo::linalg {
7676

7777
template<typename base>
7878
auto frobenius_pow(matrix<base> A, uint64_t k) {
79-
using polyn = algebra::poly_t<base>;
79+
using polyn = math::poly_t<base>;
8080
auto [T, Tinv, charps] = frobenius_form<full>(A);
8181
std::vector<matrix<base>> blocks;
8282
for(auto charp: charps) {

cp-algo/linalg/matrix.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#ifndef CP_ALGO_LINALG_MATRIX_HPP
22
#define CP_ALGO_LINALG_MATRIX_HPP
33
#include "../random/rng.hpp"
4-
#include "../algebra/common.hpp"
4+
#include "../math/common.hpp"
55
#include "vector.hpp"
66
#include <iostream>
77
#include <optional>
88
#include <cassert>
99
#include <vector>
1010
#include <array>
11-
namespace cp_algo::linalg {
11+
namespace cp_algo::math::linalg {
1212
template<typename base_t>
1313
struct matrix: valarray_base<matrix<base_t>, vec<base_t>> {
1414
using base = base_t;

cp-algo/linalg/vector.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#ifndef CP_ALGO_LINALG_VECTOR_HPP
22
#define CP_ALGO_LINALG_VECTOR_HPP
3-
#include "../algebra/modint.hpp"
43
#include "../random/rng.hpp"
4+
#include "../math/modint.hpp"
55
#include <functional>
66
#include <algorithm>
77
#include <valarray>
88
#include <iostream>
99
#include <iterator>
1010
#include <cassert>
11-
namespace cp_algo::linalg {
11+
namespace cp_algo::math::linalg {
1212
template<class vec, typename base>
1313
struct valarray_base: std::valarray<base> {
1414
using Base = std::valarray<base>;
@@ -120,7 +120,7 @@ namespace cp_algo::linalg {
120120
};
121121

122122
template<typename base>
123-
requires(std::is_base_of_v<algebra::modint_base<base>, base>)
123+
requires(std::is_base_of_v<math::modint_base<base>, base>)
124124
struct vec<base>: vec_base<vec<base>, base> {
125125
using Base = vec_base<vec<base>, base>;
126126
using Base::Base;
File renamed without changes.

cp-algo/algebra/affine.hpp renamed to cp-algo/math/affine.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#ifndef CP_ALGO_ALGEBRA_AFFINE_HPP
2-
#define CP_ALGO_ALGEBRA_AFFINE_HPP
1+
#ifndef CP_ALGO_MATH_AFFINE_HPP
2+
#define CP_ALGO_MATH_AFFINE_HPP
33
#include <optional>
44
#include <utility>
55
#include <cassert>
66
#include <tuple>
7-
namespace cp_algo::algebra {
7+
namespace cp_algo::math {
88
// a * x + b
99
template<typename base>
1010
struct lin {
@@ -68,4 +68,4 @@ namespace cp_algo::algebra {
6868
}
6969
};
7070
}
71-
#endif // CP_ALGO_ALGEBRA_AFFINE_HPP
71+
#endif // CP_ALGO_MATH_AFFINE_HPP
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#ifndef CP_ALGO_ALGEBRA_ALL
2-
#define CP_ALGO_ALGEBRA_ALL
1+
#ifndef CP_ALGO_MATH_ALL
2+
#define CP_ALGO_MATH_ALL
33
#include "modint.hpp"
44
#include "affine.hpp"
55
#include "common.hpp"
66
#include "poly.hpp"
77
#include "fft.hpp"
8-
#endif // CP_ALGO_ALGEBRA_ALL
8+
#endif // CP_ALGO_MATH_ALL

cp-algo/math/combinatorics.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef CP_ALGO_MATH_COMBINATORICS_HPP
2+
#define CP_ALGO_MATH_COMBINATORICS_HPP
3+
#include "common.hpp"
4+
namespace cp_algo::math {
5+
template<typename T>
6+
T binom_large(T n, int r) {
7+
assert(r < math::maxn);
8+
T ans = 1;
9+
for(int i = 0; i < r; i++) {
10+
ans = ans * T(n - i) * small_inv<T>(i + 1);
11+
}
12+
return ans;
13+
}
14+
template<typename T>
15+
T binom(int n, int r) {
16+
if(r < 0 || r > n) {
17+
return T(0);
18+
} else if(n > math::maxn) {
19+
return binom_large(n, r);
20+
} else {
21+
return math::fact<T>(n) * math::rfact<T>(r) * math::rfact<T>(n-r);
22+
}
23+
}
24+
}
25+
#endif // CP_ALGO_MATH_COMBINATORICS_HPP

0 commit comments

Comments
 (0)