什么是逻辑编程?和其他的有什么不同

发布于 2024-08-29 04:07:51 字数 38 浏览 4 评论 0原文

今天我和其他朋友聊天,他说他有逻辑编程能力,所以我对此很好奇。

today i have talk with other friend ,he said he has logic programming skill , so I am very curious about that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅紫色的梦幻 2024-09-05 04:07:51

wikipedia 条目解释得很好:虽然从表面上看,它似乎是一个多余的术语,因为所有编程都使用逻辑,实际上它是一个定义良好的范例的术语,例如“函数式编程”和“面向对象的编程”。具体来说,

逻辑编程,在更窄的范围内
更常见的意义上
可以理解,就是使用逻辑
既是声明性的又是程序性的
表示语言。它是基于
基于一个向后的事实
推理定理证明应用于
陈述句的形式为
影响:

If B1 and … and Bn then H

将影响视为
目标减少程序:

to show/solve H, show/solve B1 and … and Bn.

Prolog 语言(某些变体或其他形式)可能仍然是最流行的逻辑编程语言。

The wikipedia entry explains it well: while on the surface it seems a redundant terms since all programming uses logic, in practice it's term for a well-defined paradigm, like, say, "functional programming" and "object-oriented programming". Specifically,

logic programming, in the narrower
sense in which it is more commonly
understood, is the use of logic as
both a declarative and procedural
representation language. It is based
upon the fact that a backwards
reasoning theorem-prover applied to
declarative sentences in the form of
implications:

If B1 and … and Bn then H

treats the implications as
goal-reduction procedures:

to show/solve H, show/solve B1 and … and Bn.

The language Prolog (in some variant or other) is probably still the most popular logic programming language.

ㄖ落Θ余辉 2024-09-05 04:07:51

我通常将其理解为使用序言。 Prolog 允许您定义谓词和真值。然后,序言解释器可以使用标准逻辑规则得出进一步的“事实”。例如,以下每一行在第一个参数和第二个参数之间建立了一个 father_childmother_children 关系(提到的人来自辛普森一家)。

member(X, [X|_]).
member(X, [_|T]) :- member(X,T).

mother_children(marge, [bart, lisa, maggie]).
mother_children(mona, [homer, jay]).

mother_child(X, Y) :- mother_children(X, C), member(Y, C).

father_child(homer, bart).
father_child(homer, lisa).
father_child(homer, maggie).
father_child(abe, homer).
father_child(abe, herb).
father_child(abe, abbie).

sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y).

parent_child(X, Y) :- father_child(X, Y).
parent_child(X, Y) :- mother_child(X, Y).

如果您将该程序启动到 prolog 解释器中,然后询问它 sibling(X,Y),它将返回给您所有存在的兄弟姐妹对。有趣的是,我们从来没有明确地说,巴特是丽莎的兄弟姐妹。我们只是定义了父亲和母亲的关系,但通过定义进一步的规则,prolog 使用普通规则来派生出满足兄弟姐妹规则的名字。

Prolog在80年代更流行,在各种人工智能系统等中。如今它有点过时了(你在大学里可能不会知道,在那里它仍然很热门)。

I'd usually understand it to mean using prolog. Prolog allows you to define predicates, and truth values. The prolog interpreter can then derive further "truths", using standard logic rules. For example, each of the following lines establish a father_child and mother_children relationship between the first and the second parameter (the people mentioned are from the Simpsons).

member(X, [X|_]).
member(X, [_|T]) :- member(X,T).

mother_children(marge, [bart, lisa, maggie]).
mother_children(mona, [homer, jay]).

mother_child(X, Y) :- mother_children(X, C), member(Y, C).

father_child(homer, bart).
father_child(homer, lisa).
father_child(homer, maggie).
father_child(abe, homer).
father_child(abe, herb).
father_child(abe, abbie).

sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y).

parent_child(X, Y) :- father_child(X, Y).
parent_child(X, Y) :- mother_child(X, Y).

If you fire this program into a prolog interpreter, and then ask it sibling(X,Y), it will return to you all the pairs of siblings that exist. What's interesting is that we never explicit say that say, Bart is a sibling to Lisa. We just define father and mother relationships, but by defining further rules, prolog uses normal rules to derive what names fullfill the sibling rule.

Prolog was more popular in the 80s, in various AI systems and the like. It's a bit out of fashion these days (not that you'd know in universities, where it's still hot shit).

你丑哭了我 2024-09-05 04:07:51

我认为该语句的意思是“我可以编写 if/then/else 语句”。或者换句话说,我认为这句话的意思是“我无法使用任何真正的技术进行编程”。我不会留下深刻的印象。

I would take that statement to mean, "I can program if/then/else statements". Or in other words, I would take that statement to mean, "I can't program with any real technology". I would not be impressed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文