A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

32
Slide 1 A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data M.R.K. Krishna Rao King Fahd University of Petroleum and Minerals Dhahran 31261, Saudi Arabia Presented by Eric Martin University of New South Wales Sydney, Australia

description

A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data. M.R.K. Krishna Rao King Fahd University of Petroleum and Minerals Dhahran 31261, Saudi Arabia Presented by Eric Martin University of New South Wales Sydney, Australia. Outline. Learning from positive data - PowerPoint PPT Presentation

Transcript of A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Page 1: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 1

A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

M.R.K. Krishna RaoKing Fahd University of Petroleum and Minerals

Dhahran 31261, Saudi Arabia

Presented by

Eric MartinUniversity of New South Wales

Sydney, Australia

Page 2: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 2

Outline

Learning from positive data History and Motivation Recursion bounded programs Decidability of Recursion bounded programs Infererability of Recursion bounded programs

from positive data Comparison and conclusions

Page 3: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 3

Learnability from positive data Gold (1967) proved that even simple classes of

concepts like the class of regular languages cannot be inferred from positive examples alone.

Why study it?• In practice, positive examples are easier to

obtain than negative examples. Starting with Angluin (1980), many results on

learnability from positive data are published.

Page 4: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 4

Learnability from positive data Shinohara (1991): the class of linear Prolog

programs learniable from positive examples alone. • Size of terms in the body are bounded by the

size of terms in the head for all instantiations.• Hence, do not allow local variables.• Serious limitation!

Page 5: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 5

Learnability from positive data Arimura and Shinohara (1994): the class of linearly

covering programs inferable from positive data. • Uses moding annotations on predicates• Allows local variables• But, views local variables as point-to-point

communication channels • Hence many natural programs are beyond this class.• The class of linearly covering programs does not

include all linear programs – a technical limitation.

Page 6: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 6

Learnability from positive data Krishna Rao (1996): the class of linearly moded

programs inferable from positive data. • Uses moding annotations, linear inequalities on predicates,

and views local variables as broadcasting communication channels

• The class of linearly moded programs include all linear and linearly covering programs.

• Many natural programs are within this class, and automatic verification whether a given program is linear-moded or not is straightforward.

• But does not allow nonlinear input-output relations – a technical limitation.

Page 7: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 7

Learnability from positive data Martin and Sharma (1999): the class of safe

programs inferable from positive data. • Allows local variables and nonlinear input-output

relations• Uses bound kits• Automatic verification whether a given program is

safe or not clear• For a technical reason, a natural program for nth-

power is not a member of this class.

Page 8: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 8

Motivation In this paper, we present a class of programs

inferable from positive data• Can handle non-linear input-output relationships• Automatic verification whether a given program

is in this class or not is straightforward• Includes all the (terminating) linearly-moded

programs.

Page 9: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 9

Preliminaries A concept defining framework is a triple (U, E, )

of a universe U of objects, a set E of expressions and a semantic mapping .

A class of concepts C = {1, 2,… } is an indexed family of recursive concepts if there exists an algorithm that decides whether w i for any object w and natural number i.

A semantic mapping is monotonic if R R' implies (R) (R').

A formal system R is reduced w.r.t. S U if S (R) and for any proper subset R' of R, (R') S.

Page 10: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 10

Preliminaries A concept defining framework C = (U, E, ) has

bounded finite thickness if• is monotonic and• for any finite set S U and any m 0, the set

{(R) | R is reduced w.r.t.S and |R| m} is finite.

Theorem from Shinohara (1991): If a concept defining framework C = (U, E, ) has

bounded finite thickness, then the classCm = {(R) | R E and |R| m} of concepts is inferable from positive data for every m 1.

Page 11: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 11

Recursion-bounded programs The notion of recursion-bounded programs is based on

• moding information,• parametric size and• linear inequalities.

Moding information: for each predicate, some of its positions are designated ‘input’, while the others are designated ‘output’ positions.

We denote by p(s; t), an atom • with s as the sequence of input terms, and• with t as the sequence of output terms.

Page 12: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 12

Recursion-bounded programs The parametric size [t] of a term t is defined as

• if t is a variable x, then [t] is a linear expression x,• if t is a constant, then [t] is zero,• if t=f(t1, …, tn), then [t] is a linear expression 1 + [t1] + …

+ [tn]. The parametric size of a sequence t1, …, tn of terms is

the sum [t1] + … + [tn]. Example:

• The parametric sizes of terms a, [ ], [X], [a], [a,b,c], [ [ ], [ ], [ ] ], [ [a], [b], [c] ] are 0, 0, X+1, 1, 3, 3, 6 respectively.

Page 13: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 13

Recursion-bounded programs … Let P be a moded program and, I and O be

mappings such that I(p) is a subset of the input positions and O(p) is a subset of the output positions for each predicate p in P.

For an atom A = p(s; t), we denote the linear inequality

by LI(A, I, O).

)()(

][][pOj

jpIi

i ts

Page 14: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 14

Recursion-bounded programs…A moded program P is recursion bounded w.r.t. I and O

if each clause p0(s0; t0) p1(s1; t1), …, pk(sk; tk)

in it satisfies the following LI(A1, I, O), …, LI(Aj-1, I, O) together imply

[Iterms(A0, I)] > [Iterms(Aj, I)] for each j such that pj is in mutual recursion with p0 (or pj=p0 ),

LI(A1, I, O), …, LI(Ak, I, O) together imply LI(A0, I, O), and

A moded program P is recursion bounded if it is recursion bounded w.r.t. some I and O.

Page 15: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 15

Recursion-bounded programs - reverse

Example: Consider the following reverse program with moding info app(in,in, out) and rev(in, out).

app([ ], Ys, Ys) app([X|Xs], Ys, [X|Zs]) app(Xs,Ys, Zs)rev([ ], [ ]) rev([X|Xs], Zs) rev(Xs, Ys), app(Ys, [X], Zs) The first clause satisfies the requirements of the

above definition as LI(app([ ], Ys, Ys), I, O) is Ys Ys, which obviously holds.

The first clause is recursion bounded.

Page 16: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 16

Recursion-bounded programs - reverse…

Now consider the second clauseapp([X|Xs], Ys, [X|Zs]) app(Xs,Ys, Zs)

LI(app(Xs, Ys, Zs), I, O) is Xs + Ys Zs (1)

LI(app([X|Xs], Ys, [X|Zs]), I, O) is 1+X+ Xs + Ys 1+X+ Zs (2)

It’s easy to see that (1) imples (2) satisfying the requirement 2 of the above definition.

The requirement 1 of the above definition obviously holds as 1 + X + Xs + Ys > Xs + Ys.

Therefore, the second clause is recursion bounded.

Page 17: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 17

Recursion-bounded programs - reverse…

Now consider the fourth clauserev([X|Xs], Zs) rev(Xs, Ys), app(Ys, [X], Zs)

LI(rev(Xs, Ys), I, O) is Xs Ys (3)

LI(app(Ys, [X], Zs), I, O) is Ys + 1 + X Zs (4)

For the head, LI(rev([X|Xs], Zs), I, O) is 1 + X + Xs Zs (5)

It’s easy to see that (3) and (4) together imply (5) satisfying the requirement 2 of the above definition.

Page 18: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 18

Recursion-bounded programs - reverse…

The fourth clauserev([X|Xs], Zs) rev(Xs, Ys), app(Ys, [X], Zs)

satisfies the requirement 1 of the above definition on the recursive atom rev(Xs, Ys) as

1 + X + Xs > Xs. Therefore, the fourth clause is recursion bounded.

The third clause is recursion bounded as well.

The reverse program is recursion bounded.

Page 19: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 19

Recursion-bounded programs - quicksort

Example: Consider the following quick-sort program with moding info app(in,in, out), part(in, in, out, out) and qs(in, out).

app([ ], Ys, Ys) app([X|Xs], Ys, [X|Zs]) app(Xs,Ys, Zs)part([ ],H,[ ],[ ]) part([X|Xs],H,[X|Ls],Bs) H X, part(Xs,H,Ls,Bs)part([X|Xs],H,Ls,[X|Bs]) X > H, part(Xs,H,Ls,Bs) qs([ ], [ ]) qs([H|L],S) part(L,H,A,B), qs(A,A1), qs(B,B1),

app(A1,[H|B1],S)

Page 20: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 20

Recursion-bounded programs - quicksort

We prove that quick-sort program is recursion bounded w.r.t. I and O such that I(p) = in(p) and O(p) = out(p) for each predicate except that I(part) = {1}.

We consider the last clause, other clauses are easier to handle. qs([H|L],S) part(L,H,A,B), qs(A,A1),

qs(B,B1), app(A1,[H|B1],S) It may be noted that quick-sort program is not

recursion bounded w.r.t. I and O if I(part) = in(part).

Page 21: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 21

Recursion-bounded programs - quicksort

We consider the last clause, other clauses are easier to handle.qs([H|L],S) part(L,H,A,B), qs(A,A1), qs(B,B1),

app(A1,[H|B1],S)

LI(part(L,H,A,B), I, O) is L A + B (1) LI(qs(A,A1)}, I, O) is A A1 (2) LI(qs(B,B1)}, I, O) is B B1 (3) LI(app(A1,[H|B1],S), I, O) is A1 +1 +H +B1 S

(4) For the head, LI(qs([H|L],S)), I, O) is 1 + H + L S (5) It is easy to see that inequalities (1) to (4) together imply (5)

satisfying the requirement 2 of the above definition. For the recursive atoms qs(A,A1) and qs(B,B1), the

requirement 1 is implied by the inequality (1).

Page 22: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 22

Recursion-bounded programs The above two examples illustrate the main

characteristics of recursion bounded programs.

The linear inequalities capture the semantics of the programs (they capture model information used in acceptable programs).

The size of output terms in positions O is bounded by the size of input terms in positions I.

Page 23: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 23

Recursion-bounded programs The above two programs have linear

relationship between inputs and outputs. However, the class of recursion bounded

programs is rich enough to include predicates with non linear relationships (as multiplication in the next example).

The trick is to choose appropriate I and O!

Page 24: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 24

Recursion-bounded programs - multiply

Example: Consider the following multiplication program with moding info add(in,in, out) and mult(in, in, out).

add(0, Y, Y) add(s(X), Y, s(Z)) add(X, Y, Z)mult(0, Y, 0) mult(s(X), Y, Z) mult(X, Y, Z1), add(Y, Z1, Z)

This program is recursion bounded w.r.t. I and O such that I(add) = in(add), O(add) = out(add), I(mult) = in(mult) and O(mult) = .

Page 25: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 25

Recursion-bounded programs - multiply

We consider the last clause, other clauses are easier to handle.mult(s(X), Y, Z) mult(X, Y, Z1), add(Y, Z1, Z)

LI(mult(X, Y, Z1), I, O) is X+Y 0 (1) LI(add(Y, Z1, Z)}, I, O) is Y+Z1 Z (2) For the head, LI(mult(s(X), Y, Z), I, O) is 1 + X+Y 0

(3) It is easy to see that inequalities (1) and (2) together imply (3)

satisfying the requirement 2 of the above definition. For the recursive atom mult(X, Y, Z1), the requirement 1 holds

as 1 + X + Y > X + Y.

The multiplication program is recursion bounded.

Page 26: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 26

Recursion-bounded programs - decidability

Theorem: It is decidable whether a given moded program P is recursion bounded w.r.t. a given pair of mappings I and O or not.

Proof : Follows from the fact that this problem can be reduced to the satisfiability problem of linear inequalities.

Theorem: It is decidable whether a given moded program P is recursion bounded or not.

Proof : Follows from the fact that there are only finitely many choices for I and O.

Page 27: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 27

Recursion-bounded programs – semantics by LI

Theorem: Let P be a recursion bounded program w.r.t. a pair of mappings I and O. If there is an SLD-refutation for query A with computed answer substitution , then LI(A, I, O) is valid.

This theorem essentially establishes that the linear inequalities capture the semantic information.

Page 28: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 28

Recursion-bounded programs – properties

Theorem: Let P be a recursion bounded program w.r.t. a pair of mappings I and O. If B is an atom in an SLD-derivation starting with query A with partial computed answer substitution , such that the predicates of A and B are the same or in mutual recursion, then the sum of sizes of input terms of B (in positions I) is less than the sum of sizes of input terms of A (in positions I).

This theorem ensures finiteness of SLD-derivations of recursion bounded programs.

Page 29: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 29

Recursion-bounded programs – inferability from positive data

Theorem: For any recursion bounded program P and ground atom A, it is decidable whether A is in the least Herbrand model M(P) or not.

Definition: Let RBk be the set of all recursion bounded clauses of size at most k and Mc be a semantic mapping such that Mc(P) is the set of all atoms of the target predicate c in the least Herbrand model of P.

The concept defining framework <B(c), RBk, Mc> is denoted by RBk.

Page 30: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 30

Recursion-bounded programs – inferability from positive data

Theorem: For every k 1, the class of least Herbrand models of programs in RBk is an indexed family of recursive concepts.

Theorem: For every k 1, the concept defining framework RBk has bounded finite thickness.

Theorem: For every m 1, the class RBkm = {Mc(P) |

P RBk and |P| m} of concepts is inferable from positive presentations of the target predicate c.

Page 31: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 31

Related works The classes of recursion bounded and linear

moded programs are incomparable.• Multiplication program is recursion bounded but not

linear moded.• Merge-sort program is linear moded but not recursion

bounded. The classes of recursion bounded and safe

programs are incomparable.• The standard program for nth power is recursion

bounded but not safe.• Merge-sort program is safe but not recursion bounded.

Page 32: A Class of Prolog Programs with Non-linear Outputs Inferable from Positive Data

Slide 32

Conclusions The class of recursion bounded programs is

learnable from positive data. The class of recursion bounded programs is rich

enough to include many natural programs. It is decidable whether a given logic program is

recursion bounded or not. The notion of recursion bounded programs uses

very simple concepts like moding and linear inequalities.