Module: Algebra::AlgebraBase
- Included in:
- LocalizedRing, MPolynomial, MatrixAlgebra, Polynomial, ResidueClassRing
- Defined in:
- lib/algebra/algebraic-system.rb
Class Method Summary collapse
-
.append_features(klass) ⇒ Object
private :regulate.
Instance Method Summary collapse
- #*(other) ⇒ Object
- #**(n) ⇒ Object (also: #^)
- #+(other) ⇒ Object
-
#+@ ⇒ Object
Operations.
- #-(other) ⇒ Object
- #-@ ⇒ Object
- #/(other) ⇒ Object
- #==(other) ⇒ Object
- #coerce(other) ⇒ Object
- #devide?(other) ⇒ Boolean
- #ground ⇒ Object
- #ground=(bf) ⇒ Object
- #regulate(x) ⇒ Object
- #unit? ⇒ Boolean
- #unity ⇒ Object
- #unity? ⇒ Boolean
- #zero ⇒ Object
- #zero? ⇒ Boolean
Class Method Details
.append_features(klass) ⇒ Object
private :regulate
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/algebra/algebraic-system.rb', line 113 def self.append_features(klass) def klass.field? !method_defined?(:divmod) # may be overwrited end def klass.euclidian? method_defined?(:divmod) # may be overwrited end def klass.ufd? euclidian? # may be overwrited end def klass.zero new(ground.zero) end def klass.unity new(ground.unity) end def klass.regulate(x) if x.is_a? self x elsif y = ground.regulate(x) new(y) end end super end |
Instance Method Details
#*(other) ⇒ Object
180 181 182 183 184 185 186 187 |
# File 'lib/algebra/algebraic-system.rb', line 180 def *(other) if o = regulate(other) yield o else x, y = other.coerce(self) x * y end end |
#**(n) ⇒ Object Also known as: ^
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/algebra/algebraic-system.rb', line 198 def **(n) if !n.is_a?(Integer) || n < 0 raise 'index must be non negative integer' elsif n == 0 return unity elsif n == 1 self else q, r = n.divmod 2 x = self**q x *= x x *= self if r > 0 x end end |
#+(other) ⇒ Object
162 163 164 165 166 167 168 169 |
# File 'lib/algebra/algebraic-system.rb', line 162 def +(other) if o = regulate(other) yield o else x, y = other.coerce(self) x + y end end |
#+@ ⇒ Object
Operations
145 146 147 |
# File 'lib/algebra/algebraic-system.rb', line 145 def +@ self end |
#-(other) ⇒ Object
171 172 173 174 175 176 177 178 |
# File 'lib/algebra/algebraic-system.rb', line 171 def -(other) if o = regulate(other) yield o else x, y = other.coerce(self) x - y end end |
#-@ ⇒ Object
149 150 151 |
# File 'lib/algebra/algebraic-system.rb', line 149 def -@ zero - self end |
#/(other) ⇒ Object
189 190 191 192 193 194 195 196 |
# File 'lib/algebra/algebraic-system.rb', line 189 def /(other) if o = regulate(other) yield o else x, y = other.coerce(self) x / y end end |
#==(other) ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/algebra/algebraic-system.rb', line 153 def ==(other) if o = regulate(other) yield o else x, y = other.coerce(self) x == y end end |
#coerce(other) ⇒ Object
216 217 218 219 220 221 222 |
# File 'lib/algebra/algebraic-system.rb', line 216 def coerce(other) if x = regulate(other) [x, self] else raise "(ALG.SYS) can't coerce: (#{self.class}).coerce(#{other.class}) : (#{self}).coerce(#{other})" end end |
#devide?(other) ⇒ Boolean
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/algebra/algebraic-system.rb', line 97 def devide?(other) if self.class.field? true elsif self.class.euclidian? _q, r = other.divmod(self) r.zero? else raise "don't konw #{self} divides #{other}" end end |
#ground ⇒ Object
89 90 91 |
# File 'lib/algebra/algebraic-system.rb', line 89 def ground self.class.ground end |
#ground=(bf) ⇒ Object
93 94 95 |
# File 'lib/algebra/algebraic-system.rb', line 93 def ground=(bf) self.class.ground = bf end |
#regulate(x) ⇒ Object
108 109 110 |
# File 'lib/algebra/algebraic-system.rb', line 108 def regulate(x) self.class.regulate(x) end |
#unit? ⇒ Boolean
81 82 83 |
# File 'lib/algebra/algebraic-system.rb', line 81 def unit? unity == self || -unity == self end |
#unity ⇒ Object
73 74 75 |
# File 'lib/algebra/algebraic-system.rb', line 73 def unity self.class.unity end |
#unity? ⇒ Boolean
85 86 87 |
# File 'lib/algebra/algebraic-system.rb', line 85 def unity? unity == self end |
#zero ⇒ Object
69 70 71 |
# File 'lib/algebra/algebraic-system.rb', line 69 def zero self.class.zero end |
#zero? ⇒ Boolean
77 78 79 |
# File 'lib/algebra/algebraic-system.rb', line 77 def zero? zero == self end |