Substitutions of functions and types or representations in Coq

I proved some list theorems and extracted algorithms from them. Now I want to use heaps because searching and concatenation are faster. What I'm doing now to achieve this is simply to use custom definitions for the selected list type. I would like to do this in a more formal way, but ideally without having to repeat all my evidence. Let's say I have a type

Heap : Set -> Set

and isomorphism

f : forall A, Heap A -> List A.

In addition, I have H_app and H_nth functions such that

H_app (f a) (f b) = f (a ++ b)

and

H_nth (f a) = nth a

, , . , ++ nth H_app H_nth, . , simpl compute , , , , . "" .

?

: : , nat, . BinNat , BinNat nat ? ( , + BinNat?)

+4
1

, Heap : :

Inductive Heap A : Type :=
| Node : Heap A -> A -> Heap A -> Heap A
| Leaf : Heap A.

f

Fixpoint f A (h : Heap A) : list A :=
  match h with
  | Node h1 a h2 => f h1 ++ a :: f h2
  | Leaf => []
  end.

, f Heap A list A A. g : forall A, list A -> Heap A ,

forall A (l : list A), f (g l) = l

, , Heap, list , , .

, , , Coq. , parametricity, , , .

, . , (, foo) ++ nth. foo Heap , foo , :

Definition foo (T : Set -> Set)
               (app : forall A, T A -> T A -> T A)
               (nth : forall A, T A -> nat -> option A)
               A (l : T A) : T A :=
  (* ... *)

foo, :

Definition list_foo := foo list @app @nth.

Lemma list_foo_lemma : (* Some statement *).

, H_app H_nth foo , ,

Definition H_foo := foo Heap @H_app @H_nth.

Lemma foo_param : forall A (h : Heap A),
                    f (H_foo h) = list_foo (f h).

, list_foo H_foo. , , , H_app , :

forall A (h1 h2 h3 : Heap A),
  list_foo (H_app h1 (H_app h2 h3)) =
  list_foo (H_app (H_app h1 h2) h3).

, , : , , foo_param.

. , , , . , , , foo_param , Coq , . , :

  • Coq (CoqParam), . , , .

  • Coq ( CoqEAL, ) , , . , nat BinNat, . , - , , , CoqParam.

+3

Source: https://habr.com/ru/post/1584668/


All Articles