gpt4 book ai didi

prolog - 这个 Prolog 术语是否正确? (事实、规则、程序、谓词……)

转载 作者:行者123 更新时间:2023-12-04 18:20:54 26 4
gpt4 key购买 nike

获得正确的术语是成功传达概念的一部分,当在 SO 中使用错误的术语时,带有 Prolog 标签的受访者会很好地指出错误。

在阅读 William F. Clocksin 于 1997 年 ( WorldCat ) 的“条款和效果 - 工作程序员的序言编程”中是一段

A Prolog program consists of a collection of procedures. Each procedure defines a particular predicate, being a certain relationship between its arguments. A procedure consists of one or more assertions, or clauses. It is convenient to think of two kinds of clauses: facts and rules.



虽然我理解所有单词,但在交流 Prolog 时,每个粗体单词是否都是当前正确使用的术语?

特别是使用 规则 似乎不以为然。

最佳答案

来自 Prolog ISO 标准

ISO/IEC 13211-1 (First edition 1995-06-01)

Information technology - Programming languages - Prolog

Part 1: General Core


在第 2-10 页上有一个广泛的词汇表。

3.7 argument: A term which is associated with a predication or compound term.

3.9 arity: The number of arguments of a compound term. Syntactically, a non-negative integer associated with a functor orpredicate.

3.10 assert, to: To assert a clause is to add it to the user-defined procedure in the database defined by the predicate ofthat clause.

3.19 body: A goal, distinguished by its context as part of a rule (see 3.154).

3.21 built-in predicate: A procedure whose execution is implemented by the processor (see 8).

3.32 clause: A fact or a rule. It has two parts: a head, and a body.

3.35 complete database The set of procedures with respect to which execution is performed (see 7.5).

3.37 compound term: A functor of arity N, N positive, together with a sequence of N arguments.

3.45 control construct: A procedure whose definition is part of the Prolog processor (see 7.8).

3.52 database: The set of user-defined procedures which currently exist during execution (see 7.5).

3.57 directive: A term D which affects the meaning of Prolog text (see 7.4.2) and is denoted in that Prolog text by the directive-term :-(D).

3.59 dynamic (of a procedure): A dynamic procedure is one whose clauses can be inspected or altered during execution, for example byasserting or retracting clauses (see 7.5.2).

3.72 fact: A clause whose body is the goal true. NOTE - A fact can be represented in Prolog text by a term whose principal functor is neither (:-)/1 nor (:-)/2.

3.77 functor: An identifier together with an arity.

3.81 goal: A predication which is to be executed (see body, query, and 7.7.3).

3.84 head (of a rule): A predication, distinguished by its context.

3.88 identifier: A basic unstructured object used to denote an atom, functor name or predicate name.

3.129 predicate: An identifier together with an arity.

3.131 predicate indicator: A compound term A/N, where A is an atom and N is a non-negative integer, denoting one particular procedure (see 7.1.6.6).

3.133 predication: A predicate with arity N and a sequence of N arguments.

3.136 procedure: A control construct, a built-in predicate, or a user-defined procedure. A procedure is either static or dynamic. Aprocedure is either private or public (see 7.5).

3.141 Prolog text: A sequence of read-terms denoting directives and clauses (see 6.2, 7.4).

3.143 query: A goal given as interactive input to the top level.

3.154 rule: A clause whose body is not the goal true. During execution, if the body is true for some substitution, then the head is also true for that substitution. A rule is represented in Prolog textby a term whose principal functor is (:-)/2 where the first argument is converted to the head, and the second argument is converted to the body.

3.164 static (of a procedure): A static procedure is one whose clauses cannot be altered (see 7.5.2).

3.185 top level: A process whereby a Prolog processor repeatedly inputs and executes * queries.

3.195 user-defined procedure: A procedure which is defined by a sequence of clauses where the head of each clause has the samepredicate indicator, and each clause is expressed by Prolog text orhas been asserted during execution (see 8.9).


笔记
基本概述
h(A,B,C) :- g(A,B),h(B,C),j(A,C).
<-------------------------------> - A (HORN) CLAUSE, which is also a RULE.
<------------------> - BODY of the RULE, which also a GOAL.
... only one literal: ATOMIC GOAL.
<------> - HEAD of the RULE, which can appear
as GOAL depending on context.

f(A,B,C). - A CLAUSE with the elided body `true`.
This is a FACT, but _not_ a RULE.
Also called a UNIT CLAUSE.
f(A,B,C) :- true. - Same as above, still not a RULE.
f(A,B,C) :- !. - Is it a RULE? We don't know!

:- f(A,B,C). - A DIRECTIVE.
:- (foo(bar)). - Another DIRECTIVE.
Horn Clause 的条目中可以找到略有不同的定义。一个维基百科。特别是,“事实”被称为“没有变量的单元子句”——这与 ISO 定义不符。
非终端指标
除了谓词指示器符号 A/N ( functor/arity ),有符号 A//N ,它不在 ISO 标准中(或者还没有,请参阅 this draft )。它告诉读者这个谓词用在 Definite Clause Grammar (DCG) 中。除了指定的参数数量外,还为输入“差异列表”(或“列表差异”)对采用 2 个隐藏参数。
在上面指出的标准提案中,它被描述为:

3.19 non-terminal indicator: A compound term A//N where A isan atom and N is a non-negative integer, denoting one particularnon-terminal


大多数实现翻译非终端 nt//n到谓词 nt/n+2 .但是,不能依赖精确的翻译方式和通过调用相应谓词直接调用非终结符的结果,即未定义具有相同名称和两个额外参数的谓词。特别是第二个附加参数必须小心处理。直接使用可能会违反坚定性,尤其是在使用 时.
关于指令 的说明
该指令可以是另一种编写查询的方式。 From the SICStus Prolog manual :

Queries and directives are ways of directing the system to executesome goal or goals. (...) The principal use for directives (as opposedto queries) is to allow files to contain directives that call variouspredicates, but for which you do not want to have the answers printedout. In such cases you only want to call the predicates for theireffect, i.e. you do not want terminal interaction in the middle ofconsulting the file.


指令也可以是源文件标记,其位置很重要(即代码元信息)。 From the SWI Prolog manualmodule指示:

This directive can only be used as the first term of a source file. Itdeclares the file to be a module file, defining a module named Module.


指令中使用的谓词可能非常奇特,为 Prolog 处理器提供指令和谓词元信息。 From the SWI Prolog manual关于“声明谓词属性”:

This section describes directives which manipulate attributes ofpredicate definitions.


例如,“加载有限域上的约束逻辑编程库”:
:- use_module(library(clpfd)).
空头规则 :- foo ,可以解释为 false :- foo在 Prolog 中不使用来表达约束“foo 永远不是这种情况”。在 Answer Set Programming 的实现中就是这样使用的像“ASP Prolog”(它具有 Prolog-y 语法,但与 Prolog 完全不同)。
关于内置谓词的说明
在第 8 章第 63 页,我们发现:

"A built-in predicate is a procedure which is provided by astandard-conforming processor"


通俗地说,“内置谓词是 Prolog 语言的一部分”。其他谓词可能是库谓词,需要通过适当的指令将其拉入 Prolog 程序。 SWI Prolog 中的示例: library predicates .
事实说明
通俗地说,“平面事实”是由基本术语表示的事实 - 一个没有变量的术语。
关于仿函数的注释
这与范畴论的“ functor”无关。关于范畴论的仿函数,维基百科是这样说的:

The word functor was borrowed by mathematicians from the philosopherRudolf Carnap, who used the term in a linguistic context; seefunction word.


而关于“虚词”:

In linguistics, function words (also called functors) are wordsthat have little lexical meaning or have ambiguous meaning and expressgrammatical relationships among other words within a sentence, orspecify the attitude or mood of the speaker.


所以Prolog选择“仿函数”有点可惜。
关于目标的说明
目标可以是人们所说的“简单”,例如 p(X) ,在这种情况下,它是一个原子目标,或由子目标组成的树,例如 p(X),q(Y)因为 ,是主仿函数 (',')/2 的谓词.
事实上,目标通常被认为是任何可以作为规则体出现的东西。例如, p(X) -> q(Y) ; r(Z) , 主仿函数 ; (不是 -> )绝对是一个目标。
目标也可以是解析为目标的变量,它可以传递给像 call/1 这样的元谓词。例如: X=(Z is 1+2), call(X). .
变体是元谓词使用的不完整原子目标。这命名了一个带有一些参数“在左边”预设的可调用谓词。元谓词将“在右边”与参数相邻。这称为 关闭尽管与函数式编程不同,它实际上并不是一个引用在函数创建时有效的上下文的函数。
比如三个调用都输出 u v w :
foo(X,Y,Z) :- format("~q ~q ~q\n", [X,Y,Z]).

maplist(foo, [u],[v],[w]). % call "foo" with 3 arguments
maplist(foo(u), [v],[w]). % call closure foo(u) with 2 arguments
maplist(foo(u,v) ,[w]). % call closure foo(u,v) with 1 argument
关于谓词与过程与谓词指示器的说明
这个谓词的概念似乎漂浮在“语义空间”而不是“语法空间”:
  • “谓词事物”的名称或声明是谓词指示符;
  • “谓词事物”的谓词定义是过程(大概基于代码、Prolog 或其他)。

  • 例子:
    对于谓词 fact arity 2 计算阶乘函数: fact/2是谓词指示符,并且
    fact(0,1) :- !.
    fact(X,F) :- Xp is (X-1), fact(Xp,Fp), F is (Fp*X).
    是可能的对应程序。
    在实践中,谓词也用于表示任何过程,并编写谓词指示符来识别它。
    允许逻辑解释并允许其任何参数使用变量的过程将是 关系database interpetationlogic interpretation那个词。
    在“Prolog 中的编程(第 5 版)”(Clocksin & Mellish 2003)中,它只是在 p.1 上说。第188话

    The collection of clauses for a given predicate is called a procedure.


    关于 Prolog 文本的说明
    “Prolog 程序”(ISO 标准中未定义的术语)将是一组 的通俗描述。序言文本 由(可能是标准的)处理器运行。
    序言文本 还包括在顶层输入的不是 Prolog 程序的文本,例如
    ?- X is 5 * 3.
    X = 15.

    关于prolog - 这个 Prolog 术语是否正确? (事实、规则、程序、谓词……),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49898738/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com