Variable.to_cnf()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 3
rs 10
1
module PropLogic
2
  class Variable < Term
3
    def initialize(name = nil)
4
      @name = name || "v_#{object_id}"
5
      @terms = [].freeze
6
      freeze
7
    end
8
9
    public_class_method :new
10
11
    def to_s(*)
12
      @name
13
    end
14
15
    def nnf?
16
      true
17
    end
18
19
    def reduced?
20
      true
21
    end
22
23
    def to_cnf
24
      self
25
    end
26
27
    def tseitin(pool)
28
      self
29
    end
30
31
    def cnf?
32
      true
33
    end
34
35
    def variables
36
      [self]
37
    end
38
39
    def assign(trues, falses, variables = nil)
40
      if trues.include? self
41
        True
42
      elsif falses.include? self
43
        False
44
      else
45
        self
46
      end
47
    end
48
49
    # bypassing Term.get
50
    # @return [NotTerm] negated variable
51
    def not
52
      Term.__send__ :cached, NotTerm, self
53
    end
54
55
    alias_method :~, :not
56
    alias_method :-@, :not
57
58
59
  end
60
end
61