跳到正文

休闲·娱乐

四 · 则 · 运 · 算 · ♂

__yyx__约 5 分钟
原文

这是 2026年8月18日 存档的第 5 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年8月16日
收录
2026年8月17日
更新
2026年11月10日
篇幅
约 5 分钟

版本

  1. v7当前
  2. v6
  3. v5
  4. v4
更早的 3 个版本
  1. v3
  2. v2
  3. v1

四则运算改版

我们长期坚持把四则运算当做函数,比如我们会说 3+3=63 + 3 = 6,那我们不妨把加法当做一个数字,然后将 ++ 应用到数对 (3,3)(3,3) 上呢?让我们把四则运算设计成改版。

我们定义 [(⊕)  a][(\oplus) \; a] 表示将函数 (⊕)(\oplus) 运用到 aa 上,其中 ⊕\oplus 是二元运算。

那么,我们需要定义什么是代入,这样才能对 ++ 带入到数对中。我们直接抽象化:

对于函数 xx 和另一个函数 y=f(x)y = f(x),我们将 x=kx=k,kk 是常值函数(那么就是 k(x)=Ck(x) = C),那么 [y  x]=[f(x)  x]=[f(k)  k]=[y  k][y \; x] = [f(x)\; x] =[f(k)\; k] = [y\; k]。这叫做代入。

如果 ∀k∈O,[f  k]=[g  k]\forall k \in \mathbb O , [f \; k] = [g\; k],其中 O\mathbb O 为运算域,那么称 gg 为 ff 的转化,记作 g→fg \to f。同时,如果 gg 不存在,我们定义 g→fg \to f,也可以写成 g=structfg \overset{\text{struct}} = f

后文中,我们把所有已定义的函数标为蓝色。

我们只定义 void\gray{\text{void}} 为空和代数数 00。

逻辑运算

我们要定义逻辑运算,那必须要有最基本的函数:

FALSE:[FALSE  (x,y)]=yTRUE:[TRUE  (x,y)]=x\blue{FALSE}: [ \blue{FALSE} \; (x,y)] = y \\ \blue{TRUE}: [ \blue{TRUE} \; (x,y)] = x

为了算式简洁,我们把上述两个运算定义成 B0,B1\blue{B_0, B_1}。

接下来我们定义 NOT(N)\blue {NOT} (\blue{N}):

对任意 b∈O\blue b\in\mathbb O:[NOT  b]=struct[b  (B0,B1)]{[\blue{NOT}\;\blue b] \overset{\text{struct}}{=} [\blue b\;(\blue{B_0},\blue{B_1})]}。

然后我们构造 AND,OR\blue{AND},\blue{OR}。

[AND  (a,b)]=struct[a  (b,B0)][\blue{AND}\;(\blue a,\blue b)] \overset{\text{struct}}{=} [\blue a\;(\blue b,\blue{B_0})]

然后我们测试 [AND  (B1,B0)][\blue{AND}\;(\blue{B_1},\blue{B_0})]

  • [AND  (B1,B0)]=[B1  (B0,B0)]=B0[\blue{AND}\;(\blue{B_1},\blue{B_0})]=[\blue{B_1}\;(\blue{B_0},\blue{B_0})]=\blue{B_0}
[OR  (a,b)]=struct[a  (B1,b)]。[\blue{OR}\;(\blue a,\blue b)] \overset{\text{struct}}{=} [\blue a\;(\blue{B_1},\blue b)]。

测试 [OR  (B0,B1)][\blue{OR}\;(\blue{B_0},\blue{B_1})]

  • [OR  (B0,B1)]=[B0  (B1,B1)]=B1[\blue{OR}\;(\blue{B_0},\blue{B_1})]=[\blue{B_0}\;(\blue{B_1},\blue{B_1})]=\blue{B_1}。

好了,逻辑运算就位,接下来就可以随便干了。

数字

我们上述的定义是,B0,B1\blue {B_0,B_1} 都是一个筛选器。所以拓展后,我们希望丰富体系内可以干的事。考虑封装递归到数字里,这意味着我们的体系内没有数字的实体。

自然地:

[0  (x,y)]=structvoid[1  (x,y)]=struct[x  y][\blue {0}\; (x,y)] \overset{\text{struct}} = \gray{ \text{void}} \\ [\blue {1}\; (x,y)] \overset{\text{struct}} = [x \; y]

然后,我们考虑数字 22,他必须是一个递归器:

input=(x,y)[2  (x,y)]=struct[x  [x  y]]\text{input} = (x,y)\\ [\blue {2}\; (x,y)] \overset{\text{struct}} = [x \; [x \; y]]

以此类推:

input=(x,y)[3  (x,y)]=struct[x  [x  [x  y]][4  (x,y)]=struct[x  [x  [x  [x  y]]]⋮\text{input} = (x,y)\\ [\blue {3} \; (x,y)] \overset{\text{struct}} = [x \; [x \;[x \; y]]\\ [\blue {4} \; (x,y)] \overset{\text{struct}} = [x \; [x \;[x \; [x \; y]]] \\ \vdots

构造皮亚诺体系内的后继函数 SUCC(S)\blue {SUCC} (\blue{S}):

input=n[S  n]=struct[x  [n  (x,y)]]\text{input} = n\\ [\blue S \; n] \overset{\text{struct}} = [x \; [n \; (x,y)]]

前驱类似 PRE(P):\blue {PRE} (\blue{P}):

[Ktmp  n]=struct[a  (S,a)][P  n]=struct[n  (Ktmp,(0,0))][\blue{K_{tmp}} \; n] \overset{\text{struct}} = [a \; (\blue S, a)] \\ [\blue{P} \; n] \overset{\text{struct}} = [n \; (\blue{K_{tmp}},(0,0))]

补丁

我们差一个遍历器来表示方程(我们无法定义当前域的 ∞\infty),比如你要解 x5+9=41x^5 + 9 = 41,在代数范围内有解,但无法用普通代数方法求出(没有通解),因此我们需要一个用于枚举的东西。

比如(我们现在先用一下 F\blue{F} 运算表示 x5+9x^5+9)

[Θ  [F  x]]→struct41[\red \Theta \; [\blue{F} \; x]] \overset{\text{struct}} \to 41

这里,Θ\red \Theta 传入两个参数,返回常数函数,他是认为构造的,但他绝对有值,后面我们可以用 Θ\red \Theta 当做未知数来用。

参考停机问题不可判定, Θ\red \Theta 可能是无意义的值。

运算

有了数字,那就可以直接开始加减乘除了。

加法巨简单:[+  (a,b)]=struct[a  (x,[b  (x,y)])][\blue +\; (a,b)] \overset{\text{struct}} = [a \; (x,[b \; (x,y)])]

减法类似: