Download presentation

Presentation is loading. Please wait.

Published byIsrael Belford Modified over 3 years ago

1
1 Logic Programming School of Informatics, University of Edinburgh Mode Inference Given the definition of a predicate p/N infer a calling pattern p(M 1, …, M N ) where each M i is the mode of the appropriate argument. A mode can be one of the following: ‘v’ Always a variable ‘g’ Always a ground term ‘?’ Not determined ‘v’ or ‘g’ ?g?gvgvggggg????vvvv?v?v Transitions:

2
2 Logic Programming School of Informatics, University of Edinburgh Modes Are Given For Built-in Predicates N is E gggg ?g?g atom(X) ?g?g A = B ????

3
3 Logic Programming School of Informatics, University of Edinburgh sum([], 0). sum([H|T], N) :- sum(T, NT), N is NT + 1. Inferring Modes gggg ?g?ggggg?g?ggggg ?g?g ggggvgvg = given

4
4 Logic Programming School of Informatics, University of Edinburgh Program Unfolding q([], []). q([H|T], R) :- t(H), q(T, R). p(L, R) :- q(L, X), r(X, R). p([], R) :- r([], R) p([H|T], R) :- t(H), q(T, X), r(X, R) unfold

5
5 Logic Programming School of Informatics, University of Edinburgh Program Folding s(A, B) :- q(A,C), r(C,B). p(A, B) :- q(A, C), r(C, B), t(B). p(A, B) :- s(A, B), t(B). fold

6
6 Logic Programming School of Informatics, University of Edinburgh Program Folding/Unfolding Example rev([], []). rev([H|T], R) :- rev(T, T1), append(T1, [H], R). append([], L, L). append([H|T], L, [H|R]) :- append(T, L, R). r_a(L, A, R) :- rev(L, L1), append(L1, A, R). r_a([], A, R) :- append([], A, R). r_a([H|T], A, R) :- rev(T, T1), append(T1, [H], L1), append(L1, A, R). r_a([], A, A). r_a([H|T], A, R) :- rev(T, T1), append(T1, [H|A], R). r_a([], A, R). r_a([H|T], A, R) :- r_a(T, [H|A], R). r_a([], A, R) :- append([], A, R). r_a([H|T], A, R) :- rev(T, T1), append(T1, [H|A], R). unfold simplify unfold fold

7
7 Logic Programming School of Informatics, University of Edinburgh Preserving a Common Control Structure path([X|_], X, []). path([H|T], X, [H|R]) :- path(T, X, R). dist([X|_], X, 0). dist([H|T], X, D) :- dist(T, X, Dt), D is Dt + 1. path_dist(L, X, P, D) :- path(L, X, P), dist(L, X, D). path_dist([X|_], X, [], 0). path_dist([H|T], X, [H|R], D) :- path_dist(T, X, R, Dt), D is Dt + 1. unfold + fold What is wrong with this picture?

8
8 Logic Programming School of Informatics, University of Edinburgh Preserving a Common Control Structure path([X|_], X, []). path([H|T], X, [H|R]) :- path(T, X, R). dist([X|_], X, 0). dist([H|T], X, D) :- dist(T, X, Dt), D is Dt + 1. path_dist(L, X, P, D) :- path(L, X, P), dist(L, X, D). path_dist([X|T], X, [], D) :- dist([X|T], X, D). path_dist([H|T], X, [H|R], D) :- path(T, X, R), dist([H|T], X, D). path_dist([X|T], X, [], 0). path_dist([X|T], X, [], D) :- dist(T, X, Dt), D is Dt + 1. path_dist([H|T], X, [H|R], D) :- path_dist(T, X, R, Dt), D is Dt + 1. path_dist([H|T], X, [H|R], D) :- path(T, X, R), dist([H|T], X, D). unfold + fold

Similar presentations

OK

Definition: two fractions with the same value How do you find them? Multiply or divide by a “Giant One”. Example: x = One reason to use them: to add and.

Definition: two fractions with the same value How do you find them? Multiply or divide by a “Giant One”. Example: x = One reason to use them: to add and.

© 2018 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google

Ppt on non ferrous minerals in the body Ppt on obesity diet camp Ppt online viewer for pdf Ppt on condition monitoring job Ppt on question tags grammar Ppt on techniques to secure data Ppt on carbon and its compounds elements Ppt on unity in diversity studio Ppt on gps based vehicle root tracking system Download ppt on abdul kalam