Coq 证明在两个列表中查找相同元素的性质

Coq 证明在两个列表中查找相同元素的性质,coq,Coq,我是Coq的新手。我有一个函数findshare,它在两个列表中查找相同的元素。引理sameElements证明函数findshare在两个列表的串联上的结果等于应用于每个列表的函数结果的串联。我在证明引理sameeelements时有点卡住了 Require Import List . Fixpoint findshare(s1 s2: list nat): list nat:= match s1 with | nil => nil | v :

我是Coq的新手。我有一个函数
findshare
,它在两个列表中查找相同的元素。引理
sameElements
证明函数
findshare
在两个列表的串联上的结果等于应用于每个列表的函数结果的串联。我在证明引理
sameeelements
时有点卡住了

Require Import List .
Fixpoint findshare(s1 s2: list nat): list nat:=
      match s1 with
        | nil => nil
        | v :: tl =>
           if ( existsb  (Nat.eqb v)  s2)
            then v :: findshare tl s2
            else findshare tl s2
      end.

 Lemma sameElements l1 l2 tl :
  (findshare tl (l1++l2)) =
  (findshare tl (l1))++ (findshare tl (l2)).
Proof.

你有麻烦是因为你的陈述不太正确:它包含了矛盾。更准确地说,它意味着
[1;2]=[2;1]

Require Import List .
Fixpoint findshare(s1 s2: list nat): list nat:=
      match s1 with
        | nil => nil
        | v :: tl =>
           if ( existsb  (Nat.eqb v)  s2)
            then v :: findshare tl s2
            else findshare tl s2
      end.

Lemma sameElements l1 l2 tl :
  (findshare tl (l1++l2)) =
  (findshare tl (l1))++ (findshare tl (l2)).
Admitted.

Import ListNotations.

Lemma contra : False.
Proof.
pose proof (sameElements [1] [2] [2;1]).
simpl in H.
discriminate.
Qed.

你应该能够证明引理,用
l1
l2
l1++l2
交换
tl
,然后对
l1

进行归纳,你遇到了麻烦,因为你的陈述不太正确:它包含了矛盾。更准确地说,它意味着
[1;2]=[2;1]

Require Import List .
Fixpoint findshare(s1 s2: list nat): list nat:=
      match s1 with
        | nil => nil
        | v :: tl =>
           if ( existsb  (Nat.eqb v)  s2)
            then v :: findshare tl s2
            else findshare tl s2
      end.

Lemma sameElements l1 l2 tl :
  (findshare tl (l1++l2)) =
  (findshare tl (l1))++ (findshare tl (l2)).
Admitted.

Import ListNotations.

Lemma contra : False.
Proof.
pose proof (sameElements [1] [2] [2;1]).
simpl in H.
discriminate.
Qed.

你应该能够通过将
tl
l1
l2
l1++l2
进行交换来证明引理,并通过对
l1
进行归纳来继续,这是一个很好的观点。我可以用另一个操作符代替
SameeElements
中的
=
(当元素相同但顺序不同时返回true的操作符)来证明它吗?据我所知,Coq中没有一个操作符可以直接表示您想要的内容,但您可以定义一个(例如,
几乎等于l1 l2=forall x,In x l1 In x l2
)。这是一个很好的观点。我是否可以使用另一个运算符,而不是
sameElements
中的
=
(当元素相同但顺序不同时返回true的运算符)为了证明这一点?据我所知,Coq中没有一个运算符可以直接表示您想要的内容,但您可以定义一个(例如,
几乎等于l1 l2=forall x,in x l1 in x l2
)。