Class: Unifier

Inherits:
Object
  • Object
show all
Defined in:
lib/rover_prover/prover/unifier.rb

Instance Method Summary collapse

Instance Method Details

#unify_all(pairs_list) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/rover_prover/prover/unifier.rb', line 4

def unify_all(pairs_list)
  lengths = pairs_list.map { |pair| (0..(pair.length - 1)).to_a }
  first = lengths.shift
  indexes = first.product(*lengths)
  indexes.each do |index|
    possible_pairs = pairs_list.map.with_index { |pairs, i| pairs[index[i]] }
    subst = unify_list(possible_pairs)
    return subst unless subst.nil?
  end
  nil
end

#unify_list(pairs) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rover_prover/prover/unifier.rb', line 16

def unify_list(pairs)
  substitution = {}
  pairs.each do |a, b|
    substitution.each do |k, v|
      a = a.replace(k, v)
      b = b.replace(k, v)
    end
    sub = a.unify(b)
    return nil if sub.nil?
    substitution.merge!(sub)
  end
  substitution
end