Your SlideShare is downloading. ×
0
Section3 Prologppt
Section3 Prologppt
Section3 Prologppt
Section3 Prologppt
Section3 Prologppt
Section3 Prologppt
Section3 Prologppt
Section3 Prologppt
Section3 Prologppt
Section3 Prologppt
Section3 Prologppt
Section3 Prologppt
Section3 Prologppt
Section3 Prologppt
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Section3 Prologppt

704

Published on

Published in: Sports, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
704
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Chapter 3 Lists , Operators and Arithmetic
  • 2.
    • Lists are one of the fundamental data structures in A.I.
    • Lists provide an ordered collection of other data objects.
    • The great advantages is that list’s ability to grow and shrink during execution.
    • A list is a simple data structure for collecting data objects together.
    • Elements in lists can be numbers , atoms , lists or anything else.
    • We write lists within square brackets [] with items separated by commas.
  • 3.
    • Lists
    • Empty Non empty
    • []
    • no space.
    Ex.1:[ann , tennis , tom , football]. Ex.2:[ann , X , sport(tennis) , [tom , skiing]]. ann: atom X: variable sport(tennis):structure with functor sport / 1 argument. [tom , skiing]:anther list.
  • 4.
    • [ann , tennis , tom , football]
    i.e. :to represent it as a structure with functor . , and in binary tree ( 2 - arguments ).
    • We can represent list as a structure using functor ./2
    Where: Head: First argument object. Tail: The rest of objects. Functor Head Tail Two arguments
  • 5.
    • Ex.: [ann , tennis , tom , football].
    . ann . tennis . tom . football [] . (ann , . (tennis , . (tom , . (football , [])))).
  • 6.
    • Note: the tail has to be a list
    • Some operations that are useful in lists:
    • Membership.
    • Concatenation.
    • Add item.
    • Delete item
    • Sub list
    • Permutation.
    • [a , b | [c , d]] , [a , b , c | [d]] , [a , b , c , d | []]
    • Ex.: [[a , b] , c] = [[a , b] | [c]]
    • Ex.: [a , b , c , d] = [a | [b , c , d]]
  • 7. (1) Membership / 2
    • Ex.: member(a , [a , b , c])
    object
    • Ex.: member (X , L)
    • We use it to check whether some object is element of a list or not.
    Means: number of arguments are two list Yes object list member(a , [1 , b , c]) No
  • 8.
    • when X is a member in list?
    (Fact)
    • let us define the rule:
    • member (X , [X | _ ]).
    • member (X , [Head | Tail]) :- member (X , Tail).
    • X is a member of list L if either:
    • X is a head of L .
    • X is a member of tail.
    • Question: ?- member (X , [a , b , c]).
    X = a; X = b; X = c; no
  • 9.
    • How prolog answer this question?!!
    member (X , Tail)
    • Question: ?- member (a , [b , c , a , d]).
    • Let us see:
    • Member (X , [X | _ ]). dose not satisfy.
    • So , it will leave it and go to other member relations , it found member (X , [Head | Tail]):- member (X , Tail).
    • Try to satisfy ( subgoal )
    • Here : Head = b
    • Tail = [c , a , d]
  • 10.
    • To satisfy member (X , [c , a , d])
    • It go to member (X , [X | _ ]) again and try to satisfy , but it is not satisfied ,then go to member(X , Tail) again.
    • But here Head = [b , c]
    • Tail = [a , d]
    Yes To satisfy member (X , [a , d]) It go to member(X , [X | _ ]) again and try to satisfy, but here at this time it is satisfied then it answers Stop Practice
  • 11.
    • Question: ?- conc ([1 , 2] , [a , b] , [1 , 2 , b , a]).
    • prolog answers : No
    • Not in the same order.
    • L1 L2 L3
    • [] L L
    • [X | L1] L2 [X | L3]
    Why?? Two lists
    • Means combining and interference.
    • Concatenation of two lists obtain a third list.
    • conc (L1 , L2 , L3)
    Concatenation /3 Means : three lists Conc of L1 , L2. The same [Head | Tail] empty X L1 X L3 L2
  • 12.
    • Two rules:
    • Using ( trace. ) order we found that it is important to use this command to explain what prolog does to answer a question by all steps.
    Answer: practical Let us see
    • Question: ?- conc (L1 , L2 , [a , b , c]).
    conc ([] , L , L). conc ([X | L1] , L2 , [X | L3]) :- conc (L1 , L2 , L3).
    • Answer:
    • L1=[]
    • L2 =[a , b , c];
    • L1 =[a]
    • L2 =[b , c];
    L1 =[a , b] L2 =[c]; L1 =[a , b ,c] L2 =[]; no Decomposition process. For a list into two lists
  • 13.
    • Example:
    • Find the months that precede and the months that follow a given month?
    • Assume that the given month is may.
    Vip:
    • Answer:
    • ?- conc(Before , [may | After] , [ jan , feb , mar , apr , may , jun , jul , aug , sep , oct , nov , dec]).
    • Prolog answers:
    • Before =[ jan , feb , mar , apr].
    • After =[ jun , jul , aug , sep , oct , nov , dec].
  • 14.
    • Write in prolog
    • The month just after and the month just before may.
    • Define membership relation using conc relation.
    • Define the relation
    • last (Item , List)
    • So that Item is the last element of the list List .
    • Write two versions (a) using the conc relation
    • (b) without conc relation.

×