这个 Prolog 术语是否正确? (事实、规则、过程、谓词、...)
Is this Prolog terminology correct? (fact, rule, procedure, predicate, ...)
正确使用术语是成功传达概念的一部分,当在 SO 中使用带有 Prolog 标签的错误术语时,受访者会很好地指出错误。
在阅读 "Clause and Effect - Prolog Programming for the Working Programmer" 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 时使用的正确术语?
特别是 rule 的使用似乎不受欢迎。
来自 Prolog ISO 标准
ISO/IEC 13211-1 (First edition 1995-06-01)
Information technology - Programming languages - Prolog
Part 1: General Core
第 2-10 页有详尽的词汇表。
3.6 anonymous variable: A variable (represented in a term or Prolog text by _) which differs from every other variable (and anonymous
variable) (see 6.1.2, 6.4.3)
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 or
predicate.
3.10 assert, to: To assert a clause is to add it to the user-defined procedure in the database defined by the predicate of
that 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 by
asserting 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.96 instantiated: A variable is instantiated with respect to substitution if application of the substitution yields an atomic term or a compound term.
3.113 named variable: A variable which is not an anonymous variable (see 6.1.2, 6.4.3)
A term is instantiated if any of its variables are instantiated.
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. A
procedure 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 text
by 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.193 uninstantiated: A variable is uninstantiated when it is not instantiated.
3.195 user-defined procedure: A procedure which is defined by a sequence of clauses where the head of each clause has the same
predicate indicator, and each clause is expressed by Prolog text or
has been asserted during execution (see 8.9).
3.200 variable: An object which may be instantiated to a term during execution.
备注
基本概览
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). It tells the reader that this predicate is used in a Definite Clause Grammar (DCG) 并为输入“差异列表”(或“列表差异”)对采用 2 个隐藏参数,此外还有指示的参数数量。
在上面指出的标准提案中,描述为:
3.19 non-terminal indicator: A compound term A//N
where A
is
an atom and N
is a non-negative integer, denoting one particular
non-terminal
大多数实现将非终结符 nt//n
转换为谓词 nt/n+2
。但是,不能依赖于精确的翻译方式,通过调用相应的谓词直接调用非终结符的结果,即具有相同名称和两个额外参数的未定义。特别是第二个附加参数必须小心处理。直接使用可能会违反坚定性,特别是在使用 dcg-semicontext.
时
指令
注意事项
指令可以是另一种编写查询的方式。 From the SICStus Prolog manual:
Queries and directives are ways of directing the system to execute
some goal or goals. (...) The principal use for directives (as opposed
to queries) is to allow files to contain directives that call various
predicates, but for which you do not want to have the answers printed
out. In such cases you only want to call the predicates for their
effect, i.e. you do not want terminal interaction in the middle of
consulting the file.
指令也可以是源文件标记,其位置很重要(即代码元信息)。 From the SWI Prolog manual 在 module
指令上:
This directive can only be used as the first term of a source file. It
declares 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 of
predicate definitions.
例如,“为有限域上的约束逻辑编程加载库”:
:- use_module(library(clpfd)).
头部为空的规则:- foo
,可以解释为false :- foo
是not,在Prolog中用来表达约束“它永远不会foo 的情况”。它 是 在 Answer Set Programming 的实现中使用这种方式,例如“ASP Prolog”(它具有 Prolog-y 语法,但在其他方面与 Prolog 完全不同)。
内置谓词
注意事项
在第 8 章第 63 页,我们发现:
"A built-in predicate is a procedure which is provided by a
standard-conforming processor"
通俗地说,“内置谓词是 Prolog 语言的一部分”。其他谓词可能是 库谓词 ,需要通过适当的 指令 将其拉入 Prolog 程序。来自 SWI Prolog 的示例:library predicates.
关于事实的注释
通俗地说,“平面事实”是由基本项表示的事实 - 一个没有变量的项。
关于函子
的注释
这与范畴论的“functor”无关。关于范畴论的函子,维基百科是这样说的:
The word functor was borrowed by mathematicians from the
philosopher Rudolf Carnap, who used the term in a linguistic
context; see function word.
关于“虚词”:
In linguistics, function words (also called functors) are words
that have little lexical meaning or have ambiguous meaning and
express grammatical relationships among other words within a
sentence, or specify the attitude or mood of the speaker.
所以为 Prolog 选择“仿函数”有点不幸。
此外,斯坦福哲学百科全书中的逻辑学家 W.V.O Quine uses the word functor in "Predicate Functors Revisited" (and earlier) to describe a combinator that rearranges the arguments of the (atomic) predicate that (syntactically) follows it. See also: "Combinatory Logic - Alternative approaches: basic logic and predicate functors"。
另见问题 Definition of "functor"; Haskell vs. C++。
注意目标
目标可以是人们形容为“简单”的目标,例如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
关于predicate vs. procedure vs. predicate indicator
这个predicate的概念好像浮在“语义的space”而不是“语法的space”:
- “谓词事物”的名称或声明是谓词指标;
- “谓词事物”的谓词定义是过程(大概基于代码、Prolog 或其他)。
示例:
对于计算阶乘函数的 arity 2 的 predicate fact
:
fact/2
是谓词指标,
fact(0,1) :- !.
fact(X,F) :- Xp is (X-1), fact(Xp,Fp), F is (Fp*X).
是可能对应的过程.
在实践中,predicate 也用于表示任何 过程,并且可以编写 predicate 指示符 来识别它。
一个过程承认一个逻辑解释并允许其任何参数的变量将是[=75=中的关系 ]那个词。
在“Programming in Prolog(第 5 版)”(Clocksin & Mellish 2003)中,在第188那个
The collection of clauses for a given predicate is called a procedure.
关于 Prolog 文本的注释
“Prolog 程序”(ISO 标准中未定义的术语)是对一组 Prolog 文本 的口语化描述 运行由(可能是标准的)处理器。
Prolog 文本 还包括在顶层输入的非 Prolog 程序的文本,例如
?- X is 5 * 3.
X = 15.
关于术语规则的用法的附录..."is it cool to use rule?":
ISO Prolog Standard 在第 8 页定义了 规则 :
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 text
by 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.
所以 "rule" 很酷。
的确,"rule" 主要调用了一段声明性知识,称为 产生式规则 ,用于前向链接(可能是反向链接)专家系统,例如CLIPS, Jess or Drools,在那里他们可以有一个
- 自下而上logical/deduction解释或
- 非逻辑状态space轨迹解释
...可能 "search"。还有“Constraint Handling Rules”,这是非常多的前向链接规则,可以编译成 Prolog 程序并与 Prolog 顺利集成。
P.S.
为了诉诸权威,以下是 Robert Kowalski 在 RuleML.org 于 2014 年发表的博文中的引文:
The Sad State Concerning the Relationships between Logic, Rules and Logic Programming
他好像在用:
- 产生式规则 用于前向链接规则,
- 反应规则 用于动作诱导规则(可以在溯因逻辑编程框架中给出逻辑解释)和
- 逻辑编程子句 嗯,逻辑编程子句。
Confusions about the relationships between logic, rules and logic
programming are endemic in the world of computing.
...
I am particularly sensitive to the claim about the difference between
deduction and search, because two of my earliest papers (1, 2)
investigated the relationship between deduction and search. In my 2011
book (3), I discuss Thagard’s (4) various claims about logic and
rules, and I argue that there are three varieties of production
rules:
- Rules like IF you pass forty Arts courses, THEN you graduate with a B.A. These are logic programming clauses, used to reason forwards
from conditions to conclusions.
- Rules like IF you want to go home for the weekend, and you have the bus fare, THEN you can catch a bus. These are “forward chaining”
rules, used to simulate backward reasoning with logic programming
clauses, such as, you go home for the weekend, if you have the bus
fare, and you catch a bus.
- Rules like IF you are hungry THEN eat something. These are reactive rules, used to make the conclusion of the rule true whenever the condition of the rule becomes true.
In the book, I argue that reactive rules have a more general syntax
than logic programming clauses, and they are also more fundamental.
- Kowalski, R. (1970), "Search Strategies for
Theorem-proving" PDF.
- Kowalski, R. (1972), "And-or Graphs, Theorem-proving Graphs and
Bi-directional Search"
PDF.
- Kowalski, R. (2011) Computational Logic and Human Thinking: How to
be Artificially Intelligent, Cambridge University Press.
PDF of draft. Worldcat.
- Thagard, P.
(2005) Mind: Introduction to cognitive science. MIT press.
ISO 词汇表有点微妙。它还有一个条目:
3.133 predication : A predicate with arity N and a sequence of N arguments .
由于(',')/2等控制结构在Prolog中也是谓词,上面的概念谓词不是质数公式,这里是正确的:
3.81 goal : A predication which is to be executed (see body , query , and 7.7.3).`
这与一阶逻辑词汇表有很大不同,在一阶逻辑词汇表中,连词 (∧) 等逻辑连接词不被视为谓词,因此不是语言签名的一部分。这个 ISO 核心标准特定语言,与 Prolog 的同音性有关。基本上我们可以在术语之间自由切换,例如 (',')/2 作为函子和具有相同函子的目标。这是一个可以在 Prolog 中完成的示例:
?- expand_goal(H, G), G.
后者在一阶逻辑中不可用,因为一阶逻辑不允许这种“meta-programming”。 John W. Lloyd 曾尝试创建一种不同的语言,受 Prolog 启发的语言,它也将以不同的方式处理“meta-programming”。语言是:
Gödel’s meta-logical facilities provide support for meta-programs that do analysis, transformation, compilation, verification, and debugging, among other tasks.
https://en.wikipedia.org/wiki/G%C3%B6del_(programming_language)
ISO 核心标准应该在这个上下文中看到,它反映了 Prolog 关于“meta-programming”的非常具体的功能,这与一阶逻辑相去甚远。这意味着ISO核心标准中的术语属于人工词汇,分别是构造术语,专门为Prolog和ISO核心标准创建。
它不是计算机科学、数理逻辑或现实世界中其他地方的语言。就目前而言,没有什么可以更正或调整的,因为它是为 ISO 核心标准而创建的术语,并且关于计算机科学、数学逻辑或现实世界中其他用途的每项修正都是毫无根据的。
DCG 草案标准出现了类似的构造术语,多年来人们一直致力于此,直到心爱的“推回”被“半上下文”取代。 :-( :-) 由于 Ulrich Neumerkel 保存了 DCG 草案标准的所有版本,您可以观看构建术语的演变。
我不知道是否可以挖掘出一个文档集来显示 ISO 核心标准中术语的演变。谓词指示符是 N/A 形式的 Prolog 术语,谓词不是 Prolog 术语,而是抽象的 对。 3.133 predication 是一个很好的例子,用 predicate 比用 predicate indicator 更容易表达。
正确使用术语是成功传达概念的一部分,当在 SO 中使用带有 Prolog 标签的错误术语时,受访者会很好地指出错误。
在阅读 "Clause and Effect - Prolog Programming for the Working Programmer" 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 时使用的正确术语?
特别是 rule 的使用似乎不受欢迎。
来自 Prolog ISO 标准
ISO/IEC 13211-1 (First edition 1995-06-01)
Information technology - Programming languages - Prolog
Part 1: General Core
第 2-10 页有详尽的词汇表。
3.6 anonymous variable: A variable (represented in a term or Prolog text by _) which differs from every other variable (and anonymous variable) (see 6.1.2, 6.4.3)
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 or predicate.
3.10 assert, to: To assert a clause is to add it to the user-defined procedure in the database defined by the predicate of that 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 ofN
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 by asserting 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.96 instantiated: A variable is instantiated with respect to substitution if application of the substitution yields an atomic term or a compound term.
3.113 named variable: A variable which is not an anonymous variable (see 6.1.2, 6.4.3)
A term is instantiated if any of its variables are instantiated.
3.129 predicate: An identifier together with an arity.
3.131 predicate indicator: A compound term
A/N
, whereA
is an atom andN
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 ofN
arguments.3.136 procedure: A control construct, a built-in predicate, or a user-defined procedure. A procedure is either static or dynamic. A procedure 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 text by 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.193 uninstantiated: A variable is uninstantiated when it is not instantiated.
3.195 user-defined procedure: A procedure which is defined by a sequence of clauses where the head of each clause has the same predicate indicator, and each clause is expressed by Prolog text or has been asserted during execution (see 8.9).
3.200 variable: An object which may be instantiated to a term during execution.
备注
基本概览
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). It tells the reader that this predicate is used in a Definite Clause Grammar (DCG) 并为输入“差异列表”(或“列表差异”)对采用 2 个隐藏参数,此外还有指示的参数数量。
在上面指出的标准提案中,描述为:
3.19 non-terminal indicator: A compound term
A//N
whereA
is an atom andN
is a non-negative integer, denoting one particular non-terminal
大多数实现将非终结符 nt//n
转换为谓词 nt/n+2
。但是,不能依赖于精确的翻译方式,通过调用相应的谓词直接调用非终结符的结果,即具有相同名称和两个额外参数的未定义。特别是第二个附加参数必须小心处理。直接使用可能会违反坚定性,特别是在使用 dcg-semicontext.
指令
注意事项指令可以是另一种编写查询的方式。 From the SICStus Prolog manual:
Queries and directives are ways of directing the system to execute some goal or goals. (...) The principal use for directives (as opposed to queries) is to allow files to contain directives that call various predicates, but for which you do not want to have the answers printed out. In such cases you only want to call the predicates for their effect, i.e. you do not want terminal interaction in the middle of consulting the file.
指令也可以是源文件标记,其位置很重要(即代码元信息)。 From the SWI Prolog manual 在 module
指令上:
This directive can only be used as the first term of a source file. It declares 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 of predicate definitions.
例如,“为有限域上的约束逻辑编程加载库”:
:- use_module(library(clpfd)).
头部为空的规则:- foo
,可以解释为false :- foo
是not,在Prolog中用来表达约束“它永远不会foo 的情况”。它 是 在 Answer Set Programming 的实现中使用这种方式,例如“ASP Prolog”(它具有 Prolog-y 语法,但在其他方面与 Prolog 完全不同)。
内置谓词
注意事项在第 8 章第 63 页,我们发现:
"A built-in predicate is a procedure which is provided by a standard-conforming processor"
通俗地说,“内置谓词是 Prolog 语言的一部分”。其他谓词可能是 库谓词 ,需要通过适当的 指令 将其拉入 Prolog 程序。来自 SWI Prolog 的示例:library predicates.
关于事实的注释
通俗地说,“平面事实”是由基本项表示的事实 - 一个没有变量的项。
关于函子
的注释这与范畴论的“functor”无关。关于范畴论的函子,维基百科是这样说的:
The word functor was borrowed by mathematicians from the philosopher Rudolf Carnap, who used the term in a linguistic context; see function word.
关于“虚词”:
In linguistics, function words (also called functors) are words that have little lexical meaning or have ambiguous meaning and express grammatical relationships among other words within a sentence, or specify the attitude or mood of the speaker.
所以为 Prolog 选择“仿函数”有点不幸。
此外,斯坦福哲学百科全书中的逻辑学家 W.V.O Quine uses the word functor in "Predicate Functors Revisited" (and earlier) to describe a combinator that rearranges the arguments of the (atomic) predicate that (syntactically) follows it. See also: "Combinatory Logic - Alternative approaches: basic logic and predicate functors"。
另见问题 Definition of "functor"; Haskell vs. C++。
注意目标
目标可以是人们形容为“简单”的目标,例如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
关于predicate vs. procedure vs. predicate indicator
这个predicate的概念好像浮在“语义的space”而不是“语法的space”:
- “谓词事物”的名称或声明是谓词指标;
- “谓词事物”的谓词定义是过程(大概基于代码、Prolog 或其他)。
示例:
对于计算阶乘函数的 arity 2 的 predicate fact
:
fact/2
是谓词指标,
fact(0,1) :- !.
fact(X,F) :- Xp is (X-1), fact(Xp,Fp), F is (Fp*X).
是可能对应的过程.
在实践中,predicate 也用于表示任何 过程,并且可以编写 predicate 指示符 来识别它。
一个过程承认一个逻辑解释并允许其任何参数的变量将是[=75=中的关系 ]那个词。
在“Programming in Prolog(第 5 版)”(Clocksin & Mellish 2003)中,在第188那个
The collection of clauses for a given predicate is called a procedure.
关于 Prolog 文本的注释
“Prolog 程序”(ISO 标准中未定义的术语)是对一组 Prolog 文本 的口语化描述 运行由(可能是标准的)处理器。
Prolog 文本 还包括在顶层输入的非 Prolog 程序的文本,例如
?- X is 5 * 3.
X = 15.
关于术语规则的用法的附录..."is it cool to use rule?":
ISO Prolog Standard 在第 8 页定义了 规则 :
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 text by 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.
所以 "rule" 很酷。
的确,"rule" 主要调用了一段声明性知识,称为 产生式规则 ,用于前向链接(可能是反向链接)专家系统,例如CLIPS, Jess or Drools,在那里他们可以有一个
- 自下而上logical/deduction解释或
- 非逻辑状态space轨迹解释
...可能 "search"。还有“Constraint Handling Rules”,这是非常多的前向链接规则,可以编译成 Prolog 程序并与 Prolog 顺利集成。
P.S.
为了诉诸权威,以下是 Robert Kowalski 在 RuleML.org 于 2014 年发表的博文中的引文:
The Sad State Concerning the Relationships between Logic, Rules and Logic Programming
他好像在用:
- 产生式规则 用于前向链接规则,
- 反应规则 用于动作诱导规则(可以在溯因逻辑编程框架中给出逻辑解释)和
- 逻辑编程子句 嗯,逻辑编程子句。
Confusions about the relationships between logic, rules and logic programming are endemic in the world of computing.
...
I am particularly sensitive to the claim about the difference between deduction and search, because two of my earliest papers (1, 2) investigated the relationship between deduction and search. In my 2011 book (3), I discuss Thagard’s (4) various claims about logic and rules, and I argue that there are three varieties of production rules:
- Rules like IF you pass forty Arts courses, THEN you graduate with a B.A. These are logic programming clauses, used to reason forwards from conditions to conclusions.
- Rules like IF you want to go home for the weekend, and you have the bus fare, THEN you can catch a bus. These are “forward chaining” rules, used to simulate backward reasoning with logic programming clauses, such as, you go home for the weekend, if you have the bus fare, and you catch a bus.
- Rules like IF you are hungry THEN eat something. These are reactive rules, used to make the conclusion of the rule true whenever the condition of the rule becomes true.
In the book, I argue that reactive rules have a more general syntax than logic programming clauses, and they are also more fundamental.
- Kowalski, R. (1970), "Search Strategies for Theorem-proving" PDF.
- Kowalski, R. (1972), "And-or Graphs, Theorem-proving Graphs and Bi-directional Search" PDF.
- Kowalski, R. (2011) Computational Logic and Human Thinking: How to be Artificially Intelligent, Cambridge University Press. PDF of draft. Worldcat.
- Thagard, P. (2005) Mind: Introduction to cognitive science. MIT press.
ISO 词汇表有点微妙。它还有一个条目:
3.133 predication : A predicate with arity N and a sequence of N arguments .
由于(',')/2等控制结构在Prolog中也是谓词,上面的概念谓词不是质数公式,这里是正确的:
3.81 goal : A predication which is to be executed (see body , query , and 7.7.3).`
这与一阶逻辑词汇表有很大不同,在一阶逻辑词汇表中,连词 (∧) 等逻辑连接词不被视为谓词,因此不是语言签名的一部分。这个 ISO 核心标准特定语言,与 Prolog 的同音性有关。基本上我们可以在术语之间自由切换,例如 (',')/2 作为函子和具有相同函子的目标。这是一个可以在 Prolog 中完成的示例:
?- expand_goal(H, G), G.
后者在一阶逻辑中不可用,因为一阶逻辑不允许这种“meta-programming”。 John W. Lloyd 曾尝试创建一种不同的语言,受 Prolog 启发的语言,它也将以不同的方式处理“meta-programming”。语言是:
Gödel’s meta-logical facilities provide support for meta-programs that do analysis, transformation, compilation, verification, and debugging, among other tasks. https://en.wikipedia.org/wiki/G%C3%B6del_(programming_language)
ISO 核心标准应该在这个上下文中看到,它反映了 Prolog 关于“meta-programming”的非常具体的功能,这与一阶逻辑相去甚远。这意味着ISO核心标准中的术语属于人工词汇,分别是构造术语,专门为Prolog和ISO核心标准创建。
它不是计算机科学、数理逻辑或现实世界中其他地方的语言。就目前而言,没有什么可以更正或调整的,因为它是为 ISO 核心标准而创建的术语,并且关于计算机科学、数学逻辑或现实世界中其他用途的每项修正都是毫无根据的。
DCG 草案标准出现了类似的构造术语,多年来人们一直致力于此,直到心爱的“推回”被“半上下文”取代。 :-( :-) 由于 Ulrich Neumerkel 保存了 DCG 草案标准的所有版本,您可以观看构建术语的演变。
我不知道是否可以挖掘出一个文档集来显示 ISO 核心标准中术语的演变。谓词指示符是 N/A 形式的 Prolog 术语,谓词不是 Prolog 术语,而是抽象的