module Algebra::AlgebraCreator

Public Instance Methods

create(ground) click to toggle source
# File lib/algebra/algebraic-system.rb, line 12
def create(ground)
  klass = Class.new(self)
  klass.sysvar :ground, ground
  def klass.inspect
    to_s
  end

  def klass.to_s
    s = super
    s = "(#{superclass.inspect}/#{ground.inspect})" if s =~ /^#/ # /
    s.gsub(/Algebra::/, '')
  end
  klass
end
superior?(otype) click to toggle source
# File lib/algebra/algebraic-system.rb, line 38
def superior?(otype)
  if otype <= Numeric || self <= otype
    true
  elsif respond_to?(:ground) && ground.respond_to?(:superior?)
    ground.superior?(otype)
  else
    false
  end
end
sysvar(var_name, value = nil, sw = false) click to toggle source
# File lib/algebra/algebraic-system.rb, line 48
    def sysvar(var_name, value = nil, sw = false)
      var_name = var_name.id2name if var_name.is_a?(Symbol)

      class_eval <<__END_OF_CLASS_DEFINITION__
      @@#{var_name} = nil
      def self.#{var_name}; @@#{var_name}; end
      def self.#{var_name}=(value); @@#{var_name} = value; end
__END_OF_CLASS_DEFINITION__

      send(var_name + '=', value) if value

      if sw
        class_eval <<__END_OF_CLASS_DEFINITION__
        def #{var_name}; @@#{var_name}; end
        def #{var_name}=(value); @@#{var_name} = value; end
__END_OF_CLASS_DEFINITION__
      end
    end
wedge(otype) click to toggle source

Needed in the type conversion of MatrixAlgebra

# File lib/algebra/algebraic-system.rb, line 28
def wedge(otype) # =:= tensor
  if superior?(otype)
    self
  elsif otype.respond_to?(:superior?) && otype.superior?(self)
    otype
  else
    raise "wedge: unknown pair (#{self}) .wedge (#{otype})"
  end
end