11 #ifndef PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ 12 #define PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ 21 namespace persistent_cohomology {
33 typedef mpz_class Element;
36 : prod_characteristics_(0),
43 void init(
int min_prime,
int max_prime) {
45 std::cerr <<
"There is no prime less than " << max_prime << std::endl;
47 if (min_prime > max_prime) {
48 std::cerr <<
"No prime in [" << min_prime <<
":" << max_prime <<
"]" 52 int curr_prime = min_prime;
54 mpz_init_set_ui(tmp_prime, min_prime);
56 int is_prime = mpz_probab_prime_p(tmp_prime, 25);
59 mpz_nextprime(tmp_prime, tmp_prime);
60 curr_prime = mpz_get_ui(tmp_prime);
63 while (curr_prime <= max_prime) {
64 primes_.push_back(curr_prime);
65 mpz_nextprime(tmp_prime, tmp_prime);
66 curr_prime = mpz_get_ui(tmp_prime);
70 prod_characteristics_ = 1;
71 for (
auto p : primes_) {
72 prod_characteristics_ *= p;
78 for (
auto p : primes_) {
80 tmp_elem = prod_characteristics_ / p;
82 mpz_powm_ui(tmp_elem.get_mpz_t(), tmp_elem.get_mpz_t(), p - 1,
83 prod_characteristics_.get_mpz_t());
84 Uvect_.push_back(tmp_elem);
87 for (
auto uvect : Uvect_) {
88 assert(prod_characteristics_ > 0);
89 mult_id_all = (mult_id_all + uvect) % prod_characteristics_;
103 if (Q == prod_characteristics_) {
107 assert(prod_characteristics_ > 0);
109 for (
unsigned int idx = 0; idx < primes_.size(); ++idx) {
110 assert(primes_[idx] > 0);
111 if ((Q % primes_[idx]) == 0) {
112 mult_id = (mult_id + Uvect_[idx]) % prod_characteristics_;
119 Element
times(
const Element& y,
const Element& w) {
123 Element plus_equal(
const Element& x,
const Element& y) {
129 return prod_characteristics_;
133 std::pair<Element, Element>
inverse(Element x, Element QS) {
135 mpz_gcd(QR.get_mpz_t(), x.get_mpz_t(), QS.get_mpz_t());
138 Element QT = QS / QR;
140 mpz_invert(inv_qt.get_mpz_t(), x.get_mpz_t(), QT.get_mpz_t());
142 assert(prod_characteristics_ > 0);
147 assert(prod_characteristics_ > 0);
149 return prod_characteristics_ - ((x * y) % prod_characteristics_);
154 assert(prod_characteristics_ > 0);
155 Element result = (x + w * y) % prod_characteristics_;
157 result += prod_characteristics_;
161 Element prod_characteristics_;
163 std::vector<int> primes_;
164 std::vector<Element> Uvect_;
166 const Element add_id_all;
173 #endif // PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ std::pair< Element, Element > inverse(Element x, Element QS)
Definition: Multi_field.h:133
const Element & multiplicative_identity() const
Returns the multiplicative identity of the field.
Definition: Multi_field.h:98
Element times(const Element &y, const Element &w)
Definition: Multi_field.h:119
Definition: SimplicialComplexForAlpha.h:14
Element times_minus(const Element &x, const Element &y)
Definition: Multi_field.h:146
Structure representing coefficients in a set of finite fields simultaneously using the chinese remain...
Definition: Multi_field.h:31
Element plus_times_equal(const Element &x, const Element &y, const Element &w)
Definition: Multi_field.h:153
const Element & additive_identity() const
Returns the additive idendity of the field.
Definition: Multi_field.h:94
const Element & characteristic() const
Returns the characteristic of the field.
Definition: Multi_field.h:128