src/HOL/NumberTheory/IntFact.thy
author nipkow
Thu Dec 09 18:30:59 2004 +0100 (2004-12-09)
changeset 15392 290bc97038c7
parent 14271 8ed6989228bb
child 16417 9bc16273c2d4
permissions -rw-r--r--
First step in reorganizing Finite_Set
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
  d22set :: "int => int set"
paulson@9508
    22
wenzelm@11049
    23
recdef zfact  "measure ((\<lambda>n. nat n) :: int => nat)"
paulson@11868
    24
  "zfact n = (if n \<le> 0 then 1 else n * zfact (n - 1))"
paulson@9508
    25
wenzelm@11049
    26
recdef d22set  "measure ((\<lambda>a. nat a) :: int => nat)"
paulson@11868
    27
  "d22set a = (if 1 < a then insert a (d22set (a - 1)) else {})"
wenzelm@11049
    28
wenzelm@11049
    29
wenzelm@11049
    30
text {*
wenzelm@11049
    31
  \medskip @{term d22set} --- recursively defined set including all
wenzelm@11701
    32
  integers from @{text 2} up to @{text a}
wenzelm@11049
    33
*}
wenzelm@11049
    34
wenzelm@11049
    35
declare d22set.simps [simp del]
wenzelm@11049
    36
wenzelm@11049
    37
wenzelm@11049
    38
lemma d22set_induct:
wenzelm@11049
    39
  "(!!a. P {} a) ==>
paulson@11868
    40
    (!!a. 1 < (a::int) ==> P (d22set (a - 1)) (a - 1)
wenzelm@11049
    41
      ==> P (d22set a) a)
wenzelm@11049
    42
    ==> P (d22set u) u"
wenzelm@11049
    43
proof -
wenzelm@11549
    44
  case rule_context
wenzelm@11049
    45
  show ?thesis
wenzelm@11049
    46
    apply (rule d22set.induct)
wenzelm@11049
    47
    apply safe
paulson@11868
    48
     apply (case_tac [2] "1 < a")
wenzelm@11549
    49
      apply (rule_tac [2] rule_context)
wenzelm@11049
    50
       apply (simp_all (no_asm_simp))
wenzelm@11549
    51
     apply (simp_all (no_asm_simp) add: d22set.simps rule_context)
wenzelm@11049
    52
    done
wenzelm@11049
    53
qed
paulson@9508
    54
paulson@11868
    55
lemma d22set_g_1 [rule_format]: "b \<in> d22set a --> 1 < b"
wenzelm@11049
    56
  apply (induct a rule: d22set_induct)
wenzelm@11049
    57
   prefer 2
wenzelm@11049
    58
   apply (subst d22set.simps)
wenzelm@11049
    59
   apply auto
wenzelm@11049
    60
  done
wenzelm@11049
    61
wenzelm@11049
    62
lemma d22set_le [rule_format]: "b \<in> d22set a --> b \<le> a"
wenzelm@11049
    63
  apply (induct a rule: d22set_induct)
wenzelm@11049
    64
   prefer 2
wenzelm@11049
    65
   apply (subst d22set.simps)
wenzelm@11049
    66
   apply auto
wenzelm@11049
    67
  done
wenzelm@11049
    68
wenzelm@11049
    69
lemma d22set_le_swap: "a < b ==> b \<notin> d22set a"
wenzelm@11049
    70
  apply (auto dest: d22set_le)
wenzelm@11049
    71
  done
wenzelm@11049
    72
paulson@11868
    73
lemma d22set_mem [rule_format]: "1 < b --> b \<le> a --> b \<in> d22set a"
wenzelm@11049
    74
  apply (induct a rule: d22set.induct)
wenzelm@11049
    75
  apply auto
wenzelm@11049
    76
   apply (simp_all add: d22set.simps)
wenzelm@11049
    77
  done
paulson@9508
    78
wenzelm@11049
    79
lemma d22set_fin: "finite (d22set a)"
wenzelm@11049
    80
  apply (induct a rule: d22set_induct)
wenzelm@11049
    81
   prefer 2
wenzelm@11049
    82
   apply (subst d22set.simps)
wenzelm@11049
    83
   apply auto
wenzelm@11049
    84
  done
wenzelm@11049
    85
wenzelm@11049
    86
wenzelm@11049
    87
declare zfact.simps [simp del]
wenzelm@11049
    88
nipkow@15392
    89
lemma d22set_prod_zfact: "\<Prod>(d22set a) = zfact a"
wenzelm@11049
    90
  apply (induct a rule: d22set.induct)
wenzelm@11049
    91
  apply safe
wenzelm@11049
    92
   apply (simp add: d22set.simps zfact.simps)
wenzelm@11049
    93
  apply (subst d22set.simps)
wenzelm@11049
    94
  apply (subst zfact.simps)
paulson@11868
    95
  apply (case_tac "1 < a")
wenzelm@11049
    96
   prefer 2
wenzelm@11049
    97
   apply (simp add: d22set.simps zfact.simps)
wenzelm@11049
    98
  apply (simp add: d22set_fin d22set_le_swap)
wenzelm@11049
    99
  done
wenzelm@11049
   100
wenzelm@11049
   101
end