Analysis of Prolog Program: List Processing with Dot Notation

Verified

Added on  2023/04/21

|4
|828
|364
Homework Assignment
AI Summary
This assignment delves into fundamental concepts of logic programming, focusing on list manipulation and Prolog program analysis. It begins by identifying the head and tail of various lists, representing them using dot notation. Subsequently, it examines a given Prolog program designed to calculate the sum of elements within a list. The assignment provides a detailed explanation of how the Prolog program works, elucidating the recursive process and the termination condition. Finally, it constructs a search (or derivation) tree for a specific query, illustrating the step-by-step execution of the Prolog program and the derivation of the solution. This document is available on Desklib, a platform providing students with access to a wide range of study tools and resources, including solved assignments and past papers.
Document Page
Logic Programming
1. List Head and Tail Represented in Dot Notation.
Given that:
Elements of a list are items between the Outermost Square brackets separated by commas,
The head is the first Element in the list, and that everything else forms the tail,
Then:
(i) [tennis,cricket,[rowing,rafting]]
Head = tennis,
Tail = [cricket, [rowing, rafting]]
dot notation:
Head = tennis
Tail = .(cricket,.(.(rowing,.(rafting,[])),[]))
(ii) [[screwdriver,brace],hammer,hacksaw]
Head = [screwdriver, brace],
Tail = [hammer, hacksaw]
dot notation:
Head = .(screwdriver,.(brace,[]))
Tail = .(hammer,.(hacksaw,[]))
(iii) [[electric],[petrol,diesel,[hybrid]]]
Head = [electric],
Tail = [[petrol, diesel, [hybrid]]]
dot notation:
Head = .(electric,[])
Tail = .(.(petrol,.(diesel,.(.(hybrid,[]),[]))),[])
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
2. Prolog Program
check([ ], 0).
check([H | T], S) :- check(T, TS) , S is TS + H.
(i) How the above Prolog Program Works
The first line is a fact; returns 0 on an empty list.
This fact will be used to terminate the rule’s execution recursion.
The second line is a rule that states:
if there exists T, TS such that TS + H results to S, then:
there also exists a list (with head and tail) that results in S
In other words,
this Recursively adds consecutive items in a given list.
Thus, S will be the Sum of all Items in that given list.
The Summation continues until there is no item left to add, thus check([ ], 0). will be true)
Document Page
check([12, 5, 18, 10, 7, 6 ], S).
check([ ], 0). check(T, TS) , S is TS + H.
check([12, 5, 18, 10, 7, 6], S0)
check([5, 18, 10, 7, 6], TS0)
check([18, 10, 7, 6], TS1)
check([10, 7, 6], TS2)
check([6], TS4)
check([7, 6], TS3)
check([],TS5)
TS4 is 0+6
TS2 is 13+10
TS1 is 23+18
TS0 is 41+5
S0 is 46+12
TS3 is 6+7
(ii) Search Tree For Query: check([12, 5, 18, 10, 7, 6 ], S).
Fact1 Rule1
Rule1
no
Rule1
Rule1
Rule1
Rule1
Rule1
Fact1
TS5=0
TS4=6
TS3=13
TS2=23
TS1=41
TS0=46
S0 = 58
Yes
Document Page
Bibliography
Eisenstadt, M., Keane, M. T., & Rajan, T. (2018). Novice programming environments: explorations
in human-computer interaction and artificial intelligence. Routledge.
Lee, K. D. (2017). Logic Programming. In Foundations of Programming Languages (pp. 277-304).
Springer, Cham.
Gavanelli, M. (2017). SLDNF-Draw: Visualization of Prolog operational semantics in LaTeX 1.
Intelligenza Artificiale, 11(1), 81-92.
Matthews, C. (2016). An introduction to natural language processing through Prolog. Routledge.
Riguzzi, F., Bellodi, E., Lamma, E., Zese, R., & Cota, G. (2016). Probabilistic logic programming
on the web. Software: Practice and Experience, 46(10), 1381-1396.
Sharaf, N., Abdennadher, S., & Frühwirth, T. (2017). Using Rules to Animate Prolog Programs.
Sebesta, R. W. (2016). Concepts of programming languages.
Zeshen, W., & Müller, J. C. (2017). A knowledge based system for cartographic symbol design. In
Landmarks in Mapping (pp. 103-116). Routledge.
chevron_up_icon
1 out of 4
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]