5 using std::domain_error;
10 #include "../gcd/gcd_template.hpp" 24 template<
typename T, T m>
50 if (m == 0)
throw domain_error(
"Attempted to create a modulus of 0");
63 virtual bool is_one()
const override;
65 virtual bool is_zero()
const override;
89 template<
typename T, T m>
92 template<
typename T, T m>
95 template<
typename T, T m>
97 : value(other.value), invertible(other.invertible)
100 template<
typename T, T m>
103 template<
typename T, T m>
106 template<
typename T, T m>
109 template<
typename T, T m>
113 auto o =
dynamic_cast<const Mod<T, m> &
>(other);
114 result.
value = value + o.value;
119 template<
typename T, T m>
123 auto o =
dynamic_cast<const Mod<T, m> &
>(other);
124 result.
value = value - o.value;
129 template<
typename T, T m>
133 auto o =
dynamic_cast<const Mod<T, m> &
>(other);
134 result.
value = value * o.value;
139 template<
typename T, T m>
142 result.
value = value * other;
147 template<
typename T, T m>
149 if (*
this != other) {
157 template<
typename T, T m>
160 return value == o.
value;
163 template<
typename T, T m>
166 return value != o.
value;
169 template<
typename T, T m>
176 template <
typename T, T m>
177 ostream & operator << (ostream & os, const Mod<T, m> & x) {
186 template<
typename T, T m>
virtual Mod< T, m > & operator-(const Ring_Element &other) const override
implements modular subtraction
Definition: mod.hpp:120
elements of this type should have commutative multiplication
Definition: rings.hpp:39
virtual bool is_zero() const override
True iff assigned value is congruent to 0
Definition: mod.hpp:104
virtual Mod< T, m > & operator+(const Ring_Element &other) const override
implements modular addition
Definition: mod.hpp:110
virtual bool is_one() const override
True iff assigned value is congruent to 1
Definition: mod.hpp:101
Definition: integer.hpp:6
T get_value() const
returns value of this modulus
Definition: mod.hpp:170
virtual bool has_inverse() const override
True iff assigned value is relatively prime to modulus
Definition: mod.hpp:107
virtual void check_inverse()
decides whether this is invertible and sets flag accordingly; True iff (where is value) ...
Definition: mod.hpp:43
bool invertible
whether the element is invertible
Definition: mod.hpp:31
const Mod< T, m > & operator=(const Ring_Element &)
assignment operator may be needed
Definition: mod.hpp:148
a class for elements with the capabilities of ring arithmetic
Definition: rings.hpp:9
virtual bool operator!=(const Ring_Element &) const override
comparison: other element has different value
Definition: mod.hpp:164
constexpr Mod< T, m > prevent_zero_modulus
used to prevent the use of a zero modulus
Definition: mod.hpp:187
virtual Mod< T, m > & operator*(const Ring_Element &other) const override
implements modular multiplication
Definition: mod.hpp:130
templated modular arithmetic, making no assumption about the modulus
Definition: mod.hpp:25
virtual bool operator==(const Ring_Element &) const override
comparison: other element has same value
Definition: mod.hpp:158
void adjust_value()
ensures value is at least 0 but less than modulus
Definition: mod.hpp:34
Mod()
initializes to 0
Definition: mod.hpp:90
void check_modulus()
checks modulus to ensure we aren't trying to do the impossible
Definition: mod.hpp:49
T value
value of the element
Definition: mod.hpp:29