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
时,在exp
exp
的上下文中有一个本地定义
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)).