coq - 在 Coq 中求解一个变量
问题描述
有没有办法解决 Coq 中的变量?鉴于:
From Coq Require Import Reals.Reals.
Definition f_of_x (x : R) : R := x + 1.
Definition f_of_y (y : R) : R := y + 2.
我想表达
Definition x_of_y (y : R) : R :=
就像solve for x in f_of_x = f_of_y.
我希望使用策略语言然后改组术语一样。我最终想得到正确的可用定义,y + 1.
我认为想要使用我的定义:
Compute x_of_y 2. (* This would yield 3 if R was tractable or if I was using nat *)
另一种方法是用铅笔/纸手工完成,然后只用 Coq检查我的工作。这是唯一的方法吗?
解决方案
如果我理解正确,您要表达的是方程的解的存在
x + 3 = x + 2
如果是这样,您可以在 coq 中将其声明为
Lemma solution :
exists x, x + 3 = x + 2.
如果它是x + 2 = 2 * x
可以解决的,那么您可以将其解决为
Lemma solution :
exists x, x + 2 = 2 * x.
Proof.
exists 2. reflexivity.
Qed.
但是当然没有解决方案x + 3 = x + 2
。如果你想要一个解决方案,y
固定为
x + 3 = y + 2
你必须量化y
:
Lemma solution :
forall y, exists x, x + 1 = y + 2.
Proof.
intro y.
eexists. (* Here I'm saying I want to prove the equality and fill in the x later *)
eapply plus_S_inj.
rewrite plus_0.
reflexivity.
Defined.
Print solution. (* You will see the y + 1 here *)
在这里,我假设一些可以帮助我操纵数字的引理:
Lemma plus_S_inj :
forall x y z t,
x + z = y + t ->
x + (S z) = y + (S t).
Admitted.
Lemma plus_0 :
forall x,
x + 0 = x.
Admitted.
对于您的概念,您可能有类似的引理R
(我不知道它是什么,所以我不能再进一步了。)
推荐阅读
- django - 如何在 Django 模型中设置字段常量
- python - for in for 循环(for 并行工作)
- java - 如何在 Spring Mail 集成中启用 IMAPFolder 读写模式
- java - E/RecyclerView:没有附加适配器;跳过布局 D/OpenGLRenderer: eglDestroySurface = 0x730c9a02d0
- javascript - 用户离开页面/刷新时跟踪表单更改
- node.js - 对Node js的两个括号功能感到困惑
- python - 如何修复 Python 在 MySQL 数据库中输入错误的值
- bash - 如何使用 gawk 将文本包装在列中
- android - 是否必须将 ListView.Builder 小部件放置在单独的页面上
- javascript - 在 setInterval 中调用函数会导致本机反应错误