逻辑编程的最佳用途是什么?

发布于 2024-07-06 18:11:18 字数 283 浏览 4 评论 0 原文

我所说的逻辑编程是指声明性编程语言的子范式。 不要把这个问题和“用if-then-else能解决什么问题?”搞混了

像Prolog这样的语言很迷人,为了学而值得学,但我不得不想知道是什么课现实世界的问题可以通过这种语言得到最好的表达和解决。 有更好的语言吗? 在更流行的编程语言中,逻辑编程是否以另一个名称存在? 答案的愤世嫉俗版本是 Python 悖论 的变体吗?

By Logic Programming I mean the a sub-paradigm of declarative programming languages. Don't confuse this question with "What problems can you solve with if-then-else?"

A language like Prolog is very fascinating, and it's worth learning for the sake of learning, but I have to wonder what class of real-world problems is best expressed and solved by such a language. Are there better languages? Does logic programming exist by another name in more trendy programming languages? Is the cynical version of the answer a variant of the Python Paradox?

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

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

发布评论

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

评论(8

舂唻埖巳落 2024-07-13 18:11:19

原型制作

Prolog 是充满活力的,并且已经存在了 50 年。 编译器是自由的,语法是简约的,“做事”是简单、有趣和高效的。 SWI-Prolog 有一个内置的跟踪器(调试器!),甚至 图形跟踪器。 您可以使用 make/0 即时更改代码,您可以动态加载模块,在不离开解释器的情况下添加几行代码,或者编辑当前正在即时运行的文件使用编辑(1)。 您认为您发现了 foobar/2 谓词有问题吗?

?- edit(foobar).

一旦你离开编辑器,那个东西就会被重新编译。 当然,Eclipse 对 Java 做了同样的事情,但 Java 并不完全是一种原型语言。

除了纯粹的原型设计之外,Prolog 非常适合将一段逻辑转换为代码。 因此,自动证明器和此类内容可以轻松地用 Prolog 编写。

第一个 Erlang 解释器是用 Prolog 编写的 - 这是有原因的,因为 Prolog 非常适合解析和编码在解析树中找到的逻辑。 事实上,Prolog 带有一个内置的解析器! 不,不是一个库,它是在语法中,即 DCGs 。

Prolog 在 NLP 中被大量使用,特别是在语法和计算语义方面。

但是,Prolog 并未得到充分利用和重视。 不幸的是,它似乎带有学术或“无法用于任何实际目的”的耻辱。 但它可以在许多涉及事实和事实之间关系计算的现实应用中得到很好的利用。 它不太适合数字运算,但 CS 不仅仅涉及数字运算。

Prototyping.

Prolog is dynamic and has been for 50 years. The compiler is liberal, the syntax minimalist, and "doing stuff" is easy, fun and efficient. SWI-Prolog has a built-in tracer (debugger!), and even a graphical tracer. You can change the code on the fly, using make/0, you can dynamically load modules, add a few lines of code without leaving the interpreter, or edit the file you're currently running on the fly with edit(1). Do you think you've found a problem with the foobar/2 predicate?

?- edit(foobar).

And as soon as you leave the editor, that thing is going to be re-compiled. Sure, Eclipse does the same thing for Java, but Java isn't exactly a prototyping language.

Apart from the pure prototyping stuff, Prolog is incredibly well suited for translating a piece of logic into code. So, automatic provers and that type of stuff can easily be written in Prolog.

The first Erlang interpreter was written in Prolog - and for a reason, since Prolog is very well suited for parsing, and encoding the logic you find in parse trees. In fact, Prolog comes with a built-in parser! No, not a library, it's in the syntax, namely DCGs.

Prolog is used a lot in NLP, particularly in syntax and computational semantics.

But, Prolog is underused and underappreciated. Unfortunately, it seems to bear an academic or "unusable for any real purpose" stigma. But it can be put to very good use in many real-world applications involving facts and the computation of relations between facts. It is not very well suited for number crunching, but CS is not only about number crunching.

萧瑟寒风 2024-07-13 18:11:19

由于 Prolog = 句法统一 + 向后链接 + REPL

大多数使用句法统一的地方也是 Prolog 的一个很好的用途。

句法统一使用

  • AST 转换
  • 类型推断
  • 术语重写
  • 定理证明
  • 自然语言处理
  • 模式匹配
  • 组合测试用例生成
  • 从结构化数据(例如 XML 文档)中提取子结构
  • 符号计算,即微积分
  • 演绎数据库
  • 专家系统
  • 人工智能
  • 解析
  • 查询语言

Since Prolog = Syntactic Unification + Backward chaining + REPL,

most places where syntactic unification is used is also a good use for Prolog.

Syntactic unification uses

  • AST transformations
  • Type Inference
  • Term rewriting
  • Theorem proving
  • Natural language processing
  • Pattern matching
  • Combinatorial test case generation
  • Extract sub structures from structured data such as an XML document
  • Symbolic computation i.e. calculus
  • Deductive databases
  • Expert systems
  • Artificial Intelligence
  • Parsing
  • Query languages
﹏半生如梦愿梦如真 2024-07-13 18:11:19

约束逻辑编程 (CLP) 前面

已经提到了许多非常好的且非常适合的逻辑编程用例。 我想用来自逻辑编程极其重要的应用领域的几项任务来补充现有的列表:

逻辑编程与约束无缝地融合在一起,比其他范式更无缝,从而产生了一个名为的框架约束逻辑编程。

这导致了不同的专用约束求解器,例如:

  • 整数CLP(FD)
  • CLP(B) > 对于布尔
  • CLP(Q) 对于有理数 数字
  • CLP(R) 对于浮点数强>数字。

这些专用的约束求解器导致了逻辑编程的几个尚未提及的重要用例,我在下面展示了其中一些用例。

选择 Prolog 系统时,其约束求解器的功能和性能通常是决定因素,特别是对于商业用户而言。

CLP(FD) — 整数推理

实际上,CLP(FD) 是逻辑编程最重要的应用之一,用于解决以下领域的任务:

  • 日程安排
  • 资源分配
  • 规划
  • 组合优化

参见 了解更多信息和几个示例。

CLP(B) — 布尔约束

CLP(B) 通常与以下各项结合使用:

  • SAT 解答
  • 电路验证
  • 组合计数

请参阅

CLP(Q) — 有理数

CLP(Q) 用于解决运筹学中出现的重要类别问题:

  • 线性规划
  • 整数线性规划
  • 混合整数线性规划

请参阅

Constraint Logic Programming (CLP)

Many very good and well-suited use cases of logic programming have already been mentioned. I would like to complement the existing list with several tasks from an extremely important application area of logic programming:

Logic programming blends seamlessly, more seamlessly than other paradigms, with constraints, resulting in a framework called Constraint Logic Programming.

This leads to dedicated constraint solvers for different domains, such as:

  • CLP(FD) for integers
  • CLP(B) for Booleans
  • CLP(Q) for rational numbers
  • CLP(R) for floating point numbers.

These dedicated constraint solvers lead to several important use cases of logic programming that have not yeen been mentioned, some of which I show below.

When choosing a Prolog system, the power and performance of its constraint solvers are often among the deciding factors, especially for commercial users.

CLP(FD) — Reasoning over integers

In practice, CLP(FD) is one of the most imporant applications of logic programming, and is used to solve tasks from the following areas, among others:

  • scheduling
  • resource allocation
  • planning
  • combinatorial optimization

See for more information and several examples.

CLP(B) — Boolean constraints

CLP(B) is often used in connection with:

  • SAT solving
  • circuit verification
  • combinatorial counting

See .

CLP(Q) — Rational numbers

CLP(Q) is used to solve important classes of problems arising in Operations Research:

  • linear programming
  • integer linear programming
  • mixed integer linear programming

See .

卸妝后依然美 2024-07-13 18:11:19

Prolog 免费为您提供的功能之一是回溯搜索算法——您可以自己实现它,但如果您的问题通过使用该算法可以得到最好的解决,那么使用它就好了。

我发现它擅长的两件事是数学证明和自然语言理解。

One of the things Prolog gives you for free is a backtracking search algorithm -- you could implement it yourself, but if your problem is best solved by having that algorithm available, then it's nice to use it.

The two things I've seen it be good at is mathematical proofs and natural language understanding.

独﹏钓一江月 2024-07-13 18:11:19

Prolog 非常适合解决非数字问题。 这篇文章给出了Prolog的一些应用程序的一些示例,它可能会帮助您理解问题的类型它可能会解决。

Prolog is ideal for non-numeric problems. This article gives a few examples of some applications of Prolog and it might help you understand the type of problems that it might solve.

呆头 2024-07-13 18:11:19

Prolog 非常擅长解决谜题等问题。 也就是说,在解谜领域,它使简单/中等的谜题解决变得更容易,而复杂的谜题解决则更加困难。 尽管如此,为诸如 Hexiom、Sudoku 或 Nurikabe 之类的网格谜题编写求解器并不是特别困难。

Prolog is great at solving puzzles and the like. That said, in the domain of puzzle-solving it makes easy/medium puzzle-solving easier and complicated puzzle solving harder. Still, writing solvers for grid puzzles and the like such as Hexiom, Sudoku, or Nurikabe is not especially tough.

风透绣罗衣 2024-07-13 18:11:19

一个简单的答案是“构建系统”。 用于构建Makefile(至少是描述依赖关系的部分)的语言本质上是一种逻辑编程语言,尽管并不是真正的“纯粹”逻辑编程语言。

One simple answer is "build systems". The language used to build Makefiles (at least, the part to describe dependencies) is essentially a logic programming language, although not really a "pure" logic programming language.

吾性傲以野 2024-07-13 18:11:19

是的,Prolog 自 1972 年就已存在。 它是由 Alain Colmerauer 和 Philippe Roussel 基于 Robert Kowalski 对 Horn 条款的程序解释而发明的。 阿兰 (Alain) 是法国计算机科学家,1970 年至 1995 年间担任艾克斯-马赛大学教授。

阿兰发明它是为了分析自然语言。 他和他的“追随者”创造了几个成功的原型。

  • 他自己的系统Orbis可以理解有关太阳系的英语和法语问题。 请参阅他的个人网站
  • Warren 和 Pereira 的世界地理系统Chat80 QA。
  • 如今,IBM Watson 是一种基于逻辑和大量统计数据的当代 QA关于现实世界的短语。

所以你可以想象这就是它的力量所在。

他于 2006 年退休,一直活跃到 2017 年去世。1986 年,他被法国政府授予法国荣誉军团骑士勋章。

Yes, Prolog has been around since 1972. It was invented by Alain Colmerauer with Philippe Roussel, based on Robert Kowalski's procedural interpretation of Horn clauses. Alain was a French computer scientist and professor at Aix-Marseille University from 1970 to 1995.

And Alain invented it to analyse Natural Language. Several successful prototypes were created by him and his "followers".

  • His own system Orbis to understand questions in English and French about the solar system. See his personal site.
  • Warren and Pereira's system Chat80 QA on world geography.
  • Today, IBM Watson is a contempory QA based on logic with a huge dose of statistics about real world phrases.

So you can imagine that's where it's strength is.

Retired in 2006, he remained active until he died in 2017. He was named Chevalier de la Legion d’Honneur by the French government in 1986.

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