logic programming
play

Logic Programming Unification Temur Kutsia Research Institute for - PowerPoint PPT Presentation

Logic Programming Unification Temur Kutsia Research Institute for Symbolic Computation Johannes Kepler University, Linz, Austria kutsia@risc.jku.at Unification Solving term equations: Given: Two terms s and t . Find: A substitution such


  1. Logic Programming Unification Temur Kutsia Research Institute for Symbolic Computation Johannes Kepler University, Linz, Austria kutsia@risc.jku.at

  2. Unification Solving term equations: Given: Two terms s and t . Find: A substitution σ such that σ ( s ) = σ ( t ) .

  3. Substitutions ◮ A T ( F , V ) -substitution: A function σ : V → T ( F , V ) , whose domain D om ( σ ) := { x | σ ( x ) � = x } is finite.

  4. Substitutions ◮ A T ( F , V ) -substitution: A function σ : V → T ( F , V ) , whose domain D om ( σ ) := { x | σ ( x ) � = x } is finite. ◮ Range of a substitution σ : R an ( σ ) := { σ ( x ) | x ∈ D om ( σ ) } .

  5. Substitutions ◮ A T ( F , V ) -substitution: A function σ : V → T ( F , V ) , whose domain D om ( σ ) := { x | σ ( x ) � = x } is finite. ◮ Range of a substitution σ : R an ( σ ) := { σ ( x ) | x ∈ D om ( σ ) } . ◮ Variable range of a substitution σ : VR an ( σ ) := V ar ( R an ( σ )) .

  6. Substitutions ◮ A T ( F , V ) -substitution: A function σ : V → T ( F , V ) , whose domain D om ( σ ) := { x | σ ( x ) � = x } is finite. ◮ Range of a substitution σ : R an ( σ ) := { σ ( x ) | x ∈ D om ( σ ) } . ◮ Variable range of a substitution σ : VR an ( σ ) := V ar ( R an ( σ )) . ◮ Notation: lower case Greek letters σ, ϑ, ϕ, ψ, . . . . Identity substitution: ε .

  7. Substitutions ◮ Notation: If D om ( σ ) = { x 1 , . . . , x n } , then σ can be written as the set { x 1 �→ σ ( x 1 ) , . . . , x n �→ σ ( x n ) } . ◮ Example: { x �→ i ( y ) , y �→ e } .

  8. Substitutions ◮ The substitution σ can be extended to a mapping σ : T ( F , V ) → T ( F , V ) by induction: σ ( f ( t 1 , . . . , t n )) = f ( σ ( t 1 ) , . . . , σ ( t n )) .

  9. Substitutions ◮ The substitution σ can be extended to a mapping σ : T ( F , V ) → T ( F , V ) by induction: σ ( f ( t 1 , . . . , t n )) = f ( σ ( t 1 ) , . . . , σ ( t n )) . ◮ Example: σ = { x �→ i ( y ) , y �→ e } . t = f ( y, f ( x, y )) σ ( t ) = f ( e, f ( i ( y ) , e ))

  10. Substitutions ◮ The substitution σ can be extended to a mapping σ : T ( F , V ) → T ( F , V ) by induction: σ ( f ( t 1 , . . . , t n )) = f ( σ ( t 1 ) , . . . , σ ( t n )) . ◮ Example: σ = { x �→ i ( y ) , y �→ e } . t = f ( y, f ( x, y )) σ ( t ) = f ( e, f ( i ( y ) , e )) ◮ S ub : The set of substitutions.

  11. More Notions about Substitutions ◮ Composition of ϑ and σ : σϑ ( x ) := σ ( ϑ ( x )) . ◮ Composition of two substitutions is again a substitution. ◮ Composition is associative but not commutative.

  12. More Notions about Substitutions Algorithm for obtaining a set representation of a composition of two substitutions in a set form. ◮ Given: θ = { x 1 �→ t 1 , . . . , x n �→ t n } σ = { y 1 �→ s 1 , . . . , y m �→ s m } , the set representation of their composition σθ is obtained from the set { x 1 �→ σ ( t 1 ) , . . . , x n �→ σ ( t n ) , y 1 �→ s 1 , . . . , y m �→ s m } by deleting ◮ all y i �→ s i ’s with y i ∈ { x 1 , . . . , x n } , ◮ all x i �→ σ ( t i ) ’s with x i = σ ( t i ) .

  13. More Notions about Substitutions Example 3.1 (Composition) θ = { x �→ f ( y ) , y �→ z } . σ = { x �→ a, y �→ b, z �→ y } . σθ = { x �→ f ( b ) , z �→ y } .

  14. More Notions about Substitutions ◮ t is an instance of s iff there exists a σ such that σ ( s ) = t. ◮ Notation: t � s (or s � t ). ◮ Reads: t is more specific than s , or s is more general than t . ◮ � is a quasi-order. ◮ Strict part: > .

  15. More Notions about Substitutions ◮ t is an instance of s iff there exists a σ such that σ ( s ) = t. ◮ Notation: t � s (or s � t ). ◮ Reads: t is more specific than s , or s is more general than t . ◮ � is a quasi-order. ◮ Strict part: > . ◮ Example: f ( e, f ( i ( y ) , e )) � f ( y, f ( x, y )) , because σ ( f ( y, f ( x, y ))) = f ( e, f ( i ( y ) , e ) for σ = { x �→ i ( y ) , y �→ e }

  16. Unification Syntactic unification: Given: Two terms s and t . Find: A substitution σ such that σ ( s ) = σ ( t ) . ◮ σ : a unifier of s and t . ◮ σ : a solution of the equation s = ? t .

  17. Examples f ( x ) = ? f ( a ) : exactly one unifier { x �→ a } x = ? f ( y ) : infinitely many unifiers { x �→ f ( y ) } , { x �→ f ( a ) , y �→ a } , . . . f ( x ) = ? g ( y ) : no unifiers x = ? f ( x ) : no unifiers

  18. Examples x = ? f ( y ) : infinitely many unifiers { x �→ f ( y ) } , { x �→ f ( a ) , y �→ a } , . . . ◮ Some solutions are better than the others: { x �→ f ( y ) } is more general than { x �→ f ( a ) , y �→ a }

  19. Substitutions Instantiation Quasi-Ordering ◮ A substitution σ is more general than ϑ , written σ � ϑ , if there exists η such that ησ = ϑ . ◮ ϑ is called an instance of σ . ◮ The relation � is quasi-ordering (reflexive and transitive binary relation), called instantiation quasi-ordering. ◮ ∼ is the equivalence relation corresponding to � , i.e., the relation � ∩ � . Example 3.2 Let σ = { x �→ y } , ρ = { x �→ a, y �→ a } , ϑ = { y �→ x } . ◮ σ � ρ , because { y �→ a } σ = ρ . ◮ σ � ϑ , because { y �→ x } σ = ϑ . ◮ ϑ � σ , because { x �→ y } ϑ = σ . ◮ σ ∼ ϑ .

  20. Substitutions Definition 3.2 (Variable Renaming) A substitution σ = { x 1 �→ y 1 , x 2 �→ y 2 , . . . , x n �→ y n } is called variable renaming iff { x 1 , . . . , x n } = { y 1 , . . . , y n } . (Permuting the domain variables.) Example 3.3 ◮ { x �→ y, y �→ z, z �→ x } is a variable renaming. ◮ { x �→ a } , { x �→ y } , and { x �→ z, y �→ z, z �→ x } are not.

  21. Substitutions Definition 3.3 (Idempotent Substitution) A substitution σ is idempotent iff σσ = σ . Example 3.4 Let σ = { x �→ f ( z ) , y �→ z } , ϑ = { x �→ f ( y ) , y �→ z } . ◮ σ is idempotent. ◮ ϑ is not: ϑϑ = σ � = ϑ .

  22. Substitutions Lemma 3.2 σ ∼ ϑ iff there exists a variable renaming ρ such that ρσ = ϑ . Proof. Exercise.

  23. Substitutions Lemma 3.2 σ ∼ ϑ iff there exists a variable renaming ρ such that ρσ = ϑ . Proof. Exercise. Example 3.5 ◮ σ = { x �→ y } . ◮ ϑ = { y �→ x } . ◮ σ ∼ ϑ . ◮ { x �→ y, y �→ x } σ = ϑ .

  24. Substitutions Theorem 3.4 σ is idempotent iff D om ( σ ) ∩ VR an ( σ ) = ∅ . Proof. Exercise.

  25. Substitutions Definition 3.4 (Unification Problem, Unifier, MGU) ◮ Unification problem: A finite set of equations Γ = { s 1 = ? t 1 , . . . , s n = ? t n } .

  26. Substitutions Definition 3.4 (Unification Problem, Unifier, MGU) ◮ Unification problem: A finite set of equations Γ = { s 1 = ? t 1 , . . . , s n = ? t n } . ◮ Unifier or solution of Γ : A substitution σ such that σ ( s i ) = σ ( t i ) for all 1 ≤ i ≤ n .

  27. Substitutions Definition 3.4 (Unification Problem, Unifier, MGU) ◮ Unification problem: A finite set of equations Γ = { s 1 = ? t 1 , . . . , s n = ? t n } . ◮ Unifier or solution of Γ : A substitution σ such that σ ( s i ) = σ ( t i ) for all 1 ≤ i ≤ n . ◮ U (Γ) : The set of all unifiers of Γ . Γ is unifiable iff U (Γ) � = ∅ .

  28. Substitutions Definition 3.4 (Unification Problem, Unifier, MGU) ◮ Unification problem: A finite set of equations Γ = { s 1 = ? t 1 , . . . , s n = ? t n } . ◮ Unifier or solution of Γ : A substitution σ such that σ ( s i ) = σ ( t i ) for all 1 ≤ i ≤ n . ◮ U (Γ) : The set of all unifiers of Γ . Γ is unifiable iff U (Γ) � = ∅ . ◮ σ is a most general unifier (mgu) of Γ iff it is a least element of U (Γ) : ◮ σ ∈ U (Γ) , and ◮ σ � ϑ for every ϑ ∈ U (Γ) .

  29. Unifiers Example 3.6 σ := { x �→ y } is an mgu of x = ? y . For any other unifier ϑ of x = ? y , σ � ϑ because ◮ ϑ ( x ) = ϑ ( y ) = ϑσ ( x ) . ◮ ϑ ( y ) = ϑσ ( y ) . ◮ ϑ ( z ) = ϑσ ( z ) for any other variable z .

  30. Unifiers Example 3.6 σ := { x �→ y } is an mgu of x = ? y . For any other unifier ϑ of x = ? y , σ � ϑ because ◮ ϑ ( x ) = ϑ ( y ) = ϑσ ( x ) . ◮ ϑ ( y ) = ϑσ ( y ) . ◮ ϑ ( z ) = ϑσ ( z ) for any other variable z . σ ′ := { x �→ z, y �→ z } is a unifier but not an mgu of x = ? y . ◮ σ ′ = { y �→ z } σ . ◮ { z �→ y } σ ′ = { x �→ y, z �→ y } � = σ .

  31. Unifiers Example 3.6 σ := { x �→ y } is an mgu of x = ? y . For any other unifier ϑ of x = ? y , σ � ϑ because ◮ ϑ ( x ) = ϑ ( y ) = ϑσ ( x ) . ◮ ϑ ( y ) = ϑσ ( y ) . ◮ ϑ ( z ) = ϑσ ( z ) for any other variable z . σ ′ := { x �→ z, y �→ z } is a unifier but not an mgu of x = ? y . ◮ σ ′ = { y �→ z } σ . ◮ { z �→ y } σ ′ = { x �→ y, z �→ y } � = σ . σ ′′ = { x �→ y, z 1 �→ z 2 , z 2 �→ z 1 } is an mgu of x = ? y . ◮ σ = { z 1 �→ z 2 , z 2 �→ z 1 } σ ′′ . ◮ σ ′′ is not idempotent.

  32. Unification Question: How to compute an mgu of an unification problem?

  33. Rule-Based Formulation of Unification ◮ Unification algorithm in a rule-base way. ◮ Repeated transformation of a set of equations. ◮ The left-to-right search for disagreements: modeled by term decomposition.

Recommend


More recommend