1 / 22

Prolog

Prolog. or: How I Learned to Stop Worrying and Love the Search. Hello. I’m Zach, one of Sorin’s students. ztatlock@cs.ucsd.edu. Search. Any cycles?. Search. How about now?. Search. And now?. Search. Reach from stopping by ?. Search is Fundamental.

cheryl
Télécharger la présentation

Prolog

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Prolog or: How I Learned to Stop Worryingand Love the Search

  2. Hello. I’m Zach, one of Sorin’s students. ztatlock@cs.ucsd.edu

  3. Search Any cycles?

  4. Search How about now?

  5. Search And now?

  6. Search Reach from stopping by ?

  7. Search is Fundamental Natural way to phrase problems: Is there an X such that Y? Ubiquitous in Computer Science:

  8. Prolog: Interface to Search Search is declarative say what you want not how to get it Often radical simplification shorter, clearer programs less development effort fewer bugs SEARCH

  9. Prolog Anatomy 101 Prolog programs do three things: Declare Facts known points in the search space 2. Declare Rules add new points to search space based on old ones 3. Query over Search Space search for a point

  10. Prolog Anatomy 101 Facts : known points Rules : add new points from old points Query: is reachable? Query Rules Facts

  11. Prolog Basic Syntax Backtracking Search Examples in the toplevel: • Variables in Queries • Negation • Search Order

  12. Basic Syntax Declare Facts: parent(homer, bart). parent(marge, bart). parent(mona, homer). Known points in search space Basis of all we can conclude

  13. Basic Syntax Simple Query: ?- parent(homer, bart). true. ?- parent(mona, bart). false. Ask if a particular point is in search space

  14. Basic Syntax Declare Rules: grandparent(GP, GC) :- parent(GP, P), parent(P, GC). ADD THIS NEW POINT IF YOU FIND THESE OLD POINTS VARIABLES

  15. Atoms vs. Variables Atom starts with lowercase letter particular individual object only equal to self Variable starts with uppercase letter “hole” replaceable by atom

  16. Basic Syntax grandparent(GP, GC) :- parent(GP, P), parent(P, GC). grandparent(GP, GC) can be added to search space If you find 3 atoms GP,P,GC Such that both parent(GP, P) andparent(P, GC)

  17. Basic Syntax Query that requires Rule: ?- grandparent(mona, bart). true. ?- grandparent(homer, bart). false. Q: Which query takes longer?

  18. Prolog Basic Syntax Backtracking Search Examples in the toplevel: • Variables in Queries • Negation • Search Order

  19. Backtracking Search Query : is in search space? Prolog searches for backward: Start at Look for path back to Facts using Rules Top-down approach since Bottom-up is too inefficient

  20. Backtracking Search Search( ) 1. in search space? Success! 2. For each rule R that could add : For each old node R requires : If Search( ) fails, try next rule. All old nodes found. Success! 3. Not in space, no rule can add. Fail.

  21. Prolog Basic Syntax Backtracking Search Examples in the toplevel: • Variables in Queries • Negation • Search Order

More Related