简体   繁体   English

是否可以在 Ocaml 中实现罗素悖论?

[英]Is it possible to implement Russell's Paradox in Ocaml?

I recently learned about Russell's Paradox in naive set theory, where when considering the set of all sets that are not members of themselves, the set appears to be a member of itself iff it is not a member of itself, which creates the paradox.我最近在朴素集合论中了解了罗素悖论,当考虑所有不是自身成员的集合的集合时,如果它不是自身的成员,则该集合似乎是自身的成员,这就产生了悖论。 I was wondering if a function that asks whether a set is a member of itself is implementable, in a functional language such as Ocaml, since Russell's Paradox has no definite answer in itself, and if so, would like any hints on how to tackle the problem.我想知道一个 function 是否可以用诸如 Ocaml 之类的函数式语言来实现,因为罗素悖论本身没有明确的答案,如果是这样,想知道如何解决这个问题的任何提示问题。 In addition, I am interested in learning if any of these mathematical paradoxes are implementable in general.此外,我有兴趣了解这些数学悖论中的任何一个是否可以普遍实现。

I am neither a logician nor a type or set theorist.我既不是逻辑学家,也不是类型论者或集合论者。 But if you turn on -rectypes you can write a function that tests whether a list is a member of itself:但是如果你打开-rectypes你可以写一个 function 来测试一个列表是否是它自己的成员:

$ ocaml -rectypes
        OCaml version 4.10.0

let f x = List.mem x x;;
val f : ('a list as 'a) -> bool = <fun>

You can create a list that is a member of itself:您可以创建一个属于自身的列表:

# let rec mylist = [mylist];;
val mylist : 'a list as 'a = [<cycle>]
# f mylist;;
- : bool = true

I suspect this is only faintly related to Russell's paradox, unfortunately.不幸的是,我怀疑这与罗素悖论只有微弱的关系。

Update更新

Say you define a set as a function that returns true for elements of the set and false for elements not in the set.假设您将一个集合定义为 function,它对集合中的元素返回 true,对不在集合中的元素返回 false。 Then you can create Russell's paradox to a pretty reasonable degree.然后你可以在相当合理的程度上创造罗素悖论。

The empty set is a set that always returns false:空集是一个总是返回 false 的集合:

$ rlwrap ocaml -rectypes
        OCaml version 4.10.0

# let empty x = false;;
val empty : 'a -> bool = <fun>

Here is a singleton set that contains itself:这是一个包含自身的 singleton 集:

# let rec just_self x = x == just_self;;
val just_self : 'a -> bool as 'a = <fun>

You can try various tests of these values and get reasonable answers:您可以尝试对这些值进行各种测试并获得合理的答案:

# empty empty;;
- : bool = false

The empty set doesn't contain anything, including itself.空集不包含任何东西,包括它自己。

# just_self empty;;
- : bool = false

The set just_self only contains itself, not the empty set.集合just_self只包含它自己,而不是空集合。

# just_self just_self;;
- : bool = true

So then the Russell set is the set that contains sets that don't contain themselves:因此,罗素集是包含不包含自身的集合的集合:

# let russell s = not (s s);;
val russell : ('a -> bool as 'a) -> bool = <fun>

The Russell set contains the empty set (because it doesn't contain itself): Russell 集包含空集(因为它不包含自身):

# russell empty;;
- : bool = true

The Russell set does not contain just_self , because that set contains itself: Russell 集不包含just_self ,因为该集包含自身:

# russell just_self;;
- : bool = false

Now the big payoff.现在是大回报。 Does the Russell set contain itself?罗素集是否包含自身?

# russell russell;;
Stack overflow during evaluation (looping recursion?).

This is what you should expect.这是你应该期待的。 Ie, the computation diverges.即,计算发散。 (Also a very fitting result for this website.) (对于这个网站也是一个非常合适的结果。)

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

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