SlideShare uma empresa Scribd logo
1 de 41
Baixar para ler offline
Listy             Arytmetyka      Struktury        Problem małpy :-)      Operatory   Postscriptum




           Sztuczna Inteligencja i Systemy Ekspertowe
                             Prolog 2

                                       Aleksander Pohl
                                http://apohllo.pl/dydaktyka/ai

                               Wy˙ sza Szkoła Zarzadzania i Bankowo´ ci
                                 z                 ˛               s


                                              17 marca 2009



Aleksander Pohl                                                                            WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Plan prezentacji

        Listy

        Arytmetyka

        Struktury

        Problem małpy :-)

        Operatory

        Postscriptum



Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Plan prezentacji

        Listy

        Arytmetyka

        Struktury

        Problem małpy :-)

        Operatory

        Postscriptum



Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Listy




               [ann, tom, tennis]
           ◮

               „głowa” – head: ann
           ◮

               „ogon” – tail: [tom, tennis]
           ◮




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Operatory




               sklejanie .(Head, Tail)
           ◮

               rozdzielanie L = [Head | Tail]
           ◮




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Testowanie obecno´ ci (1)
                 s



        Element listy
               member(X, [X | Tail]).
           ◮

               member(X, [Head | Tail]) :-
           ◮
               member(X, Tail).




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Testowanie obecno´ ci (2)
                 s



        Element listy z wykorzystaniem odciecia
                                           ˛
               member(X, [X | Tail]) :- !.
           ◮

               member(X, [Head | Tail]) :-
           ◮
               member(X, Tail).




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Konkatenacja


               conc([],L,L).
           ◮

               conc([X | L1], L2, [X | L3]) :-
           ◮
               conc(L1, L2, L3).
        Dekompozycja
               conc(L1, L2, [a, b, c]).
           ◮

        Wyszukiwanie
               conc(Przed, [c | Po], [a, b, c, d, e, f]).
           ◮




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Usuwanie i dodawania elementu


        Usuwanie elementu
               del(X, [X | Tail],Tail).
           ◮

               del(X, [Y | Tail],[Y,Tail1]) :-
           ◮
               del(X, Tail, Tail1).
        Dodawanie elementu
               insert( X, List, BiggerList) :-
           ◮
               del( X, BiggerList, List).




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Permutacje
        Permutacje dla zbioru {a, b, c}:
               (a, b, c)
           ◮

               (a, c, b)
           ◮

               (b, a, c)
           ◮

               (c, a, b)
           ◮

               (b, c, a)
           ◮

               (c, b, a)
           ◮

        W Prologu
               permutation([],[]).
           ◮

               permutation( [X | L ],P) :-
           ◮
               permutation(L,L1), insert(X,L1,P).

Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Plan prezentacji

        Listy

        Arytmetyka

        Struktury

        Problem małpy :-)

        Operatory

        Postscriptum



Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Obliczanie warto´ ci
                s



               X = 1 + 2.
           ◮

               X=1+2
           ◮




               X is 1 + 2.
           ◮

               X = 3.
           ◮




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Porównywanie liczb


               X>Y
           ◮

               X<Y
           ◮

               X>=Y
           ◮

               X=<Y
           ◮

                           s´
               X=:=Y (równo´ c)
           ◮

                              s´
               X=/=Y (nierówno´ c)
           ◮




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Przykład porównywania liczb

               1 + 2 =:= 2 + 1.
           ◮

               yes
           ◮



               1 + 2 = 2 + 1.
           ◮

               no
           ◮



               1 + A = B + 2.
           ◮

               A=2
           ◮

               B=1
           ◮




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Przykład – obliczanie długo´ ci listy
                           s


               length1( [] , 0 ).
           ◮


               length1( [ _ | Tail ], N) :-
           ◮
               N = 1 + N1,
               length1( Tail, N1 ).

               length1( [ _ | Tail ], 1 + N) :-
           ◮
               length1( Tail, N ).




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Obliczanie długo´ ci – wyniki
                s


               ?- length1([a,b,c,d],N)
           ◮

               N = 1 + (1 + (1 + (1 + 0)))
           ◮




               ?- length1([a,b,c,d],N), Length is N.
           ◮

               N = 1 + (1 + (1 + (1 + 0)))
           ◮

               Length = 4
           ◮




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Obliczanie długo´ ci – rozwiazanie poprawne
                s            ˛



               length( [] , 0 ).
           ◮

               length( [ _ | Tail ], N) :-
           ◮
               length( Tail, N1 ),
               N is 1 + N1.




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Plan prezentacji

        Listy

        Arytmetyka

        Struktury

        Problem małpy :-)

        Operatory

        Postscriptum



Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Predykaty jako struktury




               date(5, may, 2000).
           ◮

               date – funktor główny
           ◮




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Struktura zło˙ ona
             z



        family(
        person(tom, fox, date(7,may,1960),works(bbc,4200)),
        person(ann, fox, date(9, may,1961),unemployed),
        [person(pat, fox, date(5, may,1983),unemployed),
        person(jim, fox, date(11, may,1985),unemployed)]).




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Rodzina – zapytania (1)
               family(_,_,[ _,_,_]).
           ◮

               family(person( _, fox, _ , _ ), _ ,_).
           ◮

               husband(X) :-
           ◮
               family(X, _ ,_).
               wife(X) :-
           ◮
               family(_,X,_).
               child(X) :-
           ◮
               family(_,_,Children),
               member(X, Children).
               exists(Person) :-
           ◮
               husband(Person);wife(Person);
               child(Person).

Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Rodzina – zapytania (2)

               dateofbirth(person(_,_,Date,_),Date).
           ◮

               salary(person(_,_,_,works(_,S)),S).
           ◮
               salary(person(_,_,_,unemployed),0).
               exists(person(Name,Surname,_,_)).
           ◮

               child(X), dateofbirth(X,date(_,_,2000)).
           ◮

               exists(Person),
           ◮
               dateofbirth(Person, date(_,_,Year)),
               Year<1960, salary(Person,Salary),
               Salary<8000.



Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Rodzina – zapytania (3)


               total([],0).
           ◮

               total([Person|List], Sum) :-
           ◮
               salary(Person,S),
               total(List, Rest),
               Sum is S+Rest.
               family(Husband, Wife, Children),
           ◮
               total([Husband,Wife|Children],Income).




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Plan prezentacji

        Listy

        Arytmetyka

        Struktury

        Problem małpy :-)

        Operatory

        Postscriptum



Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Ruchy małpy (1)


               move(
           ◮
               state(middle,onbox,middle,hasnot),
               grasp,
               state(middle,onbox,middle,has)).
               move(
           ◮
               state(P,onfloor,P,H),
               climb,
               state(P,onbox,P,H)).




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Ruchy małpy (2)


               move(
           ◮
               state(P1,onfloor,P1,H),
               push(P1,P2),
               state(P2, onfloor, P2, H)).
               move(
           ◮
               state( P1, onfloor, B, H),
               walk(P1,P2),
               state(P2, onfloor, B, H)).




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Cel małpy



               canget( state(_,_,_,has)).
           ◮

               canget( State1 ) :-
           ◮
               move( State1 , Move , State2),
               canget(State2), print(Move), write(’ ’).
               ?- canget(state(atdoor, onfloor, atwindow,
           ◮
               hasnot))




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Plan prezentacji

        Listy

        Arytmetyka

        Struktury

        Problem małpy :-)

        Operatory

        Postscriptum



Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Typy operatorów



               infiksowe
           ◮
               np. 5 + 10, a ∨ b
               prefiksowe
           ◮
               np. - 5, ¬ a
               postfiksowe
           ◮
               np. 5, 6 + (notacja Łukasiewicza)




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka     Struktury       Problem małpy :-)   Operatory   Postscriptum




Dyrektywy




               op(N,T,Name).
           ◮
                       N — priorytet operatora
                   ◮

                       T – typ operatora
                   ◮

                       Name – nazwa atomu
                   ◮




Aleksander Pohl                                                                       WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Priorytety

                        s´
        Im ni˙ szy warto´ c priorytetu (im wy˙ szy priorytet), tym operator
              z                              z
        wia˙ e silniej.
           ˛z
               term, bad´ wyra˙ enie w nawiasach: 0
                       ˛z     z
           ◮

               priorytet struktury: priorytet funktora głównego
           ◮

                         s´
               x – warto´ c priorytetu silnie mniejsza od warto´ ci
                                                               s
           ◮
               priorytetu operatora głównego
                         s´
               y – warto´ c priorytetu mniejsza bad´ równa warto´ ci
                                                   ˛z               s
           ◮
               priorytetowi operatora głównego




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Typy operatorów



               infiksowe
           ◮
               xfx, xfy, yfx
               prefiksowe
           ◮
               fx, fy
               postfiksowe
           ◮
               xf, yf




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Przykład


               a-b-c
           ◮

               (a-b)-c – tradycyjna interpretacja
           ◮

               definiujemy jako yfx
           ◮
               a-b priorytet równy warto´ ci operatora, czyli y ma taki
                                         s
               sam priorytet jak operator główny
               definiujemy jako xfy (błednie)
                                        ˛
           ◮
               a-b priorytet równy warto´ ci operatora, ale x nie mo˙ e
                                          s                         z
               mie´ priorytetu takiego jak operator główny
                  c




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Przykład



        not
               jako fx
           ◮
               not(not p)
               jako fy
           ◮
               not not p




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Predefiniowane operatory

               op(1200,xfx,[ :- , -> ] )
           ◮

               op(1100,xfy,’;’)
           ◮

               op(1000,xfy,’,’)
           ◮

               op(900,fy, not )
           ◮

               op(700,xfx,[ is,=,=,=:=,== ])
           ◮

               op(500,yfx,[ +,- ])
           ◮

               op(400,yfx,[ *,/,//,mod ])
           ◮

               op(200, xfx , ** )
           ◮

               op(200,fy,-)
           ◮




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Przykład (1)

               ¬(A ∨ B) ↔ ¬A ∨ ¬B
           ◮

               equiv(not( and(A,B)),or(not(A),not(B)))
           ◮



               op( 800,xfx, <===>).
           ◮

               op(700,xfy,v).
           ◮

               op(600,xfy,&).
           ◮

               op(500,fy,∼).
           ◮



               ∼(A & B) <===> ∼A v ∼B.
           ◮




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Przykład (2)


               op(300,xfx, plays).
           ◮

               op(200,xfy,and).
           ◮

               jimmy plays football and squash.
           ◮

               Who plays football and squash.
           ◮

               Who = jimmy
           ◮

               jimmy plays What.
           ◮

               What = football and squash
           ◮




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Plan prezentacji

        Listy

        Arytmetyka

        Struktury

        Problem małpy :-)

        Operatory

        Postscriptum



Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury   Problem małpy :-)   Operatory   Postscriptum




Materiały zródłowe
          ´



               L.Sterling, E.Shapiro - „The Art Of Prolog”
           ◮

               Ivan Bratko - „Prolog – Programming For Artificial
           ◮
               Intelligence”
               Slajdy zostały przygotowane za zgoda˛
           ◮
               dr. Michała Korzyckiego na podstawie jego wykładu.




Aleksander Pohl                                                                 WSZiB
Prolog 2
Listy             Arytmetyka   Struktury       Problem małpy :-)   Operatory   Postscriptum




                                           Dziekuje!
                                              ˛   ˛




Aleksander Pohl                                                                     WSZiB
Prolog 2

Mais conteúdo relacionado

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Sztuczna Intelignecja - Prolog 2

  • 1. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Sztuczna Inteligencja i Systemy Ekspertowe Prolog 2 Aleksander Pohl http://apohllo.pl/dydaktyka/ai Wy˙ sza Szkoła Zarzadzania i Bankowo´ ci z ˛ s 17 marca 2009 Aleksander Pohl WSZiB Prolog 2
  • 2. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Plan prezentacji Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Aleksander Pohl WSZiB Prolog 2
  • 3. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Plan prezentacji Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Aleksander Pohl WSZiB Prolog 2
  • 4. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Listy [ann, tom, tennis] ◮ „głowa” – head: ann ◮ „ogon” – tail: [tom, tennis] ◮ Aleksander Pohl WSZiB Prolog 2
  • 5. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Operatory sklejanie .(Head, Tail) ◮ rozdzielanie L = [Head | Tail] ◮ Aleksander Pohl WSZiB Prolog 2
  • 6. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Testowanie obecno´ ci (1) s Element listy member(X, [X | Tail]). ◮ member(X, [Head | Tail]) :- ◮ member(X, Tail). Aleksander Pohl WSZiB Prolog 2
  • 7. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Testowanie obecno´ ci (2) s Element listy z wykorzystaniem odciecia ˛ member(X, [X | Tail]) :- !. ◮ member(X, [Head | Tail]) :- ◮ member(X, Tail). Aleksander Pohl WSZiB Prolog 2
  • 8. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Konkatenacja conc([],L,L). ◮ conc([X | L1], L2, [X | L3]) :- ◮ conc(L1, L2, L3). Dekompozycja conc(L1, L2, [a, b, c]). ◮ Wyszukiwanie conc(Przed, [c | Po], [a, b, c, d, e, f]). ◮ Aleksander Pohl WSZiB Prolog 2
  • 9. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Usuwanie i dodawania elementu Usuwanie elementu del(X, [X | Tail],Tail). ◮ del(X, [Y | Tail],[Y,Tail1]) :- ◮ del(X, Tail, Tail1). Dodawanie elementu insert( X, List, BiggerList) :- ◮ del( X, BiggerList, List). Aleksander Pohl WSZiB Prolog 2
  • 10. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Permutacje Permutacje dla zbioru {a, b, c}: (a, b, c) ◮ (a, c, b) ◮ (b, a, c) ◮ (c, a, b) ◮ (b, c, a) ◮ (c, b, a) ◮ W Prologu permutation([],[]). ◮ permutation( [X | L ],P) :- ◮ permutation(L,L1), insert(X,L1,P). Aleksander Pohl WSZiB Prolog 2
  • 11. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Plan prezentacji Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Aleksander Pohl WSZiB Prolog 2
  • 12. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Obliczanie warto´ ci s X = 1 + 2. ◮ X=1+2 ◮ X is 1 + 2. ◮ X = 3. ◮ Aleksander Pohl WSZiB Prolog 2
  • 13. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Porównywanie liczb X>Y ◮ X<Y ◮ X>=Y ◮ X=<Y ◮ s´ X=:=Y (równo´ c) ◮ s´ X=/=Y (nierówno´ c) ◮ Aleksander Pohl WSZiB Prolog 2
  • 14. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Przykład porównywania liczb 1 + 2 =:= 2 + 1. ◮ yes ◮ 1 + 2 = 2 + 1. ◮ no ◮ 1 + A = B + 2. ◮ A=2 ◮ B=1 ◮ Aleksander Pohl WSZiB Prolog 2
  • 15. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Przykład – obliczanie długo´ ci listy s length1( [] , 0 ). ◮ length1( [ _ | Tail ], N) :- ◮ N = 1 + N1, length1( Tail, N1 ). length1( [ _ | Tail ], 1 + N) :- ◮ length1( Tail, N ). Aleksander Pohl WSZiB Prolog 2
  • 16. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Obliczanie długo´ ci – wyniki s ?- length1([a,b,c,d],N) ◮ N = 1 + (1 + (1 + (1 + 0))) ◮ ?- length1([a,b,c,d],N), Length is N. ◮ N = 1 + (1 + (1 + (1 + 0))) ◮ Length = 4 ◮ Aleksander Pohl WSZiB Prolog 2
  • 17. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Obliczanie długo´ ci – rozwiazanie poprawne s ˛ length( [] , 0 ). ◮ length( [ _ | Tail ], N) :- ◮ length( Tail, N1 ), N is 1 + N1. Aleksander Pohl WSZiB Prolog 2
  • 18. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Plan prezentacji Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Aleksander Pohl WSZiB Prolog 2
  • 19. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Predykaty jako struktury date(5, may, 2000). ◮ date – funktor główny ◮ Aleksander Pohl WSZiB Prolog 2
  • 20. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Struktura zło˙ ona z family( person(tom, fox, date(7,may,1960),works(bbc,4200)), person(ann, fox, date(9, may,1961),unemployed), [person(pat, fox, date(5, may,1983),unemployed), person(jim, fox, date(11, may,1985),unemployed)]). Aleksander Pohl WSZiB Prolog 2
  • 21. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Rodzina – zapytania (1) family(_,_,[ _,_,_]). ◮ family(person( _, fox, _ , _ ), _ ,_). ◮ husband(X) :- ◮ family(X, _ ,_). wife(X) :- ◮ family(_,X,_). child(X) :- ◮ family(_,_,Children), member(X, Children). exists(Person) :- ◮ husband(Person);wife(Person); child(Person). Aleksander Pohl WSZiB Prolog 2
  • 22. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Rodzina – zapytania (2) dateofbirth(person(_,_,Date,_),Date). ◮ salary(person(_,_,_,works(_,S)),S). ◮ salary(person(_,_,_,unemployed),0). exists(person(Name,Surname,_,_)). ◮ child(X), dateofbirth(X,date(_,_,2000)). ◮ exists(Person), ◮ dateofbirth(Person, date(_,_,Year)), Year<1960, salary(Person,Salary), Salary<8000. Aleksander Pohl WSZiB Prolog 2
  • 23. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Rodzina – zapytania (3) total([],0). ◮ total([Person|List], Sum) :- ◮ salary(Person,S), total(List, Rest), Sum is S+Rest. family(Husband, Wife, Children), ◮ total([Husband,Wife|Children],Income). Aleksander Pohl WSZiB Prolog 2
  • 24. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Plan prezentacji Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Aleksander Pohl WSZiB Prolog 2
  • 25. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Aleksander Pohl WSZiB Prolog 2
  • 26. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Ruchy małpy (1) move( ◮ state(middle,onbox,middle,hasnot), grasp, state(middle,onbox,middle,has)). move( ◮ state(P,onfloor,P,H), climb, state(P,onbox,P,H)). Aleksander Pohl WSZiB Prolog 2
  • 27. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Ruchy małpy (2) move( ◮ state(P1,onfloor,P1,H), push(P1,P2), state(P2, onfloor, P2, H)). move( ◮ state( P1, onfloor, B, H), walk(P1,P2), state(P2, onfloor, B, H)). Aleksander Pohl WSZiB Prolog 2
  • 28. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Cel małpy canget( state(_,_,_,has)). ◮ canget( State1 ) :- ◮ move( State1 , Move , State2), canget(State2), print(Move), write(’ ’). ?- canget(state(atdoor, onfloor, atwindow, ◮ hasnot)) Aleksander Pohl WSZiB Prolog 2
  • 29. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Plan prezentacji Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Aleksander Pohl WSZiB Prolog 2
  • 30. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Typy operatorów infiksowe ◮ np. 5 + 10, a ∨ b prefiksowe ◮ np. - 5, ¬ a postfiksowe ◮ np. 5, 6 + (notacja Łukasiewicza) Aleksander Pohl WSZiB Prolog 2
  • 31. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Dyrektywy op(N,T,Name). ◮ N — priorytet operatora ◮ T – typ operatora ◮ Name – nazwa atomu ◮ Aleksander Pohl WSZiB Prolog 2
  • 32. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Priorytety s´ Im ni˙ szy warto´ c priorytetu (im wy˙ szy priorytet), tym operator z z wia˙ e silniej. ˛z term, bad´ wyra˙ enie w nawiasach: 0 ˛z z ◮ priorytet struktury: priorytet funktora głównego ◮ s´ x – warto´ c priorytetu silnie mniejsza od warto´ ci s ◮ priorytetu operatora głównego s´ y – warto´ c priorytetu mniejsza bad´ równa warto´ ci ˛z s ◮ priorytetowi operatora głównego Aleksander Pohl WSZiB Prolog 2
  • 33. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Typy operatorów infiksowe ◮ xfx, xfy, yfx prefiksowe ◮ fx, fy postfiksowe ◮ xf, yf Aleksander Pohl WSZiB Prolog 2
  • 34. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Przykład a-b-c ◮ (a-b)-c – tradycyjna interpretacja ◮ definiujemy jako yfx ◮ a-b priorytet równy warto´ ci operatora, czyli y ma taki s sam priorytet jak operator główny definiujemy jako xfy (błednie) ˛ ◮ a-b priorytet równy warto´ ci operatora, ale x nie mo˙ e s z mie´ priorytetu takiego jak operator główny c Aleksander Pohl WSZiB Prolog 2
  • 35. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Przykład not jako fx ◮ not(not p) jako fy ◮ not not p Aleksander Pohl WSZiB Prolog 2
  • 36. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Predefiniowane operatory op(1200,xfx,[ :- , -> ] ) ◮ op(1100,xfy,’;’) ◮ op(1000,xfy,’,’) ◮ op(900,fy, not ) ◮ op(700,xfx,[ is,=,=,=:=,== ]) ◮ op(500,yfx,[ +,- ]) ◮ op(400,yfx,[ *,/,//,mod ]) ◮ op(200, xfx , ** ) ◮ op(200,fy,-) ◮ Aleksander Pohl WSZiB Prolog 2
  • 37. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Przykład (1) ¬(A ∨ B) ↔ ¬A ∨ ¬B ◮ equiv(not( and(A,B)),or(not(A),not(B))) ◮ op( 800,xfx, <===>). ◮ op(700,xfy,v). ◮ op(600,xfy,&). ◮ op(500,fy,∼). ◮ ∼(A & B) <===> ∼A v ∼B. ◮ Aleksander Pohl WSZiB Prolog 2
  • 38. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Przykład (2) op(300,xfx, plays). ◮ op(200,xfy,and). ◮ jimmy plays football and squash. ◮ Who plays football and squash. ◮ Who = jimmy ◮ jimmy plays What. ◮ What = football and squash ◮ Aleksander Pohl WSZiB Prolog 2
  • 39. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Plan prezentacji Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Aleksander Pohl WSZiB Prolog 2
  • 40. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Materiały zródłowe ´ L.Sterling, E.Shapiro - „The Art Of Prolog” ◮ Ivan Bratko - „Prolog – Programming For Artificial ◮ Intelligence” Slajdy zostały przygotowane za zgoda˛ ◮ dr. Michała Korzyckiego na podstawie jego wykładu. Aleksander Pohl WSZiB Prolog 2
  • 41. Listy Arytmetyka Struktury Problem małpy :-) Operatory Postscriptum Dziekuje! ˛ ˛ Aleksander Pohl WSZiB Prolog 2