非依赖列表类型Coq

时间:2017-08-25 21:07:41

标签: coq

我正在尝试在Coq中定义一个非依赖list类型,但我无法找到一种方法。我设法以公理方式定义ndList,修改了Coq的list定义。到目前为止,这是我的工作:

Axiom ndList : forall C: Type, Type.
Axiom nil : forall C, ndList C.
Axiom cons : forall C, forall (c: C) (l: ndList C), ndList C.
Arguments nil {_}.
Arguments cons {_} _ _.
Axiom el : forall (C L: Type), forall (a: L) (s: ndList C)
    (l: forall (x: C) (z: L), L), L.
Axiom c1 : forall (C L: Type), forall (a: L) (l: forall (x: C) (z: L), L), 
  el C L a nil l = a.
Axiom c2 : forall (C L: Type), forall (s: ndList C) (c: C) (a: L) 
  (l: forall (x: C) (z: L), L), 
    el C L a (cons c s) l = l c (el C L a s l).
Axiom c_eta : forall (C L: Type), forall (a: L) (l: forall (x: C) (z: L), L)
  (t: forall y: ndList C, L) (s: ndList C) (eq1: t nil = a) 
  (eq2: forall (x: C) (z: ndList C), t (cons x z) = l x (t z)),
    el C L a s l = t s.

有没有办法将ndList定义为Inductive类型?

感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

您的"非依赖"列表类型与Coq的list类型:

可证明是同构的
Axiom ndList : forall C: Type, Type.
Axiom nil : forall C, ndList C.
Axiom cons : forall C, forall (c: C) (l: ndList C), ndList C.
Arguments nil {_}.
Arguments cons {_} _ _.
Axiom el : forall (C L: Type), forall (a: L) (s: ndList C)
                                      (l: forall (x: C) (z: L), L), L.
Axiom c1 : forall (C L: Type), forall (a: L) (l: forall (x: C) (z: L), L),
      el C L a nil l = a.
Axiom c2 : forall (C L: Type), forall (s: ndList C) (c: C) (a: L)
                                      (l: forall (x: C) (z: L), L),
      el C L a (cons c s) l = l c (el C L a s l).
Axiom c_eta : forall (C L: Type), forall (a: L) (l: forall (x: C) (z: L), L)
                 (t: forall y: ndList C, L) (s: ndList C) (eq1: t nil = a)
                 (eq2: forall (x: C) (z: ndList C), t (cons x z) = l x (t z)),
      el C L a s l = t s.

Section iso.
  Context {A : Type}.
  Definition list_to_ndList : list A -> ndList A
    := list_rect (fun _ => ndList A)
                 nil
                 (fun x _ xs => cons x xs).
  Definition ndList_to_list (ls : ndList A) : list A
    := el A (list A)
          Datatypes.nil
          ls
          Datatypes.cons.
  Lemma list_eq (ls : list A) : ndList_to_list (list_to_ndList ls) = ls.
  Proof.
    unfold ndList_to_list, list_to_ndList.
    induction ls as [|x xs IHxs];
      repeat first [ progress simpl
                   | progress rewrite ?c1, ?c2
                   | congruence ].
  Qed.
  Lemma ndList_eq (ls : ndList A) : list_to_ndList (ndList_to_list ls) = ls.
  Proof.
    unfold ndList_to_list, list_to_ndList.
    transitivity (el A (ndList A) nil ls cons); [ symmetry | ]; revert ls;
      match goal with
      | [ |- forall ls, @?LHS ls = @?RHS ls ]
        => intro ls; apply (c_eta _ _ _ _ RHS ls)
      end;
      repeat first [ progress simpl
                   | progress intros
                   | progress rewrite ?c1, ?c2
                   | congruence ].
  Qed.
End iso.

您甚至可以自动轻松地el关于list Scheme el := Minimality for list Sort Type. Check el. (* forall A P : Type, P -> (A -> list A -> P -> P) -> list A -> P *)

import java.nio.charset.Charset;
import java.util.Scanner;


public class charset {

    public static void main(String[] args) {
        System.out.println(Charset.defaultCharset());
        Scanner sc =new Scanner(System.in,"UTF-8");
        System.out.println(sc.nextLine());
        System.out.println("á ă ấ");
    }
}

这是否足以满足您的目的,或者您想要更多?