src/HOL/NumberTheory/IntFact.thy
author nipkow
Wed Aug 18 11:09:40 2004 +0200 (2004-08-18)
changeset 15140 322485b816ac
parent 14271 8ed6989228bb
child 15392 290bc97038c7
permissions -rw-r--r--
import -> imports
wenzelm@11049
     1
(*  Title:      HOL/NumberTheory/IntFact.thy
paulson@9508
     2
    ID:         $Id$
wenzelm@11049
     3
    Author:     Thomas M. Rasmussen
wenzelm@11049
     4
    Copyright   2000  University of Cambridge
paulson@9508
     5
*)
paulson@9508
     6
wenzelm@11049
     7
header {* Factorial on integers *}
wenzelm@11049
     8
wenzelm@11049
     9
theory IntFact = IntPrimes:
wenzelm@11049
    10
wenzelm@11049
    11
text {*
wenzelm@11049
    12
  Factorial on integers and recursively defined set including all
wenzelm@11701
    13
  Integers from @{text 2} up to @{text a}.  Plus definition of product
wenzelm@11049
    14
  of finite set.
wenzelm@11049
    15
wenzelm@11049
    16
  \bigskip
wenzelm@11049
    17
*}
paulson@9508
    18
paulson@9508
    19
consts
wenzelm@11049
    20
  zfact :: "int => int"
wenzelm@11049
    21
  setprod :: "int set => int"
wenzelm@11049
    22
  d22set :: "int => int set"
paulson@9508
    23
wenzelm@11049
    24
recdef zfact  "measure ((\<lambda>n. nat n) :: int => nat)"
paulson@11868
    25
  "zfact n = (if n \<le> 0 then 1 else n * zfact (n - 1))"
paulson@9508
    26
paulson@9508
    27
defs
paulson@11868
    28
  setprod_def: "setprod A == (if finite A then fold (op *) 1 A else 1)"
wenzelm@11049
    29
wenzelm@11049
    30
recdef d22set  "measure ((\<lambda>a. nat a) :: int => nat)"
paulson@11868
    31
  "d22set a = (if 1 < a then insert a (d22set (a - 1)) else {})"
wenzelm@11049
    32
wenzelm@11049
    33
wenzelm@11049
    34
text {* \medskip @{term setprod} --- product of finite set *}
wenzelm@11049
    35
paulson@11868
    36
lemma setprod_empty [simp]: "setprod {} = 1"
wenzelm@11049
    37
  apply (simp add: setprod_def)
wenzelm@11049
    38
  done
wenzelm@11049
    39
wenzelm@11049
    40
lemma setprod_insert [simp]:
wenzelm@11049
    41
    "finite A ==> a \<notin> A ==> setprod (insert a A) = a * setprod A"
paulson@14271
    42
  by (simp add: setprod_def mult_left_commute LC.fold_insert [OF LC.intro])
wenzelm@11049
    43
wenzelm@11049
    44
text {*
wenzelm@11049
    45
  \medskip @{term d22set} --- recursively defined set including all
wenzelm@11701
    46
  integers from @{text 2} up to @{text a}
wenzelm@11049
    47
*}
wenzelm@11049
    48
wenzelm@11049
    49
declare d22set.simps [simp del]
wenzelm@11049
    50
wenzelm@11049
    51
wenzelm@11049
    52
lemma d22set_induct:
wenzelm@11049
    53
  "(!!a. P {} a) ==>
paulson@11868
    54
    (!!a. 1 < (a::int) ==> P (d22set (a - 1)) (a - 1)
wenzelm@11049
    55
      ==> P (d22set a) a)
wenzelm@11049
    56
    ==> P (d22set u) u"
wenzelm@11049
    57
proof -
wenzelm@11549
    58
  case rule_context
wenzelm@11049
    59
  show ?thesis
wenzelm@11049
    60
    apply (rule d22set.induct)
wenzelm@11049
    61
    apply safe
paulson@11868
    62
     apply (case_tac [2] "1 < a")
wenzelm@11549
    63
      apply (rule_tac [2] rule_context)
wenzelm@11049
    64
       apply (simp_all (no_asm_simp))
wenzelm@11549
    65
     apply (simp_all (no_asm_simp) add: d22set.simps rule_context)
wenzelm@11049
    66
    done
wenzelm@11049
    67
qed
paulson@9508
    68
paulson@11868
    69
lemma d22set_g_1 [rule_format]: "b \<in> d22set a --> 1 < b"
wenzelm@11049
    70
  apply (induct a rule: d22set_induct)
wenzelm@11049
    71
   prefer 2
wenzelm@11049
    72
   apply (subst d22set.simps)
wenzelm@11049
    73
   apply auto
wenzelm@11049
    74
  done
wenzelm@11049
    75
wenzelm@11049
    76
lemma d22set_le [rule_format]: "b \<in> d22set a --> b \<le> a"
wenzelm@11049
    77
  apply (induct a rule: d22set_induct)
wenzelm@11049
    78
   prefer 2
wenzelm@11049
    79
   apply (subst d22set.simps)
wenzelm@11049
    80
   apply auto
wenzelm@11049
    81
  done
wenzelm@11049
    82
wenzelm@11049
    83
lemma d22set_le_swap: "a < b ==> b \<notin> d22set a"
wenzelm@11049
    84
  apply (auto dest: d22set_le)
wenzelm@11049
    85
  done
wenzelm@11049
    86
paulson@11868
    87
lemma d22set_mem [rule_format]: "1 < b --> b \<le> a --> b \<in> d22set a"
wenzelm@11049
    88
  apply (induct a rule: d22set.induct)
wenzelm@11049
    89
  apply auto
wenzelm@11049
    90
   apply (simp_all add: d22set.simps)
wenzelm@11049
    91
  done
paulson@9508
    92
wenzelm@11049
    93
lemma d22set_fin: "finite (d22set a)"
wenzelm@11049
    94
  apply (induct a rule: d22set_induct)
wenzelm@11049
    95
   prefer 2
wenzelm@11049
    96
   apply (subst d22set.simps)
wenzelm@11049
    97
   apply auto
wenzelm@11049
    98
  done
wenzelm@11049
    99
wenzelm@11049
   100
wenzelm@11049
   101
declare zfact.simps [simp del]
wenzelm@11049
   102
wenzelm@11049
   103
lemma d22set_prod_zfact: "setprod (d22set a) = zfact a"
wenzelm@11049
   104
  apply (induct a rule: d22set.induct)
wenzelm@11049
   105
  apply safe
wenzelm@11049
   106
   apply (simp add: d22set.simps zfact.simps)
wenzelm@11049
   107
  apply (subst d22set.simps)
wenzelm@11049
   108
  apply (subst zfact.simps)
paulson@11868
   109
  apply (case_tac "1 < a")
wenzelm@11049
   110
   prefer 2
wenzelm@11049
   111
   apply (simp add: d22set.simps zfact.simps)
wenzelm@11049
   112
  apply (simp add: d22set_fin d22set_le_swap)
wenzelm@11049
   113
  done
wenzelm@11049
   114
wenzelm@11049
   115
end