Coq证明了包含实数字面值的算术表达式是相等的

Coq证明了包含实数字面值的算术表达式是相等的,coq,Coq,我有一个非常基本的表达式,涉及实数文本和+,即4=1+1+1+1 我正试图找出如何用尽可能少的聪明来证明这个事实 Require Export RIneq. (* probably overkill, but it pulls in enough real number stuff to be useful *) Open Scope R_scope. Lemma test_sum2 : 4 = 1 + 1 + 1 + 1. 我试图通过使用

我有一个非常基本的表达式,涉及实数文本和
+
,即
4=1+1+1+1

我正试图找出如何用尽可能少的聪明来证明这个事实

Require Export RIneq. (* probably overkill, but it pulls in
                         enough real number stuff to be useful *)

Open Scope R_scope.

Lemma test_sum2 : 4 = 1 + 1 + 1 + 1.
我试图通过使用策略性选择的断言和滥发
直觉
,来证明这一点,但我似乎无法使用这种技术构建
3
之上的完整实相

Require Export RIneq.

Open Scope R_scope.

Lemma test_sum2 : 4 = 1 + 1 + 1 + 1.
Proof.
assert (1 + 1 = 2).
intuition.
rewrite H.
assert (1 + 2 = 3).
intuition.
assert (1 + 2 = 2 + 1).
intuition.
rewrite H1 in H0.
rewrite H0.
assert (1 + 3 = 3 + 1).
intuition.
让我处于证明状态

1 subgoal
H : 1 + 1 = 2
H0 : 2 + 1 = 3
H1 : 1 + 2 = 2 + 1
H2 : 1 + 3 = 3 + 1
______________________________________(1/1)
4 = 3 + 1
根据答案,看起来
字段
策略会起作用。我不确定这是否太聪明了

Require Export RIneq.

Open Scope R_scope.

Lemma test_sum2 : 4 = 1 + 1 + 1 + 1.
Proof.
  field.
Qed.

(在Coq 8.9+beta1中测试)

有趣的事实:
4%R=IZR(4%Z)
。为什么不使用更通用的
Require Import Reals。
这提供了所有通用工具来生成有关数值表达式的结果。对于表达式之间的相等(不一定是线性的),正确答案应该是
,它比
字段
稍微简单。关于这一策略值得学习,因为它是非常可预测的:它解决了任何真正的模结合性、交换性、相消性、加法、乘法、减法的等式。这里提出的策略
字段
更强大,因为它还处理除法,但这更为棘手,因为它需要检查分母是否为零。