Coq 如何在不同的索引中查找值

Coq 如何在不同的索引中查找值,coq,Coq,我定义了一个函数,它从自然数列表中查找最大值,并将该值移动到列表的最前面位置。我确信,列表中的所有元素都小于或等于头部位置的值。然后我定义了index_value函数,在列表中的任何索引处寻找值。为了澄清[4,7,11,9,11]列表变成了[11,7,9,11]。我在证明下面的引理时遇到了一个问题。请引导我 ` Require Import Coq.Arith.PeanoNat. Require Import Lia. Fixpoint index_value (index: na

我定义了一个函数,它从自然数列表中查找最大值,并将该值移动到列表的最前面位置。我确信,列表中的所有元素都小于或等于头部位置的值。然后我定义了index_value函数,在列表中的任何索引处寻找值。为了澄清[4,7,11,9,11]列表变成了[11,7,9,11]。我在证明下面的引理时遇到了一个问题。请引导我

 ` Require Import Coq.Arith.PeanoNat.
   Require Import Lia.
   Fixpoint index_value (index: nat) (l: list nat) : nat :=
   match l with
         | nil => 0
         | cons h t => match (Nat.eqb index 0) with
         | true => h
         | false => index_value (index - 1) t
        end
          end.

Theorem head_value : forall ( n':nat) (l:list nat),
 (index_value 0 l)<= n'.
 Proof.
 Admitted.
 Theorem index_value1:forall (n s2:nat) (l:list nat),
 index_value  (S s2) (n :: l) <=
  index_value  0 (n :: l) \/
 index_value  (S s2) (n :: l) > 0.
 Proof.
  intros. simpl in *. left . induction s2. simpl. 
   appply head_value . simpl in *.  auto with arith.`
`需要导入Coq.Arith.PeanoNat。
需要导入Lia。
固定点索引_值(索引:nat)(l:列表nat):nat:=
匹配
|零=>0
|cons h t=>将(Nat.eqb索引0)与
|真=>h
|false=>索引值(索引-1)t
结束
结束。
定理头_值:forall(n):nat(l:list nat),

(索引值0 l)我认为你的陈述并没有你所想的那么真实。第一个是矛盾的,第二个是琐碎的:您根本不需要
index\u value
的定义:

Require Import Coq.Arith.PeanoNat.
Require Import Lia.
Require Import Coq.Lists.List.

Import ListNotations.

Fixpoint index_value (index: nat) (l: list nat) : nat :=
  match l with
  | nil => 0
  | cons h t => match (Nat.eqb index 0) with
                | true => h
                | false => index_value (index - 1) t
                end
  end.

Theorem not_head_value :
  ~ forall ( n':nat) (l:list nat),
                             (index_value 0 l)<= n'.
Proof.
  intros contra.
  specialize (contra 0 (1 :: nil)).
  simpl in *. lia.
Qed.

Theorem index_value1:forall (n s2:nat) (l:list nat),
    index_value  (S s2) (n :: l) <=
    index_value  0 (n :: l) \/
    index_value  (S s2) (n :: l) > 0.
Proof. intros n s2 l. lia. Qed.
需要导入Coq.Arith.PeanoNat。
需要导入Lia。
需要导入Coq.Lists.List。
导入列表符号。
固定点索引_值(索引:nat)(l:列表nat):nat:=
匹配
|零=>0
|cons h t=>将(Nat.eqb索引0)与
|真=>h
|false=>索引值(索引-1)t
结束
结束。
定理非头值:
~forall(n):nat(l:列出nat),

(索引值0 l)如果我们将索引值1拆分为左或右,然后应用lia,则它不起作用。证明。介绍n s2左。莉亚。你想解释一下原因吗?@rosijavi左边或右边是否成立取决于变量的值。例如,你可以证明所有n,n=0\/n>0
,但你不能证明所有n,n=0
或所有n,n>0。谢谢你的解释。关于上述函数,我有另一个引理,那就是定理索引值0:forall(n:nat)(l:list nat),(长度l=?0)=false->(长度l-长度l=?0)=false->(索引_值0 l=?0)=真。索引0处的值是零。因为列表中没有元素是零,列表是非空的。因此,为了证明这个引理,我们正在证明false=真。如何通过说这个条件在当前约束条件下不可能发生来关闭这个引理。如果我们在假设中有错误的陈述,那么我们可以证明任何事情。我想证明这两个目标定理m index_val_0:forall(l:list nat)(长度l=?0)=false->(长度l-长度l=?0)=false->(index_值(长度l-长度l-1)l=?0)=true.证明.介绍.归纳(长度l-长度l).析构函数l.反转H.单纯形in*.反转H0.单纯形in*.重写(nat.sub_0\r).定理索引_val_Sn:forall(l:list nat)(长度l=?0)=假->(长度l-长度l=?0)=假->(索引值(长度l-长度l-1)l=?SN)=真。