Constraint Logic Programming

2005--2006



Photographer wanted!
courtesy Mathias Klockenbring (2003-2004)

2003--2004 | 2002--2003 | spring 2002 | spring 2001 | fall 2000 | fall 1999

(PG211)

created 24 January 2006 from year before last, last edition 3 July 2007
Paul Y Gloess


Week by week

Back to Top

Week 1 : Wednesday 25 January 2006 repeated 1 February 2006

TD 1:  Getting started with CHIP using ~gloess/public_html/sudoku/CHIP/sudoku.pl and ~gloess/chip/nat.pl examples;

Lecture 1: Introduction to the module. Presentation of web information (Library, Prolog and Constraint Industry). [Printed version of Slides and Exercise list is available from Ms Françoise Verdier, computer science secretary: these are old versions, but very close to Library documents.]

Evaluation: based upon classical 2 hour final test, with or without taking project into account (?). Motivation: Sudoku problem.

Beginning of: LP, introduction, functional versus relational programming, first order logic syntax and semantics, validity of formulas,

Back to Week by Week or Top

Week 2 : Wednesday 8 February 2006

TD 2: Pure Prolog: exercises VI from sheet (pdf | doc), see also ~gloess/chip/clp/exercices/family.pl; This exercise is about Datalog (a subset or pure Prolog using only predicates and constants (functions of arity 0).
Write only true things!

Lecture 2: End of: LP, introduction to Prolog, Horn clauses, Prolog problem logical semantics, pure Prolog program syntax and semantics (logical, proof tree, least model, fixed point semantics),
A pure Prolog program is a finite representation of a (possibly infinite) set of ground facts. Queries are means of extracting facts.
Back to Week by Week or Top

Week 3 : Wednesday 22 February 2006

Presentation by Dr. Idir Gouachi, from Cosytec:

Back to Week by Week or Top

Week 4 : Wednesday 1 March 2006

TD 4: Pure Prolog exercises on lists (app, mem, rev, revapp, subset) from sheet (pdf | doc), using our own representation of lists, e.g.:
TP 4 (on project): Brief discussion on Sudoku project: students must associate by teams of 3 and send me a mail; most teams will work on generalizing Sudoku to size (N*N, N*N); two teams could work on graphic interface and interaction; interactive Sudoku generation is the ultimate goal of the project.

Back to Week by Week or Top

Week 5 : Wednesday 8 March 2006

TD 5: Constraints: exercise  XVIII from sheet (pdfdoc): 4-queen puzzle, then, generalization to N-queen puzzle, using Prolog to generate constraints. A solution is available in ~gloess/chip/clp/solutions/nqueens.pl.

Lecture 5: Very brief overview of CHIP constraints or builtin predicates needed for the N-queen puzzle:

Back to Week by Week or Top


Week 6 : Wednesday 15 March 2006

Lecture 6: Operational semantics of LP and CLP:
TP 6 : Brief discussion on Sudoku project:
TD 6 : CLP(FD) : SEND+MORE=MONEY:
Back to Week by Week or Top

Week 7 : Wednesday 22 March 2006

Next week I will be in Kumamoto, Japan ...
TP 7Work on Sudoku project. Teams are now formed! All teams should at least provide a general N2*N2 Sudoku solver. This is the basic core of the project: it should not be more difficult than the N-queen solver. Ideas for complementary work:

TD 7Mystery exercise:

Lecture 7: No lecture! You may want to look at Questions and Answers from year 2003-2004, Week 7.

Back to Week by Week or Top



Week 8 : Wednesday 5 April 2006

TP 8Work on Sudoku project. Each team gives an informal 5 minutes presentation of the current state of their work. Some teams have not started yet. One team has almost completed the basic part (general N2*N2 Sudoku solver). Two representations of the Sudoku grid have been proposed by the students:
  1. A flat list of N2*N2 variables, together with access predicates relating an index to the corresponding line, column, or N*N square, or a pair of indexes to the corresponding box;
  2. A list of N2 lines, where each line is a list of N2 variables.
None has chosen the representation I suggested on Week 6: a N*N matrix of N*N matrices of finite domain variables. A M*N matrix is a list of M lines of size N. To those who have not yet started, I suggested the following exercise:

Define a "transpose" predicate such that
transpose(Matrix, MatrixT) means that MatrixT is the transposition of matrix Matrix.
This is a good exercise which may provide a useful predicate for any representation. Implementation may be carried out without using numbers, if one chooses representation 2 or the representation I suggested on Week 6.

Some student questions

  1. Student: How can I check that a given Sudoku, more generally, a given query, has one solution and nomore?
    1. Professor: CHIP (like most Prolog systems) provide two meta-predicates for collecting solutions of a query into a list:
      1. set_of: duplicate solutions are eliminated from the list; the drawback is that "set_of" fails if there is no solution, instead of yielding the empty list;
      2. findall: similar to set_of, but never fails; however, duplicate solutions may be collected in the list;
      3. see ~gloess/chip/clp/solutions/findall.pl for the definition of a "findall_once" predicate that never fails and eliminates duplicate solutions;
    2. Professor: The above solution is not practical, especially in the context of the Sudoku problem, because there may be a huge number of solutions, and we just want to know whether there are two or more. Deciding (efficiently) whether a query has at least two distinct solutions probably requires the use of the dirty "cut" construction, denoted "!". I did not talk about the "cut" in class, because it was mainly introduced for providing "negation by failure" in old Prolog, whereas CLP comes with clean and declarative negative constraints which are sufficient for most purposes. For more information, look at:
      1. ~gloess/chip/clp/exercises/howManyPQ.pl, which implements efficient predicates related to this issue (for a specific "p(X)" or "q(X)" query); this can be easily generalized to any query, using some higher order logic available in CHIP and other Prolog systems;
      2. search tree semantics of the cut slide, for a graphic explanation of  the "pruning" effect of the "cut";
  2. Student: Do all teams have to write a general N2*N2 Sudoku solver? Did not you say that teams could work on different aspects?
    1. Professor: The general N2*N2Sudoku solver is not very difficult to write. I think all teams should work on it. But I also encourage teams to cooperate and work on different complementary aspects (see Week 6 for an outline); it is also true that a team could work on a completary aspect (such as a Sudoku grid generator) before having completed the general N2*N2 Sudoku solver, because my specific general 32*32 Sudoku solver is available for testing purposes;
  3. Students: What do you expect from us as a deliverable?
    1. Professor: I will write a precise description of what I expect from you. This will include:
      1. a directory containing
        1. an "index.html" file with links to a report (html or pdf) and CHIP and/or Java implementation;
        2. a "report" directory containing the report;
        3. a "chip" directory containing all the source CHIP files;
        4. some other directories if needed (for example if there is a Java development);
      2. a presentation and demonstration (30 minutes per team including questions and answers);
      3. I intend to save student directories on this page.
There were some other questions related to graphics in CHIP: I could not answer them as I never used CHIP graphic interface. Other questions dealt with the use of rational constraints for some computations that were supposed to yield natural numbers (representing indexes in a matrix) but sometimes produced rational numbers! I could only suggest to use rational constraints for computations as mich as possible, because they are simpler to manage than finite domain constraints (no declaration, no labeling). One may nevertheless be forced to use finite domain constraints for some integer computations, because there are obviously more solutions among rational numbers that among integers or natural numbers.

Some useful CHIP programs

Back to Week by Week or Top


Week 9 : Wednesday 12 April 2006

TD 9: Believe in Pure Prolog power: example of compiler design, see ~gloess/chip/solutions/compiler.pl: read and test and explain the semantics of "expression" and other (undocumented) predicates.

TP 9
Work on Sudoku project. Questions:

Some useful CHIP programs or examples


Back to Week by Week or Top


Week 10 : Wednesday 26 April 2006

TD 10: Believe in Pure Prolog power: example of compiler design, see ~gloess/chip/solutions/compiler.pl: read and test and explain the semantics of "expression" and other (undocumented) predicates. Search trees again: test ~gloess/chip/exercises/revapp.pl: draw a search tree (see comments).

TP 10
Work on Sudoku project. Questions:

Recall some useful CHIP programs or examples.

Back to Week by Week or Top


Library

We are still in the early times of computer science, where computer scientists struggle with incompatible environments and chaotic computer programs, and make the whole thing even worse by inventing as many "portable" formats as environments. None of these formats deserves this qualifier: they all tend toward an approximation of a truth which yet has to be revealed!
 
Document
Original
Html
PDF
(Acrobat)
Color Postscript 
Black&White Postscript
Logic Programming
lp.ppt (new)
(animation)
lp.htm (new, OK with Internet Explorer only)
lp.htm (old, OK with any browser)

(inanimated)
 lp.pdf (new)
lp.ps (old) *
lp.bw.ps (old) *
Constraint Logic Programming
clp.ppt
(animation)
clp.htm
(inanimated)
 clp.pdf
clp.ps *
clp.bw.ps *
Correctness of Resolution
Resolution.doc
(Word)
 
Resolution.pdf
Resolution_Adobe.pdf
 
Resolution.ps
Resolution_Adobe.ps
CLP Final test
23 May 2006
see CLP Final test 23 May 2006
TD exercises
handout
exercises.doc
(Word)
 
 exercises.pdf
 
exercises.ps
TD exercises
and programs
td_exercises
 
 
 
 
CHIP exercise
directory
~gloess/chip/clp/exercises/
 
 
 
 
Solution of exercise I
solution_I.doc
(Word)
 
solution_I.pdf
 
solution_I.ps
Solution to mystery
Mystery/
(JPG pictures)
 
 
 
 
Solution to revapp
revapp/
(JPG pictures)
 
 
 
 
CHIP solution
directory
~gloess/chip/clp/solutions/
 
 
 
 
Getting started
with CHIP
Getting started with CHIP
 
 
 
 
Chip Documentation
by Cosytec
 
local CHIP on-line documentation
 
 
 

Use ghostview with Landscape orientation and letter format.

Acrobat Reader: for easy access through your navigator, edit your preferences and associate "acroread %s" handler with "Portable Document Format" application.

Back to Top


Project

Why not a Sudoku project this year?

Student teams and work.

Deliverable see additional ".htaccess" request 16 May 2006!

Public defence

A project defence will be held in room I115, on Wednesday 17 May 2006, starting at 8:30am:

Back to Top


Prolog and Constraint Industry

Back to Top

© Copyright 1999-3000 Paul Y Gloess