首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Curry通用量化函数

Curry通用量化函数
EN

Stack Overflow用户
提问于 2017-06-04 22:27:44
回答 1查看 122关注 0票数 3

我试图编写一种用于计算函数的策略,包括通用量化的函数。

代码语言:javascript
复制
Require Import Coq.Program.Tactics.

Definition curry1 := forall A B C, (A /\ B -> C) -> (A -> B -> C).
Definition curry2 := forall A B, (forall C, A /\ B -> C) -> (forall C, A -> B -> C).
Definition curry3 := forall A, (forall B C, A /\ B -> C) -> (forall B C, A -> B -> C).
(* etc. *)

Ltac curry H :=
  let T := type of H in
  match T with
  | _ /\ _ -> _ =>
    replace_hyp H (fun H1 => fun H2 => H (conj H1 H2))
  | forall x, ?P x =>
    fail 1 "not implemented"
  | _ =>
    fail 1 "not a curried function"
  end.

Example ex1 : curry1.
Proof.
  intros A B C H.
  curry H.
  assumption.
Qed.

Example ex2 : curry2.
Proof.
  intros A B H.
  Fail curry H. (* Tactic failure: not a curried function. *)
  Fail replace_hyp H (fun H1 => let H2 := H H1 in ltac:(curry H2)). (* Cannot infer an existential variable of type "Type" in environment: [...] *)
Abort.

如何扩展我的curry策略来处理通用量化的函数?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-05 08:26:04

您基本上可以对所有变体进行模式匹配,如下所示:

代码语言:javascript
复制
Ltac curry H :=
  match type of H with
  | _ /\ _ -> _ =>
      replace_hyp H (fun a b => H (conj a b))
  | forall C, _ /\ _ -> _ =>
      replace_hyp H (fun C a b => H C (conj a b))
  | forall B C, _ /\ _ -> _ =>
      replace_hyp H (fun B C a b => H B C (conj a b))
  | forall A B C, _ /\ _ -> _ =>
      replace_hyp H (fun A B C a b => H A B C (conj a b))
  end.

注意,C有排序Type,而不是Prop。如果您愿意在Prop中工作,则可以使用逻辑等效的setoid_rewrite策略。例如:

代码语言:javascript
复制
Require Import Coq.Setoids.Setoid.

Implicit Types C : Prop.

Definition and_curry_uncurry_iff {A B C} : (A /\ B -> C) <-> (A -> B -> C) :=
  conj (fun H a b => H (conj a b)) (and_ind (P := C)).

Ltac find_and_curry :=
  match goal with
  | H : context [_ /\ _ -> _] |- _ =>
      setoid_rewrite and_curry_uncurry_iff in H
  end.

Example ex2_prop A B : (forall C, A /\ B -> C) -> (forall C, A -> B -> C).
Proof. intros H. find_and_curry. assumption. Qed.
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44359409

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档