Вы находитесь на странице: 1из 15

Cours de programmation logique

Prolog
Rahim Messaoud
Rahim.messaoud@univ-medea.dz

2015/2016
Objectifs du cours
Objectifs thoriques
Apprendre un nouveau mode de programmation la
programmation logique .
Apprendre la syntaxe et la smantique de Prolog.
Utiliser Prolog pour rsoudre des problmes de
programmation.
Objectifs pratiques
Mettre en pratique les concepts de programmation logique.
Dvelopper des programmes Prolog.
Organisation du cours
1 Cours + 1 TP/semaine
Transparents et informations diverses sur la plateforme de
tl-enseignement de luniversit de Mda.
Mail : Rahim_mes@yahoo.fr/rahim.messaoud@univ-medea.dz
Plan du cours
Introduction la programmation logique et Prolog
Les bases du langage Prolog
Aspects avancs du langage Prolog
Les listes en Prolog
Les arbres en Prolog
Bibliographie
W.F. Clocksin, C.S. Mellish, Programmer en Prolog .
Editions Eyrolles 1985
Hoogger, Programmer en logique . Masson, 1987
CONDILLAC, Prolog : Fondements et Applications .
Editions Masson.
Les fondements de la programmation en logique de J. W. Lloyd
Prolog de F. Giannesini, H. Kanoui, R. Pasero et M. Van
Caneghem
Chapitre 3:
Les listes enProlog
Plan
Dfinition
Notations
Manipulation de listes
Applications
Dfinition
Une liste en prolog est un terme compos.
Le symbole de fonction . darit 2 est le symbole de
composition.
Le premier argument est llment de tte de la liste, et le
deuxime argument est la queue (le reste) de la liste.
A une suite, ordonne ou non, on associe la liste de ses
lments.
Exemples:
suite {e1, e2, } ==> liste (e1.(e2.()))
suite des variables X et Y ==> (X.Y)
suite {gateau, fruit, glace} ==>(gateau.(fruit.glace))
8 Concepts algorithmiques
Notations
La liste vide est note nil . Elle sert souvent marquer
la fin de liste. Elle est galement note [] .
La liste (X.L) est galement note [X|L],
La liste (X1.(X2.(L)) est galement note [X1,
X2|L],
La liste (X1.(X2. , .(Xn.(L))) est galement
note [X1, X2, , Xn|L],
La liste [X1, X2, , Xn| []] est galement note
[X1, X2, , Xn].
Remarques
[1,2,3] et [2,1,3] sont deux listes diffrentes.

9 Concepts algorithmiques
Manipulation des listes
Prdicat membre : membre (X, L) est vrai, si X est un lment de L.
membre(X,[X|_H]).
membre(X,[_Y|H]) :- membre(X,H).
Prdicat longueur : il sagit de retourner le nombre dlments contenant
dans une liste;
longueur([],0).
longueur([_|L],N):-longueur(L,N1), N is N1+1.
Prdicat concat : concat(L1, L2, L3) est vrai, si L3 est la concatnation des
deux listes L1 et L2.
concat([], L, L).
concat( [A|S], L, [A|R]) :- concat(S, L, R).

Remarque
attention ! concat boucle quand on l'appelle avec son premier
et son troisime paramtres variables libres
! i.e. ne demandez donc jamais concat(X, [a, b, c], Y) !

10 Concepts algorithmiques
Applications
Prdicat membre : membre (X, L) est vrai, si X est un lment de L.
membre(X,[X|_H]).
membre(X,[_Y|H]) :- membre(X,H).
Prdicat longueur : il sagit de retourner le nombre dlments contenant
dans une liste;
longueur([],0).
longueur([_|L],N):-longueur(L,N1), N is N1+1.
Prdicat concat : concat(L1, L2, L3) est vrai, si L3 est la concatnation des
deux listes L1 et L2.
concat([], L, L).
concat( [A|S], L, [A|R]) :- concat(S, L, R).

Remarque
attention ! concat boucle quand on l'appelle avec son premier
et son troisime paramtres variables libres
! i.e. ne demandez donc jamais concat(X, [a, b, c], Y) !

11 Concepts algorithmiques
Les Matrices
Une matrice de taille nxn peut tre reprsente par des listes de
listes sur n niveaux
Exemple
1 2 3
M= 4 5 6 [[1,2,3], [4,5,6], [7, 8, 9]]
7 8 9

Exercice
Retournez le maximum dune liste dentier (max(L, M))
max([X], X).
max([X,Y|L], X) :-max([Y|L], M), X>=M.
max([X,Y|L], M) :-max([Y|L], M), M>X.

12 Concepts algorithmiques
Les arbres
Arbre binaire
Reprsentation
Un arbre vide sera reprsent par la liste vide [].
Un nud sera reprsent par une liste de 3 lments :
Le premier est sa valeur (R) Nud [R,G,D]
Le deuxime son fils gauche (G) ou
Nud [R|[G,D]]
Le troisime son fils droit (D)
Exemple
6
[6,[4,[1,[],[]],[8,[],[]]],[9, [],[]]]
4 9
[6|[[4|[1,8]],9]]
1 8

13 Concepts algorithmiques
Les arbres
Oprations
Somme des valeurs binaires : Somme(L,N) est vrai si N est
la somme de toutes les valeurs de larbre reprsent par la liste L.
somme([], 0).
somme([R,G,D], N) :-somme(G, N1), somme(D, N2),
N is R+N1+N2.
Ajout 1 tous les nuds dun arbre
ajout1([], []).
ajout1([R,G,D], [R1, G1, D1]) :-R1 is R+1,
ajout1(G, G1), ajout1(D, D1).

Exercice : crire les prdicats qui permettent de parcourir un


arbre en profondeur et en largeur.
14 Concepts algorithmiques
Les arbres
Arbre de recherche binaire (ARB) : Pour tout nud r de ARB,
pour tout nud g appartenant au fils gauches de r et pour tout nud
d appartenant au fils droit de r : gr<d
Oprations
Vrification si un arbre donn est un ARB
arb([]).
arb([R]).
arb([R,G,D]):-arb(G), G\=[], max(G)<=R, arb(D),
D\=[], R<min(D).

Minimum dun ARB


min([R], R).
min([R,[],_], R).
min([_,G,_],M) :-G\=[], min(G, M).

15 Concepts algorithmiques

Вам также может понравиться

  • Équations différentielles: Les Grands Articles d'Universalis
    Équations différentielles: Les Grands Articles d'Universalis
    От Everand
    Équations différentielles: Les Grands Articles d'Universalis
    Оценок пока нет
  • Exercices Et Problemes
    Exercices Et Problemes
    Документ12 страниц
    Exercices Et Problemes
    akrep23
    Оценок пока нет
  • Structure
    Structure
    Документ22 страницы
    Structure
    MOUNIR HLALI
    Оценок пока нет
  • TP3 Correction
    TP3 Correction
    Документ2 страницы
    TP3 Correction
    Nihed Jebali
    Оценок пока нет
  • TD3 - Corr Listes
    TD3 - Corr Listes
    Документ2 страницы
    TD3 - Corr Listes
    Ameni Boughanmi
    Оценок пока нет
  • Prolog Cours3
    Prolog Cours3
    Документ57 страниц
    Prolog Cours3
    Ali Yussuf
    Оценок пока нет
  • Safari - 1 Mai 2021 À 13:47
    Safari - 1 Mai 2021 À 13:47
    Документ1 страница
    Safari - 1 Mai 2021 À 13:47
    frank elebeng
    Оценок пока нет
  • R Cours5
    R Cours5
    Документ15 страниц
    R Cours5
    diarrassouba kolotieloma
    Оценок пока нет
  • Prolog SUPERFICHE
    Prolog SUPERFICHE
    Документ9 страниц
    Prolog SUPERFICHE
    Brahim Adama Abanda
    Оценок пока нет
  • CoursIA Prolog Partie2
    CoursIA Prolog Partie2
    Документ15 страниц
    CoursIA Prolog Partie2
    yap
    Оценок пока нет
  • Safari - 1 Mai 2021 À 13:49
    Safari - 1 Mai 2021 À 13:49
    Документ1 страница
    Safari - 1 Mai 2021 À 13:49
    frank elebeng
    Оценок пока нет
  • Data Mining (Partie 2)
    Data Mining (Partie 2)
    Документ56 страниц
    Data Mining (Partie 2)
    Wail Choukhairi
    Оценок пока нет
  • Tp2-Les Listes
    Tp2-Les Listes
    Документ3 страницы
    Tp2-Les Listes
    Nihed Jebali
    Оценок пока нет
  • Lambda Map
    Lambda Map
    Документ11 страниц
    Lambda Map
    Douaa Elachhab
    Оценок пока нет
  • Exos
    Exos
    Документ4 страницы
    Exos
    houssam houssam
    Оценок пока нет
  • Guide Langage R
    Guide Langage R
    Документ30 страниц
    Guide Langage R
    Barnicha Hafsa
    Оценок пока нет
  • Cours Prolog 3
    Cours Prolog 3
    Документ25 страниц
    Cours Prolog 3
    Li li
    Оценок пока нет
  • Suite Prolog
    Suite Prolog
    Документ25 страниц
    Suite Prolog
    Nihed Jebali
    Оценок пока нет
  • 1PRO
    1PRO
    Документ48 страниц
    1PRO
    arounekoumar
    Оценок пока нет
  • Python Resume Revisions PDF
    Python Resume Revisions PDF
    Документ5 страниц
    Python Resume Revisions PDF
    Soufiane
    Оценок пока нет
  • Resume Python
    Resume Python
    Документ11 страниц
    Resume Python
    Khouloud Sassi
    Оценок пока нет
  • Document 2.saif
    Document 2.saif
    Документ4 страницы
    Document 2.saif
    Seif Guetiti
    Оценок пока нет
  • Résumé Python
    Résumé Python
    Документ11 страниц
    Résumé Python
    rinemzammit
    Оценок пока нет
  • PrologTD3 2020
    PrologTD3 2020
    Документ2 страницы
    PrologTD3 2020
    Ali Yussuf
    Оценок пока нет
  • TP2 - Les Listes en Python
    TP2 - Les Listes en Python
    Документ4 страницы
    TP2 - Les Listes en Python
    HAMZA TAHIRI
    Оценок пока нет
  • tp2 PDF
    tp2 PDF
    Документ10 страниц
    tp2 PDF
    SK RUODA
    Оценок пока нет
  • Compte Rendu TP 1.seif
    Compte Rendu TP 1.seif
    Документ8 страниц
    Compte Rendu TP 1.seif
    Seif Guetiti
    Оценок пока нет
  • Leçon 4 Programmation Logique
    Leçon 4 Programmation Logique
    Документ12 страниц
    Leçon 4 Programmation Logique
    DAHA
    Оценок пока нет
  • Compte Rendu
    Compte Rendu
    Документ5 страниц
    Compte Rendu
    Amal Rebei
    Оценок пока нет
  • Prolog TP
    Prolog TP
    Документ13 страниц
    Prolog TP
    Hadj Ben Aichouche Maroua C1 B1
    Оценок пока нет
  • Cours Prolog 5
    Cours Prolog 5
    Документ52 страницы
    Cours Prolog 5
    Li li
    Оценок пока нет
  • WWW - Cours Gratuit - Com CoursAir Id5364
    WWW - Cours Gratuit - Com CoursAir Id5364
    Документ124 страницы
    WWW - Cours Gratuit - Com CoursAir Id5364
    Ferdaous Hd
    Оценок пока нет
  • TP2 Correction
    TP2 Correction
    Документ2 страницы
    TP2 Correction
    Hedir Ben Moussa
    Оценок пока нет
  • Serie 5 Et 6
    Serie 5 Et 6
    Документ2 страницы
    Serie 5 Et 6
    Bakiss
    Оценок пока нет
  • NOTES Matlab PDF
    NOTES Matlab PDF
    Документ5 страниц
    NOTES Matlab PDF
    Mustapha El Metoui
    Оценок пока нет
  • TP N3 PDF
    TP N3 PDF
    Документ2 страницы
    TP N3 PDF
    RABAH ABBAS
    Оценок пока нет
  • Listes Comprehension
    Listes Comprehension
    Документ8 страниц
    Listes Comprehension
    Louk Hoogenraaf
    Оценок пока нет
  • Sciences Des Données Appliquées (Fondamentales) : Cours 4
    Sciences Des Données Appliquées (Fondamentales) : Cours 4
    Документ62 страницы
    Sciences Des Données Appliquées (Fondamentales) : Cours 4
    Oumayma ISMAAILI
    Оценок пока нет
  • Exercice 2
    Exercice 2
    Документ2 страницы
    Exercice 2
    ezio bilal7
    Оценок пока нет
  • TP 1
    TP 1
    Документ4 страницы
    TP 1
    Lamethyste
    Оценок пока нет
  • 852 Correc TPfichiers 2017
    852 Correc TPfichiers 2017
    Документ10 страниц
    852 Correc TPfichiers 2017
    noussa79
    Оценок пока нет
  • Fiche N2 Bis Leslistes
    Fiche N2 Bis Leslistes
    Документ6 страниц
    Fiche N2 Bis Leslistes
    nathalie daniel
    Оценок пока нет
  • TP Synthese Python
    TP Synthese Python
    Документ28 страниц
    TP Synthese Python
    abouqora
    Оценок пока нет
  • Listes
    Listes
    Документ4 страницы
    Listes
    Presta
    Оценок пока нет
  • tp1 2013
    tp1 2013
    Документ5 страниц
    tp1 2013
    loic
    Оценок пока нет
  • Cours Matlab2
    Cours Matlab2
    Документ26 страниц
    Cours Matlab2
    Yassine EL FAKHAOUI
    Оценок пока нет
  • Résumé de MATLAB Onramp
    Résumé de MATLAB Onramp
    Документ3 страницы
    Résumé de MATLAB Onramp
    Mustapha Ait sidi ben lahcen lamrani
    Оценок пока нет
  • Algo Voyageur de Commerce
    Algo Voyageur de Commerce
    Документ12 страниц
    Algo Voyageur de Commerce
    ZANKOU MESSAN JEAN PIERRE
    Оценок пока нет
  • 3 Python Les Collections
    3 Python Les Collections
    Документ11 страниц
    3 Python Les Collections
    Mohamed Khefacha
    Оценок пока нет
  • Chapitre Itérable
    Chapitre Itérable
    Документ48 страниц
    Chapitre Itérable
    Ahmed Mohamed
    Оценок пока нет
  • Mod Elisation Et M Ethodes Num Eriques Pour Les Sciences Du Vivant. TP1 - Initiation
    Mod Elisation Et M Ethodes Num Eriques Pour Les Sciences Du Vivant. TP1 - Initiation
    Документ11 страниц
    Mod Elisation Et M Ethodes Num Eriques Pour Les Sciences Du Vivant. TP1 - Initiation
    oscar chambaud
    Оценок пока нет
  • Exam Compil 2015
    Exam Compil 2015
    Документ5 страниц
    Exam Compil 2015
    Nahrawess Slama
    Оценок пока нет
  • TP1 Exercices Correction
    TP1 Exercices Correction
    Документ18 страниц
    TP1 Exercices Correction
    Mustapha Elkabous
    100% (1)
  • Initiation Python
    Initiation Python
    Документ2 страницы
    Initiation Python
    hanane
    Оценок пока нет
  • Sérien 1
    Sérien 1
    Документ4 страницы
    Sérien 1
    Robert Haba
    Оценок пока нет
  • Chap 4
    Chap 4
    Документ9 страниц
    Chap 4
    GT
    Оценок пока нет
  • Les Listes
    Les Listes
    Документ3 страницы
    Les Listes
    Fatma Ben Dhaou
    100% (1)
  • Série Dexercices 02
    Série Dexercices 02
    Документ1 страница
    Série Dexercices 02
    vbzrg
    Оценок пока нет
  • Scheme Doctor Racket
    Scheme Doctor Racket
    Документ21 страница
    Scheme Doctor Racket
    renaud
    Оценок пока нет
  • TP TSS 1 PDF
    TP TSS 1 PDF
    Документ2 страницы
    TP TSS 1 PDF
    No face
    Оценок пока нет
  • Meth Et 08 PDF
    Meth Et 08 PDF
    Документ15 страниц
    Meth Et 08 PDF
    AbdelkhalekBenOmar
    Оценок пока нет
  • CH04 Analyse Descendante
    CH04 Analyse Descendante
    Документ40 страниц
    CH04 Analyse Descendante
    elmoundhir loucif
    Оценок пока нет
  • 03 Les Chaines de Caractères7421337488772115259
    03 Les Chaines de Caractères7421337488772115259
    Документ4 страницы
    03 Les Chaines de Caractères7421337488772115259
    Fateh Didi
    Оценок пока нет
  • Chapitre 4 Logiques Et Techniques de Démontration en Mathématiques
    Chapitre 4 Logiques Et Techniques de Démontration en Mathématiques
    Документ7 страниц
    Chapitre 4 Logiques Et Techniques de Démontration en Mathématiques
    Adjii Rassoul
    Оценок пока нет
  • LangageSQL 4p
    LangageSQL 4p
    Документ16 страниц
    LangageSQL 4p
    Bahaa Eddine Eddine
    Оценок пока нет
  • Cours Compilation
    Cours Compilation
    Документ45 страниц
    Cours Compilation
    echafai
    Оценок пока нет
  • Présentation Compilation AFD
    Présentation Compilation AFD
    Документ9 страниц
    Présentation Compilation AFD
    sss
    Оценок пока нет
  • Cours Compilation
    Cours Compilation
    Документ61 страница
    Cours Compilation
    chfakht
    Оценок пока нет
  • Algorithmique Avancée Introduction PDF
    Algorithmique Avancée Introduction PDF
    Документ22 страницы
    Algorithmique Avancée Introduction PDF
    فركوس محمد العيد
    Оценок пока нет
  • Chapitre 6 Langage SQL
    Chapitre 6 Langage SQL
    Документ27 страниц
    Chapitre 6 Langage SQL
    Dean Zouari
    Оценок пока нет
  • TLA Chap2
    TLA Chap2
    Документ77 страниц
    TLA Chap2
    eya benhjaal
    Оценок пока нет
  • Revisions Logique Combinatoire
    Revisions Logique Combinatoire
    Документ20 страниц
    Revisions Logique Combinatoire
    Kamel Tayahi
    100% (1)
  • Support Algo POO
    Support Algo POO
    Документ284 страницы
    Support Algo POO
    Momo Abdellatif
    Оценок пока нет
  • Logique PDF
    Logique PDF
    Документ8 страниц
    Logique PDF
    OMAR SECK
    Оценок пока нет
  • Recursiviteeeeeeeeee 120820172712 Phpapp01
    Recursiviteeeeeeeeee 120820172712 Phpapp01
    Документ10 страниц
    Recursiviteeeeeeeeee 120820172712 Phpapp01
    AzZa
    Оценок пока нет
  • Mathématique Pour Économiste
    Mathématique Pour Économiste
    Документ22 страницы
    Mathématique Pour Économiste
    Ohouo Silvatanulo Emmanuel
    Оценок пока нет
  • TD 3
    TD 3
    Документ2 страницы
    TD 3
    Lahcen Lahcen
    100% (1)
  • 1 Generalites Econometrie PDF
    1 Generalites Econometrie PDF
    Документ28 страниц
    1 Generalites Econometrie PDF
    ezouine
    Оценок пока нет
  • Fibonacci
    Fibonacci
    Документ20 страниц
    Fibonacci
    wallman
    Оценок пока нет
  • THL Serie1 2015
    THL Serie1 2015
    Документ2 страницы
    THL Serie1 2015
    Nesrine Azaiez
    100% (2)
  • TD 1 Comil Corr
    TD 1 Comil Corr
    Документ5 страниц
    TD 1 Comil Corr
    Hamdi Rabeh
    Оценок пока нет
  • 02 - Grammaires Cours THL
    02 - Grammaires Cours THL
    Документ42 страницы
    02 - Grammaires Cours THL
    THE SINAN
    Оценок пока нет
  • Alphabet Langage
    Alphabet Langage
    Документ29 страниц
    Alphabet Langage
    Daoud Djamel
    Оценок пока нет
  • Chap8 Good
    Chap8 Good
    Документ29 страниц
    Chap8 Good
    mln35
    Оценок пока нет
  • X Ens Informatique 2016 MP Option Info Corrige
    X Ens Informatique 2016 MP Option Info Corrige
    Документ10 страниц
    X Ens Informatique 2016 MP Option Info Corrige
    Hassan Façoiti
    Оценок пока нет
  • TD Gram LL
    TD Gram LL
    Документ2 страницы
    TD Gram LL
    Fred Ndjateng
    Оценок пока нет
  • 14) Analyse Syntaxique
    14) Analyse Syntaxique
    Документ39 страниц
    14) Analyse Syntaxique
    issam.benmhammed
    Оценок пока нет
  • Fondements Des Mathématiques PDF
    Fondements Des Mathématiques PDF
    Документ21 страница
    Fondements Des Mathématiques PDF
    wesh007
    Оценок пока нет
  • Chapitre1 PDF
    Chapitre1 PDF
    Документ6 страниц
    Chapitre1 PDF
    Ahmed Brahem
    Оценок пока нет
  • C1&C2 - MotsLangages
    C1&C2 - MotsLangages
    Документ36 страниц
    C1&C2 - MotsLangages
    cherif haidara
    Оценок пока нет