简体   繁体   English

在Prolog中定义条件材料

[英]Defining the material conditional in Prolog

I have been trying to acclimate to Prolog and Horn clauses, but the transition from formal logic still feels awkward and forced. 我一直试图适应Prolog和Horn条款,但从形式逻辑的过渡仍然感到尴尬和被迫。 I understand there are advantages to having everything in a standard form, but: 我知道以标准形式提供所有东西都有好处,但是:

What is the best way to define the material conditional operator --> in Prolog, where A --> B succeeds when either A = true and B = true OR B = false ? 定义材料条件运算符的最佳方法是什么-->在Prolog中,当A = trueB = trueB = false时, A --> B成功? That is, an if->then statement that doesn't fail when if is false without an else . 也就是说, iffalse而没有else ,则if->then语句不会fail

真相表

Also, what exactly are the non-obvious advantages of Horn clauses? 另外,Horn条款的非显而易见的优点究竟什么?

What is the best way to define the material conditional operator --> in Prolog 在Prolog中定义材质条件运算符的最佳方法是什么?

When A and B are just variables to be bound to the atoms true and false , this is easy: AB只是要绑定到原子的变量truefalse ,这很容易:

cond(false, _).
cond(_, true).

But in general, there is no best way because Prolog doesn't offer proper negation, only negation as failure , which is non-monotonic. 但总的来说,没有最好的方法,因为Prolog没有提供适当的否定,只有作为失败的否定 ,这是非单调的。 The closest you can come with actual propositions A and B is often 最接近实际命题AB的经常是

(\+ A ; B)

which tries to prove A , then goes on to B if A cannot be proven (which does not mean that it is false due to the closed-world assumption ). 试图证明A ,然后如果A 无法证明则继续B (这并不意味着由于封闭世界假设它是假的)。

Negation, however, should be used with care in Prolog. 然而,在Prolog中应谨慎使用否定。

Also, what exactly are the non-obvious advantages of Horn clauses? 另外,Horn条款的非显而易见的优点究竟是什么?

That they have a straightforward procedural reading. 他们有一个简单的程序性阅读。 Prolog is a programming language , not a theorem prover. Prolog是一种编程语言 ,而不是一个定理证明者。 It's possible to write programs that have a clear logical meaning, but they're still programs. 编写具有明确逻辑意义的程序是可能的,但它们仍然是程序。

To see the difference, consider the classical problem of sorting. 要了解差异,请考虑经典的排序问题。 If L is a list of numbers without duplicates, then 如果L是没有重复的数字列表,那么

sort(L, S) :-
    permutation(L, S),
    sorted(S).
sorted([]).
sorted([_]).
sorted([X,Y|L]) :-
    X < Y,
    sorted([Y|L]).

is a logical specification of what it means for S to contain the elements of L in sorted order. S按排序顺序包含L元素的含义的逻辑规范。 However, it also has a procedural meaning, which is: try all the permutations of L until you have one that it sorted. 但是,它也有一个程序意义,即:尝试L所有排列,直到你有一个排序。 This procedure, in the worst case, runs through all n ! 在最坏的情况下,这个程序贯穿所有n permutations, even though sorting can be done in O( n lg n ) time, making it a very poor sorting program. 排列,即使排序可以在O( n lg n )时间内完成,使其成为一个非常差的排序程序。

See also this question . 另见这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM