Content deleted Content added
→Subparadigms: make main article links more prominent using {{main}} |
Rescuing 9 sources and tagging 0 as dead.) #IABot (v2.0.9.5 |
||
Line 5:
In [[computer science]], '''declarative programming''' is a [[programming paradigm]]—a style of building the structure and elements of computer programs—that expresses the logic of a [[computation]] without describing its [[control flow]].<ref>{{citation|last=Lloyd|first=J.W.|title=Practical Advantages of Declarative Programming}}</ref>
Many languages that apply this style attempt to minimize or eliminate [[side effect (computer science)|side effects]] by describing ''what'' the program must accomplish in terms of the [[___domain knowledge|problem ___domain]], rather than describing ''how'' to accomplish it as a sequence of the programming [[language primitive]]s<ref name="FOLDOC 2004">{{cite web | title=declarative language | website=FOLDOC | date=17 May 2004 | url=https://foldoc.org/declarative+language | access-date=7 September 2023 | archive-date=7 September 2023 | archive-url=https://web.archive.org/web/20230907151526/https://foldoc.org/declarative+language | url-status=live }}</ref> (the ''how'' being left up to the language's [[programming language implementation|implementation]]). This is in contrast with [[imperative programming]], which implements [[algorithm]]s in explicit steps.<ref name="Sebesta 2016">{{cite book | last=Sebesta | first=Robert | title=Concepts of programming languages | publisher=Pearson | publication-place=Boston | year=2016 | isbn=978-0-13-394302-3 | oclc=896687896}}</ref><ref>{{Cite web |date=2021-05-21 |title=Imperative programming: Overview of the oldest programming paradigm |url=https://www.ionos.com/digitalguide/websites/web-development/imperative-programming/ |access-date=2023-05-23 |website=IONOS Digital Guide |language=en-US |archive-date=2022-05-03 |archive-url=https://web.archive.org/web/20220503083342/https://www.ionos.com/digitalguide/websites/web-development/imperative-programming/ |url-status=live }}</ref>
Declarative programming often considers [[program (machine)|programs]] as theories of a [[Mathematical_logic#Formal_logical_systems|formal logic]], and computations as deductions in that logic space. Declarative programming may greatly simplify writing [[parallel computing|parallel programs]].<ref>{{cite web|url=http://www.cse.unsw.edu.au/~pls/damp09/ |title=DAMP 2009: Workshop on Declarative Aspects of Multicore Programming |publisher=Cse.unsw.edu.au |date=20 January 2009 |access-date=15 August 2013 |archive-url=https://web.archive.org/web/20130913162703/http://www.cse.unsw.edu.au/~pls/damp09/ |archive-date=13 September 2013 |url-status=dead}}</ref>
Line 16:
* A high-level program that describes what a computation should perform.
* Any programming language that lacks [[side effect (computer science)|side effects]] (or more specifically, is [[referential transparency|referentially transparent]]).
* A language with a clear correspondence to [[mathematical logic]].<ref>{{cite thesis |first=Manuel M. T. |last=Chakravarty |date=14 February 1997 |url=http://www.cse.unsw.edu.au/~chak/papers/diss.ps.gz |title=On the Massively Parallel Execution of Declarative Programs |type=Doctoral dissertation |publisher=[[Technical University of Berlin]] |access-date=26 February 2015 |quote=In this context, the criterion for calling a programming language declarative is the existence of a clear, mathematically established correspondence between the language and mathematical logic such that a declarative semantics for the language can be based on the model or the proof theory (or both) of the logic. |archive-date=23 September 2015 |archive-url=https://web.archive.org/web/20150923211531/http://www.cse.unsw.edu.au/~chak/papers/diss.ps.gz |url-status=live }}</ref><!-- this citation is just for this bullet point -->
These definitions overlap substantially.
Line 55:
===Modeling===
{{Main|Mathematical model}}
Models, or mathematical representations, of physical systems may be implemented in computer code that is declarative. The code contains a number of equations, not imperative assignments, that describe ("declare") the behavioral relationships. When a model is expressed in this formalism, a computer is able to perform algebraic manipulations to best formulate the solution algorithm. The mathematical causality is typically imposed at the boundaries of the physical system, while the behavioral description of the system itself is declarative or acausal. Declarative [[modeling language]]s and environments include [[Analytica (software)|Analytica]], [[Modelica]] and [[Simile (computing)|Simile]].<ref>{{cite web |url=http://www.simulistics.com/tour/declarative.htm |title=Declarative modelling |publisher=Simulistics |access-date=15 August 2013 |archive-date=11 August 2003 |archive-url=https://web.archive.org/web/20030811073949/http://www.simulistics.com/tour/declarative.htm |url-status=live }}</ref>
==Examples==
Line 94:
| first = Michael J. C.
| author-link = Michael J. C. Gordon
| year = 1996
| title = From LCF to HOL: a short history
| url = http://www.cl.cam.ac.uk/~mjcg/papers/HolHistory.html
| access-date = 2021-10-30
| access-date = 2021-10-30}}</ref> stands for "Meta Language." ML is statically typed, and function arguments and return types may be annotated.<ref name="cpl_3rd-ch9-233">{{cite book▼
| archive-date = 2016-09-05
| archive-url = https://web.archive.org/web/20160905201847/http://www.cl.cam.ac.uk/~mjcg/papers/HolHistory.html
| url-status = live
▲
| last = Wilson
| first = Leslie B.
Line 131 ⟶ 135:
| title = Birth of Prolog
| date = November 1992
| access-date = 2022-05-25
}}</ref> using SL resolution<ref>{{cite journal |author1=Robert Kowalski |author2=Donald Kuehner |url=http://www.doc.ic.ac.uk/~rak/papers/sl.pdf |title=Linear Resolution with Selection Function |journal=Artificial Intelligence |issn=0004-3702 |volume=2 |issue=3–4 |date=Winter 1971 |pages=227–260 |doi=10.1016/0004-3702(71)90012-9}}</ref> both to deduce answers to queries and to parse and generate natural language sentences.▼
| archive-date = 2015-04-02
| archive-url = https://web.archive.org/web/20150402111123/http://alain.colmerauer.free.fr/alcol/ArchivesPublications/PrologHistory/19november92.pdf
| url-status = live
▲ }}</ref> using SL resolution<ref>{{cite journal |author1=Robert Kowalski |author2=Donald Kuehner |url=http://www.doc.ic.ac.uk/~rak/papers/sl.pdf |title=Linear Resolution with Selection Function |journal=Artificial Intelligence |issn=0004-3702 |volume=2 |issue=3–4 |date=Winter 1971 |pages=227–260 |doi=10.1016/0004-3702(71)90012-9 |access-date=2023-08-13 |archive-date=2015-09-23 |archive-url=https://web.archive.org/web/20150923215814/http://www.doc.ic.ac.uk/~rak/papers/sl.pdf |url-status=live }}</ref> both to deduce answers to queries and to parse and generate natural language sentences.
The building blocks of a Prolog program are ''facts'' and ''rules''. Here is a simple example:
Line 150 ⟶ 158:
Given this program, the query <syntaxhighlight inline lang=prolog>eat(tom,jerry)</syntaxhighlight> succeeds, while <syntaxhighlight inline lang=prolog>eat(jerry,tom)</syntaxhighlight> fails. Moreover, the query <syntaxhighlight inline lang=prolog>eat(X,jerry)</syntaxhighlight> succeeds with the answer substitution <syntaxhighlight inline lang=prolog>X=tom</syntaxhighlight>.
Prolog executes programs top-down, using [[SLD resolution]] to [[backward chaining |reason backwards]], reducing goals to subgoals. In this example, it uses the last rule of the program to reduce the goal of answering the query <syntaxhighlight inline lang=prolog>eat(X,jerry)</syntaxhighlight> to the subgoals of first finding an X such that <syntaxhighlight inline lang=prolog>big(X)</syntaxhighlight> holds and then of showing that <syntaxhighlight inline lang=prolog>small(jerry)</syntaxhighlight> holds. It repeatedly uses rules to further reduce subgoals to other subgoals, until it eventually succeeds in [[Unification (computer science)#Application: unification in logic programming |unifying]] all subgoals with facts in the program. This backward reasoning, goal-reduction strategy treats rules in logic programs as procedures, and makes Prolog both a declarative and [[procedural programming#Logic programming |procedural programming]] language.<ref>Robert Kowalski [http://www.doc.ic.ac.uk/~rak/papers/IFIP%2074.pdf Predicate Logic as a Programming Language] {{Webarchive|url=https://web.archive.org/web/20160207012437/http://www.doc.ic.ac.uk/~rak/papers/IFIP%2074.pdf |date=2016-02-07 }} Memo 70, Department of Artificial Intelligence, University of Edinburgh. 1973. Also in Proceedings IFIP Congress, Stockholm, North Holland Publishing Co., 1974, pp. 569-574.</ref>
The broad range of Prolog applications is highlighted in the Year of Prolog Book,<ref name="Prolog Book">{{cite book |last1=Warren |first1=D.S. |editor-last1=Warren |editor-first1=D.S. |editor-last2=Dahl |editor-first2=V. |editor-last3=Eiter |editor-first3=T. |editor-last4=Hermenegildo |editor-first4=M.V. |editor-last5=Kowalski |editor-first5=R. |editor-last6=Rossi |editor-first6=F. |chapter=Introduction to Prolog |title=Prolog: The Next 50 Years |series=Lecture Notes in Computer Science() |date=2023 |volume=13900 |publisher=Springer, Cham. |doi=10.1007/978-3-031-35254-6_1 |pages=3–19|isbn=978-3-031-35253-9 }}</ref> celebrating the 50 year anniversary of Prolog.
Line 173 ⟶ 181:
eats(X, jerry).</syntaxhighlight>
Datalog has been applied to such problems as [[data integration]], [[information extraction]], [[Computer network|networking]], [[security]], [[cloud computing]] and [[machine learning]].<ref>{{cite conference | url = http://www.cs.ucdavis.edu/~green/papers/sigmod906t-huang.pdf | conference = SIGMOD 2011 | title = Datalog and Emerging applications | last1 = Huang | first1 = Shan Shan | last2 = Green | first2 = Todd J. | last3 = Loo | first3 = Boon Thau | publisher = Association for Computing Machinery | date = June 12–16, 2011 | ___location = Athens, Greece | isbn = 978-1-4503-0661-4 | access-date = 2023-08-13 | archive-date = 2020-10-22 | archive-url = https://web.archive.org/web/20201022234145/https://www.cs.ucdavis.edu/~green/papers/sigmod906t-huang.pdf | url-status = live }}</ref><ref>{{Cite conference|title=Neural Datalog Through Time: Informed Temporal Modeling via Logical Specification|book-title=Proceedings of ICML 2020|last1=Mei |first1=Hongyuan |last2=Qin |first2=Guanghui |last3=Xu |first3=Minjie |last4=Eisner |first4=Jason |year=2020 |arxiv=2006.16723 }}</ref>
=== Answer Set Programming===
|