Coq Can';t将变量绑定到包装的开放式公式
首先,对于通常的开放式公式Coq Can';t将变量绑定到包装的开放式公式,coq,Coq,首先,对于通常的开放式公式 Require Import Coq.Init.Nat. Variable x : nat. Lemma test1: ~ exists a : nat, let x := a in x * x = 2. Proof. simpl. Admitted. 我可以看到a在simple.之后绑定到x 1 subgoal ______________________________________(1/1) ~ (exists a : nat,
Require Import Coq.Init.Nat.
Variable x : nat.
Lemma test1:
~ exists a : nat,
let x := a in
x * x = 2.
Proof.
simpl. Admitted.
我可以看到a
在simple.
之后绑定到x
1 subgoal
______________________________________(1/1)
~ (exists a : nat, a * a = 2)
1 subgoal
______________________________________(1/1)
~ (exists _ : nat, True /\ x * x = 2)
现在,我基于Prop
,编写包装的开放式公式formula
,
使用展开操作f2p
Require Import Coq.Init.Nat.
Require Import Lists.List.
Import ListNotations.
(* I: injection, A: and, T: then, S: square *)
Inductive formula := I (p : Prop) | A (f g : formula) | T (p : Prop) (f : formula) | S (f : formula).
(* unwrap formula to prop *)
Fixpoint f2p (f : formula) : Prop :=
match f with
| I p => p
| A f g => f2p(f) /\ f2p(g)
| T p f => p -> f2p(f)
| _ => True
end.
Definition andl (l : list Prop) : Prop :=
fold_left and l True.
Variable x : nat.
Lemma test2:
let l := [I (x*x = 2)] in
~ exists a : nat,
let x := a in
andl (map f2p l).
Proof.
unfold andl. simpl.
Admitted.
但是在这种情况下,我看不到a
在simple.
之后绑定到x
1 subgoal
______________________________________(1/1)
~ (exists a : nat, a * a = 2)
1 subgoal
______________________________________(1/1)
~ (exists _ : nat, True /\ x * x = 2)
你看不到它,因为它不是发生的事情。 你有表情
let x := a in andl (map f2p l)
它确实将x
定义为a
在andl(map f2p l)
中,但是这个术语没有提到x
,正如您所看到的。它确实提到了另一个名为x
的变量:
Variable x : nat.
但是他们不一样
当您在exp中写入let x:=a
时,在expexp
的上下文中有一个本地定义x:=a
,因此您可以在x*x中写入let x:=a,它将减少为a*a
。
您试图做的不是局部定义,而是实例化变量,实现方法是使用函数应用程序
let l := fun x => [I (x*x = 2)] in
~ exists a : nat,
let x := a in
andl (map f2p (l x)).