1 Replies - 3364 Views - Last Post: 20 April 2013 - 06:54 AM Rate Topic: -----

#1 antonin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-April 13

Unification (prolog) in Python

Posted 20 April 2013 - 06:33 AM

I'm beginning to study Python and I read that you can define functions of predicates unification (prolog style) in Python .

I want to define a function:
def unif(list1, list2):

which returns: b_ok, d_subst
b_ok : True if the unification is possible, False sinon
d_subst : one correct substitution of the case (a substitution function)

ex: unif(['p','A'],['p','a']) ----> True, {'A':'a'}

I really do not see how to write python`s code for this...

any help??


Is This A Good Question/Topic? 0
  • +

Replies To: Unification (prolog) in Python

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2539
  • View blog
  • Posts: 4,024
  • Joined: 21-June 11

Re: Unification (prolog) in Python

Posted 20 April 2013 - 06:54 AM

Assuming I understood what you want correctly, this should work:

Loop over the two lists in parallel (assuming they're the same size - otherwise they can't be unified), keeping track of mappings from variables to values or other variables. If the current elements of both lists are atoms or variables that already have an entry mapping them to an atom, check that the atoms equal. If one element is an atom or a variable mapped to an atom and the other is a variable, then map that variable (and any other variables that are currently mapped to that variable) to the atom. If both are variables, map the variables to each other.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1