kururuããããããã¾ããã®è¨¼æããã¦ããã®ãè¦ã¦
http://d.hatena.ne.jp/kururu_goedel/20100702
ãããè¦ã¦ãã¨ãããã綺éºã«æ¸ãç´ããã¨ãã¦ã¿ããä¸æ¥ããã£ãã
ããããããã§ä¸è¬ãããã¾ããã¸ã®éãè¦ãã¦ããããï¼
ããã«ç½®ãããhttp://github.com/kik/sandbox/blob/master/coq/tarai.v
å¤å°ã解説
Fixpoint ntarai3 (n : nat) (a b c : option Z) := match a with | None => None | Some av => match b with | None => None | Some bv => if Z_le_dec av bv then b else match n with | 0%nat => None | S np => match c with | None => None | Some cv => (ntarai3 np (ntarai3 np (Some (av-1)) b c) (ntarai3 np (Some (bv-1)) c a) (ntarai3 np (Some (cv-1)) a b)) end end end end.
ãããããã®ãããã´ã£ã¦ããã¨ãããcall-by-nameãªã®ã§å¿
è¦ã«ãªãã¾ã§ option Z ã®ä¸èº«ã¯ã¿ãªãã
ãã®å®ç¾©ã®ã¾ã¾ã証æãå§ããã¨fixããunfoldããããã¾ããé
管çè½åãå¿
è¦ã§ãã¾ã£ããæ¬è³ªã§ãªãã¨ããã§è¦å´ãããã¨ãããããã
ããããã¨ãã¯ãInductive ã使ã£ã¦ãntarai3 é¢æ°ãç¹å¾´ä»ãã¦ããã°ãã
Inductive Tarai_value (n: nat) (a b c: option Z) (v: Z) : Prop := | Tarai_a_le_b (av bv: Z) (Hle: av <= bv) (Hv: bv = v) (Ha: a = Some av) (Hb: b = Some bv): Tarai_value n a b c v | Tarai_a_gt_b_1 (av bv cv: Z) (n': nat) (Hgt: av > bv) (Ha: a = Some av) (Hb: b = Some bv) (Hc: c = Some cv) (Hn: n = S n') (v1: Z) (Hle2: v1 <= v) (Hrec1: Tarai_value n' (Some (av-1)) b c v1) (Hrec2: Tarai_value n' (Some (bv-1)) c a v) | Tarai_a_gt_b_2 (av bv cv: Z) (n': nat) (Hgt: av > bv) (Ha: a = Some av) (Hb: b = Some bv) (Hc: c = Some cv) (Hn: n = S n') (v1 v2 v3: Z) (Hle2: ~v1 <= v2) (Hrec1: Tarai_value n' (Some (av-1)) b c v1) (Hrec2: Tarai_value n' (Some (bv-1)) c a v2) (Hrec3: Tarai_value n' (Some (cv-1)) a b v3) (Hrec4: Tarai_value n' (Some v1) (Some v2) (Some v3) v): Tarai_value n a b c v.
Tarai_value n a b c v ã¨ããè¿°èªã¯ãntarai3 n a b c ãåæ¢ãã¦ãçµæã v ã«ãªãã¨ããæå³ã
ããã¯ãçµå±ï¼éããããªãã¦ãa <= b ã®ã¨ãã«ã¯åæ¢ãã¦ãb = v ã§ãã(Tarai_a_le_b)ã
a > b ã㤠n > 0 ã㤠Tarai_value (n-1) (a-1) b c v1 ã㤠Tarai_value (n-1) c a v ãã¤ãv1 <= v ã®ã¨ã(Tarai_a_gt_b_1)ãa > b ã㤠n > 0 ã㤠v1 > v2 ãããåãã®çµæã v ã«ãªãå ´å(Tarai_a_gt_b_2)ã
ãã¨ããããã£ã¦ååãã¤ãã¨ãã¨destructããã¨ãã«ãã®ååã使ã£ã¦ããã¦èªã¿ãããã
æåã«ãTarai_value ãæ£ããå®ç¾©ããã¦ããã¨ã証æãã¾ãã
Lemma lem_saficient: forall n a b c v, Tarai_value n a b c v -> ntarai3 n a b c = Some v. Lemma lem_invert: forall n a b c v, ntarai3 n a b c = Some v -> Tarai_value n a b c v.
ãã®äºã¤ã証æããã°ããã fix ã®ãã¨ã¯å¿ãã¦ãTarai_value ã«å°å¿µã§ãã¾ãããã®è¨¼æã¯å¤§å¤ã§ãããç¹ã«ä¸ã®ãã¤ã
ããã¾ã§çµããã°ãç¸å½ç°¡åã«ãªãã¾ã(Coqã«é¢ãã¦ã¯ã証æèªä½ã¯è¤éã ãã©)ã
ã©ããããç°¡åã«ãªããã¨ããã¨
bv : Z cv : Z H : bv <= cv ______________________________________(1/2) Tarai_value 1 (Some (bv + 1)) (Some bv) (Some cv) cv
ã証æãããã¨æã£ãããbv+1 > bv ãªã®ã§ãTarai_a_gt_b_1 ã Tarai_a_gt_b_2 ã®ã©ã¡ããã§åæ¢ãããã¨ã«ãªãã¾ããã¨ãããããTarai_a_gt_b_1 ã apply ãã¦ã¿ãã¨
apply Tarai_a_gt_b_1 with (bv + 1) bv cv 0%nat bv; auto; try omega.
ããã§ã証æããªãã¨ãããªããã¨ãï¼ã¤ã«ãªãã¾ãã
bv : Z cv : Z H : bv <= cv ______________________________________(1/3) Tarai_value 0 (Some (bv + 1 - 1)) (Some bv) (Some cv) bv ______________________________________(2/3) Tarai_value 0 (Some (bv - 1)) (Some cv) (Some (bv + 1)) cv
ä¸ã®ã»ãã¯ãbv + 1 - 1 <= bv ãªã®ã§ãTarai_a_le_b ã«ããåæ¢ãã¾ããä¸ã®ã»ãã bv - 1 <= cv ãªã®ã§åæ§ã§ãã
apply Tarai_a_le_b with (bv + 1 - 1) bv; auto; omega. apply Tarai_a_le_b with (bv - 1) cv; auto; omega.
ããã§ãã§ããããã§ãã
çµæ§ãã¤ãã¤ããã ã®ã§ãä¸è¬ãããã¾ããããããããªãâ¦
ããã綺éºã«æ¸ãç´ãã
ä¸ã«æ¸ããã®ãããããèãããããããã¨ãããç´ãã¦ãoption Z ã¨ããããªããããã¨ãæãç´ããã
ããã«ææ°ã®ãç½®ãã¦ãããhttp://github.com/kik/sandbox/blob/master/coq/tarai.v