女人眉尾有痣代表什么| 窝里横是什么意思| 白天梦见蛇是什么预兆| 吃维生素b1有什么好处和副作用| 大便干结是什么原因| 撒是什么意思| 吃什么药马上硬起来| 双子座爱吃什么| 四川有什么好吃的| 血栓是什么症状| 牙龈爱出血是什么原因| 妮子什么意思| 恨铁不成钢是什么意思| 真空什么意思| 胸闷是什么病的前兆| 分解酒精的是什么酶| 血沉高是什么意思| 胆结石挂什么科室| 姜子牙为什么没有封神| 月经来了喝红糖水有什么好处| 常务副县长是什么级别| 酸辣土豆丝用什么醋| 发烧吃什么药| 克拉是什么单位| 难产是什么意思| mcu是什么| 橘子是什么季节的水果| 1985是什么年| 玉米淀粉可以做什么| 烂苹果气味的是什么病| 取缔役什么意思| 颈椎病用什么药最好| 初潮是什么| 什么药治高血压效果最好| 请大家知悉是什么意思| 结婚要准备什么| 女人烂桃花多说明什么| 指甲有白点是缺什么| red是什么颜色| 横店是什么| 梦见屎是什么预兆| 脖子痛挂什么科| 梦见过生日是什么意思| 结石是什么原因造成的| 空调长时间不用再开注意什么| 白案是什么意思| 生气过度会气出什么病| 陷阱是什么意思| 取卵后需要注意什么| 润滑油可以用什么代替| 足字旁的字和什么有关| 酸奶有什么营养价值| 今年37岁属什么生肖| 趣味相投是什么意思| 1月22日是什么星座| 吃了螃蟹后不能吃什么| 消费税是什么| 白细胞低要吃什么| 饭铲头是什么蛇| 肛门痒挂什么科| 监视居住是什么意思| 18年是什么年| 怀孕一个月有点见红是什么情况| 可否是什么意思| 孩子咳嗽吃什么饭菜好| 淋巴在什么部位| 胎头位于耻上是什么意思| 脾胃虚吃什么| 溥仪为什么没有生育能力| 植物有什么| 9.11是什么星座| 黄精什么功效| 疤痕痒是什么原因| 大三阳是什么病| 七六年属什么生肖| 拔火罐对身体有什么好处| 邂逅什么意思| 乙肝两对半阳性是什么意思| 为什么鼻子无缘无故流鼻血| 胖脸适合什么发型| 手指甲凹凸不平是什么原因| 沉迷是什么意思| 借鉴是什么意思| 七点到九点是什么时辰| 风暴是什么意思| 舍我其谁是什么意思| 胃疼吃什么药好| 於是什么意思| 类风湿什么症状| 血清是什么意思| 晨对什么| 10月25日什么星座| 断码是什么意思| 做梦吃屎有什么预兆| 五子登科是什么意思| 脸部下垂什么方法提升效果好| 白带黄色是什么原因| 赵字五行属什么| 猫什么时候绝育| 悲伤是什么意思| 排便困难拉不出来是什么原因| 1990年的马是什么命| 茶艺师是做什么的| 去医院检查艾滋病挂什么科| 验血能查出什么病| 中医学专业学什么| 下午一点到三点是什么时辰| 年薪12万什么水平| 乙肝病毒核心抗体阳性是什么意思| 梦到吃肉是什么意思周公解梦| ha什么意思| 肾结石要忌口什么东西| 老是打嗝是什么病的征兆| 产后屁多是什么原因| hip是什么意思| 视线模糊是什么原因| 朝鲜和韩国是什么关系| 英国全称是什么| 植树节什么时候| 水痘长什么样子| 大舅哥是什么意思| 九寨沟什么时候去最好| 心脏不好最忌讳吃什么| 泪崩是什么意思| 糖尿病是什么原因造成的| 血糖查什么项目| 阴阳两虚用什么药| 孕妇血糖高吃什么| arf是什么意思| 小鸡喜欢吃什么食物| 5月10日什么星座| 什么病不能吃狗肉| 大腿内侧痒是什么原因| 堃是什么意思| 4五行属什么| 肋下未及是什么意思| 肝损伤是怎么回事什么是肝损伤| 血红蛋白低是什么原因| 手发麻发木是什么病的前兆| 朱红色是什么颜色| 不是什么而是什么造句| 什么是汉服| 鱼和熊掌不可兼得什么意思| 手指僵硬暗示什么疾病| 男人下面胀痛什么原因造成呢| 单脐动脉对胎儿有什么影响| 温州有什么特产| 剪刀手什么意思| 小仙女什么意思| 皮疹是什么症状| 大生化检查都包括什么项目| 急火攻心是什么生肖| 单纯性苔藓是什么病| 胃蛋白酶原1偏低是什么意思| 说笑了是什么意思| 阿是什么意思| 劳士顿手表什么档次| 座驾是什么意思| 藿香正气水什么味道| 刚拔完智齿可以吃什么| 早餐吃什么最减肥瘦身| 胰腺炎吃什么食物| 谷读什么| 爽文是什么意思| 雪菊有什么功效| 流氓兔什么意思| 为什么会晒黑| 紫外线是什么| 中巴友谊为什么这么好| 皂角是什么| 孕妇可以吃什么水果| 寒湿重吃什么中成药| 什么叫占位病变| 四个火读什么| 食品级pp材质是什么| shit什么意思中文| 一月十一是什么星座| 杜冷丁是什么| 胸部ct平扫能检查出什么| 手淫多了有什么危害| 今天是什么节气| 爱母环是什么形状图片| 吃鱼肝油有什么好处| 为什么叫五七干校| 藏干是什么意思| 山楂有什么功效和作用| ercp是什么| 糜烂性胃炎吃什么药| 山竹为什么这么贵| 家里为什么会有跳蚤| 下午6点半是什么时辰| 麒麟臂什么意思| 中药学学什么| 心跳过速吃什么药| 守宫是什么动物| 窦道是什么意思| 疣体是什么病| 结婚28年是什么婚| 天生丽质是什么生肖| 举不胜举的举是什么意思| chloe什么牌子| 牡丹花什么时候开花| 催乳素过高会有什么严重的后果| 拉谷谷女装什么档次的| 头发有点黄是什么原因| 学籍卡是什么样子图片| mcm是什么意思| 甲功三项是检查什么| 空调不制冷是什么原因| 股东是什么意思| 熙熙攘攘什么意思| 坐月子适合吃什么水果| 心率变异性是什么意思| 是故是什么意思| b是什么牌子| 煮花生放什么调料好吃| 什么开什么笑| 今是什么结构| 小猫不能吃什么| cab是什么意思| 1976年五行属什么| 什么叫腔梗| 饿了胃疼是什么原因| 胚芽是什么| 什么菜| 西米露是什么做的| 肚子左边是什么器官| 嘴巴苦是什么原因引起的| 英氏属于什么档次的| 月经2天就没了什么原因| 为什么头发总是很油| 牙齿疼是什么原因| 1926年属什么生肖| 梦见考试是什么意思| 嘴唇发紫是什么病| 路亚竿什么品牌好| 子宫肌瘤有什么症状表现| anello是什么牌子| 不停的出汗是什么原因| 请问支气管炎吃什么药最有效| pnc是什么意思| 尿毒症什么症状| 数典忘祖指什么动物| 对照是什么意思| 检查hpv需要注意什么提前注意什么| 9月3日是什么星座的| 什么是蚂蚁上树| 总胆红素偏高是什么原因| 实则是什么意思| 阉鸡是什么鸡| 纳是什么| 宫保鸡丁是什么菜系| 动则气喘是什么原因| 生肖羊和什么生肖相冲| 为什么不能拜女娲娘娘| 什么是非处方药| 脑梗前兆是什么症状| 血小板分布宽度是什么意思| 吹空调嗓子疼吃什么药| 网线是什么| 为什么会长痣| 一诺千金是什么生肖| 酒精和碘伏有什么区别| 梗塞是什么意思| 百度

我国沙尘天气频次逐年减少 专家解析沙尘天气成

百度   原标题:中国向巴铁提供光学跟踪测量系统,已完成培训和试验任务测设中的光测系统  香港《南华早报》22日报道称,印度近年来导弹进展速度飞速。

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.[1]

Many languages that apply this style attempt to minimize or eliminate side effects by describing what the program must accomplish in terms of the problem domain, rather than describing how to accomplish it as a sequence of the programming language primitives[2] (the how being left up to the language's implementation). This is in contrast with imperative programming, which implements algorithms in explicit steps.[3][4]

Declarative programming often considers programs as theories of a formal logic, and computations as deductions in that logic space. Declarative programming may greatly simplify writing parallel programs.[5]

Common declarative languages include those of database query languages (e.g., SQL, XQuery), regular expressions, logic programming (e.g., Prolog, Datalog, answer set programming), functional programming, configuration management, and algebraic modeling systems.

Definition

edit

Declarative programming is often defined as any style of programming that is not imperative. A number of other common definitions attempt to define it by simply contrasting it with imperative programming. For example:

These definitions overlap substantially.[citation needed]

Declarative programming is a non-imperative style of programming in which programs describe their desired results without explicitly listing commands or steps that must be performed. Functional and logic programming languages are characterized by a declarative programming style. In logic programming, programs consist of sentences expressed in logical form, and computation uses those sentences to solve problems, which are also expressed in logical form.

In a pure functional language, such as Haskell, all functions are without side effects, and state changes are only represented as functions that transform the state, which is explicitly represented as a first-class object in the program. Although pure functional languages are non-imperative, they often provide a facility for describing the effect of a function as a series of steps. Other functional languages, such as Lisp, OCaml and Erlang, support a mixture of procedural and functional programming.[citation needed]

Some logic programming languages, such as Prolog, and database query languages, such as SQL, while declarative in principle, also support a procedural style of programming.[citation needed]

Subparadigms

edit

Declarative programming is an umbrella term that includes a number of better-known programming paradigms.

Constraint programming

edit

Constraint programming states relations between variables in the form of constraints that specify the properties of the target solution. The set of constraints is solved by giving a value to each variable so that the solution is consistent with the maximum number of constraints. Constraint programming often complements other paradigms: functional, logical, or even imperative programming.

Domain-specific languages

edit

Well-known examples of declarative domain-specific languages (DSLs) include the yacc parser generator input language, QML, the Make build specification language, Puppet's configuration management language, regular expressions, Datalog, answer set programming and a subset of SQL (SELECT queries, for example). DSLs have the advantage of being useful while not necessarily needing to be Turing-complete, which makes it easier for a language to be purely declarative.

Many markup languages such as HTML, MXML, XAML, XSLT or other user-interface markup languages are often declarative. HTML, for example, only describes what should appear on a webpage - it specifies neither control flow for rendering a page nor the page's possible interactions with a user.

As of 2013, some software systems[which?] combine traditional user-interface markup languages (such as HTML) with declarative markup that defines what (but not how) the back-end server systems should do to support the declared interface. Such systems, typically using a domain-specific XML namespace, may include abstractions of SQL database syntax or parameterized calls to web services using representational state transfer (REST) and SOAP.[citation needed]

Functional programming

edit

Functional programming languages such as Haskell, Scheme, and ML evaluate expressions via function application. Unlike the related but more imperative paradigm of procedural programming, functional programming places little emphasis on explicit sequencing. Instead, computations are characterised by various kinds of recursive higher-order function application and composition, and as such can be regarded simply as a set of mappings between domains and codomains. Many functional languages, including most of those in the ML and Lisp families, are not purely functional, and thus allow introducing stateful effects in programs.

Hybrid languages

edit

Makefiles, for example, specify dependencies in a declarative fashion,[7] but include an imperative list of actions to take as well. Similarly, yacc specifies a context free grammar declaratively, but includes code snippets from a host language, which is usually imperative (such as C).

Logic programming

edit

Logic programming languages, such as Prolog, Datalog and answer set programming, compute by proving that a goal is a logical consequence of the program, or by showing that the goal is true in a model defined by the program. Prolog computes by reducing goals to subgoals, top-down using backward reasoning, whereas most Datalog systems compute bottom-up using forward reasoning. Answer set programs typically use SAT solvers to generate a model of the program.

Modeling

edit

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 languages and environments include Analytica, Modelica and Simile.[8]

Examples

edit

Lisp

edit

Lisp is a family of programming languages loosely inspired by mathematical notation and Alonzo Church's lambda calculus. Some dialects, such as Common Lisp, are primarily imperative but support functional programming. Others, such as Scheme, are designed for functional programming.

In Scheme, the factorial function can be defined as follows:

(define (factorial n)
    (if (= n 0)                     
        1                             ;;; 0! = 1
        (* n (factorial (- n 1)))))   ;;; n! = n*(n-1)!

This defines the factorial function using its recursive definition. In contrast, it is more typical to define a procedure for an imperative language.

In lisps and lambda calculus, functions are generally first-class citizens. Loosely, this means that functions can be inputs and outputs for other functions. This can simplify the definition of some functions.

For example, writing a function to output the first n square numbers in Racket can be done accordingly:

(define (first-n-squares n)
    (map (lambda (x) (* x x))          ;;; A function mapping x -> x^2
         (range n)))                   ;;; Lists the first n naturals

The map function accepts a function and a list; the output is a list of results of the input function on each element of the input list.

ML (1973)[9] stands for Meta Language. ML is statically typed, and function arguments and return types may be annotated.[10]

fun times_10(n : int) : int = 10 * n;

ML is not as bracket-centric as Lisp, and instead uses a wider variety of syntax to codify the relationship between code elements, rather than appealing to list ordering and nesting to express everything. The following is an application of times_10:

times_10 2

It returns "20 : int", that is, 20, a value of type int.

Like Lisp, ML is tailored to process lists, though all elements of a list must be the same type.[11]

Prolog

edit

Prolog (1972) stands for "PROgramming in LOGic." It was developed for natural language question answering,[12] using SL resolution[13] 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:

cat(tom).                        % tom is a cat
mouse(jerry).                    % jerry is a mouse

animal(X) :- cat(X).             % each cat is an animal
animal(X) :- mouse(X).           % each mouse is an animal

big(X)   :- cat(X).              % each cat is big
small(X) :- mouse(X).            % each mouse is small

eat(X,Y) :- mouse(X), cheese(Y). % each mouse eats each cheese
eat(X,Y) :- big(X),   small(Y).  % each big being eats each small being

Given this program, the query eat(tom,jerry) succeeds, while eat(jerry,tom) fails. Moreover, the query eat(X,jerry) succeeds with the answer substitution X=tom.

Prolog executes programs top-down, using SLD resolution to 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 eat(X,jerry) to the subgoals of first finding an X such that big(X) holds and then of showing that small(jerry) holds. It repeatedly uses rules to further reduce subgoals to other subgoals, until it eventually succeeds in 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 language.[14]

The broad range of Prolog applications is highlighted in the Year of Prolog Book,[15] celebrating the 50 year anniversary of Prolog.

Datalog

edit

The origins of Datalog date back to the beginning of logic programming, but it was identified as a separate area around 1977. Syntactically and semantically, it is a subset of Prolog. But because it lacks compound terms, it is not Turing-complete.

Most Datalog systems execute programs bottom-up, using rules to reason forwards, deriving new facts from existing facts, and terminating when there are no new facts that can be derived, or when the derived facts unify with the query. In the above example, a typical Datalog system would first derive the new facts:

animal(tom).
animal(jerry).
big(tom).
small(jerry).

Using these facts, it would then derive the additional fact:

eats(tom, jerry).

It would then terminate, both because no new, additional facts can be derived, and because the newly derived fact unifies with the query

eats(X, jerry).

Datalog has been applied to such problems as data integration, information extraction, networking, security, cloud computing and machine learning.[16][17]

Answer set programming

edit

Answer set programming (ASP) evolved in the late 1990s, based on the stable model (answer set) semantics of logic programming. Like Datalog, it is a subset of Prolog; and, because it lacks compound terms, it is not Turing-complete.

Most implementations of ASP execute a program by first grounding the program, replacing all variables in rules by constants in all possible ways, and then using a propositional SAT solver, such as the DPLL algorithm to generate one or more models of the program.

Its applications are oriented towards solving difficult search problems and knowledge representation.[18][19]

See also

edit

References

edit
  1. ^ Lloyd, J.W. Practical Advantages of Declarative Programming (Report).
  2. ^ "declarative language". FOLDOC. 17 May 2004. Archived from the original on 7 September 2023. Retrieved 7 September 2023.
  3. ^ Sebesta, Robert (2016). Concepts of programming languages. Boston: Pearson. ISBN 978-0-13-394302-3. OCLC 896687896.
  4. ^ "Imperative programming: Overview of the oldest programming paradigm". IONOS Digital Guide. 2025-08-07. Archived from the original on 2025-08-07. Retrieved 2025-08-07.
  5. ^ "DAMP 2009: Workshop on Declarative Aspects of Multicore Programming". Cse.unsw.edu.au. 20 January 2009. Archived from the original on 13 September 2013. Retrieved 15 August 2013.
  6. ^ Chakravarty, Manuel M. T. (14 February 1997). On the Massively Parallel Execution of Declarative Programs (Doctoral dissertation). Technische Universit?t Berlin. Archived from the original on 23 September 2015. Retrieved 26 February 2015. 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.
  7. ^ "An overview on dsls". Archived from the original on October 23, 2007.
  8. ^ "Declarative modelling". Simulistics. Archived from the original on 11 August 2003. Retrieved 15 August 2013.
  9. ^ Gordon, Michael J. C. (1996). "From LCF to HOL: a short history". Archived from the original on 2025-08-07. Retrieved 2025-08-07.
  10. ^ Wilson, Leslie B. (2001). Comparative Programming Languages, Third Edition. Addison-Wesley. p. 233. ISBN 0-201-71012-9.
  11. ^ Wilson, Leslie B. (2001). Comparative Programming Languages, Third Edition. Addison-Wesley. p. 235. ISBN 0-201-71012-9.
  12. ^ "Birth of Prolog" (PDF). November 1992. Archived (PDF) from the original on 2025-08-07. Retrieved 2025-08-07.
  13. ^ Robert Kowalski; Donald Kuehner (Winter 1971). "Linear Resolution with Selection Function" (PDF). Artificial Intelligence. 2 (3–4): 227–260. doi:10.1016/0004-3702(71)90012-9. ISSN 0004-3702. Archived (PDF) from the original on 2025-08-07. Retrieved 2025-08-07.
  14. ^ Robert Kowalski Predicate Logic as a Programming Language Archived 2025-08-07 at the Wayback Machine Memo 70, Department of Artificial Intelligence, University of Edinburgh. 1973. Also in Proceedings IFIP Congress, Stockholm, North Holland Publishing Co., 1974, pp. 569-574.
  15. ^ Warren, D.S. (2023). "Introduction to Prolog". In Warren, D.S.; Dahl, V.; Eiter, T.; Hermenegildo, M.V.; Kowalski, R.; Rossi, F. (eds.). Prolog: The Next 50 Years. Lecture Notes in Computer Science (LNCS). Vol. 13900. Springer, Cham. pp. 3–19. doi:10.1007/978-3-031-35254-6_1. ISBN 978-3-031-35253-9.
  16. ^ Huang, Shan Shan; Green, Todd J.; Loo, Boon Thau (June 12–16, 2011). Datalog and Emerging applications (PDF). SIGMOD 2011. Athens, Greece: Association for Computing Machinery. ISBN 978-1-4503-0661-4. Archived (PDF) from the original on 2025-08-07. Retrieved 2025-08-07.
  17. ^ Mei, Hongyuan; Qin, Guanghui; Xu, Minjie; Eisner, Jason (2020). "Neural Datalog Through Time: Informed Temporal Modeling via Logical Specification". Proceedings of ICML 2020. arXiv:2006.16723.
  18. ^ Baral, Chitta (2003). Knowledge Representation, Reasoning and Declarative Problem Solving. Cambridge University Press. ISBN 978-0-521-81802-5.
  19. ^ Gelfond, Michael (2008). "Answer sets". In van Harmelen, Frank; Lifschitz, Vladimir; Porter, Bruce (eds.). Handbook of Knowledge Representation. Elsevier. pp. 285–316. ISBN 978-0-08-055702-1. as PDF Archived 2025-08-07 at the Wayback Machine
edit
小孩腿抽筋是什么原因引起的 漫游什么意思 7月13日是什么星座 妊娠是什么 joseph是什么意思
四月八日是什么星座 五音指什么 韬字五行属什么 66岁属什么 不造是什么意思
10度左右穿什么衣服合适 蚕豆病不能吃什么 鱼疗是什么鱼 免疫五项能查出什么病 头发定型用什么好
腮腺炎吃什么消炎药 盆浴是什么意思 大学硕士点是什么意思 果蝇是什么 曹操属什么
附睾炎吃什么药最有效hcv9jop2ns0r.cn 盐酸安罗替尼胶囊主要治疗什么hcv8jop4ns9r.cn 男人血精是什么原因造成的hcv9jop4ns7r.cn 保姆代表什么生肖hcv8jop3ns8r.cn 口舌生疮是什么原因hcv9jop4ns9r.cn
东坡肉是什么菜系hcv9jop3ns1r.cn 梦见和老公吵架是什么意思hcv7jop9ns8r.cn 梦见鳝鱼是什么预兆hcv7jop6ns0r.cn 做什么饭简单又好吃hcv9jop3ns4r.cn 吃什么对肺有好处hcv9jop0ns9r.cn
恍然大悟是什么意思hcv8jop9ns8r.cn 不加一笔是什么字hcv9jop6ns6r.cn 拆线去医院挂什么科huizhijixie.com 0.618是什么意思hcv8jop8ns3r.cn 桃树什么时候修剪最好hcv8jop3ns9r.cn
ct与核磁共振有什么区别cl108k.com 什么西瓜hcv8jop5ns5r.cn 什么是富贵包hcv8jop3ns1r.cn 血糖高喝酒有什么影响hcv8jop3ns2r.cn 小便失禁是什么原因hcv8jop8ns5r.cn
百度