Proof Party ã®åé¡ãCoqã§ææ¦ãã¦ã¿ãã
Proof Party ã«è¡ããªããã©ãåå ãã¦ãã¤ããã§åé¡ã«ææ¦ãã¦ã¿ããä»æ¥ã¯åå¤å±ã§ä¸äººè¨¼æãã¼ãã£ãããºã«ã¨å¿ç¨åé¡ã¯è§£ãã¦ããªãã
æ±äº¬ã¯é ãã®ã§ãProof Partyã®æ¬¡åãããããã° åå¤å±ãé¢è¥¿ã§éå¬ãã¦ããã ããã°ãããããã§ãã> ranhaãã
èªç¶æ°(ã¨ã³ã³ã¼ãã£ã³ã°ã¯åãã)ã®å ç®ã®å¯ææ³åãçµåæ³åãåé æ³åã証æã
èªç¶æ°ã®æ§ã ãªæ§è³ªã¯æ¢ã«Coqã®æ¨æºã©ã¤ãã©ãªã«è±å¯ã«æã£ã¦ãããããããã®æ§è³ªã¯é常ã«ãã¼ã·ãã¯ãªã®ã§ãä¸ããå®ç¾©ãã¦è¨¼æãã¦ã¿ãã以ä¸ã¯Coqã®Arithã©ã¤ãã©ãªãç¹å¥ãªã¿ã¯ãã£ãã¯ã使ããã«å®è£ ããã
ã¾ããèªç¶æ°å ¨ä½ã®å nat ãå®ç¾©ããã
Inductive nat : Set := | O : nat | S : nat -> nat.
次ã«ãã®èªç¶æ°ä¸ã§ã®è¶³ãç®ãè¨ç®ãã plus é¢æ°ãå®ç¾©ããã
Fixpoint plus x y := match x with | O => y | S x => S (plus x y) end where "x + y" := (plus x y).
ã¾ãä¸çªç°¡åãªè¶³ãç®ã®çµååã証æããã
Proposition p01_plus_assoc : forall x y z, x + (y + z) = (x + y) + z. Proof. intros x y z; induction x; simpl in |- *. reflexivity. rewrite IHx in |- *; reflexivity. Qed.
次ã«è¶³ãç®ã®å¯ææ§ã証æãããã¨æããããã®ããã«æ¬¡ã®2ã¤ã®è£é¡ã証æãã¦ããã
ã¡ãªã¿ã« O+x = x 㨠S x + y = S (x + y) ã¯å®ç¾©ããæããã«æãç«ã¤ãã¨ãªã®ã§ãããã¦è£é¡ãç¨æãããã¨ã¯ããªãã
Lemma plus_O : forall x, x + O = x. Proof. intro x; induction x; simpl in |- *. reflexivity. rewrite IHx in |- *; reflexivity. Qed. Lemma plus_Sy : forall x y, x + S y = S (x + y). Proof. intros x y; induction x; simpl in |- *. reflexivity. rewrite IHx in |- *; reflexivity. Qed.
ããã¦ã足ãç®ã®å¯ææ§ã
Proposition p01_plus_comm : forall x y, x + y = y + x. Proof. intros x y; induction x; simpl. rewrite plus_O in |- *; reflexivity. rewrite IHx in |- *; rewrite plus_Sy in |- *. reflexivity. Qed.
ãã¨ã¯åé æ³åã ããããã«ã¯æãç®ãå¿ è¦ãªã®ã§æãç®ãå®ç¾©ããã
Fixpoint mult x y := match x with | O => O | S x => y + mult x y end where "x * y" := (mult x y).
å·¦ããã®åé æ³åã¯ç°¡åã§ãããä¸ã§è¨¼æãã足ãç®ã®çµååãå¯ææ§ãããªããªä½¿ã£ã¦ããã®ããããã ããã
Proposition p01_distr_l : forall x y k, k * (x + y) = k * x + k * y. Proof. intros x y k; induction k; simpl in |- *. reflexivity. rewrite IHk in |- *. rewrite <- (p01_plus_assoc x y _) in |- *. rewrite (p01_plus_assoc y (k * x) (k * y)) in |- *. rewrite (p01_plus_comm y (k * x)) in |- *. rewrite <- (p01_plus_assoc (k * x) y (k * y)) in |- *. rewrite (p01_plus_assoc x (k * x) _) in |- *. reflexivity. Qed.
æãç®ã®å¯ææ§ãããã°å³ããã®åé æ³åã示ããã®ã§ãæãç®ã®å¯ææ§ã証æã足ãç®ã®å¯ææ§ã¨åæ§ã«ããã¤ãã®è£é¡ã証æãã¦ä½¿ã£ãã
Lemma mult_O : forall x, x * O = O. Proof. intros x; induction x; simpl in |- *. reflexivity. apply IHx. Qed. Lemma mult_Sy : forall x y, x * S y = x + x * y. Proof. intros x y; induction x; simpl in |- *. reflexivity. rewrite IHx in |- *. rewrite (p01_plus_assoc y x (x * y)) in |- *. rewrite (p01_plus_comm y x) in |- *. rewrite <- (p01_plus_assoc x y (x * y)) in |- *. reflexivity. Qed. Lemma mult_comm : forall x y, x * y = y * x. Proof. intros x y; induction x; simpl in |- *. rewrite mult_O in |- *; reflexivity. rewrite mult_Sy in |- *. rewrite IHx in |- *. reflexivity. Qed.
å³ããã®åé æ³åã
Proposition p01_distr_r : forall x y k, (x + y) * k = x * k + y * k. Proof. intros x y k. rewrite (mult_comm (x + y) k) in |- *. rewrite (mult_comm x k) in |- *. rewrite (mult_comm y k) in |- *. apply p01_distr_l. Qed.
(1 + 2 + ... + n) = n*(n+1) / 2ã®è¨¼æ
ãã®åé¡ã¯Coqã®èªç¶æ°ã©ã¤ãã©ãªã使ã£ããã¾ããè¨ç®ããsumé¢æ°ãå®ç¾©ããã
Require Import Arith. Fixpoint sum n := match n with | O => O | S n => S n + sum n end.
èªç¶æ°ã§ã¯å²ãç®ãé£ããã®ã§ãå ¨ä½ã«2ãæãã次ã®å½¢ãã¾ã証æããã
Lemma p02_aux : forall n, 2 * sum n = n * (n + 1). Proof. intro n; induction n. reflexivity. unfold sum in |- *; fold sum in |- *. rewrite mult_plus_distr_l in |- *. rewrite IHn in |- *. ring. Qed.
èªç¶æ°ã§ã¯å²ãç®ãèªç±ã«ã§ããªããã次ã®div2 ã¨ããé¢æ°ãæ¨æºã©ã¤ãã©ãªã«ãã£ãã®ã§ããã使ã£ãã
Require Import Div2. Proposition p02 : forall n, sum n = div2 (n * (n + 1)). Proof. intros. rewrite <- p02_aux in |- *. rewrite div2_double in |- *; reflexivity. Qed.
ä»åã¯èªç¶æ°ã®ç¯å²ã§è¨¼æããããæçæ°ä¸ã§è¨¼æããæ¹ããããã ã£ããããããªããCoqã®æ¨æºã©ã¤ãã©ãªã«ã¯QArithã¨ããã®ããããæçæ°ãæ¨æºçã«æ±ããã¨ãã§ããã
å®æ°ã®æ§æã«ã¤ãã¦
Coqã§ã®å®æ°ã¯9ã¤ã®é ã¨17ã®å ¬çã§å®ç¾©ããã¦ãããé ã®åã¨æå³ã¯ã ããã次ã®æ§ãªæãã
Parameter R : Set. (* å®æ°å ¨ä½ *) Parameter R0 : R. (* å®æ°ã®0 *) Parameter R1 : R. (* å®æ°ã®1 *) Parameter Rplus : R -> R -> R. (* å®æ°ä¸ã§ã®è¶³ãç® *) Parameter Rmult : R -> R -> R. (* å®æ°ä¸ã§ã®æãç® *) Parameter Ropp : R -> R. (* 足ãç®ã«é¢ããéå *) Parameter Rinv : R -> R. (* æãç®ã«é¢ããéå *) Parameter Rlt : R -> R -> Prop. (* å®æ°ä¸ã®"ãã大ãã"ã表ãè¿°èª *) Parameter up : R -> Z. (* up x ã¯x以ä¸ã®æå°ã®æ´æ° *)
17ã®å ¬çã¯ã大ããè¦ã¦4ã¤ã®é¨åã«åããããã
- å®æ°Rã¯éèªæãªä½ã§ãã
Axiom Rplus_comm : forall r1 r2:R, r1 + r2 = r2 + r1. Axiom Rplus_assoc : forall r1 r2 r3:R, r1 + r2 + r3 = r1 + (r2 + r3). Axiom Rplus_opp_r : forall r:R, r + - r = 0. Axiom Rplus_0_l : forall r:R, 0 + r = r. Axiom Rmult_comm : forall r1 r2:R, r1 * r2 = r2 * r1. Axiom Rmult_assoc : forall r1 r2 r3:R, r1 * r2 * r3 = r1 * (r2 * r3). Axiom Rinv_l : forall r:R, r <> 0 -> / r * r = 1. Axiom Rmult_1_l : forall r:R, 1 * r = r. Axiom R1_neq_R0 : 1 <> 0. Axiom Rmult_plus_distr_l : forall r1 r2 r3:R, r1 * (r2 + r3) = r1 * r2 + r1 * r3.
- å®æ°Rã¯å ¨é åºéåã§ãã
Axiom total_order_T : forall r1 r2:R, {r1 < r2} + {r1 = r2} + {r1 > r2}. Axiom Rlt_asym : forall r1 r2:R, r1 < r2 -> ~ r2 < r1. Axiom Rlt_trans : forall r1 r2 r3:R, r1 < r2 -> r2 < r3 -> r1 < r3. Axiom Rplus_lt_compat_l : forall r r1 r2:R, r1 < r2 -> r + r1 < r + r2. Axiom Rmult_lt_compat_l : forall r r1 r2:R, 0 < r -> r1 < r2 -> r * r1 < r * r2.
- ã¢ã«ãã¡ãã¹ã®åç(ãããªãå®æ°ã«å¯¾ãã¦ããããã大ããæ´æ°ãåå¨ããã)
up xã¯å¤©äºé¢æ°ãIZRã¯æ´æ°Zããã®å å«åå
Axiom archimed : forall r:R, IZR (up r) > r /\ IZR (up r) - r <= 1.
- å®æ°Rã®é£ç¶æ§(ä¸ã«æçãªé å E â R ã«ã¯å¸¸ã«ä¸éãåå¨ãã)ã
Axiom completeness : forall E:R -> Prop, bound E -> (exists x : R, E x) -> { m:R | is_lub E m }.
Bolzano & Weierstrassã®å®ç(æçãªæ°åã¯åæããé¨ååãæã¤)
Bolzano Weierstrass ã®å®çã¯Coqã§ã¯ããæ¢ã«è¨¼æããã¦ãã¦ããããããã¯æ¨æºã©ã¤ãã©ãªã«åãã£ã¦ããï¼
Rtopology.vã¨ããã©ã¤ãã©ãªã®ã½ã¼ã¹ãè¦ãã°ãã®å®çãè¦ã¤ãããã¨ãã§ããã
Theorem Bolzano_Weierstrass : forall (un:nat -> R) (X:R -> Prop), compact X -> (forall n:nat, X (un n)) -> exists l : R, ValAdh un l.
å®æ°åun㯠nat -> R åã§ãé å X â R ã¯R -> Prop åã§è¡¨ç¾ãã¦ããããã ã
ValAdh un lã®å®ç¾©ã¯ä»¥ä¸ã®ã¨ããã§ãlã«åæããunã®é¨ååãåå¨ãããã¨ã¨åçã®å½é¡ã¿ããã ã
Definition ValAdh (un:nat -> R) (x:R) : Prop := forall (V:R -> Prop) (N:nat), neighbourhood V x -> exists p : nat, (N <= p)%nat /\ V (un p).
ä¸éå¤ã®å®ç(The Intermediate Value Theorem)
ä¸éå¤ã®å®çãCoqã®æ¨æºã©ã¤ãã©ãªã«åå¨ãããRsqrt_def.vã®ä¸ã«IVTã¨ããååã§è¦ã¤ãããã¨ãã§ããã
Lemma IVT : forall (f:R -> R) (x y:R), continuity f -> x < y -> f x < 0 -> 0 < f y -> { z:R | x <= z <= y /\ f z = 0 }.
ãã ãä¸éå¤ã f x 㨠f y ã®éã®ä»»æã®å¤ã¨ããããã§ã¯ãªãã0åºå®ã ã£ãã®ã§ããããä»»æã®å¤ãåããããã«æ¹è¯ããã
Require Import Reals. Require Import FunctionalExtensionality. Open Scope R_scope. Proposition p05 : forall (f:R -> R) a b y, continuity f -> a < b -> f a < y -> y < f b -> (exists c, a <= c <= b /\ f c = y). Proof. intros. elim (IVT (fun x => f x - y) a b). intros c H3; elim H3; intros; exists c. split. apply H4. apply (Rplus_eq_reg_l (- y)). rewrite Rplus_opp_l in |- *. rewrite Rplus_comm in |- *. apply H5. rewrite (functional_extensionality (fun x : R => f x - y) (f - (fun _ => y))%F) in |- *. apply continuity_minus. apply H. apply continuity_const. intros p q; reflexivity. intro x; reflexivity. apply H0. apply (Rlt_minus (f a) y H1). apply (Rlt_Rminus y (f b) H2). Qed.
ãªã¹ãã®çµåé¢æ° ++ ã®çµåå l1 ++ (l2 ++ l3) == (l1 ++ l2) ++ l3
ãªã¹ãã®appendã®çµååã¯é常ã«ä¾¿å©ã ãã証æã¯ç°¡åã ããããã£ãæ§è³ªã¯ãã¹ãã§ã¯ç¶²ç¾ çã«ãã§ãã¯ã§ããªãããã証æã¨ããæ¤è¨¼æ¹æ³ãããã°ã©ã ã®å質ãé«ããä¸ã§é常ã«æå¹ã ã¨æãã
Require Import List. Proposition p06 : forall {A} (l1 l2 l3: list A), l1 ++ (l2 ++ l3) = (l1 ++ l2) ++ l3. Proof. intros A l1 l2 l3; induction l1; simpl in |- *. reflexivity. rewrite IHl1 in |- *. reflexivity. Qed.
ããã½ã¼ãé¢æ°ãã¡ããã¨ã½ã¼ãããäºã証æ
以åMerge Sort ãå®è£
ãã¦è¨¼æããã
http://d.hatena.ne.jp/yoshihiro503/20090923
ã½ã¼ã¹ã³ã¼ãå
¨ä½ã¯ä»¥ä¸ã
http://bitbucket.org/yoshihiro503/mergesort/
1éå½é¡è«çã§resolutionãæãç«ã¤äºã示ã
ã¾ãAãBãã§å ´åãåãã¦ãAã®ã¨ãã¯Â¬AãCãã§å ´ååãããã°ã§ãããAã¨Â¬Aãåæã«æãç«ã¤ã¨ãªãã§ã証æã§ãã¦ãã¾ãã¨ãããã¨ãå©ç¨ããããæä¸å¾ã¯å¥ã«å¿ è¦ãªã証æã§ããã
Proposition p09 : forall A B C, (A \/ B) /\ (~A \/ C) -> B \/ C. Proof. intros A B C H; elim H; intros. elim H0. elim H1. intros H2 H3; elim H2. apply H3. intros H2 _; right; apply H2. intro H2; left; apply H2. Qed.
ç´è¦³ä¸»ç¾©è«çã§ã®äºéå¦å®é¤å»ã¨æä¸å¾ã®åå¤æ§
åå¤æ§ã示ãããã«ããããã®ç¢å°ã示ãããè«çããºã«ã¿ãããªåé¡ã ãã¬ãæ±ãããç·´ç¿åé¡ã ã¨æãã
Lemma p10_left : (forall A, ~~A -> A) -> (forall A B, (~B -> ~A) -> (A -> B)). Proof. intros. apply H. intro. elim (H0 H2). apply H1. Qed. Lemma p10_right : (forall A B, (~B -> ~A) -> (A -> B)) -> (forall A, ~~A -> A). Proof. intros. apply (H True A). intro. intro. elim H0. apply H1. apply I. Qed.