Download presentation
Presentation is loading. Please wait.
Published byTyler Brundage Modified over 9 years ago
1
1 Logic Programming School of Informatics, University of Edinburgh Transformations Specification-Program An introduction to moving between Prolog and First Order Predicate Logic.
2
2 Logic Programming School of Informatics, University of Edinburgh Why Worry About Specifications? Equivalence p(X) ( Y.(q(X) r(Y))) p(X) ( Y.(q(X) r(Y))) p(X) :- \+ (q(X), \+ r(Y)) is logically equivalent to may be equivalent to
3
3 Logic Programming School of Informatics, University of Edinburgh Why Worry About Specifications? Refinement subset([], S2) subset([H|T], S2) :- member(H,S2), subset(T, S2) subset(S1, S2) list(S1) list(S2) E.(member(E,S1) member(E,S2)) subset(S1, S2) :- list(S1),list(S2), \+ (member(E,S1), \+ member(E,S2))
4
4 Logic Programming School of Informatics, University of Edinburgh Why Worry About Specifications? Desirable properties (e.g. termination) subset([], S2) subset([H|T], S2) member(H,S2) subset(T, S2) size(subset([H|T], S2)) = len([H|T]) + len(S2) = len(T) + 1 + len(S2) > len(S2) = size(member(H,S2)) size(subset ([H|T], S2)) = len([H|T]) + len(S2) = len(T) + 1 + len(S2) > len(T) + len(S2) = size(subset(T,S2)) size(member(H,[H|T])) = len([H|T]) = len(T) + 1 > len(T) = size(member(H,T)) len([H|T]) = len(T) + 1 size(subset(S1,S2)) = len(S1) + len(S2) size(member(E,S)) = len(S) Given:
5
5 Logic Programming School of Informatics, University of Edinburgh Pure Prolog l Negation l Control predicates l Meta-logical predicates l External state predicates l Clause-base altering predicates Without: p(X) :- not(q(X)), r(X). q(2). r(1). p(X) :- q(X), !, r(X). q(2). r(1). r(2). p(X) :- var(X), q(X). q(1). p(X) :- read(X). p(X) :- assert(r(X)). q(X) :- r(X).
6
6 Logic Programming School of Informatics, University of Edinburgh Pure Prolog to Horn Clauses p(X,Y) (q(X) r(Y)) s(X, Y) p(X,Y) :- (q(X), r(Y)) ; s(X, Y).
7
7 Logic Programming School of Informatics, University of Edinburgh Clark Completion p(a 1,…,a N ) body 1 p(b 1,…,b N ) body 2 p(X 1,…,X N ) X 1 = a 1 … X N = a N body 1 p(Y 1,…,Y N ) Y 1 = b 1 … Y N = b N body 2 Make head arguments into distinct variables Existentially quantify any variable in the body that is not in the head. p(X 1,…,X N ) V 1 …V i.X 1 = a 1 … X N = a N body 1 p(Y 1,…,Y N ) W 1 …W j.Y 1 = b 1 … Y N = b N body 2 Combine clauses p(X 1,…,X N ) ( V 1 …V i.X 1 = a 1 … X N = a N body 1 ) ( W 1 …W j.Y 1 = b 1 … Y N = b N body 2 )
8
8 Logic Programming School of Informatics, University of Edinburgh Clark Completion (Example) subset([], S2) subset([H|T], S2) member(H,S2) subset(T, S2) subset(S1, S2) S1 = [] subset([H|T], S2) S1 = [H|T] member(H,S2) subset(T, S2) Make head arguments into distinct variables Existentially quantify any variable in the body that is not in the head. Combine clauses subset(S1, S2) S1 = [] subset(S1, S2) S1 = [H|T] member(H,S2) subset(T, S2) subset(S1, S2) (S1 = []) (S1 = [H|T] member(H,S2) subset(T, S2))
9
9 Logic Programming School of Informatics, University of Edinburgh Lloyd-Topor Transformation (Simplified) H 1 V 2 H 1 2 H 1 H 2 H 1 2 H 1 (A B) 2 H 1 A 2 H 1 B 2
10
10 Logic Programming School of Informatics, University of Edinburgh Lloyd-Topor Transformation (Example) p(X) a(X) ( Y.q(X,Y) r(X,Y) s(X,Y)) p(X) a(X) ((q(X,Y) r(X,Y)) s(X,Y)) p(X) :- a(X), \+ ((q(X,Y) ; r(X,Y)), \+ s(X,Y))
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.