Mackey  V3.3
A C++ library for computing RO(G) graded homology
Z_n.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <iostream>
3 #include <array>
4 #include <Eigen/Dense>
5 #include "Types/SFINAE.hpp"
6 
9 
10 namespace mackey {
13 
16  template<int64_t N, typename T = int64_t>
17  class Z_mod {
18  public:
19  constexpr static int64_t order = N;
20  T x;
21  Z_mod() : x(0) {}
22  Z_mod(bool x) : x(x) {}
23  Z_mod(int x);
24  Z_mod(int64_t x);
25  explicit operator char() const;
26  explicit operator short() const;
27  explicit operator int() const;
28  explicit operator int64_t() const;
29  explicit operator unsigned char() const;
30  explicit operator unsigned short() const;
31  explicit operator unsigned int() const;
32  explicit operator uint64_t() const;
39  bool operator ==(Z_mod<N, T> a) const;
40  bool operator !=(Z_mod<N, T> a) const;
41  bool operator <=(Z_mod<N, T> a) const;
42  };
43 
44 
45  template<int64_t N, typename T>
47 
48  template<int64_t N, typename T>
49  Z_mod<N, T> operator *(Z_mod<N, T> a, Z_mod<N, T> b); //Eigen needs this to be non member
50 
51  template<int64_t N, typename T>
53 
55  template<typename T>
56  T abs(T a);
57 
58  template<int64_t N, typename T> //Eigen needs this to be non member
59  std::ostream& operator<<(std::ostream& out, const Z_mod<N, T> a);
60 
62  using Z2 = Z_mod<2, bool>;
63 }
64 
66 namespace Eigen {
67  using namespace mackey;
68 
70  template<int64_t N, typename T>
71  struct NumTraits<Z_mod<N, T>>
72  {
73  typedef Z_mod<N, T> Real;
74  typedef Z_mod<N, T> Nested;
75  typedef int Literal;
76  enum {
77  IsComplex = 0,
78  IsInteger = 0,
79  IsSigned = 0,
80  RequireInitialization = 0,
81  ReadCost = 1,
82  AddCost = 1,
83  MulCost = 1
84  };
85  static inline Z_mod<N, T> dummy_precision() { return Z_mod<N, T>(0); }
86  static inline int digits10() { return 0; }
87  };
88 }
89 
90 #include "impl/Z_n.ipp"
Contains all the SFINAE tricks.
The class of Z/N coefficients where N is prime.
Definition: Z_n.hpp:17
Z_mod< N, T > operator-(Z_mod< N, T > b) const
Z_mod()
Default value 0.
Definition: Z_n.hpp:21
Z_mod< N, T > & operator-=(Z_mod< N, T > b)
constexpr static int64_t order
The N of Z/N.
Definition: Z_n.hpp:19
Z_mod< N, T > operator+(Z_mod< N, T > b) const
Z_mod(bool x)
Initialize from 0,1.
Definition: Z_n.hpp:22
Z_mod(int x)
Initialize from int.
Z_mod< N, T > & operator+=(Z_mod< N, T > b)
Z_mod(int64_t x)
Initialize from 64bit int.
bool operator!=(Z_mod< N, T > a) const
bool operator==(Z_mod< N, T > a) const
T x
A modulo N number.
Definition: Z_n.hpp:20
Z_mod< N, T > & operator/=(Z_mod< N, T > b)
bool operator<=(Z_mod< N, T > a) const
Needed for Eigen pruning; standard order on 0,...,N-1.
Z_mod< N, T > & operator*=(Z_mod< N, T > b)
Everything in this library is under this namespace.
Definition: Box.hpp:9
std::ostream & operator<<(std::ostream &, const Chains< rank_t, diff_t > &)
Prints chain complex.
Z_mod< N, T > operator-(Z_mod< N, T > a)
T abs(T a)
The usual absolute value for integer and Z/N types.
Z_mod< N, T > operator*(Z_mod< N, T > a, Z_mod< N, T > b)
Z_mod< N, T > operator/(Z_mod< N, T > a, Z_mod< N, T > b)