ϵ">]>
1. CVIČENIE Z PREDMETU ÚVOD DO DEKLARATÍVNEHO PROGRAMOVANIA
http://ii.fmph.uniba.sk/cl/courses/1-AIN-505-udp/0809ls/ex/ex01.cl
Dátum: pondelok 16. 2. 2009, streda 18. 2. 2009
Odporúčaná verzia CL: 5.81.19
WWW: http://ii.fmph.uniba.sk/cl/courses?lang=sk
Kontakt na vyučujúcich: voda_at_fmph.uniba.sk, kluka_at_fmph.uniba.sk
Assignment 1. Your task is to use CL as a simple calculator for the evaluation of arithmetic expressions in the form of so-called queries. The window Query which appears at the end is designed for the input of queries. The result of a given query will be displayed in the window Results.
Examples of simple queries:
Addition. Query: . CL-syntax is: . Result: true for .
Subtraction (modified). Query: . CL-syntax is: . Result: true for .
Multiplication. Query: . CL-syntax is: . Result: true for .
Integer division (modified). Query: . CL-syntax is: . Result: true for .
Remainder after integer division (modified). Query: . CL-syntax is: . Result: true for .
Further apply these queries:
The last two examples illustrate the following properties of arithmetic operators: , and .
It is possible to evaluate also compound queries (conjunctions of simple queries). E.g.
CL-syntax is:
Result: true for , , and .
Examples of syntactically incorrect queries:
. The variable has not been assigned a value.
. The variable has not been assigned a value.
. The variable has not been assigned a value.
Assignment 2. Your next task is to use CL for the evaluation of arithmetic comparison relations.
Examples of simple queries:
Query: . CL-syntax: . Result: true.
Query: . CL-syntax: . Result: false.
Query: . CL-syntax: . Result: true.
Query: . CL-syntax: . Result: false.
Query: . CL-syntax: . Result: false.
Query: . CL-syntax: . Result: true.
Example of a compound query:
Query: . Result: true.
Examples of syntactically incorrect queries:
. The variable has not been assigned a value.
. The variable has not been assigned a value.
Example. The following component contains a CL-definition (program) of a function which computes the square of the number . Try to evaluate this function for several arguments; e.g. execute the query .
Note. CL identifier conventions:
Function identifier. An alpha-numeric string starting with a capital letter and containing lower case letters, digits, and underline symbols '_'. Example: , , .
Variable identifier. A string of lower case letters possibly followed by one or two digits as indices. Example: , , .
Assignment 3. Your task is to write a definition of a function computing the cube of the number , i.e. .
Insert a new component below this assignment by clicking [Insert].
By a component we mean a remark, a definition or a theorem. In our case, the component is a definition of a function.
Example. We define functions by equations with conditions (so-called clauses or conditional equations). A definition of a function computing the minimum of the numbers and follows:
Here is an example of a syntactically incorrect definition:
The clauses must have identical arguments.
Assignment 5. Define a function computing the maximum of the three numbers , , and . (You may use the previously defined function ).
Assignment 6. (2 marks) Define a function computing the minimum of the three numbers , , and . (You may use the previously defined function ).
Assignment 7. Define a function computing the average of the numbers , , and over natural numbers.
Assignment 9. Define a function computing the median (the middle number) of the numbers , , and .