☰ Functional and Logic Programming
Instructors
- Lecture
- Prof.dr. Horia F. Pop, Email:
- Seminars
- Lect.dr. Alina Călin, Email:
- Lect.dr. Horea Muresan, Email:
- Lect.dr. Zsuzsanna Onet-Marian, Email:
- Labs
- Lect.dr. Zsuzsanna Onet-Marian, Email:
- Drd. Sara Boanca, Email:
- Drd. Daria Marc, Email:
- Drd. Daniel Pop, Email:
- Drd. Melisa Sarkozi, Email:
- Ms Roberta Fabian, Email:
Objectives
- The purpose of this lecture is to realize an introduction to the study of functional and logic programming as an alternative to imperative programming, through the languages Lisp and Prolog, useful to those working in the field of Artificial Intelligence.
- To introduce two new programming paradigms (functional programming and logic programming).
- To introduce a programming language for each paradigm (Common Lisp and Prolog) and to familiarize the students with the principles of functional and logic programming.
- To introduce the idea of using these paradigms based on applications necessities.
- To provide the necessary basis to allow learning advanced lectures.
- The Common Lisp interpreters recommended in this class are SBCL or CLisp.
- The Prolog interpreter recommended in this class is SWI Prolog.
Final grade
- 60% - Written graded paper
- 15% - Practical test in Prolog
- 15% - Practical test in Lisp
- 10% - Programs documentation and delivery
- 5% - BONUS - Evaluation of seminaries activity
Minimal passing criteria
- minimum grade of 5 at the written graded paper
- minimum final grade of 5
If the final grade is less than 5 while at least one of the activities (written evaluations, practical tests) was absented, the final mark will be absent, and not failed. The final grade will be determined during the retake session.
Class activities
All activities require physical class participation. This is a full attendance, not a distance learning program.
According to the National Education Act (1/2011), the recording of didactical activity by any means is only possible by explicit agreement of the teaching person. Consequently, no recording of any didactical activity, by any means and on any support, is allowed.
The Teams class access code is r6h7r85.
The seminars and labs attendance sheet is available here. The identification code is the unique code from Academic Info.
Contents
Introduction
- Programming and programming languages. Imperative programming vs. declarative programming. Introduction
Logic Programming. The PROLOG programming language
- Basic elements of Prolog. Facts and rules in Prolog. Goals. The control strategy in Prolog. Variables and composed propositions. Anonymous variables. Rules for matching. The flux model. Sections of a Prolog program. Examples.
- The Prolog program. Predefined domains. Internal and external goals. Multiple arity predicates. The IF symbol (Prolog) and the IF instruction (other languages). Compiler directives. Arithmetic expressions and comparisons. Input/output operations. Strings.
- Backtracking. The backtracking control. The "fail" and "!"(cut) predicates. Using the "!" predicate. Type of cuts. The "not" predicate. Lists in Prolog. Recursion. Examples for backtracking in Prolog. Finding all solutions in the same time. Examples of predicates in Prolog. Non-deterministic predicates.
- Composed objects and functors. Unifying composed objects. Arguments of multiple types; heterogeneous lists. Comparisons for composed objects. Backtracking with cycles. Examples of recursive procedures. The stack frame. Optimization using the "tail recursion". Using the "cut" predicate in order to keep the "tail recursion".
- Recursive data structures. Trees as data structures. Creating and transversing a tree. Search trees. The internal database of Prolog. The "database" section. Declaration of the internal database. Predicates concerning operations with the internal database.
- Advanced issues on backtracking and efficiency in Prolog.
- Files management in Prolog. Elements of graphic.
Functional Programming. The LISP programming language
- Basic elements in Lisp. Dynamic data structures. Syntactic and semantic rules. Functions' classification in Lisp. Primitive functions in Lisp. Basic predicates in Lisp. Predicates for lists; for numbers. Logic and arithmetic functions. Defining user functions. The conditional form. The collecting variable method. Examples.
- Symbols management. Other functions for lists' accessing. OBLIST and ALIST. Destructive functions. Comparisons. Other interesting functions. Examples.
- Definitional mechanisms. The EVAL form. Functional forms; the functions FUNCALL and APPLY. LAMBDA expressions, LABEL expressions. Generators, functional arguments. MAP functions. Iterative forms. Examples.
- Other elements in Lisp. Data structures. Macro-definitions. Optional arguments. Examples.
Other skills
- Other functional and logic languages. Versions of LISP. Versions of PROLOG.
- Examples of applications. Programs presented comparatively in Lisp, Prolog and in imperative languages. Specific applications.
Bibliography
- Gabriela Czibula, H.F. Pop, Elemente Avansate de Programare in Lisp si Prolog. Aplicatii in Inteligenta Artificiala, Editura Albastra, Cluj, 2012
Other references
- A. Field, Functional Programming, Addison Wesley, 1988
- C. Giumale et. al., LISP, 2 Volume, Editura Tehnica,1987
- C. J. Hogger, Introduction to Logic Programming, Academic Press, 1984
- B. Parv, A. Vancea, Fundamentele limbajelor de programare, Litografia Universitatii "Babes-Bolyai" ~Cluj-Napoca, 1992
- H. F. Pop, Gabriela Serban, Programare in Inteligenta Artificiala - Limbajele Lisp si Prolog, Editura Albastra, Cluj, 2003
- H. F. Pop, Programare Functionala si Logica, Litografia Universitatii "Babes-Bolyai", 1998
- C. Reede, Elements of Functional Programming, Addison Wesley, 1989
- I. Streinu, LISP, Editura Stiintifica si Enciclopedica, 1986
- A. Walker et. al., Knowledge Systems and Prolog. A Logical Approach to Expert Systems and Natural Processing, Addison Wesley, 1987
- P. H. Winston, Lisp, Addison Wesley, 1984, 2nd edition
- P. H. Winston, Artificial Intelligence, Addison Wesley, 1984, 2nd edition
- P. Flach, Simply Logical Intelligent reasoning by Example, John Wiley & Sons, Chichester, England, 1994
- Documentatia implementarilor Common Lisp
- Documentatia implementarilor Prolog
- http://www.ifcomputer.com/IFProlog/home_en.html
- http://www.lpa.co.uk - Logic Programming
Course schedule
- Week 1: Introduction. Recursion
- Weeks 2-6: Logic programming with Prolog
- Weeks 7-12: Functional programming with Lisp
- Weeks 13-14: Final written test paper
- Due to the National Holiday celebrations, there will be no classes on 30/11 and 1/12.
Lab schedule
| Lab | | Lab topic |
| receive | deliver |
| 1 | 1 | R1 | Recursive programming |
| 1 | 2 | P1 | Prolog Lists |
| 2 | 3 | P2 | Prolog Heterogeneous Lists |
| 3 | 4 | P3 | Using backtracking in Prolog |
| | 4 | | Practical test in Prolog (one hour) |
| 4 | 5 | L1 | Recursive programming in Lisp (1) |
| 5 | 6 | L2 | Recursive programming in Lisp (2) |
| 6 | 7 | L3 | Using Map functions in Lisp |
| | 7 | | Practical test in Lisp (one hour) |
- The scheduling situations due to the National Holiday celebrations will be dealt with accordingly by the laboratory teacher.
Lecture notes
- Lecture notes and other resources are available on the UBB Sharepoint platform.
- Please understand that the lecture notes will be posted here AFTER the class.
Software and resources for Prolog
Software
SWI-Prolog
Resources
Software and resources for Lisp
Software
GNU CLisp
Steel Bank Common Lisp
Resources
Written test paper
The written test paper will take place during the last two weeks of school. Specific details on how the written test will take place will be communicated later.
This is not an exam, but a written test organized as part of a colloquium assessment. As such, the students will participate at the test at the specific date the test is offered for each of them, as scheduled. There are no exceptions.
Seminar attendance requirements
Attendance at seminar activities is compulsory in proportion of 75% (minimum 5 seminars out of 7).
The seminar attendance may be redone with another group inside the two weeks allocated to that seminar, with the explicit agreement of the seminar instructor (pending space availability).
The students without minimum 5 attendances at seminar activities CANNOT participate to the written paper (during weeks 13-14 and during the resit session) and CANNOT get a passing grade.
Lab attendance requirements
Attendance at lab activities is compulsory in proportion of 90% (minimum 6 seminars out of 7).
The lab attendance may be redone for at most one lab, during the two weeks allocated to that lab, with the explicit agreement of the lab instructor (pending space availability), but the lab doc is graded in the usual way, considering the delay penalty.
In case of illness, the absence is justified to the lab instructor based on medical evidence only. Medical documentation will be provided with a maximum delay of one week after the missed event.
The students without minimum 6 attendances at laboratory activities CANNOT participate to the written paper (during weeks 13-14 and during the resit session) and CANNOT get a passing grade.
Lab papers grading and submission
Each lab paper is evaluated with a grade from 1 to 10 in the following way:
- 2 points: formal descriptions and explanations of recursive models
- PROLOG - recursive models and flow models of all predicates used, meaning of all predicate parameters
- LISP - mathematical models (recursive formulas describing functions), meaning of all function parameters
- 0.50 points: source code in Prolog/Lisp for all predicates / functions
- 0.50 points: testing examples covering as many testing cases as possible, for the essential predicates / functions
- 1 points: execution verification of the written program
- 6 points:
- explanations of the written algorithm, recursive models, source code
- extra requirement to change the code, solved on the spot
A copied lab paper means cheating and will be graded with 0 (zero).
If a lab paper is submitted with another lab subgroup inside the same two weeks frame, the lab grade is multiplied by 0.8; if the submission is delayed one lab, the lab grade is multiplied by 0.6; if the delay is larger than one lab, the final grade is 0 (zero).
At most two lab themes may be delivered during one lab class. As well, the Prolog labs may be delivered until no later than ween 7/8.
The lab grade will be determined as the average of the grades of all the lab works. If a lab doc is not delivered, its grade is 0.
Resit session
In the resit session the same grading algorithm will apply.
- students with an attendance of less than 5 seminars and 6 labs CANNOT participate in the resit session.
- the labs cannot be submitted during the resit session;
- only the written test paper can be taken during the resit session;
- for grade increases only the written test paper can be taken.
© Prof.dr. Horia F. Pop