簡體   English   中英

如何在Coq中定義受限域

[英]How to define a limited domain in coq

我正在嘗試在證明檢查器Coq中定義一個域。 我該怎么做呢?

我正在嘗試做V in [0,10]V in [0,10]的等效項。

我試圖Definition V := forall v in R, 0 <= v /\\ v <= 10. ,但這會導致常數的問題,例如根據Coq在V不存在0

一種簡單的方法可能類似於

Require Import Omega.

Inductive V : Set :=
  mkV : forall (v:nat), 0 <= v /\ v <= 10 -> V.

Lemma member0 : V.
Proof. apply (mkV 0). omega. Qed.

Definition inc (v:V) : nat := match v with mkV n _ => n + 1 end.

Lemma inc_bounds : forall v, 0 <= inc v <= 11.
Proof. intros v; destruct v; simpl. omega. Qed.

當然, member0的類型可能不如您希望的那樣有用。 在這種情況下,您可能希望通過與集合的每個元素相對應的nat索引V

Require Import Omega.

Inductive V : nat -> Set :=
  mkV : forall (v:nat), 0 <= v /\ v <= 10 -> V v.

Lemma member0 : V 0.
Proof. apply (mkV 0). omega. Qed.

Definition inc {n} (v:V n) : nat := n + 1.

Lemma inc_bounds : forall {n:nat} (v:V n), 0 <= inc v <= 11.
Proof. intros n v. unfold inc. destruct v. omega. Qed.

我以前沒有使用Reals ,但是上面的內容也可以在R上實現。

Require Import Reals.
Require Import Fourier.
Open Scope R_scope.

Inductive V : R -> Set :=
  mkV : forall (v:R), 0 <= v /\ v <= 10 -> V v.

Lemma member0 : V 0.
Proof. apply (mkV 0). split. right; auto. left; fourier. Qed.

Definition inc {r} (v:V r) : R := r + 1.

Lemma inc_bounds : forall {r:R} (v:V r), 0 <= inc v <= 11.
Proof. intros r v; unfold inc. 
  destruct v as (r,pf). destruct pf. split; fourier. 
Qed.

我相信這樣做的自然方法是使用sig類型,Yves在評論中也提到了這一點。

V的元素將是R中的數字x,以及證明b確實應在集合V中的證明。

Require Import Reals Fourier.
Open Scope R_scope.

Definition V_prop (x : R) : Prop := 0 <= x /\ x <= 10.

Definition V : Set := { x : R | V_prop x }.

Lemma V_prop0: V_prop 0.
Proof.
    unfold V_prop; split;
    [right; auto | left; fourier].
Qed.

Definition V0 : V := exist _ 0 V_prop0.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM