Class: TruthTable

Inherits:
Object
  • Object
show all
Defined in:
lib/logical/algorithms/truth_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formula) ⇒ TruthTable

Returns a new instance of TruthTable.



6
7
8
9
10
# File 'lib/logical/algorithms/truth_table.rb', line 6

def initialize(formula)
  @formula = formula
  letters = formula.literals.map(&:letter)
  @evaluations = Interpretation.all(letters).map { |i| Evaluation.new(i, formula) }
end

Instance Attribute Details

#evaluationsObject (readonly)

Returns the value of attribute evaluations.



4
5
6
# File 'lib/logical/algorithms/truth_table.rb', line 4

def evaluations
  @evaluations
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/logical/algorithms/truth_table.rb', line 20

def invalid?
  !satisfied?
end

#satisfied?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/logical/algorithms/truth_table.rb', line 16

def satisfied?
  @evaluations.map(&:value).any?
end

#valid?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/logical/algorithms/truth_table.rb', line 12

def valid?
  @evaluations.map(&:value).all?
end