Prolog

Prolog
linguaggio di programmazione
AutoreAlain Colmerauer
Data di origine1972
Utilizzolinguaggio general-purpose
ParadigmiProgrammazione logica
Tipizzazionenon esistono tipi di dati
Specifiche di linguaggioISO/IEC 13211-1 (1995)
Estensioni comuni.pl .pro .P
Influenzato daPlanner

Il Prolog (contrazione del francese PROgrammation en LOGique) è un linguaggio di programmazione che adotta il paradigma di programmazione logica.

È stato ideato da Robert Kowalski (aspetto teorico), Marten Van Emdem (dimostrazione sperimentale) e implementato da Alain Colmerauer negli anni settanta, e costituisce un tentativo di costruire un linguaggio di programmazione che consenta l'espressione del problema in forma logica, invece che in forma di un algoritmo di soluzione eseguibile dalla macchina. L'attuale implementazione di Prolog è dovuta in gran parte all'efficiente codifica di David H.D. Warren, implementata tramite la sua Warren Abstract Machine (1983).

Il Prolog è impiegato in molti programmi di intelligenza artificiale; la sintassi e la semantica sono molto semplici e chiare, in quanto lo scopo per cui venne ideato era quello di fornire uno strumento di lavoro a linguisti privi di conoscenze informatiche.

Il Prolog si basa sul calcolo dei predicati (precisamente il calcolo di predicati del primo ordine); tuttavia la sintassi è limitata a formule dette clausole di Horn che sono disgiunzioni di letterali del primo ordine, quantificate universalmente, con al più un letterale positivo.

L'esecuzione di un programma Prolog è comparabile alla dimostrazione di un teorema mediante la regola di inferenza detta risoluzione (introdotta da Robinson nel 1965). I concetti fondamentali sono l'unificazione, la ricorsione in coda e il backtracking.

Molti linguaggi, come Datalog o AnsProlog, sono basati su Prolog.

Sintassi

Nel Prolog, la logica del programma è espressa sotto forma di relazioni, e le attività di calcolo vengono attivate da un'interrogazione relativa a tali relazioni.

Tipi di dati

L'elemento generico del Prolog si chiama termine. I termini possono essere costanti (atomi o numeri), variabili o termini composti.

  • Un atomo è un nome generico senza significato intrinseco, es.: x, blu, 'Taco', 'questo signore'.
  • Un numero può essere intero o decimale.
  • Una variabile è indicata per mezzo di una stringa di lettere, numeri e underscore (_) che comincia con una maiuscola o un trattino basso.
  • Un termine composto è formato da un atomo detto "funtore" e da uno o più argomenti - anch'essi termini - scritti tra parentesi e separati da virgole, p.es. data(27,'marzo',1980) anno_modello_auto('Mazda','cx 5',1986) e 'Amici'(zelda,[tom,jim]).

Casi speciali di termini composti:

  • Una lista è una collezione ordinata di termini, separati da virgole; viene indicata per mezzo di parentesi quadre; è ammessa la lista vuota []. Esempi: [1,2,3] e [rosso,verde,blu].
  • Una stringa è una sequenza di caratteri delimitata da doppi apici ("), p.es. "essere o non essere".

Regole e fatti

Una regola ha la forma:

Testa :- Corpo.

che si legge: "Testa è vera se Corpo è vero." (Si noti che la regola termina con un punto.)

Un singolo termine (anche composto), senza il segno :-, viene chiamato fatto. I fatti equivalgono a regole senza corpo, che sono considerate automaticamente vere. Un esempio di fatto è:

gatto(tommaso).

Al di là dell'uso strettamente previsto dalla teoria, il Prolog offre anche dei predicati speciali che servono per input/output e altre attività accessorie. P.es. write/1 visualizza un termine sullo schermo.

Programma di esempio

Il seguente esempio stampa il testo "Hello world".

?- write('Hello World'), nl.

Permutazioni

La potenza di Prolog non risiede comunque nella sua gestione dell'input/output, quanto nella possibilità di rappresentare semplicemente concetti complessi, ad esempio algoritmi combinatori. Ecco un programma che calcola tutte le possibili permutazioni di una parola data come lista di caratteri:

permutation([],[]).
permutation(Xs,[Z|Zs]) :- select(Z,Xs,Ys), permutation(Ys,Zs).
select(X,[X|Xs],Xs).
select(Y,[X|Xs],[X|Ys]) :- select(Y,Xs,Ys).

Meta-Interpretazione

In Prolog è semplice scrivere interpreti e compilatori. Ad esempio, un meta-interprete di Prolog (cioè un interprete Prolog scritto in Prolog) è costituito da solo 3 linee di codice:

vanilla(true).
vanilla((A,B)):- vanilla(A), vanilla(B).
vanilla(X):- X\==true, clause(X,B), vanilla(B).

Implementazioni

Bibliografia

Voci correlate

Altri progetti

Collegamenti esterni

Controllo di autoritàLCCN (ENsh85107397 · BNF (FRcb11970224v (data) · J9U (ENHE987007538888605171
  Portale Informatica: accedi alle voci di Wikipedia che trattano di informatica

Read other articles:

Czech actress This biography of a living person needs additional citations for verification. Please help by adding reliable sources. Contentious material about living persons that is unsourced or poorly sourced must be removed immediately from the article and its talk page, especially if potentially libelous.Find sources: Barbora Kodetová – news · newspapers · books · scholar · JSTOR (June 2019) (Learn how and when to remove this template message) Bar...

Hòa Bình FCTên đầy đủCâu lạc bộ bóng đá Hòa BìnhBiệt danhTự hào Tây BắcTên ngắn gọnHBFCThành lập22 tháng 4 năm 2021; 2 năm trước (2021-04-22)SânSân vận động Hòa Bình, Số 54 đường Trần Hưng Đạo, Phường Phương Lâm, Thành phố Hòa Bình, Tỉnh Hòa BìnhSức chứa3.600Chủ sở hữuCông ty Cổ phần Bóng đá Hòa BìnhChủ tịch điều hànhNguyễn Xuân HiểnHuấn luyện viênPhạm Thành ...

Pour les articles homonymes, voir Chapman. Tracy Chapman Tracy Chapman en concert à Bruges en 2009.Informations générales Naissance 30 mars 1964 (59 ans)Cleveland (Ohio) Activité principale chanteuse, musicienne, compositrice Genre musical Folk, blues rock, soul Instruments voix, guitare, harmonica Années actives depuis 1988 Labels Elektra Records Site officiel www.tracychapman.com modifier Tracy Chapman est une autrice-compositrice-interprète américaine née le 30 mars 1964 à Cl...

Der Titel dieses Artikels ist mehrdeutig. Zum bestehenden Landkreis in Niedersachsens siehe Landkreis Diepholz. Basisdaten Preußische Provinz Hannover Regierungsbezirk Hannover Verwaltungssitz Diepholz Bestandszeitraum 1885–1932 Fläche 633 km² (1925) Einwohner 24.298 (1925) Bevölkerungsdichte 38 Einw./km² (1925) Gemeinden 35 (1932) Lage des Kreises Diepholz in der Provinz Hannover Die Zusammensetzung des Kreises Diepholz, auf einem Notgeldschein von 1921. Der Kreis Diepholz war von 188...

Bettingerode Stadt Bad Harzburg Wappen von Bettingerode Koordinaten: 51° 55′ N, 10° 34′ O51.913510.573227Koordinaten: 51° 54′ 49″ N, 10° 34′ 23″ O Höhe: 227 (175–227) m ü. NHN Fläche: 6,62 km²[1] Einwohner: 408 (31. Dez. 2022)[2] Bevölkerungsdichte: 62 Einwohner/km² Eingemeindung: 1. Juli 1972 Postleitzahl: 38667 Vorwahl: 05322 Karte Lage von Bettingerode in Bad Ha...

  Patagioenas fasciata Estado de conservaciónPreocupación menor (UICN 3.1)[1]​TaxonomíaReino: AnimaliaFilo: ChordataClase: AvesOrden: ColumbiformesFamilia: ColumbidaeGénero: PatagioenasEspecie: P. fasciata(Say, 1823)Distribución Sinonimia Columba fasciata Say, 1823 [editar datos en Wikidata] La paloma de collar, paloma encinera, paloma collareja, paloma gargantilla, paloma nuca blanca, paloma de nuca blanca o paloma torcaza septentrional (Patagioenas fasciata)[2...

Зображення Еквітас на реверсі монети (антонініана) часів Клавдія II Е́квітас (лат. Aequitas) — рівність, справедливість) — уособлення справедливості в Стародавньому Римі. За часів імперії встановлено її культ. Зображувалася на монетах у вигляді зіпертої на спис жінки в ...

Coordenadas: 30° 4' 50.5 S 51° 13' 11.5 O FM Express FM Express Rede Pampa de Comunicação Ltda. País  Brasil Frequência(s) FM 104.9 MHz (2018-2019) Sede Porto Alegre, RS Slogan Tocando só as melhores Fundação 2 de julho de 2018 (5 anos) Extinção 1 de julho de 2019 (4 anos) Fundador Otávio Dumit Gadret Pertence a Rede Pampa de Comunicação Proprietário(s) Otávio Dumit Gadret Formato Web rádio Comercial (2018-2019) Gênero Entretenimento e ...

2017 video game 2018 video gameHeartboundPublisher(s)Pirate SoftwareDesigner(s)Jason Thor HallArtist(s)Bradie Shaye RehmelComposer(s)Stijn van WakerenEngineGameMaker Studio 2Platform(s)Microsoft Windows, LinuxReleaseEarly Access: December 25, 2018[1]Genre(s)Role-playingMode(s)Single-player Heartbound is an upcoming role-playing video game developed by American indie developer Pirate Software. The game centers around a boy who deals with depression, anxiety, and fear as he embarks on a...

Human settlement in EnglandArkholme-with-CawoodArkholme motte and the west end of theChurch of St John the BaptistArkholme-with-CawoodLocation in the City of Lancaster districtShow map of the City of Lancaster districtArkholme-with-CawoodLocation within LancashireShow map of LancashirePopulation333 (2011)OS grid referenceSD581721Civil parishArkholme-with-CawoodDistrictLancasterShire countyLancashireRegionNorth WestCountryEnglandSovereign stateUnited KingdomPost townCA...

Danial HajibaratDanial Hajibarat 2020Lahir4 Juni 1983 (umur 40)Tehran, IranKebangsaanIranPekerjaanSutradara film, penulis latar, produser filmTahun aktif2003–sekarangKarya terkenalThe Road of LoveLiberation Danial Hajibarat (Persia: دانیال حاجی برات , kelahiran 4 Juni, 1983 di Tehran) adalah seorang sutradara dan penulis film Iran. Dia memulai karirnya pada tahun 2003 sebagai pembuat film independen.[1] Filmografi Tahun Judul Judul dalam Bahasa Inggris 20...

Hulk Hogan Hulk Hogan im Juli 2010 Personalia Geburtsname Terrence Gene Bollea Geburtstag 11. August 1953 Geburtsort Augusta, Georgia, USA Karriereinformationen Ringname(n) Hollywood HoganHulk HoganHulk MachineMr. AmericaSterling GoldenTerry BolleaThe Super Destroyer Namenszusätze The FabulousThe HulksterThe ImmortalThe Incredible Körpergröße 201 cm[1] Kampfgewicht 137 kg Angekündigt aus Venice Beach, Kalifornien Trainiert von Hiro Matsuda Debüt 19. August 1977 Ruhestand 27. Jan...

2004 EP by the American math rock band Battles B EPEP by BattlesReleasedSeptember 14, 2004GenreMath rockLength29:28LabelDim Mak RecordsProducerBattlesBattles chronology EP C(2004) B EP(2004) EP C/B EP(2006) Professional ratingsReview scoresSourceRatingAllMusic[1]Pitchfork(8.3/10)[2] B EP is a 2004 EP by the American math rock band Battles.[3] It was part of a trio of EPs released by Battles over the course of three months, and has been called another sketchbook rev...

Indo-Aryan language native to the Punjab Punjabiਪੰਜਾਬੀپَن٘جابی'Punjabi' written in Shahmukhi script used in Punjab, Pakistan (top) and Gurmukhi script used in Punjab, India (bottom)Pronunciation Punjabi: [pəɲˈdʒɑb̆.bi] English: /pʌnˈdʒɑːbi/ Native toPakistan and IndiaRegionPunjabEthnicityPunjabisNative speakers113 million (2011–2017)[a][1]Language familyIndo-European Indo-IranianIndo-AryanNorthwesternPunjabiEarly formsProto-In...

Italian actor and author Mario ScacciaScaccia in La calandria (1972)Born(1919-12-26)26 December 1919Rome, ItalyDied26 January 2011(2011-01-26) (aged 91)Rome, ItalyOccupation(s)Actor, authorHeight1.80 m (5 ft 11 in) Mario Scaccia (26 December 1919 – 26 January 2011) was an Italian actor and author. He was a prominent figure in the Italian theatre of '900. Biography Born in Rome, the son of a painter, during the Second World War Scaccia was conscripted into the army as an ...

Sir Frederic G. KenyonLahirFrederic George Kenyon(1863-01-15)15 Januari 1863London, InggrisMeninggal23 Agustus 1952(1952-08-23) (umur 89)Godstone, Surrey, InggrisKarya akademisMinat utamaPaleografi, Kritik Alkitab dan Klasika Sir Frederic George Kenyon GBE KCB TD FBA FSA (15 Januari 1863 – 23 Agustus 1952) adalah seorang palaeografer serta sarjana Alkitab dan klasik asal Inggris. Ia menjabat dari tahun 1889 hingga tahun 1931 serangkaian posisi di Briti...

Untuk aktor Indonesia dengan nama yang sama, lihat Rifat Sungkar (aktor). Rifat SungkarLahirRifat Helmy Sungkar22 Oktober 1978 (umur 45)Jakarta, IndonesiaNama lainRifat SungkarPekerjaanPembalapolahragawanTahun aktif1998–sekarangSuami/istri Amalya Gamyla ​ ​(m. 2009; c. 2010)​ Sissy Priscillia ​(m. 2010)​ Anak2Kerabat Jevin Julian (ipar) Vanesha Prescilla (ipar) KeluargaIda Hannas (mertua) Rifat Helmy...

Indian actor (born 1992) For the Indian cricketer, see Pradeep Pandey (cricketer). Pradeep PandeyBorn (1992-12-09) 9 December 1992 (age 30)Bombay, Maharashtra, IndiaOther namesChintuOccupationsActorsingermodelYears active2009–present Pradeep Pandey Chintu is an Indian actor mainly active in Bhojpuri language films. In 2009 Pandey made his acting debut in the Bhojpuri film Deewana, for which he won the Juri Mention Award. Early life and education Pradeep Pandey was born on 9 D...

Relief Hindu, Museum Quanzhou. Citra ini menggambarkan legenda Narasinga untuk festival Holika dan Holi. Hinduisme dipraktikkan oleh minoritas penduduk Tiongkok. Hinduisme sendiri memiliki eksistensi yang sangat terbatas di daratan Tiongkok, tetapi bukti arkeologis menunjukkan eksistensi Hinduisme di berbagai wilayah di Tiongkok pada Abad Pertengahan.[1] Pengaruh Hinduisme juga diserap di negara ini melalui penyebaran Buddhisme selama sejarahnya.[2] Praktik yang berasal dari t...

Chaetocladius suecicus Klasifikasi ilmiah Kerajaan: Animalia Filum: Arthropoda Kelas: Insecta Ordo: Diptera Famili: Chironomidae Genus: Chaetocladius Spesies: Chaetocladius suecicus Chaetocladius suecicus adalah spesies lalat yang berasal dari genus Chaetocladius dan famili Chironomidae. Lalat ini juga merupakan bagian dari ordo Diptera, kelas Insecta, filum Arthropoda, dan kingdom Animalia. Lalat ini dapat ditemukan habitatnya di perairan maupun semiperairan. Referensi Bisby F.A., Roskov Y.R...