Rings for MAT 685
Mathematical ring implementation to demonstrate templates and inheritance
rings.hpp
1 #ifndef __RINGS_HPP_
2 #define __RINGS_HPP_
3 
4 namespace Rings {
5 
9 class Ring_Element {
10 public:
12  virtual bool is_one() const = 0;
14  virtual bool is_zero() const = 0;
16  virtual bool has_inverse() const = 0;
18  virtual bool is_commutative() const { return false; }
23  virtual bool is_cancellable() const { return false; }
24 
26  virtual bool operator == (const Ring_Element &) const = 0;
28  virtual bool operator != (const Ring_Element &) const = 0;
29 
31  virtual const Ring_Element & operator + (const Ring_Element & ) const = 0;
33  virtual const Ring_Element & operator - (const Ring_Element & ) const = 0;
35  virtual const Ring_Element & operator * (const Ring_Element & ) const = 0;
36 };
37 
40 public:
42  virtual bool is_commutative() const override { return true; }
43 };
44 
54 public:
59  virtual bool is_cancellable() const override { return not is_zero(); }
60 };
61 
63 class Field_Element : virtual public Integral_Domain_Element {
64 
65 public:
66 
68  virtual bool has_inverse() const override { return not is_zero(); }
69 
71  virtual Field_Element & operator / (const Field_Element &) const = 0;
73  virtual Field_Element & inverse() const = 0;
74 
75 };
76 
77 }
78 
79 #endif
virtual bool is_commutative() const
should be True iff element commutes under multiplication
Definition: rings.hpp:18
elements of this type should have commutative multiplication
Definition: rings.hpp:39
virtual const Ring_Element & operator-(const Ring_Element &) const =0
subtraction: other element should be of same type, use a cast
a field is an integral domain whose nonzero elements have inverses
Definition: rings.hpp:63
virtual bool is_cancellable() const override
integral domains are commutative rings without zero divisors, so the element should be cancellable (s...
Definition: rings.hpp:59
virtual bool is_zero() const =0
should be True iff element is additive identity
virtual bool is_one() const =0
should be True iff element is multiplicative identity
elements of this type should be cancellable; there should be no zero divisors
Definition: rings.hpp:53
Definition: integer.hpp:6
virtual bool operator==(const Ring_Element &) const =0
comparison: other element has same value
virtual const Ring_Element & operator+(const Ring_Element &) const =0
addition: other element should be of same type, use a cast
virtual bool has_inverse() const =0
should be True iff element has a multiplicative inverse
virtual bool is_cancellable() const
should be True iff element can cancel across an equation; e.g., .
Definition: rings.hpp:23
virtual bool is_commutative() const override
Duh.
Definition: rings.hpp:42
virtual const Ring_Element & operator*(const Ring_Element &) const =0
multiplicationL other element should be of same type, use a cast
a class for elements with the capabilities of ring arithmetic
Definition: rings.hpp:9
virtual bool has_inverse() const override
fields are integral domains where nonzero elements have inverses
Definition: rings.hpp:68
virtual bool operator!=(const Ring_Element &) const =0
comparison: other element has different value