gpt4 book ai didi

coq - 取元组列表中的第一个类型

转载 作者:行者123 更新时间:2023-12-01 23:33:45 25 4
gpt4 key购买 nike

我有一个列表 l 有类型:l: list (list (A * B * C * D)) 我希望它为我返回一个类型列表(列表A)

我正在尝试使用带有参数 list (A * B * C * D)split 函数来查看结果。

Require Import List.
Variables A B C D : Type.
Definition split_list (l: list (A * B * C * D)) : list (A * B * C) * list D
:= split l.

如何编写函数?

最佳答案

我会这样做:

π1 : A × B → A
π1 ∘ π1 : A × B × C → A
π1 ∘ π1 ∘ π1 : A × B × C × D → A
map (π1 ∘ π1 ∘ π1) : (A × B × C × D) * → A *
map (map (π1 ∘ π1 ∘ π1)) : ((A × B × C × D) *) * → (A *) *

你可能需要这个:

Definition comp {s1 s2 s3 : Set} (f2 : s2 -> s3) (f1 : s1 -> s2) (o1 : s1) : s3 :=
f2 (f1 o1).

Notation "f2 ∘ f1" := (comp f2 f1) (at level 30, right associativity).

Inductive Prod (s1 s2 : Set) : Set :=
| Pair : s1 -> s2 -> Prod s1 s2.

Arguments Pair {_ _} _ _.

Notation "s1 × s2" := (Prod s1 s2) (at level 40, left associativity).

Notation "( o1 , o2 , .. , o3 )" := (Pair .. (Pair o1 o2) .. o3) (at level 0).

Definition proj_1 {s1 s2 : Set} (p1 : s1 × s2) : s1 :=
match p1 with
| (o1, _) => o1
end.

Notation "'π1'" := proj_1 (at level 0).

Inductive List (s1 : Set) : Set :=
| Nil : List s1
| Cons : s1 -> List s1 -> List s1.

Arguments Nil {_}.

Arguments Cons {_} _ _.

Notation "s1 *" := (List s1) (at level 30, no associativity).

Notation "'ε'" := Nil (at level 0).

Notation "o1 ◁ l1" := (Cons o1 l1) (at level 60, right associativity).

Fixpoint map {s1 s2 : Set} (f1 : s1 -> s2) (l1 : s1 *) : s2 * :=
match l1 with
| ε => ε
| o1 ◁ l2 => (f1 o1) ◁ (map f1 l2)
end.

关于coq - 取元组列表中的第一个类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14017097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com