Class: MagicLogic::FORM
- Inherits:
-
Struct
- Object
- Struct
- MagicLogic::FORM
- Includes:
- Base
- Defined in:
- lib/magic_logic.rb
Instance Attribute Summary collapse
-
#ope ⇒ Object
Returns the value of attribute ope.
-
#vars ⇒ Object
Returns the value of attribute vars.
Instance Method Summary collapse
- #!@ ⇒ Object
- #depth ⇒ Object
- #include?(p) ⇒ Boolean
-
#initialize(vars, ope) ⇒ FORM
constructor
A new instance of FORM.
- #to_s ⇒ Object
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
#ope ⇒ Object
Returns the value of attribute ope
119 120 121 |
# File 'lib/magic_logic.rb', line 119 def ope @ope end |
#vars ⇒ Object
Returns the value of attribute 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 |
#depth ⇒ Object
138 |
# File 'lib/magic_logic.rb', line 138 def depth; [p.depth, q.depth].max+1; end |
#include?(p) ⇒ Boolean
140 141 142 |
# File 'lib/magic_logic.rb', line 140 def include?(p) vars.include?(p) end |
#to_s ⇒ Object
126 |
# File 'lib/magic_logic.rb', line 126 def to_s; "(#{vars.map(&:to_s).join(_ ope, '|', '&')})" end |