A Generic Framework for the Analysis and Specialization of Logic - - PowerPoint PPT Presentation

a generic framework for the analysis and specialization
SMART_READER_LITE
LIVE PREVIEW

A Generic Framework for the Analysis and Specialization of Logic - - PowerPoint PPT Presentation

A Generic Framework for the Analysis and Specialization of Logic Programs an Puebla , Elvira Albert , and Manuel Hermenegildo , Germ ( ) Technical University of Madrid (Spain) ( ) Complutense University of


slide-1
SLIDE 1

ucm-seal upm-seal unm-seal

A Generic Framework for the Analysis and Specialization of Logic Programs

Germ´ an Puebla∗, Elvira Albert∗∗, and Manuel Hermenegildo∗,∗∗∗ (∗)Technical University of Madrid (Spain) (∗∗)Complutense University of Madrid (Spain) (∗ ∗ ∗)University of New Mexico (USA) 15th Workshop on Logic-based Methods In Programming Environments (WLPE’05) Sitges, October 5, 2005

Germ´ an Puebla (UPM/UCM/UNM) Analysis and Specialization of Logic Programs Sitges, October 5, 2005 1 / 14

slide-2
SLIDE 2

ucm-seal upm-seal unm-seal

Motivation

Traditional partial evaluation of logic programs

◮ Based on SLD semantics ◮ Nice and simple ◮ Agressive transformations ◮ But sometimes is not very accurate!

Traditional partial evaluation of logic programs

◮ Based on And–Or trees ◮ Well understood ◮ Often accurate results ◮ But sometimes is not very accurate! Germ´ an Puebla (UPM/UCM/UNM) Analysis and Specialization of Logic Programs Sitges, October 5, 2005 2 / 14

slide-3
SLIDE 3

ucm-seal upm-seal unm-seal

Partial Deduction and SLD-Trees

Germ´ an Puebla (UPM/UCM/UNM) Analysis and Specialization of Logic Programs Sitges, October 5, 2005 3 / 14

slide-4
SLIDE 4

ucm-seal upm-seal unm-seal

Loss of Information in SLD-Trees

Germ´ an Puebla (UPM/UCM/UNM) Analysis and Specialization of Logic Programs Sitges, October 5, 2005 4 / 14

slide-5
SLIDE 5

ucm-seal upm-seal unm-seal

Challenges in combining abstract information and unfolding

  • 1. Exploiting abstract information to abstractly execute atoms which

allows more unfolding

◮ All calls to the tests ground2,1(X) and var2,2(W) will succeed ◮ Calls to ground8,1(X) will succeed, while calls to var7,1(X) will fail ◮ Groundness and freeness not sufficient to determine that, in 2nd

execution of formula, tests ground2,1(X) and var2,2(W) succeed.

  • 2. Unfolding steps to prune away useless branches, which results in

improved success information

◮ On success of minus2,4(T,X,X2), X2 not guaranteed to be ground

(minus6/3 succeeds with X2 variable)

◮ However, for calls described by the entry, third clause for minus/3

is useless, i.e., will never contribute to a success

◮ Unfolding makes calls to minus/3 sufficiently instantiated (third

clause disregarded) and, thus, all its calls succeed with X2 ground.

Germ´ an Puebla (UPM/UCM/UNM) Analysis and Specialization of Logic Programs Sitges, October 5, 2005 5 / 14

slide-6
SLIDE 6

ucm-seal upm-seal unm-seal

Challenges in combining abstract information and unfolding

  • 3. Propagating success information (fixpoint computations)

simultaneously results in improved unfolding:

◮ Need fixpoint computation to determine that, upon success of

twice2,5(X2,W) (thus success of formula1,1(X,W)), W is ground.

◮ Success substitution for formula1,1(X,X1) is call substitution for

formula1,2(X1,X2).

◮ Success of test ground2,1(X) (reachable from formula1,2(X1,X2))

cannot be established unless we propagate success.

  • 4. Having information on non downwards-closed properties

◮ Whenever we call formula(X,W), W is a variable ◮ This property cannot be captured if we restrict ourselves to

downwards-closed domains.

Our framework is able to abstractly execute all calls to mode tests ground/1 and var/1, and predicates two/1 and minus/3 are both fully unfolded and no longer appear in the residual code.

Germ´ an Puebla (UPM/UCM/UNM) Analysis and Specialization of Logic Programs Sitges, October 5, 2005 6 / 14

slide-7
SLIDE 7

ucm-seal upm-seal unm-seal

Partial Evaluation

Abstract Unfold AGene− ralize

Table Generaliz Table Specializ

SPECIALIZED DEFINITION

Patterns Calling Program Program Specialized

Germ´ an Puebla (UPM/UCM/UNM) Analysis and Specialization of Logic Programs Sitges, October 5, 2005 7 / 14

slide-8
SLIDE 8

ucm-seal upm-seal unm-seal

Abstract Interpretation

Patterns Calling Program

Table Answer ABSTRACT INTERPRETER Table Depend

Table Answer

Abstract Domain Widening Calls

Germ´ an Puebla (UPM/UCM/UNM) Analysis and Specialization of Logic Programs Sitges, October 5, 2005 8 / 14

slide-9
SLIDE 9

ucm-seal upm-seal unm-seal

Abstract Interpretation with Specialized Definitions

Calls Widening Domain Abstract

Dependency Table Abstract Unfold AGene− ralize

ABSTRACT INTERPRETER

Table Answer

SPECIALIZED DEFINITION Table Generaliz Table Specializ

Program Specialized Patterns Calling Answer Table Program

Germ´ an Puebla (UPM/UCM/UNM) Analysis and Specialization of Logic Programs Sitges, October 5, 2005 9 / 14

slide-10
SLIDE 10

ucm-seal upm-seal unm-seal

Integration of abstract interpretation and partial deduction

Previous (partial) integrations starting from both the partial deduction and abstract interpretation perspectives. Proposal: first fully described generic algorithm for efficient and precise integration from an abstract interpretation perspective. Starting point: state-of-the-art algorithms for context-sensitive, polyvariant abstract interpretation and (abstract) partial deduction Key ingredients: combining the best of both worlds:

1

accurate success propagation inherent to abstract interpretation

2

powerful program transformations achievable by partial deduction

Specialized definitions: calls in analysis graph are not analyzed w.r.t.

  • riginal definition of procedures but w.r.t. specialized definitions

◮ specialized definitions obtained by unfolding and abstract executability.

Benefits:

1

Different combinations of parameters correspond to existing algorithms for program analysis and specialization.

2

Strictly more precise results than individual techniques.

Proposed algorithm: a key component of the CiaoPP system.

Germ´ an Puebla (UPM/UCM/UNM) Analysis and Specialization of Logic Programs Sitges, October 5, 2005 10 / 14

slide-11
SLIDE 11

ucm-seal upm-seal unm-seal

Analysis Graph for the Example

{X/G,X2/V}main(s3(X), X2){X/G,X2/G}

✞ ✝ ☎ ✆

SPEC DEF(main(s3(X), X2) : {X/G, X2/V})

  • main(s3(0), 0)

main(s4(B), A)

  • {B/G,C/V}tw(B, C){B/G,C/G}
  • {C/G,A/V}f(C, A){C/G,A/G}

✞ ✝ ☎ ✆

SPEC DEF(tw(B, C) : {B/G, C/V})

✝ ☎ ✆

SPEC DEF(f(C, A) : {C/G, A/V})

  • tw(0, 0)

tw(s(B), s2(C) f(0, s4(0))))) f(s(A), s6(B)

  • {B/G,C/V}tw(B, C){B/G,C/G}
  • {A/G,B/V}tw(A, B){A/G,B/G}
  • Germ´

an Puebla (UPM/UCM/UNM) Analysis and Specialization of Logic Programs Sitges, October 5, 2005 11 / 14

slide-12
SLIDE 12

ucm-seal upm-seal unm-seal

Generic framework for analysis and specialization

Generic framework for analysis and specialization of LP: currently the basis of the analysis/specialization system implemented in the CiaoPP preprocessor Versatility can be seen by recasting well-known specialization and analysis frameworks as instances:

◮ Polyvariant AI: Our algorithm can behave as Polyvariant AI by

defining:

⋆ AGeneralize operator which returns always the base form of an

expression

⋆ AUnfold operator which performs a single derivation step ◮ Multivariant AS: The specialization power of abstract specialization

can be obtained by using:

⋆ the same AGeneralize described above ⋆ AUnfold operator which always performs a derive step followed by zero

  • r more abstract execution steps.

Germ´ an Puebla (UPM/UCM/UNM) Analysis and Specialization of Logic Programs Sitges, October 5, 2005 12 / 14

slide-13
SLIDE 13

ucm-seal upm-seal unm-seal

Generic framework for analysis and specialization

Classical PD: Our method can be used to perform classical PD by using:

◮ an abstract domain with the single abstract value ⊤ ◮ the identity function as Widen Call rule

APD: Several approaches have been proposed which extend PD by using abstract substitutions.

◮ They either fail to do so or propose means for propagating success

information which are not fully integrated with the APD algorithm

◮ These proposals are either strongly coupled to a particular (downward

closed) abstract domain or do not provide the exact description of

  • perations on the abstract domain which are needed by the framework,
  • ther than general correctness criteria.

Germ´ an Puebla (UPM/UCM/UNM) Analysis and Specialization of Logic Programs Sitges, October 5, 2005 13 / 14

slide-14
SLIDE 14

ucm-seal upm-seal unm-seal

Conclusions

Novel scheme for a seamless integration of the techniques of abstract interpretation and partial deduction. Parametric w.r.t. the abstract domain and the control issues which guide the partial deduction process. Existing proposals use AI as a means for improving PD rather than as a goal. Thus, their objective is to yield a PD rather than to compute a safe approximation of its success. Unlike them, our main objective is to improve success information by analyzing the specialized code, rather than the original one. Achieved by smoothly interleaving both techniques which improves success information. With more accurate success information, we can improve further the quality of partial evaluation. The overall method thus yields not only a specialized program but also a safe approximation of its behaviour.

Germ´ an Puebla (UPM/UCM/UNM) Analysis and Specialization of Logic Programs Sitges, October 5, 2005 14 / 14