src/HOL/Old_Number_Theory/IntFact.thy
author haftmann
Fri Nov 27 08:41:10 2009 +0100 (2009-11-27)
changeset 33963 977b94b64905
parent 32479 521cc9bf2958
child 35440 bdf8ad377877
permissions -rw-r--r--
renamed former datatype.ML to datatype_data.ML; datatype.ML provides uniform view on datatype.ML and datatype_rep_proofs.ML
haftmann@32479
     1
(*  Author:     Thomas M. Rasmussen
wenzelm@11049
     2
    Copyright   2000  University of Cambridge
paulson@9508
     3
*)
paulson@9508
     4
wenzelm@11049
     5
header {* Factorial on integers *}
wenzelm@11049
     6
haftmann@16417
     7
theory IntFact imports IntPrimes begin
wenzelm@11049
     8
wenzelm@11049
     9
text {*
wenzelm@11049
    10
  Factorial on integers and recursively defined set including all
wenzelm@11701
    11
  Integers from @{text 2} up to @{text a}.  Plus definition of product
wenzelm@11049
    12
  of finite set.
wenzelm@11049
    13
wenzelm@11049
    14
  \bigskip
wenzelm@11049
    15
*}
paulson@9508
    16
paulson@9508
    17
consts
wenzelm@11049
    18
  zfact :: "int => int"
wenzelm@11049
    19
  d22set :: "int => int set"
paulson@9508
    20
wenzelm@11049
    21
recdef zfact  "measure ((\<lambda>n. nat n) :: int => nat)"
paulson@11868
    22
  "zfact n = (if n \<le> 0 then 1 else n * zfact (n - 1))"
paulson@9508
    23
wenzelm@11049
    24
recdef d22set  "measure ((\<lambda>a. nat a) :: int => nat)"
paulson@11868
    25
  "d22set a = (if 1 < a then insert a (d22set (a - 1)) else {})"
wenzelm@11049
    26
wenzelm@11049
    27
wenzelm@11049
    28
text {*
wenzelm@11049
    29
  \medskip @{term d22set} --- recursively defined set including all
wenzelm@11701
    30
  integers from @{text 2} up to @{text a}
wenzelm@11049
    31
*}
wenzelm@11049
    32
wenzelm@11049
    33
declare d22set.simps [simp del]
wenzelm@11049
    34
wenzelm@11049
    35
wenzelm@11049
    36
lemma d22set_induct:
wenzelm@18369
    37
  assumes "!!a. P {} a"
wenzelm@18369
    38
    and "!!a. 1 < (a::int) ==> P (d22set (a - 1)) (a - 1) ==> P (d22set a) a"
wenzelm@18369
    39
  shows "P (d22set u) u"
wenzelm@18369
    40
  apply (rule d22set.induct)
wenzelm@18369
    41
  apply safe
wenzelm@18369
    42
   prefer 2
wenzelm@18369
    43
   apply (case_tac "1 < a")
wenzelm@18369
    44
    apply (rule_tac prems)
wenzelm@18369
    45
     apply (simp_all (no_asm_simp))
wenzelm@18369
    46
   apply (simp_all (no_asm_simp) add: d22set.simps prems)
wenzelm@18369
    47
  done
paulson@9508
    48
paulson@11868
    49
lemma d22set_g_1 [rule_format]: "b \<in> d22set a --> 1 < b"
wenzelm@11049
    50
  apply (induct a rule: d22set_induct)
wenzelm@18369
    51
   apply simp
wenzelm@18369
    52
  apply (subst d22set.simps)
wenzelm@18369
    53
  apply auto
wenzelm@11049
    54
  done
wenzelm@11049
    55
wenzelm@11049
    56
lemma d22set_le [rule_format]: "b \<in> d22set a --> b \<le> a"
wenzelm@11049
    57
  apply (induct a rule: d22set_induct)
wenzelm@18369
    58
  apply simp
wenzelm@11049
    59
   apply (subst d22set.simps)
wenzelm@11049
    60
   apply auto
wenzelm@11049
    61
  done
wenzelm@11049
    62
wenzelm@11049
    63
lemma d22set_le_swap: "a < b ==> b \<notin> d22set a"
wenzelm@18369
    64
  by (auto dest: d22set_le)
wenzelm@11049
    65
wenzelm@18369
    66
lemma d22set_mem: "1 < b \<Longrightarrow> b \<le> a \<Longrightarrow> b \<in> d22set a"
wenzelm@11049
    67
  apply (induct a rule: d22set.induct)
wenzelm@11049
    68
  apply auto
wenzelm@11049
    69
   apply (simp_all add: d22set.simps)
wenzelm@11049
    70
  done
paulson@9508
    71
wenzelm@11049
    72
lemma d22set_fin: "finite (d22set a)"
wenzelm@11049
    73
  apply (induct a rule: d22set_induct)
wenzelm@11049
    74
   prefer 2
wenzelm@11049
    75
   apply (subst d22set.simps)
wenzelm@11049
    76
   apply auto
wenzelm@11049
    77
  done
wenzelm@11049
    78
wenzelm@11049
    79
wenzelm@11049
    80
declare zfact.simps [simp del]
wenzelm@11049
    81
nipkow@15392
    82
lemma d22set_prod_zfact: "\<Prod>(d22set a) = zfact a"
wenzelm@11049
    83
  apply (induct a rule: d22set.induct)
wenzelm@11049
    84
  apply safe
wenzelm@11049
    85
   apply (simp add: d22set.simps zfact.simps)
wenzelm@11049
    86
  apply (subst d22set.simps)
wenzelm@11049
    87
  apply (subst zfact.simps)
paulson@11868
    88
  apply (case_tac "1 < a")
wenzelm@11049
    89
   prefer 2
wenzelm@11049
    90
   apply (simp add: d22set.simps zfact.simps)
wenzelm@11049
    91
  apply (simp add: d22set_fin d22set_le_swap)
wenzelm@11049
    92
  done
wenzelm@11049
    93
wenzelm@11049
    94
end