Beruflich Dokumente
Kultur Dokumente
org/dep-cs
Artificial Intelligence (A.I) :- Is the branch of computer science that concerned with the
automation of intelligence behaviour.
A.I:- Is the part of computer science concerned with designing intelligent computer system that
exhibit the character static associate with intelligent in human behavior. This require many
process:-
1- learning :- acquiring the knowledge and rules that used these knowledge.
2- Reasoning:- Used the previous rules to access to nearly reasoning or fixed reasoning.
A.I Principles:-
1- The data structures used in knowledge representation.
2- the algorithms needed to apply that knowledge.
3- the language and programming techniques used their implementation.
A.I Application:-
1- Game application.
2-Automated reasoning and theorm proving.
3-Perception.
4-Expert Systems
5- Natural language understanding and semantic modeling.
6- planning and robotics
machine learning
language & environment for A.I
Pattern recognition
A.I & Philosophy.
A.I Branches:-
1- Logical A.I
2-Search
3- Representation
4-Inference
5-knowledge & Reasoning
6- Planning
7- Epistemology.
8- Ontology.
9- Heuristics.
10-Genetig Programming.
Search Algorithms:
To successfully design and implement search algorithms, a programmer must be able to
analyze and predict their behavior.
Many questions needed to be answered by the algorithm these include:
- is the problem solver guranteed to find a solution?
- Will the problem solver always terminate , or can it become caught in an infinite loop?
- When a solution is found , is it guaranteed to be optimal?
- -What is the complexity of the search process in terms of time usage ? space search?
- How can the interpreter be designed to most effectively utilize a representation language?
- Graph Theory:-
A graph consist of a set of a nodes and a set of arcs or links connecting pairs of nodes. The
domain of state space search , the nodes are interpreted to be stated in problem_solving
process, and the arcs are taken to be transitions between states.
Graph theory is our best tool for reasoning about the structure of objects and relations.
e
c
d
a
b
Nodes={a,b,c,d,e}
Arcs={(a,b), (a,d),(b,c),(c,b),(d,e),(e,c),(e,d)}
a
b d
c
e f g h i j
Nodes=={a,b,c,d,e,f,g,h,i}
Arcs={(a,b),(a,c),(a,d),(b,e),(b,f),(c,f),(c,g),(c,h),(c,i),(d,j)}
125 b
300
e 125
50
50
c
100
d
The complexity of exhaustive search in the traveling Saleman is (N-1)!, where N is the No.
of cities in the graph. There are several technique that reduce the search complexity.
1- Branch and Bound Algorithm :-Generate one path at a time , keeping track of the best circute
so far. Use the best circuit so far as a bound of future branches of the search .
figure below illustrate branch and bound algoritm.
c
a
100 75
b
150 125 e
100
c
c d
250
d e c e
300
e d
e
375
a a a
2- Nearest Nieghbor Heuristic: At each stage of the circuit , go to the nearest unvisited city. This
strategy reduces the complexity to N, so it is highly efficient , but it is not guranteed to find the
shortest path , as the following example:
a
100
75
100
125 b
300
e 125
50
50
c
100
d
W F
C G
State(e, w , e ,w)
F
W G
State(w,w,e,w) C
W F C F
C State(e,w,e,e) State(e,e,e,e) G
G W
F
W C State(w,w,w,e) state(w,e,w,w) F
G C W
G
F
G W
State(e,e,w,e) C
F W
G C
state(w,e,w,e)
F
state(e,e,e,e) W
G Goal state
C
The following move rule operates only when the farmer and wolf are in the same location
and takes them to the opposite side of the river. Note that the goat and cabbage do not change their
present location:-
Move(state(X,X,G,C),state(Y,Y,G,C)):-opp(X,Y).
X opposite (opp) the value of Y
Opp (e , w).
Opp (w, e).
A predicate must be created to test whether each new state is safe , so that nothing is eaten
in the process of getting across the river. These unsafe situations may be represented with the
following rules:-
Unsafe (state(X,X,Y,Y)):-opp(X,Y).
Unsafe(state(X,W,Y,Y)):-opp(X,Y).
move(st(X,W,X,C),st(Y,W,Y,C)):-opp(X,Y),not(unsafe(st(Y,W,Y,C))),writelist(["try farmer
takes goat",Y,W,Y,C]).
move(st(X,W,G,X),st(Y,W,G,Y)):-opp(X,Y),not(unsafe(st(Y,W,G,Y))),writelist(["try farmer
takes cabbage",Y,W,G,Y]).
move(st(X,W,G,C),st(Y,W,G,C)):-opp(X,Y),not(unsafe(st(Y,W,G,C))),writelist(["farmer
takes self",Y,W,G,C]).
move(st(F,W,G,C),st(f,w,g,c)):-writelist([" BACKTRACK from:",F,W,G,C]),FAIL.
path(Z,Z,L):-write("solution path is:"),rpt(L).
path(X,Y,L):-move(X,Z),not(member(Z,L)),path(Z,Y,[Z|L]).
member(X,[X|_]).
member(X,[_|T]):-member(X,T).
writelist([]):-nl.
writelist([H|T]):-print(H),writelist(T).
rpt([]).
rpt([H|T]):-rpt(T),write(H),nl.
opp(e,w).
opp(w,e).
unsafe(st(X,Y,Y,_)):-opp(X,Y).
unsafe(st(X,_,Y,Y)):-opp(X,Y).
print(A):-write(A).
goal= path(state(w,w,w,w),state(e,e,e,e),[state(w,w,w,w)]).
(0,0)
0,3 4,0
0,3 4,0
0,0 0,3
3,3 1,0
1,0
4,0 3,3 0,0 4,1
0,2
4,0 0,1
4,2 0,0 2,3
2,0
The goal
The goal
a. b. c. d.
w:-r,z.
r:-a,b.
z:-c,d.
sol/
a. b. c. d. r. z. w. the goal is true
1) w:-r,z. 6
2) r:-a,b. 4
3) z:-c,d. 5
4)r:-b.
5) z:-d.
6)w:-z.
ﻣﻼﺣﻈﺎت ﻋﻦ F.W
(١ﻧﺒﺪأ ﺑﺎﻟﺤﻘﺎﺋﻖ ) (Factsﺑﺎﻟﺒﺤﺚ ﻋﻨﻬﺎ ﻓﻲ اﻟﻘﻮاﻋﺪ) (Rulesﻓﻲ ﺟﻬﺔ اﻟﻴﻤﻴﻦ ﻓﺄذا آﺎﻧﺖ ﻣﻮﺟﻮدة ﺗﺤﺬف ﻣﻦ اﻟﻄﺮف اﻟﻴﻤﻴﻦ-:
(٢اذا أﺻﺒﺤﺖ ال ruleﻓﻲ اﻟﻄﺮف اﻷﻳﻤﻦ ﻓﺎرﻏﺔ ﺗﺘﺤﻮل ال ruleاﻟﻰ factواﻻ ﻓﺘﻀﺎف ruleﺟﺪﻳﺪة ﺑﻌﺪ ﻋﻤﻠﻴﺔ اﻟﺤﺬف.
(٣ﺑﻌﺪ ﺗﺄﺷﻴﺮ آﻞ factsإذا آﺎن اﻟﻬﺪف ﻣﻮﺟﻮد ﺿﻤﻦ ال factsﻓﻬﻮ trueواﻻ ﻓﻬﻮ .false
ﻣﻼﺣﻈﺎت ﻋﻦ F.W
(١ﻧﺒﺪأ ﺑﺎﻟﻬﺪف وذﻟﻚ ﺑﺎﻟﺒﺤﺚ ﻋﻨﻪ ﻓﻲ ال factsإذا آﺎن ﻣﻮﺟﻮد ﻓﻬﻮ trueوأﻻ ﻓﻬﻮ .False
(٢ﻧﺒﺤﺚ ﻋﻦ اﻟﻬﺪف ﻓﻲ Rulesﻓﻲ ﺟﻬﺔ اﻟﻴﺴﺎر ﻓﻲ ﺣﺎﻟﺔ وﺟﻮدﻩ ﻧﺤﺎول إﺛﺒﺎت اﻟﻄﺮف اﻷﻳﻤﻦ .True
Example: Try the following facts & Rules with (F.W) & (B.W) Chaining.
a(1). B. c. d(1).
W:-r(x),z(x).
R(w):-a(w),b.
Z(v),c.
Sol/
a(1). B. c. d(1). r(1). Z(1). W. the goal is true
1) w:-r(x),z(x). 6
2) r (w):-a(w),b. 4
3) z (v):d(v),c. 5
4) r (1):-b.
5) z(v):-d(v).
6) w:-z(1).
2) r(w):-a(w),b. 4
3) z(v):-d(v),c. 5
4) z(1):-c.
5) r(1):-b.
6) w:-r(1).
H.W/ Using B.W & F.W chaining to reasoning that the goal (Z) is true or not.
a(1). b(2). c(3). d(1). e.
r:-a(x),b(y).
z:-e, not (f),not(b(3)),w.
w:-c(z),d(l),not (a(3)),r.
2) Backtracking Search Algorithm
Backtracking search begins at the start state and pursues a path until it reaches a goal or "dead
end", if it reaches a goal , it returns the solution path and quits. If it reaches a dead end , it
backtracks to the most recent node in the path having unexamined siblings and continues down
on of those branches.
The backtrack algorithm uses three lists plus one variable:
SL, The state list, lists the states in the current path being tried , if a goal is found , SL contains
the ordered list of states on the solution path.
NSL, The new state list, contains nodes a waiting evaluation, nodes whose descendants have
not yet been generated and searched.
DE, dead ends, lists states whose descendants have failed to contain a goal end. If these states
are encountered again, they will be immediately eliminated from consideration.
B C D
E G
F
H I J
Iteration CS SL NSL DE
0 A [A] [A] []
1 B [B A] [B C D A] []
2 E [E B A] [E F B C D A] []
3 H [H E B A] [H I E F B C D A] []
4 I [I E B A] [I E F B C D A] [H]
5 F [F B A] [F B C D A] [E I H]
6 J [J F B A] [J F B C D A] [E I H]
7 C [C A] [C D A] [B F J E I H]
8 G [G C A] [G C D A] [B F J E I H]
Blind Search
This type of search takes all nodes of tree in specific order until it reaches to goal. The order can
be in breath and the strategy will be called breadth – first – search, or in depth and the strategy will
be called depth first search.
B C D
E F G H F J
K L M NO P Q R
Y
Fig (2 – 1): Breadth – first – search
1 – Open = [A]; closed = [ ].
2 – Open = [B, C, D]; closed = [A].
3 – Open = [C, D, E, F]; closed = [B, A].
4 – Open = [D, E, F, G, H]; closed = [C, B, A].
5 – Open = [E, F, G, H, I, J]; closed = [D, C, B, A].
6 – Open = [F, G, H, I, J, K, L]; closed = [E, D, C, B, A].
7 – Open = [G, H, I, J, K, L, M]; closed = [F, E, D, C, B, A].
8 – Open = [H, I, J, K, L, M, N,]; closed = [G, F, E, D, C, B, A].
9 – and so on until either U is found or open = [ ].
Begin
Open: = [start];
Closed: = [ ];
While open ≠ [ ] do
Remove leftmost state from open, callitx;
Ifxis agoal then return (success)
Else begin
Geerate children of x;
Put x on closed;
Eliminate children of x on open or closed; put remaining children on left end of open end
End;
Return (failure)
End.
B C D
E F G H I J
K L M N O P Q R
S T U
Fig (2 – 2) Depth first search
1 – Open = [A]; closed = [ ].
2 – Open = [B, C, D]; closed = [A].
3 – Open = [E, F, C, D]; closed = [B, A].
4 – Open = [K, L, F, , D]; closed = [E, B, A].
5 – Open = [S, L, F, C, D]; closed = [K, E, B, A].
6 – Open = [L, F, C, D]; closed = [S, K, E, B, A].
7 – Open = [T, F, C, D]; closed = [L, S, K, E, B, A].
8 – Open = [F, C, D,]; closed = [T, L, S, K, E, B, A].
9 – Open = [M, C, D] as L is already on; closed = [F, T, L, S, K, E, B, A].
Heuristic Search
A heuristic is a method that might not always find the best solution but is guaranteed to find
a good solution in reasonable time. By sacrificing completeness it increase efficiency. Heuristic
search is useful in solving problems which:-
1) Hill Climbing
The idea here is that , you don’t keep the big list of states around you just keep track of the one state you
are considering , and the path that got you there from the initial state. At every state you choose the state
leads you closer to the goal (according to the heuristic estimate ), and continue from there.
The name “Hill Climbing” comes from the idea that you are trying to find the top of a hill , and you go in
the direction that is up from wherever you are. This technique often works, but since it only uses local
information.
The smaller peak is an example of a “local maxima” in a domain (or “local minima”). Hill
climbing search works well (and is fast ,takes a little memory) if an accurate heuristic measure is
available in the domain , and there are now local maxima.
Hill Climbing Algorithm
Begin
Cs=start state;
Open=[start];
Stop=false;
Path=[start];
While (not stop) do
{
if (cs=goal) then
return (path);
generate all children of cs and put it into open
if (open=[]) then
stop=true
else
{
x:= cs;
for each state in open do
{
compute the heuristic value of y (h(y));
if y is better than x then
x=y
}
if x is better than cs then
cs=x
else
stop =true;
}
}
return failure;
}
A trace of Hill Climbing Algorithm
B2 C3 D1
E3 L4 G4 F2
Q5 H1 P7
N5 M4
T5 R4 U7 O6
R4 S4 R4
Open Close X
A _ A
C3 B2 D1 A C3
G4 F2 A C3 G4
N5 M4 A C3 N5
R4 S4 A C3 G4 N5 R4
J 20 K 20
L 15
F 10 G 30 I 15
M 20 N 35
P 15 S 15
O 20 L 25
R 10 X 15 Y 25
Z 20
Goal state
2- A Plateau: Is a flat area of the search space in which a number of states have the same best
value , on plateau its not possible to determine the best direction in which to move.
A اﻟﺴﻄﻮح
اﻟﻤﺴﺘﻮﻳﺔ
B 20 C 20 D 20 E 20
3- A ridge: Is an area of the search space that is higher than surrounding areas , but that can
not be traversed by a single move in any one direction.
A
E 25
B 10 C 20 D 15
J 20 H 15
F 10 G 20 H 25 I 10
2) Best-First-Search
{
Open:=[start];
Closed:=[];
While open ≠ [] do
{
Remove the leftmost from open, call it x;
If x= goal then
Return the path from start to x
Else
{
Generate children of x;
For each child of x do
Do case
The child is not already on open or closed;
{ assign a heuristic value to the child state ;
Add the child state to open;
}
The child is already on open:
If the child was reached along a shorter path than the state currently on open then give the
state on open this shorter path value
B4 C4 D6
E5 F5 G4 H3
I J
O2 R4
N
T5 R4 P3 Q
open closed
[A5] []
[B4 C4 D6] [A5]
[C4 E5 F5 D6] [B4 A5]
[H3 G4 E5 F5 D6] [C4 B4 A5]
[O2 P3 G4 E5 F5 D6] H3 C4 B4 A5]
P3 G4 E5 F5 D6] [O2 H3 C4 B4 A5]
The solution path is: A5 - B4 - C4 - H3 – O2- P3
8_PUZZLE AS APPLICATION OF (BFS)
Implementing Heuristic Evaluation Function:-
ﻣﻦ ﻣﺴﺎوئ ﺧﻮارزﻣﻴﺔ اﻟﺒﺤﺚ ﻋﻦ اﻻﻓﻀﻞ ) (Best – First – Searchاﻧﻬﺎ ﺗﺮآﺰ ﻋﻤﻠﻴﺔ اﻟﺒﺤﺚ ﻋﻠﻰ ﻓﺮع ﻓﻲ ﻓﻀﺎء اﻟﺒﺤﺚ ﻋﻠﻰ
ﺣﺴﺎب ﺑﻘﻴﺔ اﻻﻓﺮع .وﻳﺤﺪث ذﻟﻚ اذا اﺳﺘﻤﺮ اﻻﻗﺘﺮان اﻻﺟﺘﻬﺎدي ) آﻠﻔﺔ ال (nodeﻓﻲ اﻋﻄﺎء آﻠﻒ او ﻗﻴﻢ اﺟﺘﻬﺎدﻳﺔ ﺟﻴﺪة ﻟﻠﺤﺎﻻت
اﻟﻤﻮﺟﻮدة ﻋﻠﻰ ﻓﺮع ﻣﺎ .وﻗﺪ ﻳﻜﻮن ذﻟﻚ ﺳﻴﺌﺎ ﻟﻌﺪم وﺟﻮد اﻟﺤﺎﻟﺔ اﻟﻬﺪﻓﻴﺔ ﻋﻠﻰ ذﻟﻚ اﻟﻔﺮع ﻣﻦ ﻓﻀﺎء اﻟﺒﺤﺚ .او ﺑﺴﺒﺐ وﺟﻮد ﺣﺎﻟﺔ
هﺬﻓﻴﺔ اﻗﺮب ) ذات ﻣﺴﺎر اﻗﺼﺮ ( ﻋﻠﻰ ﻓﺮع اﺧﺮ.
وﻟﺘﺠﻨﺐ هﺬﻩ اﻟﻤﺸﻜﻠﺔ ﻳﻨﺼﺢ ﻋﺎدة ﺑﺎﺳﺘﺨﺪام اﻗﺘﺮان اﺟﺘﻬﺎدي ) (Heuristic functionﺗﺄﺧﺬ ﺑﻨﻈﺮ اﻻﻋﺘﺒﺎر ﻣﻘﺪار ﺑﻌﺪ اﻟﺤﺎﻟﺔ
اﻟﻤﺨﺘﺎرة ﻋﻦ ﺣﺎﻟﺔ اﻟﺒﺪاﻳﺔ ﺑﺤﻴﺚ ﺗﻔﻀﻞ اﻟﺤﺎﻟﺔ اﻷﻗﺮب .وذﻟﻚ ﻟﺘﺠﻨﺐ اﻻﺳﺘﻤﺮار ﻓﻲ اﻟﺒﺤﺚ ﻓﻲ ﻓﺮع واﺣﺪ ﻋﻠﻰ ﺣﺴﺎب ﺑﻘﻴﺔ اﻻﻓﺮع .
وﺳﺘﻜﻮن Heuristic Functionﻟﻬﺎ اﻟﺼﻴﻐﺔ اﻟﺘﺎﻟﻴﺔ-:
)Fn= g(n) + h(n
g(n):- Measures the actual length of path from any state (n) to the start state.
H(n):- is a heuristic estimate of the distance from state n to the goal.
• ﻋﻨﺪﻣﺎ ﺗﺴﺘﺨﺪم ﺧﻮارزﻣﻴﺔ Best-Firstﻣﻊ Heuristic Functionآﻤﺎ ﻓﻲ اﻟﺼﻴﻐﺔ ) (١ﻓﺎن اﻟﺨﻮارزﻣﻴﺔ اﻟﻨﺎﺗﺠﺔ ﺗﺴﻤﻰ
.A- Algorithm
A Algorithm
Trace of A- Algorithm (Search
)Connect(a,b,3
)Connect(a,c,4
)Connect(a,d,2
)Connect(b,e,7
)Connect(b,f,7
Connect(c,g,3).
Connect(c,h,2).
)Connect(d,I,4
Connect(d,j,3).
Connect(f,k,3).
Connect(h,k,1).
Connect(I,k,2).
A
B3 C4 D2
E7 F7 H2 G3
I4 J3
K3 K1 K2
B 13 C7 D8
E 23 F13 H7 G 13
I8 J 14
K K K
Open Close
[A] []
[C7 D8 B13] [A]
[H7 D8 B13 G13] [C7 A]
[K D8 B13 G13] [H7 C7 A]
[K H7 C7 A]
h*(n) returns the actual cost of the shortest path from n to the goal.
F*(n) is the actual cost of the optimal path from a start node to a goal node that passes through
node n.
If we employ best-first –search with the evaluation function F* ,the resulting search strategy is
admissible.
In A algorithm , g(n) , The cost of the current path to state n , is a reasonable estimate of g*(n),
but they may not be equal g(n)≥g*(n).These are equal only if the graph search has discovered the
optimal the optimal path to state n.
Similarly, We replace h*(n) with h(n) , a heuristic estimate of the minimal path to a goal state. If
A Algorithm uses an evaluation F in which h(n) ≤ h* (n) it is called A* Algorithm .So all A*
Algorithm are admissible.
2) Monotonicity
A heuristic function h is monotone if :-
a. For all state ni and nj , where nj is a descendant of ni
h(ni)-h(nj) ≤ cost(ni,nj).
Where cost (ni,nj) is the actual cost of going from state ni to nj.
3) Informedness
For two A* heuristics h1 and h2 , if h1(n) ≤ h2(n), for all states n in the search space , heuristics h2
is said to be more informed than h1.
Knowledge Representation
There are many methods can be used for knowledge representation and they can be
described as follows:-
1- Semantic net.
2- Conceptual graph.
3- Frames
4- Predicates logic.
5- Clause forms
1) Semantic Net
It is consist of a set of nodes and arcs , each node is represented as a rectangle to describe
the objects, the concepts and the events. The arcs are used to connect the nodes and they
divided to three parts:-
can
(Reciever) ( واﻟﻤﺴﺘﻘﺒﻞagent) ﺗﺨﺮج ﻣﻦ اﻟﻔﻌﻞ ﻟﺘﻮﺿﺢ او ﻟﺘﺸﻴﺮ اﻟﻰ اﻟﻔﺎﻋﻞarcs ﻓﻲ وﺻﻒ اﻟﻠﻐﺎت اﻟﻄﺒﻴﻌﻴﺔ ﻓﺎن
. اﻟﺤﺎﺿﺮ او اﻟﻤﺴﺘﻘﺒﻞ، ( آﻤﺎ ﺗﺸﻴﺮ اﻟﻰ وﻗﺖ ﺣﺪوث اﻟﻔﻌﻞ أي ﻓﻲ اﻟﻤﺎﺿﻲobject) واﻟﻜﺎﺋﻦ
Example1: Computer has many part like a CPU and the computer divided into two type, the first
one is the mainframe and the second is the personal computer ,Mainframe has line printer with
large sheet but the personal computer has laser printer , IBM as example to the mainframe and PIII
and PIV as example to the personal computer.
Has a
Computer CPU
Is a Is a
Has a Has a
Laser PC Mainframe Line
printer printer
Is a Is a Is a
agent receiver
Layla gave Selma
time
object
Past book
time
time
past
proposition
receiver
Gave Selma
object
past a book
Example 4: Ali gave Ban a disk which is Zaki bought
agent receiver
Ali gave Ban
time
object
Past disk
object
agent
Zaki bought
time
Past
time
present
instrument time
time
present
time
past
3) Frame:
Frame-list
Slot-list
Example:
monitor
computer Mother board
keyboard
No. of function key
peripherals ports
printer
speed
plotters mouse
Example1:
1) Fido is a dog
Dog (Fido).
2)All dogs are animals.
(dog(x)→ animal(x))
3) All animals will die.
(animal(y)→ die(y)).
4) Prove that ,Fido will die
¬ die (Fido)
Example 2:-
1) Any one passing their history exam and winning the lottery is happy.
5) Clause Forms:-
The statements that produced from predicate logic method are nested and very complex
to understand, so this will lead to more complexity in resolution stage , therefore the following
algorithm is used to convert the predicate logic to clause forms:-
Resolution Theorem Proving:
Resolution is a technique for proving theorems in the predicate calculus that has been a
part of A.I –Problem solving research using Resolution by refutation.
The resolution refutation proof procedure answers a query or deduces a new result by
reducing the set of clause to a contradiction , represented by the full clause ( ).
np
np vp
S→ NP VP
NP→ noun | del noun
VP → verb NP
noun→ Ali| verb NP
verb → eat
del → the
The sentences in natural language include:
Nouns , verbs , adjectives , adverbs & prepositions.
The nouns like: Ahmed, Ali ,the man , the girl, apple, animals, ………. etc.
The adjectives like : the tall , big , the shorter , the shortest, thin ,…… ,etc.
The Noun Phrase (NP) can include only noun such as (Ahmed) or determiner noun such as
( The man) or determiner adjective noun (the tall man ) or determiner adjective adverb noun
( the last month exactly).
The Verb Phrase (VP) can include only verb like ( eat) or verb followed by Noun Phrase(
NP) such as (eat apple) or ( threw the ball).
The preposition Phrase (PP) can include only the preposition with noun ( at Sunday) or
preposition with determiner noun such as (in the school).
Examples:
1- animals
noun → animals
2- large cities
NP → adj noun
3- the broker
np → del noun
5- In the bank
PP → preposition np
6- thinks
vp → verb
7- schemed obsessively
vp→ verb adverb.
Example : “The boy throw the ball through the window” phrase the sentence above ,
then write a complete prolog program for the syntax rules.
NP NP
NP VP PP
S
S → NP VP PP
NP→ del noun
VP → verb NP
PP → pre NP
noun→ boy| ball | window
verb → throw
del → the
pre → through
domains
s=string
a=s*
predicates
sen (a)
np(a).
vp(a).
pp(a).
noun(s).
del(s).
verb(s).
pre(s).
append(a,a,a).
clauses
sen(S):-np(S1),write(S1),vp(S2),write(S2),append(S1,S2,S3),write(S3),pp(S4),write(S4),!,
append(S3,S4,S),write("the statement is True").
np(X):- del(X1),noun(X2),append([X1],[X2],X).
vp(X):-verb(X1),np(X2),append([X1],X2,X).
pp(X):-pre(X1),np(X2),append([X1],X2,X).
del("the").
noun("boy").
noun("ball").
noun("window").
verb("throw").
pre("through").
append([],L,L).
append([H|T],L,[H|T1]):-append(T,L,T1).