Class: Hilbert::World::PropositionalLogic::FORM
- Inherits:
-
Object
- Object
- Hilbert::World::PropositionalLogic::FORM
show all
- Includes:
- Base
- Defined in:
- lib/hilbert/world/propositional_logic.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Utils
#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.
123
124
125
126
|
# File 'lib/hilbert/world/propositional_logic.rb', line 123
def initialize(vars, ope)
vars = vars.map { |var| var.is_form?(ope) ? var.vars : var }.flatten
@vars, @ope = vars, ope
end
|
Instance Attribute Details
#ope ⇒ Object
Returns the value of attribute ope.
122
123
124
|
# File 'lib/hilbert/world/propositional_logic.rb', line 122
def ope
@ope
end
|
#vars ⇒ Object
Returns the value of attribute vars.
122
123
124
|
# File 'lib/hilbert/world/propositional_logic.rb', line 122
def vars
@vars
end
|
Instance Method Details
#!@ ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/hilbert/world/propositional_logic.rb', line 155
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
147
148
149
150
151
152
153
|
# File 'lib/hilbert/world/propositional_logic.rb', line 147
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
|
#deep ⇒ Object
170
|
# File 'lib/hilbert/world/propositional_logic.rb', line 170
def deep; [p.deep, q.deep].max+1; end
|
#include?(p) ⇒ Boolean
128
129
130
|
# File 'lib/hilbert/world/propositional_logic.rb', line 128
def include?(p)
vars.include?(p)
end
|
#loope ⇒ Object
139
140
141
|
# File 'lib/hilbert/world/propositional_logic.rb', line 139
def loope
@ope == :* ? '&' : '|'
end
|
#reope ⇒ Object
143
144
145
|
# File 'lib/hilbert/world/propositional_logic.rb', line 143
def reope
is_and? ? :+ : :*
end
|
#to_s ⇒ Object
132
133
134
135
136
137
|
# File 'lib/hilbert/world/propositional_logic.rb', line 132
def to_s
str = vars.each.with_index.inject('(') do |str, (p, i)|
str = str + "#{p}#{i < vars.count-1 ? loope : ')'}"
str
end
end
|