关于证明:在Coq中定义间隔函数

Defining interval function in Coq

我正在尝试在Coq中定义一个名为interval的函数,该函数给出两个自然数来计算这两个之间的所有自然数的列表。 但是我的定义不是原始递归的。 这是我的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Require Coq.Program.Tactics.
Require Coq.Program.Wf.

Inductive bool : Type :=
  | true : bool
  | false : bool.

Fixpoint leq_nat (m:nat) (n:nat) : bool :=
match m with
  | 0 => true
  | S x => match n with
    | 0 => false
    | S y => leq_nat x y
  end
end.

Notation"m <= n" := (leq_nat m n).
Notation"x :: l" := (cons x l) (at level 60, right associativity).

Program Fixpoint intervalo (m:nat) (n:nat) {measure ((S n) - m)}: list nat :=
match m <= n with
  | false => nil
  | true => m :: (intervalo (S m) n)
end.
Next Obligation.

如您所见,我在间隔的长度上使用了完善的递归。 我将度量定义为该值,即S n-m。

我希望被要求证明forall m, n, true = m <= n -> S n - S m < S n - m

但是,我得到的证明义务看起来并非如此,令人困惑。 我被要求证明:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 m : nat
  n : nat
  intervalo : forall m0 n0 : nat,
              match m0 with
              | 0 => S n0
              | S l => n0 - l
              end < match m with
                    | 0 => S n
                    | S l => n - l
                    end -> list nat
  Heq_anonymous : true = (m <= n)
  ============================
   n - m < match m with
           | 0 => S n
           | S l => n - l
           end

然后:

1
2
3
4
5
6
7
8
  ============================
   well_founded
     (Wf.MR lt
        (fun recarg : {_ : nat & nat} =>
         match projT1 recarg with
         | 0 => S (projT2 recarg)
         | S l => projT2 recarg - l
         end))

有人可以解释一下为什么Coq要求我证明这一点,而不仅仅是forall m, n, true = m <= n -> S n - S m < S n - m。 此外,我该如何完成此证明? 或者如何使它看起来更像我期望Coq要求我进行证明?

谢谢。


令您感到困惑的是,术语S n - m的一部分被展开,并且您还有其他假设。 如果输入:

1
2
3
4
5
6
clear intervalo.
change (match m with
        | 0 => S n
        | S l => n - l
        end) with (S n - m).
change (n - m) with (S n - S m).

那么您会发现,要求您证明的第一个目标确实是forall m, n, true = m <= n -> S n - S m < S n - m的直接结果。

第二个简单地说明您的度量是有充分根据的(一旦抛出S n - m具有一定程度的展开,就会更多)。 我可能有不同版本的Coq(版本8.5beta2),因为在我看来,这是自动释放的。