Class: MagicLogic::FORM

Inherits:
Struct
  • 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.



121
122
123
124
# File 'lib/magic_logic.rb', line 121

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

Instance Attribute Details

#opeObject

Returns the value of attribute ope

Returns:

  • (Object)

    the current value of ope



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

def ope
  @ope
end

#varsObject

Returns the value of attribute vars

Returns:

  • (Object)

    the current value of vars



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

def vars
  @vars
end

Instance Method Details

#!@Object



128
129
130
131
132
133
134
135
136
# File 'lib/magic_logic.rb', line 128

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



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

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

#include?(p) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#to_sObject



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

def to_s; "(#{vars.map(&:to_s).join(_ ope, '|', '&')})" end