[PDF] PREMIERS PAS EN PROLOG Clocksin Mellish





Previous PDF Next PDF



PREMIERS PAS EN PROLOG

Clocksin Mellish



Prolog-cours1.pdf

20 avr. 2020 Plan du cours. 1 – Introduction à la programmation logique. 2 – Le langage Prolog. 3 – Les listes. 4 – Les graphes et les arbres en Prolog.



PROLOG: concepts de base

26 mars 2018 UN LANGAGE DÉCLARATIF ET UNE SÉMANTIQUE. LOGIQUE. Programmer en logique = Décrire l'univers du problème. • Programme Prolog = Ensemble de ...



Chapitre 1 Introduction `a Prolog

Prolog est un langage de programmation basé sur la logique du premier Un programme Prolog se présente comme une suite de r`egles ou clauses de la forme.



Le langage Prolog

Prolog est un langage de programmation déclarative qui repose sur la logique des prédicats restreinte aux clauses de Horn. Prolog ? Programmation en logique.



Support de cours Programmation logique: PROLOG

Introduction à la programmation logique : langage PROLOG. II. Principales caractéristiques de ce type de programmation. III. Syntaxe et structures de données – 



Cours n°5 Grammaire et automates en langage Prolog

Constitué des symboles terminaux du langage. ? V. N. : vocabulaire non terminal. N'a rien à voir avec 



LE LANGAGE PROLOG

Prolog est un langage de programmation qui a comme base deux principes associés `a la logique : – un programme est un ensemble de r`egles (communément appelées 



PROLOG

Comme langage de programmation Prolog utilise un formalisme dif- férent des autres langages de programmation pour l'écriture des programmes et la définition 



Étude du langage de programmation prologue

Pour cela on se restreint à des formules du type de Horn : le langage Prolog peut alors être vu comme un ensemble de clause de Horn.



Introduction to Prolog Programming - Universiteit van Amsterdam

Prolog (programming in logic) is one of the classical programming languages developed speci cally for applications in AI As opposed to imperative languages such as C or Java (the latter of which also happens to be object-oriented) it is a declarative programming language



Prolog Language - riptutorialcom

Prolog is a language that is useful for doing symbolic and logic-based computation It?s declarative: very different from imperative style programming like Java C++ Python A program is partly like a database but much more powerful since we can also have general rulesto infer new facts!



Prolog Language - riptutorialcom

You can share this PDF with anyone you feel could benefit from it downloaded the latest version from: prolog-language It is an unofficial and free Prolog Language ebook created for educational purposes All the content is extracted from Stack Overflow Documentation which is written by many hardworking individuals at Stack Overflow



Prolog Step-by-Step - School of Informatics University of

Prolog is a high-level logic programming language (PROgramming in LOGic); Good at pattern matching (by uni?cation) and searching; Not very good for repetitive number crunching; Excellent for language processing rule-based expert systems planning and other AI applications;



Searches related to langage prolog pdf PDF

Prolog is known to be a di?cult language to master It does not have the familiar control primitives used by languages like RATFOR ALGOL and PASCAL so the system does not give too much help to the programmer to employ structured programming concepts Also many programmers have become used to strongly typed languages

What is the Prolog language PDF?

You can share this PDF with anyone you feel could benefit from it, downloaded the latest version from: prolog-language It is an unofficial and free Prolog Language ebook created for educational purposes. All the content is extracted from Stack Overflow Documentation, which is written by many hardworking individuals at Stack Overflow.

What are some examples of problems with Prolog?

The Prolog you are using will load all clauses that parse as correct and throw away any ones that do not parse. Some example problems: the ?rst is where we have typed a ‘,’ instead of a ‘.’. a:- a:- b, b, c, is read as c, d:- d:-e. e. There are problems with this reading which will be reported by Prolog.

What is the syntax for multimangle in Prolog?

However, some modern Prologs go further and offer a custom syntax for this type of predicate. For example, in Visual Prolog: mangle(X) = Y :- Y = ((X*5)+2). multimangle(X,Y) :- Y = mangle(mangle(mangle(X))).

How to parse Prolog?

This is done through the idea of a parse tree as applied to a simple model for the construction of English sentences. Three ways of parsing Prolog are described: the ?rst illustrates the ideas, the second is more e?cient and the third provides an easy way of coding a parser viaGrammar Rules.

FonctionnementUtilisation pour des bases de connaissancesListesPREMIERSPASENPROLOG

PROGRAMMATIONLOGIQUE¢Origines :—1970, Marseille, Colmerauer—Edimbourg, Warren¢Bibliographie—L. Sterling, E. Shapiro, L'art de Prolog, Masson—Clocksin, Mellish, Programmer en Prolog, EyrollesLicence Lyon1 -UE LIFprolog2N. Guin

LELANGAGEPROLOG¢Langage d'expression des connaissances fondé sur le langage des prédicats du premier ordre¢Programmation déclarative:—L'utilisateur définit une base de connaissances—L'interpréteur Prolog utilise cette base de connaissances pour répondre à des questionsLicence Lyon1 -UE LIFprolog3N. Guin

CONSTANTESETVARIABLES¢Constantes—Nombres : 12, 3.5—Atomes¢Chaînes de caractères commençant par une minuscule¢Chaînes de caractères entre ""¢Liste vide []¢Variables¢Chaînes de caractères commençant par une majuscule¢Chaînes de caractères commençant par _¢La variable "indéterminée» : _Licence Lyon1 -UE LIFprolog4N. Guin

TROISSORTESDECONNAISSANCES: FAITS, RÈGLES, QUESTIONS¢Faits : P(...).avec P un prédicatpere(jean, paul).pere(albert, jean).Clause deHorn réduite à un littéral positif¢Règles : P(...) :-Q(...), ..., R(...).papy(X,Y) :-pere(X,Z), pere(Z,Y).Clause de Horn complète¢Questions : S(...), ..., T(...).pere(jean,X), mere(annie,X).Clause de Horn sans littéral positifLicence Lyon1 -UE LIFprolog5N. Guin

RÉFUTATIONPARRÉSOLUTION¢Programme P—P1 :pere(charlie, david).—P2 :pere(henri, charlie).—P3 : papy(X,Y) :-pere(X,Z), pere(Z,Y).¢Appel du programme P—A : papy(X,Y).¢Réponse : X=henri, Y=davidLicence Lyon1 -UE LIFprolog6N. Guin

INTERPRÉTATIONPROCÉDURALE: ARBREET-OUéchecéchecY=davidsuccèspapy(X,Y)pere(X,Z)pere(Z,Y)etX=charlieZ=davidouP1P2ouP1P2pere(david,Y)ouP1P2X=henriZ=charliepere(charlie,Y)P38N. GuinLicence Lyon1 -UE LIFprolog

MONPREMIERPROGRAMME(1)lirispc1$ swiprologWelcometo SWI-Prolog (Version 3.3.0)Copyright (c) 1993-1999 Universityof Amsterdam. All rightsreserved.For help, use ?-help(Topic). or ?-apropos(Word).?-[pere].% perecompiled0.00 sec, 824 bytestrue.?-listing.pere(charlie, david).pere(henri, charlie).papy(A, B) :-pere(A, C),pere(C, B).true.Licence Lyon1 -UE LIFprolog9N. Guinpere(charlie,david).pere(henri,charlie).papy(X,Y) :-pere(X,Z), pere(Z,Y).

?-papy(x,y).false.?-papy(X,Y).X = henriY = david?-papy(henri,X).X = davidtrue.?-halt.lirispc1$?-pere(charlie,david).true.?-pere(charlie,henri).false.?-pere(X,Y).X = charlieY = davidtrue.?-pere(X,Y).X = charlieY = david;X = henriY = charlieMONPREMIERPROGRAMME(2)Licence Lyon1 -UE LIFprolog10N. Guin

ORDREDESRÉPONSESpere(charlie, david).pere(henri, charlie).pere(david, luc).mere(sophie, charlie).mere(anne, david).parents(E, P, M) :-pere(P, E),mere(M, E).?-parents(X,Y,Z).X = davidY = charlieZ = anne;X = charlieY = henriZ = sophie;false.Prolog parcourt le paquet de clauses de haut en bas, chaque clause étant parcourue de gauche à droiteLicence Lyon1 -UE LIFprolog11N. Guin

EXERCICES¢Construire l'arbre ET-OU permettant à Prolog de donner l'ensemble des réponses satisfaisant la requête parents(X,Y,Z).¢On définit le programme suivant :b(1).b(2). c(3).c(4).d(5).d(6).a(X,Y,Z) :-b(X), c(Y), d(Z).—Donner toutes les réponses à la requête a(X,Y,Z) dans l'ordre où Prolog les fournit.N. GuinLicence Lyon1 -UE LIFprolog12

L'ÉNIGMEPOLICIÈREENPROLOG¢On dispose des informations suivantes :—La secrétaire déclare qu'elle a vu l'ingénieur dans le couloir qui donne sur la salle de conférences—Le coup de feu a été tiré dans la salle de conférences, on l'a donc entendu de toutes les pièces voisines—L'ingénieur affirme n'avoir rien entendu¢On souhaite démontrer que si la secrétaire dit vrai, alors l'ingénieur mentLicence Lyon1 -UE LIFprolog13N. Guin

L'ÉNIGMEPOLICIÈREENPROLOG¢Ordre 1 : un individu entend un bruit s'il se trouve dans une pièce voisine de celle où le bruit a été produitentend(Ind,Bruit) :-lieu(Ind,Piece1), lieu(Bruit,Piece2), voisin(Piece1,Piece2).¢Faits relatifs à l'énigme :voisin(couloir,salle_de_conf).lieu(coup_de_feu,salle_de_conf).lieu(ingenieur,couloir) :-secretaire_dit_vrai.ingenieur_ment:-entend(ingenieur,coup_de_feu).Licence Lyon1 -UE LIFprolog14N. Guin

L'ÉNIGMEPOLICIÈREENPROLOG¢Hypothèsesecretaire_dit_vrai.¢Pour la démonstration, on pose la requête :ingenieur_ment.Licence Lyon1 -UE LIFprolog15N. Guin

SYMBOLESFONCTIONNELS¢La fonction "femme de Jean» est différente du prédicat femme(marie,jean).nom(femme(jean),marie).age(femme(jean),25).¢On peut parler de la femme de jean, mais pas la "calculer»Licence Lyon1 -UE LIFprolog16N. Guin

PROGRAMMATIONRÉCURSIVE¢Un programme récursif est un programme qui s'appelle lui-même¢Exemple : factorielle—factorielle(1) = 1 (Cas d'arrêt)—factorielle(n) = n * factorielle(n-1)si n≠1Appel récursifLicence Lyon1 -UE LIFprolog17N. Guin

POURÉCRIREUNPROGRAMMERÉCURSIF¢Il faut :—Choisir sur quoi faire l'appel récursif—Choisir comment passer du résultat de l'appel récursif au résultat que l'on cherche—Choisir le(s) cas d'arrêtLicence Lyon1 -UE LIFprolog18N. Guin

BOUCLAGE?-maries(jean,sophie).true.?-maries(sophie,jean).true.?-maries(X,Y).X = jeanY = sophie;X = philippeY = stephanie;X = sophieY = jean ;X = stephanieY = philippe;X = jeanY = sophie;...?-sont_maries(X,Y).X = jeanY = sophie;X = philippeY = stephanie;X = sophieY = jean ;X = stephanieY = philippe;false.?-maries(jean, sophie).maries(philippe, stephanie).maries(A, B) :-maries(B, A).Licence Lyon1 -UE LIFprolog19N. Guinmaries(jean, sophie).maries(philippe, stephanie).sont_maries(A, B) :-maries(A, B).sont_maries(A, B) :-maries(B, A).

ARITHMÉTIQUE¢Comparaisons : =:=, =\=, >, <, >=, =< ¢Affectaction: is?-X is3+2.X=5¢Fonctions prédéfinies : -, +, *, /, ^, mod, abs, min, max, sign, random, sqrt, sin, cos, tan, log, exp, ...Licence Lyon1 -UE LIFprolog20N. Guin

UNEXEMPLE: FACTORIELLE(1)?-fact(5,R).R = 120 ;ERROR: Out of local stackException: (36,276)_G4661 is-36263-1 ? abort% ExecutionAborted?-trace, fact(3,R).Call: (8) fact(3, _G237)? creep^ Call: (9) _G308 is3-1 ? creep^ Exit: (9) 2 is3-1 ? creepCall: (9) fact(2, _G306)? creep^ Call: (10) _G311 is2-1 ? creep^ Exit: (10) 1 is2-1 ? creepCall: (10) fact(1, _G309)? creepExit: (10) fact(1, 1)? creep^ Call: (10) _G314 is2*1 ? creep^ Exit: (10) 2 is2*1 ? creepExit: (9) fact(2, 2)? creep^ Call: (9) _G237 is3*2 ? creep^ Exit: (9) 6 is3*2 ? creepExit: (8) fact(3, 6)? creepR = 6 ;Redo: (10) fact(1, _G309)? creep^ Call: (11) _G314 is1-1 ? creep^ Exit: (11) 0 is1-1 ? creepCall: (11) fact(0, _G312)? creep^ Call: (12) _G317 is0-1 ? creep^ Exit: (12) -1 is0-1 ? creepCall: (12) fact(-1, _G315)? creep^ Call: (13) _G320 is-1-1 ? creep^ Exit: (13) -2 is-1-1 ? creepIl faut faire des cas exclusifsfact(1, 1).fact(N, R) :-Nm1 isN-1,fact(Nm1, Rnm1),R isRnm1*N.Licence Lyon1 -UE LIFprolog21N. Guin

UNEXEMPLE: FACTORIELLE(2)?-fact(3,R).ERROR: Arguments are not sufficientlyinstantiated^ Exception: (9) 1 is_G241-1 ? creepException: (8) fact(_G241, _G255) ? creepException: (7) fact(3, _G195) ? creep% ExecutionAborted?-5 isX-1.ERROR: Arguments are not sufficientlyinstantiated% ExecutionAborted?-plus(3,2,5).true.?-plus(X,2,5).X = 3true.fact(1, 1).fact(N, R) :-fact(Nm1, Rnm1),Nm1 isN-1,R isRnm1*N.Licence Lyon1 -UE LIFprolog22N. Guin

EXERCICE¢Définir un prédicat calculant le nièmeterme de la suite : u0= 2, un= 2un-1+3N. GuinLicence Lyon1 -UE LIFprolog23

UNEFACTORIELLEAVECACCUMULATEUR?-trace, fact(3,N).Call: (7) fact(3, _G234) ? creepCall: (8) fact(3, 1, _G234)? creepCall: (9) 3>1 ? creepExit: (9) 3>1 ? creep^ Call: (9) _G305 is1*3 ? creep^ Exit: (9) 3 is1*3 ? creep^ Call: (9) _G308 is3-1 ? creep^ Exit: (9) 2 is3-1 ? creepCall: (9) fact(2, 3, _G234)? creepCall: (10) 2>1 ? creepExit: (10) 2>1 ? creep^ Call: (10) _G311 is3*2 ? creep^ Exit: (10) 6 is3*2 ? creep^ Call: (10) _G314 is2-1 ? creep^ Exit: (10) 1 is2-1 ? creepCall: (10) fact(1, 6, _G234)? creepCall: (11) 1>1 ? creepFail: (11) 1>1 ? creepRedo: (10) fact(1, 6, _G234) ? creepExit: (10) fact(1, 6, 6)? creepN = 6 fact(N,R) :-fact(N,1,R).fact(1,R,R).fact(N,I,R) :-N>1,Nm1 is N-1, NewIis N*I, fact(Nm1,NewI,R).Licence Lyon1 -UE LIFprolog24N. Guin

COMPARAISONETUNIFICATIONDETERMES¢Vérifications de type : var, nonvar, integer, float, number, atom, string, ...¢Comparer deux termes :T1==T2 réussit si T1 est identiqueà T2T1\==T2 réussit si T1 n'est pas identiqueà T2T1=T2 unifieT1 avec T2T1\=T2 réussit si T1 n'est pas unifiableà T2Licence Lyon1 -UE LIFprolog25N. Guin

DIFFÉRENTSPRÉDICATSDECOMPARAISON?-A is 3, A=:=3.A = 3.?-A is 3, A=:=2+1.A = 3.?-a=\=b.ERRORN. GuinLicence Lyon1 -UE LIFprolog26?-A is 3, A==3.A = 3.?-A is 3, A==2+1.false.?-a\==b.true.?-A==3.false.?-p(A)\==p(1).true.?-A=3.A = 3.?-p(A)\=p(1).false.=:= =\=== \=== \=

LISTES¢Liste vide : [ ]¢Cas général : [Tete|Queue][a,b,c] º[a|[b|[c|[ ]]]]Licence Lyon1 -UE LIFprolog27N. Guin

EXEMPLES¢[X|L] = [a,b,c] ®X = a, L = [b,c]¢[X|L] = [a] ®X = a, L = []¢[X|L] = [] ®échec¢[X,Y]=[a,b,c] ®échec¢[X,Y|L]=[a,b,c] ®X = a, Y = b, L = [c] ¢[X|L]=[X,Y|L2] ®L=[Y|L2]Licence Lyon1 -UE LIFprolog28N. Guin

SOMMEDESÉLÉMENTSD'UNELISTEDENOMBRES?-somme([1,2,3,5],N).N = 11/* somme(L, S) L listede nbdonnée, S nbrésultat*/somme([],0).somme([X|L],N) :-somme(L,R), N is R+X.Licence Lyon1 -UE LIFprolog29N. Guin

EXERCICE¢Définir un prédicat ajoute1(L,L1) où L est une liste de nombres, et L1 une liste identique où tous les nombres sont augmentés de 1.N. GuinLicence Lyon1 -UE LIFprolog30

VARIABLEINDÉTERMINÉE(1)[ieme].Warning: (/Users/nath/Enseignement/Option Prolog/ieme:2):Singleton variables: [L]Warning: (/Users/nath/Enseignement/Option Prolog/ieme:3):Singleton variables: [X]% iemecompiled0.01 sec, 736 bytestrue./* ieme(L,I,X) L listedonnée, I entierdonné, X eltres */ieme([X|L],1,X).ieme([X|L],I,R) :-I>1, Im1 is I-1, ieme(L,Im1,R).Licence Lyon1 -UE LIFprolog31N. Guin

VARIABLEINDÉTERMINÉE(2)?-ieme([a,b,c,d],2,N).N = b ;false./* ieme(L,I,X) L listedonnée, I entierdonné, X eltres */ieme([X|_],1,X).ieme([_|L],I,R) :-I>1, Im1 is I-1, ieme(L,Im1,R).Licence Lyon1 -UE LIFprolog32N. Guin

TESTOUGÉNÉRATION?-appart(a,[b,a,c]).true.?-appart(d,[b,a,c]).false.?-appart(X,[b,a,c]).X = b ;X = a ;X = c ;false.?-trace, appart(X,[b,a,c]).Call: (7) appart(_G284, [b, a, c]) ? creepExit: (7) appart(b, [b, a, c])? creepX = b;Redo: (7) appart(_G284, [b, a, c])? creepCall: (8) appart(_G284, [a, c])? creepExit: (8) appart(a, [a, c])? creepX = a ;Redo: (8) appart(_G284, [a, c]) ? creepCall: (9) appart(_G284, [c])? creepExit: (9) appart(c, [c]) ? creepX = c ;Redo: (9) appart(_G284, [c]) ? creepCall: (10) appart(_G284, []) ? creepFail: (10) appart(_G284, [])? creepfalse./* appart(X,L) X elt donné, L liste donnée */appart(X,[X|_]).appart(X,[_|L]) :-appart(X,L).Licence Lyon1 -UE LIFprolog33N. Guin

LEPRÉDICATMEMBER¢Le prédicat appart est prédéfini en Prolog¢Il est très utile :—?-member(c,[a,z,e,c,r,t]).true—?-member(X,[a,z,e,r,t]).X = a ; X = z ; X = e ; X = r ; X = t.—?-member([3,V],[[4,a],[2,n],[3,f],[7,g]]).V = f .N. GuinLicence Lyon1 -UE LIFprolog34

UTILISATIONDUPRÉDICATAPPENDAppend est le prédicat prédéfini pour la concaténation de listes?-append([a,b,c],[d,e],L).L = [a, b, c, d, e]Il est complètement symétrique et peut donc être utilisé pour•Trouver le dernier élément d'une liste :?-append(_,[X],[a,b,c,d]).X = d •Couper une liste en sous-listes :?-append(L1,[a|L2],[b,c,d,a,e,t]).L1 = [b, c, d],L2 = [e, t]Licence Lyon1 -UE LIFprolog35N. Guin

DÉFINITIOND'UNPRÉDICAT: QUESTIONSÀSEPOSER¢Comment vais-je l'utiliser ?¢Quelles sont les données ?¢Quels sont les résultats ?¢Est-ce souhaitable qu'il y ait plusieurs solutions ?¢Si l'on veut une seule solution, il faut faire des cas exclusifsLicence Lyon1 -UE LIFprolog36N. Guin

EXERCICE¢Définir le prédicat renverse(L1,L2) satisfait si la liste L2 est miroir de la liste L1.¢Construire l'arbre de résolution des requêtes suivantes: —renverse([a,b,c],L)—renverse(L,[a,z,e]).¢Définir une version avec accumulateur du prédicat renverse. ¢Construire l'arbre de résolution des deux requêtes précédentes.N. GuinLicence Lyon1 -UE LIFprolog37

quotesdbs_dbs4.pdfusesText_8
[PDF] exercice prolog

[PDF] tp prolog corrigé

[PDF] exemple programme prolog

[PDF] exercice prolog liste corrigé

[PDF] prolog cours pdf

[PDF] west side story tonight analyse

[PDF] west side story fiche technique

[PDF] tp fibre optique bac pro sen

[PDF] bac pro environnement nucléaire salaire

[PDF] fibre optique bac pro eleec

[PDF] bac pro techniques d'interventions sur installations nucléaires

[PDF] cours fibre optique bac pro sen

[PDF] bareme 3x500 bac general

[PDF] 3x500 record du monde

[PDF] détection