Class: Hilbert::World::PropositionalLogic::FORM

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/hilbert/world/propositional_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.



127
128
129
130
# File 'lib/hilbert/world/propositional_logic.rb', line 127

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

Instance Attribute Details

#opeObject

Returns the value of attribute ope.



126
127
128
# File 'lib/hilbert/world/propositional_logic.rb', line 126

def ope
  @ope
end

#varsObject

Returns the value of attribute vars.



126
127
128
# File 'lib/hilbert/world/propositional_logic.rb', line 126

def vars
  @vars
end

Instance Method Details

#!@Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/hilbert/world/propositional_logic.rb', line 159

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

#are_there_neg?Boolean

Returns:

  • (Boolean)


151
152
153
154
155
156
157
# File 'lib/hilbert/world/propositional_logic.rb', line 151

def are_there_neg?
  pvars = vars.reject { |var| var.is_neg? }
  nvars = vars.select { |var| var.is_neg? }
  pvars.any? { |pvar|
    nvars.any? { |nvar| nvar.neg?(pvar) }
  }
end

#deepObject



174
# File 'lib/hilbert/world/propositional_logic.rb', line 174

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

#include?(p) ⇒ Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/hilbert/world/propositional_logic.rb', line 132

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

#loopeObject



143
144
145
# File 'lib/hilbert/world/propositional_logic.rb', line 143

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

#reopeObject



147
148
149
# File 'lib/hilbert/world/propositional_logic.rb', line 147

def reope
  is_and? ? :+ : :*
end

#to_sObject



136
137
138
139
140
141
# File 'lib/hilbert/world/propositional_logic.rb', line 136

def to_s
  str = vars.each.with_index.inject('(') do |str, (p, i)|
    str = str + "#{p}#{i < vars.count-1 ? loope : ')'}"
    str
  end
end