Class: MagicLogic::FORM

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/magic_logic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#dpll!, #is_and?, #is_form?, #is_neg?, #is_or?, #neg?

Methods included from Operator

#*, #+, #<=>, #>=, #~@

Constructor Details

#initialize(vars, ope) ⇒ FORM

Returns a new instance of FORM.



117
118
119
120
# File 'lib/magic_logic.rb', line 117

def initialize(vars, ope)
  @vars = vars.map { |var| var.is_form?(ope) ? var.vars : var }.flatten
  @ope = ope
end

Instance Attribute Details

#opeObject (readonly)

Returns the value of attribute ope.



116
117
118
# File 'lib/magic_logic.rb', line 116

def ope
  @ope
end

#varsObject (readonly)

Returns the value of attribute vars.



116
117
118
# File 'lib/magic_logic.rb', line 116

def vars
  @vars
end

Instance Method Details

#!@Object



124
125
126
127
128
129
130
131
132
# File 'lib/magic_logic.rb', line 124

def !@
  if is_or? && (and_form = vars.find { |var| var.is_and? })
    and_form.vars.map { |a| a + FORM.new((vars - [and_form]), :+) }.inject(:*)
  elsif are_there_neg?
    is_or? ? $tout : $utout
  else
    vars.map(&:!).inject(ope)
  end
end

#depthObject



134
# File 'lib/magic_logic.rb', line 134

def depth;       [p.depth, q.depth].max+1;     end

#include?(p) ⇒ Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/magic_logic.rb', line 136

def include?(p)
  vars.include?(p)
end

#loopeObject



140
141
142
# File 'lib/magic_logic.rb', line 140

def loope
  ope == :* ? '&' : '|'
end

#reopeObject



144
145
146
# File 'lib/magic_logic.rb', line 144

def reope
  is_and? ? :+ : :*
end

#to_sObject



122
# File 'lib/magic_logic.rb', line 122

def to_s; "(#{vars.map(&:to_s).join(loope)})" end