ããã¤ã®å¡
ä¹ ãã¶ãã«Coqã§éã¼ããã¨æã£ã¦ãããåé¡ã¯ãªããã¨èããã¨ãããããã¤ã®å¡ããããé¢ç½ãããããªããããã¨ãããã¨ã§è¨¼æãã¦ã¿ãã
証æããããã¨ã¯ããã¤ã®å¡ãå®æãããæçææ°ã¯2^n-1ã§ãããã¨â¦
ã¨æã£ã¦å°ãæ¸ãã¦ã¿ããã ãã©ãããã¯ããªã大å¤ã ã¨ãããã¨ã«ãªã£ã¦ãããã¤ã®å¡ã®è§£çãè¨ç®ããé¢æ°ãæ£ãã解ã«ãªã£ã¦ãããã¨ã証æãããã¨ãæåã®ç®æ¨ã¨ãã¦ã¿ãã
åé¡è¨å®ã¯ä»¥ä¸ã®éã
Inductive pos : Set := pos1 | pos2 | pos3. Inductive move : Set := | from_to (from to: pos): move. Definition tower := list pos. Definition moves := list move. Fixpoint single_tower (t: tower) (p: pos) : Prop. Definition legal_move (t: tower) (m: move) : Prop. Definition make_move (t:tower) (m:move) : tower. Fixpoint legal_moves (m:moves) (t:tower) := match m with | hd::tl => legal_move t hd /\ legal_moves tl (make_move t hd) | nil => True end. Definition make_moves (m:moves) (t:tower) := fold_left make_move m t. Fixpoint answer (n: nat) (from to rest: pos) {struct n} := match n with | O => nil | S m => answer m from rest to ++ (from_to from to::nil) ++ answer m rest to from end. Theorem hanoi: forall (n:nat) (t: tower) (from to rest: pos), from <> to -> from <> rest -> to <> rest -> length t = n -> single_tower t from -> legal_moves (answer n from to rest) t /\ single_tower (make_moves (answer n from to rest) t) to.
å¡ãã©ã®ããã«list posã§è¡¨ç¾ãããã§æ³¥æ²¼ãã¾ã£ã¦ãããï¼
ã¨ãããããæ¸ æ¸ãã¦ãªã300è¡ãã証æ㯠http://github.com/kik/sandbox/blob/c1b16b684feb7482f0582480a43b2db4a9be3ce0/coq/Hanoi.v ã«ãããã©ãèªåã§è¨¼æããã人ã¯è¦ãªãããã«ã
Coq 8.1ã§ãã£ãããæ°ããã®ã ã¨åé¡ããããã