SlideShare a Scribd company logo
1 of 17
Download to read offline
c P. Heeman, 2005
    CSE560 Class 06: 1





                                 Overview

    ⇒ Search
    • Depth-first
    • Breadth-first
    • Prolog’s Search Strategy
    • The ‘Pro’ part of Prolog
    • Programming Search in Prolog




                                                         c P. Heeman, 2005
    CSE560 Class 06: 2





                                  Search

    • To convert proof procedure into a reasoning procedure, need to
      resolve non-determism
    • Search is a way to implement nondeterminism
c P. Heeman, 2005
    CSE560 Class 06: 3





                                    Search Graphs

    • A graph consists of
       - a set N of nodes
       - a set A of ordered pairs of nodes, called arcs
    • Node n2 is a neighbor of n1 if there is an arc from n1 to n2
       - if n1, n2 ∈ A
    • A path is a sequence of nodes n0, n1, ..., nk such that
      ni1 , ni ∈ A
    • Given a set of start nodes and goal nodes, a solution is a path
       from a start node to a goal node




                                                                     c P. Heeman, 2005
    CSE560 Class 06: 4





       Search Graph for Resolution (Top-Down) Proof

                                                yes←a∧d
    (From Official Lecture slides)

                                                       yes←h∧d
      a ← b ∧ c.        a ← g.      yes←b∧c∧d   yes←g∧d
                                                          yes←m∧d
      a ← h.            b ← j.              yes←m∧d
                               yes←j∧c∧d
      b ← k.            d ← m.                  yes←f∧d
                                     yes←k∧c∧d
      d ← p.            f ← m.             yes←m∧d yes←p∧d
      f ← p.            g ← m.        yes←m∧c∧d
                                                          yes←d
      g ← f.            k ← m.
                                                             yes←p
                                                    yes←m
      h ← m.            p.
                                                              yes←
      ?a ∧ d
c P. Heeman, 2005
    CSE560 Class 06: 5





                                Graph Searching

    • Generic search algorithm: given a graph, start nodes, and goal
      nodes, incrementally explore paths from the start nodes
    • Maintain a frontier of paths from the start node that have been
      explored
    • As search proceeds, the frontier expands into the unexplored
      nodes until a goal node is encountered
    • The way in which the frontier is expanded defines the search
      strategy




                                                          c P. Heeman, 2005
    CSE560 Class 06: 6





                       Illustration of Graph Searching

                           frontier
       start
       node




      explored nodes

                                      unexplored nodes
c P. Heeman, 2005
    CSE560 Class 06: 7





                  Generic Graph Search Algorithm

    search(F0) ←
      select(Node,F0,F1) ∧
      is goal(Node).
    search(F0) ←
      select(Node,F0,F1) ∧
      neighbors(Node,NN) ∧
      add to frontier(NN,F1,F2) ∧
      search(F2).
    - Definition of predicates:
      + search(Frontier) is true if path from element of Frontier to a goal node
      + is goal(N) is true if N is a goal node
      + neighbors(N,NN) means NN is list of neighbors of N
      + select(N,F0,F1) means N∈F0 and F1 = F0-{N}. Fails if F 0 is empty
      + add to frontier(NN,F1,F2) means that F2 = F1 ∪ NN




                                                                         c P. Heeman, 2005
    CSE560 Class 06: 8





             Summary of Generic Search Algorithm

    • select and add to frontier define the search strategy
      - Whether add to frontier puts new elements on top or bottom of list
        matters
    • neighbors defines the graph
    • is goal defines what is a solution

    • We wrote this in datalog
      - Which is a bit perverse as we will be using this to implement a datalog
        top-down reasoning procedure
    • Could just as easily do written it in Tcl as this can be easily
      converted to procedural code
c P. Heeman, 2005
    CSE560 Class 06: 9





                                    Overview

    • Search
    ⇒ Depth-first
    • Breadth-first
    • Prolog’s Search Strategy
    • The ‘Pro’ part of Prolog
    • Programming Search in Prolog




                                                                     c P. Heeman, 2005
    CSE560 Class 06: 10





                             Depth-first Search
    • Depth-first search treats the frontier as a stack: it always selects
      the last element added to the frontier
      select(Node,p(Node,Frontier),Frontier).
      add to frontier(Neighbors,Frontier1,Frontier) ←
        append(Neighbors,Frontier1,Frontier2).
    • Frontier: p(e1,p(e2,...))
      - e1 is selected. Its neighbors are added to the front of the stack
      - e2 is only selected when all paths from e1 have been explored
c P. Heeman, 2005
    CSE560 Class 06: 11





                       Illustration of Depth-first Search

                                               1

                                 2


                       3                  13

              4            12        14


          5        7            15        16


     6        8            10


         9        11




                                                           c P. Heeman, 2005
    CSE560 Class 06: 12





                       Complexity of Depth-first Search

    • Depth-first search isnt guaranteed to halt on infinite graphs or
      graphs with cycles
    • The space complexity is linear in the size of the path being
      explored
    • Search is unconstrained by the goal until it happens to stumble
      on the goal
c P. Heeman, 2005
    CSE560 Class 06: 13





                                   Overview

    • Search
    • Depth-first
    ⇒ Breadth-first
    • Prolog’s Search Strategy
    • The ‘Pro’ part of Prolog
    • Programming Search in Prolog




                                                                    c P. Heeman, 2005
    CSE560 Class 06: 14





                              Breadth-first Search

    • Breadth-first search treats the frontier as a queue: it always
      selects the earliest element added to the frontier
      select(Node,p(Node,Frontier),Frontier).
      add to frontier(Neighbors,Frontier1,Frontier) ←
        append(Frontier1,Neighbors,Frontier2).
    • Frontier: p(e1,p(e2,...))
      - e1 is selected. Its neighbors are added to the end of the queue
      - e2 is selected next
c P. Heeman, 2005
    CSE560 Class 06: 15





                  Illustration of Breadth-first Search

                                             1

                           2                              3


                   4                5            6                 7


              8        9       10       11           12       13       14

         15       16




                                                                            c P. Heeman, 2005
    CSE560 Class 06: 16





                  Complexity of Breadth-first Search

    • The branching factor of a node is the number of its neighbors
    • If the branching factor for all nodes is finite, breadth-first search
      is guaranteed to find a solution if one exists
      - It is guaranteed to find the path with fewest arcs.
    • Time complexity is exponential in the path length: bn, where b is
      branching factor, n is path length.
    • The space complexity is exponential in path length: bn
    • Search is unconstrained by the goal
c P. Heeman, 2005
    CSE560 Class 06: 17





                                     Overview

    • Search
    • Depth-first
    • Breadth-first
    ⇒ Prolog’s Search Strategy
    • The ‘Pro’ part of Prolog
    • Programming Search in Prolog




                                                                      c P. Heeman, 2005
    CSE560 Class 06: 18





                           Top-Down Resolution

    • Need search strategy for doing top-down resolution
      - Always resolve first atom of answer clause first
      - But many rules/facts from KB might unify with first atom
      - Can search through these using depth-first search
      - Search is ordered by order of clauses in KB
         + Knowledge engineer can order clauses to ensure solution is found quickly
      - Search over space of answer clauses, not over space of proofs
    ⇒ Prolog
c P. Heeman, 2005
    CSE560 Class 06: 19





                              Cycles in Prolog

    • What about cycles (since Prolog is depth-first search)?
      connected(X,Y) ← connected(Y,X)
      - Could check for cycles: list of atoms in answer clause identical to list
         earlier up in proof
      - Would have to keep answer clauses along the current path we are
        exploring
    • Cycles part of larger problem of endless loops
      - Cannot detect all endless loops (halting problem)
      - Prolog also doesn’t do any cycle checking
      - Knowledge engineer’s job to be careful in defining clauses




                                                                    c P. Heeman, 2005
    CSE560 Class 06: 20





                                    Overview

    • Search
    • Depth-first
    • Breadth-first
    • Prolog’s Search Strategy
    ⇒ The ‘Pro’ part of Prolog
    • Programming Search in Prolog
c P. Heeman, 2005
    CSE560 Class 06: 21





                  The ‘Pro’ Stands for Programming

    • Prolog is intended as a programming language,
       in which programs are written as theorems,
       and program execution is theorem proving
    • As Prolog is a programming language, can program search in it
    • Tension in Prolog between its role as
       - A logic specification
       - A general purpose programming language
    • Has the built-in is(X,Expr) command
       - Expr evaluated using normal rules for expressions
       - Semantics for is are messy, as it only has a value if Expr is ground




                                                                        c P. Heeman, 2005
    CSE560 Class 06: 22





                                      Prolog Lists
    • A special recursive data structure
       - with special syntax to make dealing with lists simpler
    • List is
       - Empty list: []
       - An element on top of a list: [ Top | RestOfList ]
       - Rewriting our path structure in List notation: [1|[2|[6|[10|[]]]]]
       - To get top and remainder, unify with [Top|Rest]
    • Syntax shortform:
       - [1|[2|[6|[10|[]]]]] can be written as [1, 2, 6, 10]
       - or as [1, 2|[6|[10]]] or as [1|[2, 6, 10]] or as ....
       - How does [X, Y ] unify with [a, b]?
       - How does [X|Y ] unify with [a, b]?
c P. Heeman, 2005
    CSE560 Class 06: 23





                          Append and Member

    • Rewrite append in new list syntax
       append(nil,Z,Z)
       append(p(A,X),Y,p(A,Z)) ←
          append(X,Y,Z).




    • Rewrite member
      - member(X,List) true if X is an element in List




                                                                   c P. Heeman, 2005
    CSE560 Class 06: 24





                           Singleton Variables

    • ‘ ’ special syntax for naming a variable
      - Used when don’t care about, used for singleton variables
       length([ |Rest],Len) ←
              length(Rest,L)
              Len is L + 1
      - Can be used multiple times in same clause, but each use is really a
         different varaible
c P. Heeman, 2005
    CSE560 Class 06: 25





                                 ‘Not’ in Prolog

    • The operator not(X) means that
      - X is not derivable in Prolog given the current instantion of X
      - Following two definitions are not equivalent
          brother(X,Y) ←             brother(X,Y) ←
               mother(X,Z)                 mother(X,Z)
               mother(Y,Z)                 not(X = Y)
               not(X = Y)                  mother(Y,Z)
    • Semantics are not very clean
      - Its truth depends on order that clauses are evaluated
      - Truth does not correlate with semantics of models




                                                                         c P. Heeman, 2005
    CSE560 Class 06: 26





                                 Maze Example
    • Example: path through a maze
                                                                1      2     3      4
      connected(1,2).
      connected(2,3).
                                                                5      6     7      8
      connected(2,6).
      connected(4,8).
                                                                9     10    11     12
      ...
                                                                13    14    15     16
      connectedto(X,Y) :- connected(X,Y).
      connectedto(X,Y) :- connected(Y,X).

    • Book defined breadth-first and depth-first search in Datalog
      - In this example, searching for end point
    • But how can we define the neighbors clause that is needed?
      - Could define neighbors as primitive
      - Or, define neighbors(X,Set) in terms of connected(X,Y)
         + No way to do this in Datalog: Set = all Y s.t. connected(X,Y) is true
c P. Heeman, 2005
    CSE560 Class 06: 27





                                Prolog’s Findall

    • findall(X,connected(1,X),L)
      - Returns a list of all X in which connected(1,X) is true
    • findall can return a list of any arbitrary structures
       findall(cell(X),connected(Y,X),L)        assume Y is already instantiated
      - findall(connected(X,Y),connected(X,Y),L)
      - findall(X+Y,connected(X,Y),L)
         + + is just an infix operator that we chose to use
         + Could have used any valid Prolog term, e.g. a(X, Y ), [X, Y ]
    • Semantics of findall are messy
      - Requires universal quantification which is not part of Datalog
      - Universal quantification on things that can be named
         + Rather than on objects in the domain, as first order predicate defines it




                                                                           c P. Heeman, 2005
    CSE560 Class 06: 28





                                      Overview

    • Search
    • Depth-first
    • Breadth-first
    • Prolog’s Search Strategy
    • The ‘Pro’ part of Prolog
    ⇒ Programming Search in Prolog
c P. Heeman, 2005
    CSE560 Class 06: 29





                     Depth-First Search on Nodes
    • Define path using KB and use Prolog’s depth-first search
      search(16).
      search(X) ←
           connected(X,Z),
           search(Z).
      ?search(1)
      - Prolog keeps track of backtracking alternatives automatically
    • Define depth-first search using KB
      search([16| ]).
      search(Frontier0) ←
           Frontier0 = [X|Frontier1],
           findall(Z,connected(Z,X),NN),           ← calls Prolog to find all solutions
           append(NN,Frontier1,Frontier2),
           search(Frontier2).
      ?search([1])
      - Explicitly keep backtracking alternatives, and don’t use Prolog’s




                                                                          c P. Heeman, 2005
    CSE560 Class 06: 30





                   Depth-First Search saving Paths
    • Define path using KB and use Prolog’s depth-first search
      search(Path,Path) ←
           Path = [16| ].
      search([X|Rest],Answer) ←
           connected(X,Z),
           search([Z,X|Rest],Answer).
      ?search([1],Answer)
    • Define depth-first search using KB
      search([Path| ],Path) ←
           Path = [16| ].
      search(Frontier0,Answer) ←
           Frontier0 = [Path|Frontier1],
           Path = [X|Rest],
           findall([Z,X|Rest],connected(Z,X),NN)
           append(NN,Frontier1,Frontier2)
           search(Frontier2,Answer)
      ?search([[1]],Answer)
c P. Heeman, 2005
    CSE560 Class 06: 31





                                 Breadth-First Search
    • Define breadth-first search using KB
      search([Path| ],Path) ←
           Path = [16| ].
      search(Frontier0,Answer) ←
           Frontier0 = [Path|Frontier1],
           Path = [X|Rest],
           findall([Z,X|Rest],connected(Z,X),NN)
           append(Frontier1,NN,Frontier2)
           search(Frontier2,Answer)
      ?search([[1]],Answer)
    • Should we use Prolog to implement search?
      - We can, since Prolog is intended as a full programming language
      - But, can implement it in anything, including Tcl/Tk
         + Might make it more clear what logic programming is, if we don’t try to do
           everything in it
      - findall would be call to a theorem prover




                                                                        c P. Heeman, 2005
    CSE560 Class 06: 32





                                   Cycle Checking

    • Depth-First search of Maze can easily get stuck in cycle
      - i.e. 1 - 2 - 1 - 2 - 1
    • Approach:
      - Use version where we keep the paths
      - Change our definition of path
         + A path is a list of nodes, each connected to the next one, but where any node
           only occurs once
c P. Heeman, 2005
    CSE560 Class 06: 33





                          Adding in Cycle Checking

    • Ensure new cells not already in path
      search([Path| ],Path) ←
           Path = [16| ].
      search(Frontier0,Answer) ←
           Frontier0 = [Path|Frontier1],
           Path = [X|Rest],
           findall([Z,X|Rest],neighbor(Z,[X|Rest]),NN)
           append(Frontier1,NN,Frontier2)
           search(Frontier2)
      neighbor(Z,[X|Rest]) ←
           connected(Z,X)
           not(member(Z,[X|Rest]))
      ?search([[1]],Rest)




                                                                      c P. Heeman, 2005
    CSE560 Class 06: 34





                           Another Cycle Checker

    • Ensure that any cell is just visited once
      - For simplicity, doing this with version where frontier is list of cells
      search([16| ], ).
      search(Frontier0,Seen0) ←
            Frontier0 = [X|Frontier1]
            findall(Z,neighbor(Z,X,Seen0),NN)
            append(Frontier1,NN,Frontier2)
            append(Seen0,NN,Seen1)
            search(Frontier2,Seen1)
      neighbor(Z,X,Seen) ←
            connected(Z,X)
            not(member(Z,Seen))
      ?search([1],[])

More Related Content

Viewers also liked

! Rif13.17apr s14--ivanova-подход к повышению эффективности рекламы. туризм
! Rif13.17apr s14--ivanova-подход к повышению эффективности рекламы. туризм! Rif13.17apr s14--ivanova-подход к повышению эффективности рекламы. туризм
! Rif13.17apr s14--ivanova-подход к повышению эффективности рекламы. туризмТарасов Константин
 
Traverus Presentation 050509
Traverus Presentation 050509Traverus Presentation 050509
Traverus Presentation 050509Holly Henderson
 
Omnichannel Commerce & The Customer Experience - Featuring Don Peppers
Omnichannel Commerce & The Customer Experience - Featuring Don PeppersOmnichannel Commerce & The Customer Experience - Featuring Don Peppers
Omnichannel Commerce & The Customer Experience - Featuring Don PeppersMargot Heiligman
 
MONG THONGDEE'S PAPER PLANE AND GREAT SCIENCE LEARNING
MONG THONGDEE'S PAPER PLANE AND GREAT SCIENCE LEARNINGMONG THONGDEE'S PAPER PLANE AND GREAT SCIENCE LEARNING
MONG THONGDEE'S PAPER PLANE AND GREAT SCIENCE LEARNINGNSTDA THAILAND
 
Uzasadnienie Domeny Publicznej w filozofii
Uzasadnienie Domeny Publicznej w filozofiiUzasadnienie Domeny Publicznej w filozofii
Uzasadnienie Domeny Publicznej w filozofiiKOED
 
HIGH-TECH DEVICES TO SOLVE UNREST IN 3 SOUTHERN CITIES
HIGH-TECH DEVICES TO SOLVE UNREST IN 3 SOUTHERN CITIESHIGH-TECH DEVICES TO SOLVE UNREST IN 3 SOUTHERN CITIES
HIGH-TECH DEVICES TO SOLVE UNREST IN 3 SOUTHERN CITIESNSTDA THAILAND
 
Adjustments of Toys for Disabled Kids
Adjustments of Toys for Disabled KidsAdjustments of Toys for Disabled Kids
Adjustments of Toys for Disabled KidsNSTDA THAILAND
 
Llegandoaserunmaestroconstructivista
LlegandoaserunmaestroconstructivistaLlegandoaserunmaestroconstructivista
Llegandoaserunmaestroconstructivistaguest9dfe6f
 
Покоряя РСЯ:Секреты успеха (на примере финансов) Леонид Гольдфарб
Покоряя РСЯ:Секреты успеха (на примере финансов) Леонид ГольдфарбПокоряя РСЯ:Секреты успеха (на примере финансов) Леонид Гольдфарб
Покоряя РСЯ:Секреты успеха (на примере финансов) Леонид ГольдфарбТарасов Константин
 
Himalaye 14 osmitisicovek
Himalaye 14 osmitisicovekHimalaye 14 osmitisicovek
Himalaye 14 osmitisicovekKostas Tampakis
 

Viewers also liked (18)

! Rif13.17apr s14--ivanova-подход к повышению эффективности рекламы. туризм
! Rif13.17apr s14--ivanova-подход к повышению эффективности рекламы. туризм! Rif13.17apr s14--ivanova-подход к повышению эффективности рекламы. туризм
! Rif13.17apr s14--ivanova-подход к повышению эффективности рекламы. туризм
 
A face of greece!!
A face of greece!!A face of greece!!
A face of greece!!
 
Publicidade criativa
Publicidade criativaPublicidade criativa
Publicidade criativa
 
Glooq
GlooqGlooq
Glooq
 
Staircasegr
StaircasegrStaircasegr
Staircasegr
 
Traverus Presentation 050509
Traverus Presentation 050509Traverus Presentation 050509
Traverus Presentation 050509
 
Omnichannel Commerce & The Customer Experience - Featuring Don Peppers
Omnichannel Commerce & The Customer Experience - Featuring Don PeppersOmnichannel Commerce & The Customer Experience - Featuring Don Peppers
Omnichannel Commerce & The Customer Experience - Featuring Don Peppers
 
MONG THONGDEE'S PAPER PLANE AND GREAT SCIENCE LEARNING
MONG THONGDEE'S PAPER PLANE AND GREAT SCIENCE LEARNINGMONG THONGDEE'S PAPER PLANE AND GREAT SCIENCE LEARNING
MONG THONGDEE'S PAPER PLANE AND GREAT SCIENCE LEARNING
 
Simultaneous Equation Poster
Simultaneous Equation PosterSimultaneous Equation Poster
Simultaneous Equation Poster
 
Uzasadnienie Domeny Publicznej w filozofii
Uzasadnienie Domeny Publicznej w filozofiiUzasadnienie Domeny Publicznej w filozofii
Uzasadnienie Domeny Publicznej w filozofii
 
The canvas prison
The canvas prisonThe canvas prison
The canvas prison
 
HIGH-TECH DEVICES TO SOLVE UNREST IN 3 SOUTHERN CITIES
HIGH-TECH DEVICES TO SOLVE UNREST IN 3 SOUTHERN CITIESHIGH-TECH DEVICES TO SOLVE UNREST IN 3 SOUTHERN CITIES
HIGH-TECH DEVICES TO SOLVE UNREST IN 3 SOUTHERN CITIES
 
Adjustments of Toys for Disabled Kids
Adjustments of Toys for Disabled KidsAdjustments of Toys for Disabled Kids
Adjustments of Toys for Disabled Kids
 
Llegandoaserunmaestroconstructivista
LlegandoaserunmaestroconstructivistaLlegandoaserunmaestroconstructivista
Llegandoaserunmaestroconstructivista
 
20100623 hla-b1502
20100623 hla-b150220100623 hla-b1502
20100623 hla-b1502
 
Покоряя РСЯ:Секреты успеха (на примере финансов) Леонид Гольдфарб
Покоряя РСЯ:Секреты успеха (на примере финансов) Леонид ГольдфарбПокоряя РСЯ:Секреты успеха (на примере финансов) Леонид Гольдфарб
Покоряя РСЯ:Секреты успеха (на примере финансов) Леонид Гольдфарб
 
Himalaye 14 osmitisicovek
Himalaye 14 osmitisicovekHimalaye 14 osmitisicovek
Himalaye 14 osmitisicovek
 
Advertising review sites_ekaterinburg
Advertising review sites_ekaterinburgAdvertising review sites_ekaterinburg
Advertising review sites_ekaterinburg
 

Recently uploaded

CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best Female service 🦺
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best Female service  🦺CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best Female service  🦺
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best Female service 🦺anilsa9823
 
9990611130 Find & Book Russian Call Girls In Ghazipur
9990611130 Find & Book Russian Call Girls In Ghazipur9990611130 Find & Book Russian Call Girls In Ghazipur
9990611130 Find & Book Russian Call Girls In GhazipurGenuineGirls
 
大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改
大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改
大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改atducpo
 
TAM Sports_IPL 17 Till Match 37_Celebrity Endorsement _Report.pdf
TAM Sports_IPL 17 Till Match 37_Celebrity Endorsement _Report.pdfTAM Sports_IPL 17 Till Match 37_Celebrity Endorsement _Report.pdf
TAM Sports_IPL 17 Till Match 37_Celebrity Endorsement _Report.pdfSocial Samosa
 
Tableaux 9ème étape circuit fédéral 2024
Tableaux 9ème étape circuit fédéral 2024Tableaux 9ème étape circuit fédéral 2024
Tableaux 9ème étape circuit fédéral 2024HechemLaameri
 
Atlanta Dream Exec Dan Gadd on Driving Fan Engagement and Growth, Serving the...
Atlanta Dream Exec Dan Gadd on Driving Fan Engagement and Growth, Serving the...Atlanta Dream Exec Dan Gadd on Driving Fan Engagement and Growth, Serving the...
Atlanta Dream Exec Dan Gadd on Driving Fan Engagement and Growth, Serving the...Neil Horowitz
 
ALL NFL NETWORK CONTACTS- April 29, 2024
ALL NFL NETWORK CONTACTS- April 29, 2024ALL NFL NETWORK CONTACTS- April 29, 2024
ALL NFL NETWORK CONTACTS- April 29, 2024Brian Slack
 
Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...
Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...
Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...World Wide Tickets And Hospitality
 
Top Call Girls In Jankipuram ( Lucknow ) 🔝 8923113531 🔝 Cash Payment
Top Call Girls In Jankipuram ( Lucknow  ) 🔝 8923113531 🔝  Cash PaymentTop Call Girls In Jankipuram ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment
Top Call Girls In Jankipuram ( Lucknow ) 🔝 8923113531 🔝 Cash Paymentanilsa9823
 
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docxSlovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docxWorld Wide Tickets And Hospitality
 
CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service 🧣
CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service  🧣CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service  🧣
CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service 🧣anilsa9823
 
Albania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docx
Albania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docxAlbania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docx
Albania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docxWorld Wide Tickets And Hospitality
 
08448380779 Call Girls In IIT Women Seeking Men
08448380779 Call Girls In IIT Women Seeking Men08448380779 Call Girls In IIT Women Seeking Men
08448380779 Call Girls In IIT Women Seeking MenDelhi Call girls
 
Chennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 
08448380779 Call Girls In Lajpat Nagar Women Seeking Men
08448380779 Call Girls In Lajpat Nagar Women Seeking Men08448380779 Call Girls In Lajpat Nagar Women Seeking Men
08448380779 Call Girls In Lajpat Nagar Women Seeking MenDelhi Call girls
 
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...Eticketing.co
 
08448380779 Call Girls In International Airport Women Seeking Men
08448380779 Call Girls In International Airport Women Seeking Men08448380779 Call Girls In International Airport Women Seeking Men
08448380779 Call Girls In International Airport Women Seeking MenDelhi Call girls
 
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics TradeTechnical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics TradeOptics-Trade
 

Recently uploaded (20)

CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best Female service 🦺
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best Female service  🦺CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best Female service  🦺
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best Female service 🦺
 
9990611130 Find & Book Russian Call Girls In Ghazipur
9990611130 Find & Book Russian Call Girls In Ghazipur9990611130 Find & Book Russian Call Girls In Ghazipur
9990611130 Find & Book Russian Call Girls In Ghazipur
 
大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改
大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改
大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改
 
TAM Sports_IPL 17 Till Match 37_Celebrity Endorsement _Report.pdf
TAM Sports_IPL 17 Till Match 37_Celebrity Endorsement _Report.pdfTAM Sports_IPL 17 Till Match 37_Celebrity Endorsement _Report.pdf
TAM Sports_IPL 17 Till Match 37_Celebrity Endorsement _Report.pdf
 
Tableaux 9ème étape circuit fédéral 2024
Tableaux 9ème étape circuit fédéral 2024Tableaux 9ème étape circuit fédéral 2024
Tableaux 9ème étape circuit fédéral 2024
 
Call Girls 🫤 Paharganj ➡️ 9999965857 ➡️ Delhi 🫦 Russian Escorts FULL ENJOY
Call Girls 🫤 Paharganj ➡️ 9999965857  ➡️ Delhi 🫦  Russian Escorts FULL ENJOYCall Girls 🫤 Paharganj ➡️ 9999965857  ➡️ Delhi 🫦  Russian Escorts FULL ENJOY
Call Girls 🫤 Paharganj ➡️ 9999965857 ➡️ Delhi 🫦 Russian Escorts FULL ENJOY
 
Atlanta Dream Exec Dan Gadd on Driving Fan Engagement and Growth, Serving the...
Atlanta Dream Exec Dan Gadd on Driving Fan Engagement and Growth, Serving the...Atlanta Dream Exec Dan Gadd on Driving Fan Engagement and Growth, Serving the...
Atlanta Dream Exec Dan Gadd on Driving Fan Engagement and Growth, Serving the...
 
ALL NFL NETWORK CONTACTS- April 29, 2024
ALL NFL NETWORK CONTACTS- April 29, 2024ALL NFL NETWORK CONTACTS- April 29, 2024
ALL NFL NETWORK CONTACTS- April 29, 2024
 
Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...
Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...
Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...
 
Top Call Girls In Jankipuram ( Lucknow ) 🔝 8923113531 🔝 Cash Payment
Top Call Girls In Jankipuram ( Lucknow  ) 🔝 8923113531 🔝  Cash PaymentTop Call Girls In Jankipuram ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment
Top Call Girls In Jankipuram ( Lucknow ) 🔝 8923113531 🔝 Cash Payment
 
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docxSlovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
Slovenia Vs Serbia UEFA Euro 2024 Fixture Guide Every Fixture Detailed.docx
 
CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service 🧣
CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service  🧣CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service  🧣
CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service 🧣
 
Albania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docx
Albania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docxAlbania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docx
Albania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docx
 
08448380779 Call Girls In IIT Women Seeking Men
08448380779 Call Girls In IIT Women Seeking Men08448380779 Call Girls In IIT Women Seeking Men
08448380779 Call Girls In IIT Women Seeking Men
 
Chennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts service
 
08448380779 Call Girls In Lajpat Nagar Women Seeking Men
08448380779 Call Girls In Lajpat Nagar Women Seeking Men08448380779 Call Girls In Lajpat Nagar Women Seeking Men
08448380779 Call Girls In Lajpat Nagar Women Seeking Men
 
Call Girls Service Noida Extension @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
Call Girls Service Noida Extension @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...Call Girls Service Noida Extension @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...
Call Girls Service Noida Extension @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
 
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
Croatia vs Italy Euro Cup 2024 Three pitfalls for Spalletti’s Italy in Group ...
 
08448380779 Call Girls In International Airport Women Seeking Men
08448380779 Call Girls In International Airport Women Seeking Men08448380779 Call Girls In International Airport Women Seeking Men
08448380779 Call Girls In International Airport Women Seeking Men
 
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics TradeTechnical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
 

Class06

  • 1. c P. Heeman, 2005 CSE560 Class 06: 1 Overview ⇒ Search • Depth-first • Breadth-first • Prolog’s Search Strategy • The ‘Pro’ part of Prolog • Programming Search in Prolog c P. Heeman, 2005 CSE560 Class 06: 2 Search • To convert proof procedure into a reasoning procedure, need to resolve non-determism • Search is a way to implement nondeterminism
  • 2. c P. Heeman, 2005 CSE560 Class 06: 3 Search Graphs • A graph consists of - a set N of nodes - a set A of ordered pairs of nodes, called arcs • Node n2 is a neighbor of n1 if there is an arc from n1 to n2 - if n1, n2 ∈ A • A path is a sequence of nodes n0, n1, ..., nk such that ni1 , ni ∈ A • Given a set of start nodes and goal nodes, a solution is a path from a start node to a goal node c P. Heeman, 2005 CSE560 Class 06: 4 Search Graph for Resolution (Top-Down) Proof yes←a∧d (From Official Lecture slides) yes←h∧d a ← b ∧ c. a ← g. yes←b∧c∧d yes←g∧d yes←m∧d a ← h. b ← j. yes←m∧d yes←j∧c∧d b ← k. d ← m. yes←f∧d yes←k∧c∧d d ← p. f ← m. yes←m∧d yes←p∧d f ← p. g ← m. yes←m∧c∧d yes←d g ← f. k ← m. yes←p yes←m h ← m. p. yes← ?a ∧ d
  • 3. c P. Heeman, 2005 CSE560 Class 06: 5 Graph Searching • Generic search algorithm: given a graph, start nodes, and goal nodes, incrementally explore paths from the start nodes • Maintain a frontier of paths from the start node that have been explored • As search proceeds, the frontier expands into the unexplored nodes until a goal node is encountered • The way in which the frontier is expanded defines the search strategy c P. Heeman, 2005 CSE560 Class 06: 6 Illustration of Graph Searching frontier start node explored nodes unexplored nodes
  • 4. c P. Heeman, 2005 CSE560 Class 06: 7 Generic Graph Search Algorithm search(F0) ← select(Node,F0,F1) ∧ is goal(Node). search(F0) ← select(Node,F0,F1) ∧ neighbors(Node,NN) ∧ add to frontier(NN,F1,F2) ∧ search(F2). - Definition of predicates: + search(Frontier) is true if path from element of Frontier to a goal node + is goal(N) is true if N is a goal node + neighbors(N,NN) means NN is list of neighbors of N + select(N,F0,F1) means N∈F0 and F1 = F0-{N}. Fails if F 0 is empty + add to frontier(NN,F1,F2) means that F2 = F1 ∪ NN c P. Heeman, 2005 CSE560 Class 06: 8 Summary of Generic Search Algorithm • select and add to frontier define the search strategy - Whether add to frontier puts new elements on top or bottom of list matters • neighbors defines the graph • is goal defines what is a solution • We wrote this in datalog - Which is a bit perverse as we will be using this to implement a datalog top-down reasoning procedure • Could just as easily do written it in Tcl as this can be easily converted to procedural code
  • 5. c P. Heeman, 2005 CSE560 Class 06: 9 Overview • Search ⇒ Depth-first • Breadth-first • Prolog’s Search Strategy • The ‘Pro’ part of Prolog • Programming Search in Prolog c P. Heeman, 2005 CSE560 Class 06: 10 Depth-first Search • Depth-first search treats the frontier as a stack: it always selects the last element added to the frontier select(Node,p(Node,Frontier),Frontier). add to frontier(Neighbors,Frontier1,Frontier) ← append(Neighbors,Frontier1,Frontier2). • Frontier: p(e1,p(e2,...)) - e1 is selected. Its neighbors are added to the front of the stack - e2 is only selected when all paths from e1 have been explored
  • 6. c P. Heeman, 2005 CSE560 Class 06: 11 Illustration of Depth-first Search 1 2 3 13 4 12 14 5 7 15 16 6 8 10 9 11 c P. Heeman, 2005 CSE560 Class 06: 12 Complexity of Depth-first Search • Depth-first search isnt guaranteed to halt on infinite graphs or graphs with cycles • The space complexity is linear in the size of the path being explored • Search is unconstrained by the goal until it happens to stumble on the goal
  • 7. c P. Heeman, 2005 CSE560 Class 06: 13 Overview • Search • Depth-first ⇒ Breadth-first • Prolog’s Search Strategy • The ‘Pro’ part of Prolog • Programming Search in Prolog c P. Heeman, 2005 CSE560 Class 06: 14 Breadth-first Search • Breadth-first search treats the frontier as a queue: it always selects the earliest element added to the frontier select(Node,p(Node,Frontier),Frontier). add to frontier(Neighbors,Frontier1,Frontier) ← append(Frontier1,Neighbors,Frontier2). • Frontier: p(e1,p(e2,...)) - e1 is selected. Its neighbors are added to the end of the queue - e2 is selected next
  • 8. c P. Heeman, 2005 CSE560 Class 06: 15 Illustration of Breadth-first Search 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 c P. Heeman, 2005 CSE560 Class 06: 16 Complexity of Breadth-first Search • The branching factor of a node is the number of its neighbors • If the branching factor for all nodes is finite, breadth-first search is guaranteed to find a solution if one exists - It is guaranteed to find the path with fewest arcs. • Time complexity is exponential in the path length: bn, where b is branching factor, n is path length. • The space complexity is exponential in path length: bn • Search is unconstrained by the goal
  • 9. c P. Heeman, 2005 CSE560 Class 06: 17 Overview • Search • Depth-first • Breadth-first ⇒ Prolog’s Search Strategy • The ‘Pro’ part of Prolog • Programming Search in Prolog c P. Heeman, 2005 CSE560 Class 06: 18 Top-Down Resolution • Need search strategy for doing top-down resolution - Always resolve first atom of answer clause first - But many rules/facts from KB might unify with first atom - Can search through these using depth-first search - Search is ordered by order of clauses in KB + Knowledge engineer can order clauses to ensure solution is found quickly - Search over space of answer clauses, not over space of proofs ⇒ Prolog
  • 10. c P. Heeman, 2005 CSE560 Class 06: 19 Cycles in Prolog • What about cycles (since Prolog is depth-first search)? connected(X,Y) ← connected(Y,X) - Could check for cycles: list of atoms in answer clause identical to list earlier up in proof - Would have to keep answer clauses along the current path we are exploring • Cycles part of larger problem of endless loops - Cannot detect all endless loops (halting problem) - Prolog also doesn’t do any cycle checking - Knowledge engineer’s job to be careful in defining clauses c P. Heeman, 2005 CSE560 Class 06: 20 Overview • Search • Depth-first • Breadth-first • Prolog’s Search Strategy ⇒ The ‘Pro’ part of Prolog • Programming Search in Prolog
  • 11. c P. Heeman, 2005 CSE560 Class 06: 21 The ‘Pro’ Stands for Programming • Prolog is intended as a programming language, in which programs are written as theorems, and program execution is theorem proving • As Prolog is a programming language, can program search in it • Tension in Prolog between its role as - A logic specification - A general purpose programming language • Has the built-in is(X,Expr) command - Expr evaluated using normal rules for expressions - Semantics for is are messy, as it only has a value if Expr is ground c P. Heeman, 2005 CSE560 Class 06: 22 Prolog Lists • A special recursive data structure - with special syntax to make dealing with lists simpler • List is - Empty list: [] - An element on top of a list: [ Top | RestOfList ] - Rewriting our path structure in List notation: [1|[2|[6|[10|[]]]]] - To get top and remainder, unify with [Top|Rest] • Syntax shortform: - [1|[2|[6|[10|[]]]]] can be written as [1, 2, 6, 10] - or as [1, 2|[6|[10]]] or as [1|[2, 6, 10]] or as .... - How does [X, Y ] unify with [a, b]? - How does [X|Y ] unify with [a, b]?
  • 12. c P. Heeman, 2005 CSE560 Class 06: 23 Append and Member • Rewrite append in new list syntax append(nil,Z,Z) append(p(A,X),Y,p(A,Z)) ← append(X,Y,Z). • Rewrite member - member(X,List) true if X is an element in List c P. Heeman, 2005 CSE560 Class 06: 24 Singleton Variables • ‘ ’ special syntax for naming a variable - Used when don’t care about, used for singleton variables length([ |Rest],Len) ← length(Rest,L) Len is L + 1 - Can be used multiple times in same clause, but each use is really a different varaible
  • 13. c P. Heeman, 2005 CSE560 Class 06: 25 ‘Not’ in Prolog • The operator not(X) means that - X is not derivable in Prolog given the current instantion of X - Following two definitions are not equivalent brother(X,Y) ← brother(X,Y) ← mother(X,Z) mother(X,Z) mother(Y,Z) not(X = Y) not(X = Y) mother(Y,Z) • Semantics are not very clean - Its truth depends on order that clauses are evaluated - Truth does not correlate with semantics of models c P. Heeman, 2005 CSE560 Class 06: 26 Maze Example • Example: path through a maze 1 2 3 4 connected(1,2). connected(2,3). 5 6 7 8 connected(2,6). connected(4,8). 9 10 11 12 ... 13 14 15 16 connectedto(X,Y) :- connected(X,Y). connectedto(X,Y) :- connected(Y,X). • Book defined breadth-first and depth-first search in Datalog - In this example, searching for end point • But how can we define the neighbors clause that is needed? - Could define neighbors as primitive - Or, define neighbors(X,Set) in terms of connected(X,Y) + No way to do this in Datalog: Set = all Y s.t. connected(X,Y) is true
  • 14. c P. Heeman, 2005 CSE560 Class 06: 27 Prolog’s Findall • findall(X,connected(1,X),L) - Returns a list of all X in which connected(1,X) is true • findall can return a list of any arbitrary structures findall(cell(X),connected(Y,X),L) assume Y is already instantiated - findall(connected(X,Y),connected(X,Y),L) - findall(X+Y,connected(X,Y),L) + + is just an infix operator that we chose to use + Could have used any valid Prolog term, e.g. a(X, Y ), [X, Y ] • Semantics of findall are messy - Requires universal quantification which is not part of Datalog - Universal quantification on things that can be named + Rather than on objects in the domain, as first order predicate defines it c P. Heeman, 2005 CSE560 Class 06: 28 Overview • Search • Depth-first • Breadth-first • Prolog’s Search Strategy • The ‘Pro’ part of Prolog ⇒ Programming Search in Prolog
  • 15. c P. Heeman, 2005 CSE560 Class 06: 29 Depth-First Search on Nodes • Define path using KB and use Prolog’s depth-first search search(16). search(X) ← connected(X,Z), search(Z). ?search(1) - Prolog keeps track of backtracking alternatives automatically • Define depth-first search using KB search([16| ]). search(Frontier0) ← Frontier0 = [X|Frontier1], findall(Z,connected(Z,X),NN), ← calls Prolog to find all solutions append(NN,Frontier1,Frontier2), search(Frontier2). ?search([1]) - Explicitly keep backtracking alternatives, and don’t use Prolog’s c P. Heeman, 2005 CSE560 Class 06: 30 Depth-First Search saving Paths • Define path using KB and use Prolog’s depth-first search search(Path,Path) ← Path = [16| ]. search([X|Rest],Answer) ← connected(X,Z), search([Z,X|Rest],Answer). ?search([1],Answer) • Define depth-first search using KB search([Path| ],Path) ← Path = [16| ]. search(Frontier0,Answer) ← Frontier0 = [Path|Frontier1], Path = [X|Rest], findall([Z,X|Rest],connected(Z,X),NN) append(NN,Frontier1,Frontier2) search(Frontier2,Answer) ?search([[1]],Answer)
  • 16. c P. Heeman, 2005 CSE560 Class 06: 31 Breadth-First Search • Define breadth-first search using KB search([Path| ],Path) ← Path = [16| ]. search(Frontier0,Answer) ← Frontier0 = [Path|Frontier1], Path = [X|Rest], findall([Z,X|Rest],connected(Z,X),NN) append(Frontier1,NN,Frontier2) search(Frontier2,Answer) ?search([[1]],Answer) • Should we use Prolog to implement search? - We can, since Prolog is intended as a full programming language - But, can implement it in anything, including Tcl/Tk + Might make it more clear what logic programming is, if we don’t try to do everything in it - findall would be call to a theorem prover c P. Heeman, 2005 CSE560 Class 06: 32 Cycle Checking • Depth-First search of Maze can easily get stuck in cycle - i.e. 1 - 2 - 1 - 2 - 1 • Approach: - Use version where we keep the paths - Change our definition of path + A path is a list of nodes, each connected to the next one, but where any node only occurs once
  • 17. c P. Heeman, 2005 CSE560 Class 06: 33 Adding in Cycle Checking • Ensure new cells not already in path search([Path| ],Path) ← Path = [16| ]. search(Frontier0,Answer) ← Frontier0 = [Path|Frontier1], Path = [X|Rest], findall([Z,X|Rest],neighbor(Z,[X|Rest]),NN) append(Frontier1,NN,Frontier2) search(Frontier2) neighbor(Z,[X|Rest]) ← connected(Z,X) not(member(Z,[X|Rest])) ?search([[1]],Rest) c P. Heeman, 2005 CSE560 Class 06: 34 Another Cycle Checker • Ensure that any cell is just visited once - For simplicity, doing this with version where frontier is list of cells search([16| ], ). search(Frontier0,Seen0) ← Frontier0 = [X|Frontier1] findall(Z,neighbor(Z,X,Seen0),NN) append(Frontier1,NN,Frontier2) append(Seen0,NN,Seen1) search(Frontier2,Seen1) neighbor(Z,X,Seen) ← connected(Z,X) not(member(Z,Seen)) ?search([1],[])