使用List.filter的列表的交集

时间:2019-03-03 02:41:32

标签: coq

根据我的问题here,我证明两个列表的交集是否不为空,然后通过向每个列表中添加另一个列表,交集仍不为空。我不知道如何证明引理filterKeepIntersection。我尝试通过filter_cat库中的seq策略解决此问题,但似乎不足以证明这一引理。

 Require Import  List Nat.
 Inductive customType : Type :=
  |Const1:  nat -> customType
  |Const2: list nat -> customType.

Inductive mydata : Set :=
   |Set1: customType * customType ->mydata
   |Set2: customType ->mydata.

   Fixpoint custome_Equal (c1 c2:customType) :bool:=
        match c1 with
            |Const1 nt => match c2 with 
                       |Const1 mt =>  eqb nt  mt
                       |Const2 (hm::lmt) => eqb nt hm
                      | _ => false
                                     end
           |Const2 (hn::lnt) => match c2 with                                                                            
                           |Const1 mt => eqb  hn  mt
                           |Const2 (hm:: lmt) => eqb hn  hm
                           | _ => false
                                     end
           | _ => false
          end.

 Fixpoint Search (l: mydata) (t:customType):  bool :=
    match l with
       |Set1 (a1, a2) =>  if (custome_Equal a2 t)  then  true else false
       | _=>false
    end.

Fixpoint search2 (c1 c2:mydata) :bool:=
         match c1,c2  with
       |Set1 (a1, a2) ,Set1(a3,a4)=>  if (custome_Equal a2 a4)  then  true else false
       | _,_=>false
    end.


Lemma filterKeepIntersection(l1 l2 l3 l4: list mydata):
(List.filter (fun n => List.existsb (search2 n) l2) l1) <> nil->
(List.filter (fun n => List.existsb (search2 n) (l3++l2)) (l4++l1))<>nil.
Proof.

1 个答案:

答案 0 :(得分:1)

predI稍微修饰内部谓词再加上filter_predI的使用确实可以立即证明,但可以直接使用mem_filter