23 #ifndef PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ 24 #define PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ 33 namespace persistent_cohomology {
45 typedef mpz_class Element;
48 : prod_characteristics_(0),
55 void init(
int min_prime,
int max_prime) {
57 std::cerr <<
"There is no prime less than " << max_prime << std::endl;
59 if (min_prime > max_prime) {
60 std::cerr <<
"No prime in [" << min_prime <<
":" << max_prime <<
"]" 64 int curr_prime = min_prime;
66 mpz_init_set_ui(tmp_prime, min_prime);
68 int is_prime = mpz_probab_prime_p(tmp_prime, 25);
71 mpz_nextprime(tmp_prime, tmp_prime);
72 curr_prime = mpz_get_ui(tmp_prime);
75 while (curr_prime <= max_prime) {
76 primes_.push_back(curr_prime);
77 mpz_nextprime(tmp_prime, tmp_prime);
78 curr_prime = mpz_get_ui(tmp_prime);
82 prod_characteristics_ = 1;
83 for (
auto p : primes_) {
84 prod_characteristics_ *= p;
90 for (
auto p : primes_) {
92 tmp_elem = prod_characteristics_ / p;
94 mpz_powm_ui(tmp_elem.get_mpz_t(), tmp_elem.get_mpz_t(), p - 1,
95 prod_characteristics_.get_mpz_t());
96 Uvect_.push_back(tmp_elem);
99 for (
auto uvect : Uvect_) {
100 assert(prod_characteristics_ > 0);
101 mult_id_all = (mult_id_all + uvect) % prod_characteristics_;
115 if (Q == prod_characteristics_) {
119 assert(prod_characteristics_ > 0);
121 for (
unsigned int idx = 0; idx < primes_.size(); ++idx) {
122 assert(primes_[idx] > 0);
123 if ((Q % primes_[idx]) == 0) {
124 mult_id = (mult_id + Uvect_[idx]) % prod_characteristics_;
131 Element
times(
const Element& y,
const Element& w) {
135 Element plus_equal(
const Element& x,
const Element& y) {
141 return prod_characteristics_;
145 std::pair<Element, Element>
inverse(Element x, Element QS) {
147 mpz_gcd(QR.get_mpz_t(), x.get_mpz_t(), QS.get_mpz_t());
150 Element QT = QS / QR;
152 mpz_invert(inv_qt.get_mpz_t(), x.get_mpz_t(), QT.get_mpz_t());
154 assert(prod_characteristics_ > 0);
159 assert(prod_characteristics_ > 0);
161 return prod_characteristics_ - ((x * y) % prod_characteristics_);
166 assert(prod_characteristics_ > 0);
167 Element result = (x + w * y) % prod_characteristics_;
169 result += prod_characteristics_;
173 Element prod_characteristics_;
175 std::vector<int> primes_;
176 std::vector<Element> Uvect_;
178 const Element add_id_all;
185 #endif // PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ const Element & multiplicative_identity() const
Returns the multiplicative identity of the field.
Definition: Multi_field.h:110
const Element & characteristic() const
Returns the characteristic of the field.
Definition: Multi_field.h:140
std::pair< Element, Element > inverse(Element x, Element QS)
Definition: Multi_field.h:145
Element times(const Element &y, const Element &w)
Definition: Multi_field.h:131
Definition: SimplicialComplexForAlpha.h:26
Element times_minus(const Element &x, const Element &y)
Definition: Multi_field.h:158
const Element & additive_identity() const
Returns the additive idendity of the field.
Definition: Multi_field.h:106
Structure representing coefficients in a set of finite fields simultaneously using the chinese remain...
Definition: Multi_field.h:43
Element plus_times_equal(const Element &x, const Element &y, const Element &w)
Definition: Multi_field.h:165