(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ã¨ããã®ããããæçæ°ãæ¨æºçã«æ±ããã¨ãã§ããã