class Algebra::MIndex
Constants
- Unity
Public Class Methods
[](*ind)
click to toggle source
# File lib/algebra/m-index.rb, line 118 def self.[](*ind) new(ind) end
get_module(ord, v_ord = nil)
click to toggle source
# File lib/algebra/m-index.rb, line 276 def self.get_module(ord, v_ord = nil) ord = ord.id2name ord = 'V_' + ord if v_ord eval(ord.capitalize) end
monomial(idx, height = 1)
click to toggle source
# File lib/algebra/m-index.rb, line 140 def self.monomial(idx, height = 1) ind0 = [] (0..idx).each do |i| ind0.push(i == idx ? height : 0) end new(ind0) end
new(array = [])
click to toggle source
# File lib/algebra/m-index.rb, line 82 def initialize(array = []) @body = array end
set_V_ORDER(v_ord)
click to toggle source
# File lib/algebra/m-index.rb, line 265 def self.set_V_ORDER(v_ord) remove_const 'V_ORDER' if const_defined? 'V_ORDER' const_set('V_ORDER', v_ord) end
set_ord(ord)
click to toggle source
# File lib/algebra/m-index.rb, line 260 def self.set_ord(ord) mod = get_module(ord) adopt_module(mod) end
set_v_ord(ord, v_ord)
click to toggle source
# File lib/algebra/m-index.rb, line 270 def self.set_v_ord(ord, v_ord) set_V_ORDER(v_ord) vord = get_module(ord, v_ord) adopt_module(vord) end
Public Instance Methods
+(other)
click to toggle source
# File lib/algebra/m-index.rb, line 186 def +(other) self.class.new((0...[size, other.size].max).collect do |i| self[i] + other[i] end) end
-(other)
click to toggle source
# File lib/algebra/m-index.rb, line 192 def -(other) self.class.new((0...[size, other.size].max).collect do |i| x = self[i] - other[i] raise "#{self} is not devided by #{other}" if x < 0 x end).compact! end
==(other)
click to toggle source
# File lib/algebra/m-index.rb, line 179 def ==(other) 0.upto [size, other.size].max - 1 do |i| return false if self[i] != other[i] end true end
[](i)
click to toggle source
# File lib/algebra/m-index.rb, line 130 def [](i) @body[i] || 0 end
[]=(i, x)
click to toggle source
# File lib/algebra/m-index.rb, line 134 def []=(i, x) k = (self[i] = x) raise 'illegal operation' if totdeg == 0 k end
annihilate(at)
click to toggle source
# File lib/algebra/m-index.rb, line 200 def annihilate(at) self - self.class.monomial(at, self[at]) end
compact()
click to toggle source
# File lib/algebra/m-index.rb, line 223 def compact # more safe dup.compact! end
compact!()
click to toggle source
# File lib/algebra/m-index.rb, line 216 def compact! # be careful, when this index is used plural places!! i = size - 1 i -= 1 while i >= 0 && self[i].zero? @body.slice!((i + 1)..-1) if i < size - 1 self end
devide?(other)
click to toggle source
# File lib/algebra/m-index.rb, line 152 def devide?(other) each_with_index do |x, i| return false if x > other[i] end true end
devide_or?(other0, other1)
click to toggle source
# File lib/algebra/m-index.rb, line 159 def devide_or?(other0, other1) each_with_index do |x, i| return false if x > other0[i] || x > other1[i] end true end
dup()
click to toggle source
# File lib/algebra/m-index.rb, line 227 def dup self.class.new(@body) end
each() { |x| ... }
click to toggle source
# File lib/algebra/m-index.rb, line 98 def each @body.each do |x| yield x end end
empty?()
click to toggle source
# File lib/algebra/m-index.rb, line 90 def empty? @body.empty? end
eql?(other)
click to toggle source
def ==(other)
@body == other.to_a
end
# File lib/algebra/m-index.rb, line 108 def eql?(other) @body.eql? other.to_a end
gcm(other)
click to toggle source
# File lib/algebra/m-index.rb, line 210 def gcm(other) self.class.new((0...[size, other.size].max).collect do |i| [self[i], other[i]].min end).compact! end
hash()
click to toggle source
# File lib/algebra/m-index.rb, line 112 def hash @body.hash end
inspect(var = nil, po = nil)
click to toggle source
# File lib/algebra/m-index.rb, line 256 def inspect(var = nil, po = nil) to_s(var, po) end
lcm(other)
click to toggle source
# File lib/algebra/m-index.rb, line 204 def lcm(other) self.class.new((0...[size, other.size].max).collect do |i| [self[i], other[i]].max end) end
multideg()
click to toggle source
# File lib/algebra/m-index.rb, line 148 def multideg @body end
prime_to?(other)
click to toggle source
# File lib/algebra/m-index.rb, line 166 def prime_to?(other) each_with_index do |x, i| return false if x > 0 && other[i] > 0 end true end
size()
click to toggle source
# File lib/algebra/m-index.rb, line 94 def size @body.size end
to_a()
click to toggle source
# File lib/algebra/m-index.rb, line 86 def to_a @body end
to_s(var = nil, pr = nil, po = nil)
click to toggle source
# File lib/algebra/m-index.rb, line 252 def to_s(var = nil, pr = nil, po = nil) $DEBUG ? @body.inspect.gsub(/\s+/, '') : to_s!(var, pr, po) end
to_s!(vars = nil, pr = nil, po = nil)
click to toggle source
# File lib/algebra/m-index.rb, line 231 def to_s!(vars = nil, pr = nil, po = nil) return @body.inspect unless vars a = '' each_with_index do |n, i| case n when 0 else # u = n == 1 ? vars[i].to_s : vars[i].to_s + "#{po}#{n}" u = if n == 1 vars[i].to_s elsif /^\}/ =~ po "{#{vars[i]}#{po}#{n}" else "#{vars[i]}#{po}#{n}" end a.concat(a.empty? ? u : "#{pr}#{u}") end end a end
totdeg()
click to toggle source
# File lib/algebra/m-index.rb, line 173 def totdeg s = 0 each { |n| s += n; } s end
unity()
click to toggle source
# File lib/algebra/m-index.rb, line 122 def unity Unity.dup end
unity?()
click to toggle source
# File lib/algebra/m-index.rb, line 126 def unity? self == Unity end