一个句子数论(我们的目的)的是下列符号序列:
0
和'
(后继) -后继手段+1
,所以0'''' = 0 + 1 + 1 + 1 + 1 = 4
+
(加法)和*
(乘法)=
(等于)(
和)
(括号)- 逻辑运算符
nand
(a nand b
是not (a and b)
) forall
(通用量词)v0
,v1
,v2
等。(变量)这是一个句子的示例:
forall v1 (forall v2 (forall v3 (not (v1*v1*v1 + v2*v2*v2 = v3*v3*v3))))
这not x
是简写x nand x
-实际的句子会用到(v1*v1*v1 + v2*v2*v2 = v3*v3*v3) nand (v1*v1*v1 + v2*v2*v2 = v3*v3*v3)
,因为x nand x = not (x and x) = not x
。
这说明,对于三个自然数v1
,,v2
和的每个组合v3
,v1 3 + v2 3 = v3 3都不是这种情况(由于费马最后定理,这是正确的,除了它会得到0 ^ 3 + 0 ^ 3 = 0 ^ 3)。
不幸的是,正如哥德尔所证明的那样,无法确定数论中的一个句子是否正确。
这是可能的,但是,如果我们限制自然数集到有限集。
因此,这一挑战是确定以某个正整数为模数 时,数论句子是否为真。例如,句子n
n
forall v0 (v0 * v0 * v0 = v0)
(对于所有数字x,x 3 = x 的陈述)
对于普通算术(例如2 3 = 8≠2)不是正确的,但是当取模3时是正确的:
0 * 0 * 0 ≡ 0 (mod 3)
1 * 1 * 1 ≡ 1 (mod 3)
2 * 2 * 2 ≡ 8 ≡ 2 (mod 3)
输入输出格式
输入是n
任何“合理”格式的句子和正整数。这是forall v0 (v0 * v0 * v0 = v0)
数论模3中句子的合理格式示例:
("forall v0 (v0 * v0 * v0 = v0)", 3)
"3:forall v0 (((v0 * v0) * v0) = v0)"
"(forall v0)(((v0 * v0) * v0) = v0) mod 3"
[3, "forall", "v0", "(", "(", "(", "v0", "*", "v0", ")", "*", "v0", ")", "=", "v0", ")"]
(3, [8, 9, 5, 5, 5, 9, 3, 9, 6, 3, 9, 6, 4, 9, 6]) (the sentence above, but with each symbol replaced with a unique number)
"f v0 = * * v0 v0 v0 v0"
[3, ["forall", "v0", ["=", ["*", "v0", ["*", "v0", "v0"]], "v0"]]]
"3.v0((v0 * (v0 * v0)) = v0)"
输入可以来自标准输入,命令行参数,文件等。
程序可以有两个截然不同的输出来判断句子是否正确,例如,可以输出yes
是否正确no
。
您不需要支持将一个变量作为forall
两次的主题,例如(forall v0 (v0 = 0)) nand (forall v0 (v0 = 0))
。您可以假定您的输入具有有效的语法。
测试用例
forall v0 (v0 * v0 * v0 = v0) mod 3
true
forall v0 (v0 * v0 * v0 = v0) mod 4
false (2 * 2 * 2 = 8 ≡ 0 mod 4)
forall v0 (v0 = 0) mod 1
true (all numbers are 0 modulo 1)
0 = 0 mod 8
true
0''' = 0 mod 3
true
0''' = 0 mod 4
false
forall v0 (v0' = v0') mod 1428374
true
forall v0 (v0 = 0) nand forall v1 (v1 = 0) mod 2
true (this is False nand False, which is true)
forall v0 ((v0 = 0 nand v0 = 0) nand ((forall v1 (v0 * v1 = 0' nand v0 * v1 = 0') nand forall v2 (v0 * v2 = 0' nand v0 * v2 = 0')) nand (forall v3 (v0 * v3 = 0' nand v0 * v3 = 0') nand forall v4 (v0 * v4 = 0' nand v0 * v4 = 0')))) mod 7
true
(equivalent to "forall v0 (v0 =/= 0 implies exists v1 (v0 * v1 = 0)), which states that every number has a multiplicative inverse modulo n, which is only true if n is 1 or prime)
forall v0 ((v0 = 0 nand v0 = 0) nand ((forall v1 (v0 * v1 = 0' nand v0 * v1 = 0') nand forall v2 (v0 * v2 = 0' nand v0 * v2 = 0')) nand (forall v3 (v0 * v3 = 0' nand v0 * v3 = 0') nand forall v4 (v0 * v4 = 0' nand v0 * v4 = 0')))) mod 4
false
这是代码高尔夫,所以请尝试使您的程序尽可能短!
var number
甚至可以使用1 + number
(1
应该是v0
,2
将会是v1
,等等)
'v number
代替使用v number'
吗?
v number
?