module Algebra::AlgebraBase
Public Class Methods
append_features(klass)
click to toggle source
private :regulate
Calls superclass method
# 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
Public Instance Methods
*(other) { |o| ... }
click to toggle source
# 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)
click to toggle source
# 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
Also aliased as: ^
+(other) { |o| ... }
click to toggle source
# 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
+@()
click to toggle source
Operations
# File lib/algebra/algebraic-system.rb, line 145 def +@ self end
-(other) { |o| ... }
click to toggle source
# 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
-@()
click to toggle source
# File lib/algebra/algebraic-system.rb, line 149 def -@ zero - self end
/(other) { |o| ... }
click to toggle source
# 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) { |o| ... }
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/algebra/algebraic-system.rb, line 89 def ground self.class.ground end
ground=(bf)
click to toggle source
# File lib/algebra/algebraic-system.rb, line 93 def ground=(bf) self.class.ground = bf end
regulate(x)
click to toggle source
# File lib/algebra/algebraic-system.rb, line 108 def regulate(x) self.class.regulate(x) end
unit?()
click to toggle source
# File lib/algebra/algebraic-system.rb, line 81 def unit? unity == self || -unity == self end
unity()
click to toggle source
# File lib/algebra/algebraic-system.rb, line 73 def unity self.class.unity end
unity?()
click to toggle source
# File lib/algebra/algebraic-system.rb, line 85 def unity? unity == self end
zero()
click to toggle source
# File lib/algebra/algebraic-system.rb, line 69 def zero self.class.zero end
zero?()
click to toggle source
# File lib/algebra/algebraic-system.rb, line 77 def zero? zero == self end