Module: MagicLogic::Utils
- Included in:
- Base
- Defined in:
- lib/magic_logic/utils.rb
Constant Summary collapse
- ATOM_PREFIX =
"__ATOM__PREFIX__"
Instance Method Summary collapse
- #dpll ⇒ Object
- #evl ⇒ Object
- #include?(p) ⇒ Boolean
- #is_and? ⇒ Boolean
- #is_form?(ope = nil) ⇒ Boolean
- #is_neg? ⇒ Boolean
- #is_or? ⇒ Boolean
- #neg?(p) ⇒ Boolean
Instance Method Details
#dpll ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/magic_logic/utils.rb', line 46 def dpll case self when *[Taut, UTaut, Atom] self else #TODO: refactor count = $atoms.count rslt = (1 .. 2 ** count).map do |i| s = evl count.times { |j| s.sbst!(j, (i >> j) & 1 == 1) } eval(s) end case rslt.uniq when [true] then $tout when [false] then $utout else self end end end |
#evl ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/magic_logic/utils.rb', line 30 def evl case self when Taut then "(true)" when UTaut then "(false)" when Atom then "(#{ATOM_PREFIX}#{$atoms.index(self)})" when FORM then "(#{vars.map(&:evl).join(_ ope, '||', '&&')})" when NEG then "(!#{p.evl})" end end |
#include?(p) ⇒ Boolean
26 27 28 |
# File 'lib/magic_logic/utils.rb', line 26 def include?(p) false end |
#is_and? ⇒ Boolean
22 23 24 |
# File 'lib/magic_logic/utils.rb', line 22 def is_and? is_form?(:*) end |
#is_form?(ope = nil) ⇒ Boolean
13 14 15 16 |
# File 'lib/magic_logic/utils.rb', line 13 def is_form?(ope=nil) return is_a?(FORM) && self.ope == ope if ope is_a?(FORM) end |
#is_or? ⇒ Boolean
18 19 20 |
# File 'lib/magic_logic/utils.rb', line 18 def is_or? is_form?(:+) end |
#neg?(p) ⇒ Boolean
5 6 7 |
# File 'lib/magic_logic/utils.rb', line 5 def neg?(p) (is_neg? && self.p == p) || (p.is_neg? && p.p == self) end |