src/HOL/Old_Number_Theory/Factorization.thy
author blanchet
Thu, 16 May 2013 14:15:22 +0200
changeset 52032 0370c5f00ce8
parent 44890 22f665a2e91c
child 57512 cc97b347b301
permissions -rw-r--r--
more work on SPASS datatypes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38159
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
     1
(*  Title:      HOL/Old_Number_Theory/Factorization.thy
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
     2
    Author:     Thomas Marthedal Rasmussen
9944
2a705d1af4dc moved Primes, Fib, Factorization from HOL/ex
paulson
parents:
diff changeset
     3
    Copyright   2000  University of Cambridge
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
     4
*)
9944
2a705d1af4dc moved Primes, Fib, Factorization from HOL/ex
paulson
parents:
diff changeset
     5
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
     6
header {* Fundamental Theorem of Arithmetic (unique factorization into primes) *}
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
     7
27368
9f90ac19e32b established Plain theory and image
haftmann
parents: 26316
diff changeset
     8
theory Factorization
41413
64cd30d6b0b8 explicit file specifications -- avoid secondary load path;
wenzelm
parents: 38159
diff changeset
     9
imports Primes "~~/src/HOL/Library/Permutation"
27368
9f90ac19e32b established Plain theory and image
haftmann
parents: 26316
diff changeset
    10
begin
9944
2a705d1af4dc moved Primes, Fib, Factorization from HOL/ex
paulson
parents:
diff changeset
    11
2a705d1af4dc moved Primes, Fib, Factorization from HOL/ex
paulson
parents:
diff changeset
    12
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    13
subsection {* Definitions *}
9944
2a705d1af4dc moved Primes, Fib, Factorization from HOL/ex
paulson
parents:
diff changeset
    14
38159
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
    15
definition primel :: "nat list => bool"
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
    16
  where "primel xs = (\<forall>p \<in> set xs. prime p)"
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
    17
38159
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
    18
primrec nondec :: "nat list => bool"
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
    19
where
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    20
  "nondec [] = True"
38159
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
    21
| "nondec (x # xs) = (case xs of [] => True | y # ys => x \<le> y \<and> nondec xs)"
9944
2a705d1af4dc moved Primes, Fib, Factorization from HOL/ex
paulson
parents:
diff changeset
    22
38159
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
    23
primrec prod :: "nat list => nat"
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
    24
where
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11468
diff changeset
    25
  "prod [] = Suc 0"
38159
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
    26
| "prod (x # xs) = x * prod xs"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    27
38159
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
    28
primrec oinsert :: "nat => nat list => nat list"
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
    29
where
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    30
  "oinsert x [] = [x]"
38159
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
    31
| "oinsert x (y # ys) = (if x \<le> y then x # y # ys else y # oinsert x ys)"
9944
2a705d1af4dc moved Primes, Fib, Factorization from HOL/ex
paulson
parents:
diff changeset
    32
38159
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
    33
primrec sort :: "nat list => nat list"
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
    34
where
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    35
  "sort [] = []"
38159
e9b4835a54ee modernized specifications;
wenzelm
parents: 32479
diff changeset
    36
| "sort (x # xs) = oinsert x (sort xs)"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    37
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    38
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    39
subsection {* Arithmetic *}
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    40
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11468
diff changeset
    41
lemma one_less_m: "(m::nat) \<noteq> m * k ==> m \<noteq> Suc 0 ==> Suc 0 < m"
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
    42
  apply (cases m)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    43
   apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    44
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    45
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11468
diff changeset
    46
lemma one_less_k: "(m::nat) \<noteq> m * k ==> Suc 0 < m * k ==> Suc 0 < k"
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
    47
  apply (cases k)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    48
   apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    49
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    50
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    51
lemma mult_left_cancel: "(0::nat) < k ==> k * n = k * m ==> n = m"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    52
  apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    53
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    54
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11468
diff changeset
    55
lemma mn_eq_m_one: "(0::nat) < m ==> m * n = m ==> n = Suc 0"
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
    56
  apply (cases n)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    57
   apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    58
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    59
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    60
lemma prod_mn_less_k:
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11468
diff changeset
    61
    "(0::nat) < n ==> 0 < k ==> Suc 0 < m ==> m * n = k ==> n < k"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    62
  apply (induct m)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    63
   apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    64
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    65
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    66
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    67
subsection {* Prime list and product *}
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    68
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    69
lemma prod_append: "prod (xs @ ys) = prod xs * prod ys"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    70
  apply (induct xs)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    71
   apply (simp_all add: mult_assoc)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    72
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    73
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    74
lemma prod_xy_prod:
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    75
    "prod (x # xs) = prod (y # ys) ==> x * prod xs = y * prod ys"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    76
  apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    77
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    78
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    79
lemma primel_append: "primel (xs @ ys) = (primel xs \<and> primel ys)"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    80
  apply (unfold primel_def)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    81
  apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    82
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    83
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
    84
lemma prime_primel: "prime n ==> primel [n] \<and> prod [n] = n"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    85
  apply (unfold primel_def)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    86
  apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    87
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    88
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
    89
lemma prime_nd_one: "prime p ==> \<not> p dvd Suc 0"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    90
  apply (unfold prime_def dvd_def)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    91
  apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    92
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    93
23814
cdaa6b701509 tidied using sledgehammer
paulson
parents: 21404
diff changeset
    94
lemma hd_dvd_prod: "prod (x # xs) = prod ys ==> x dvd (prod ys)" 
cdaa6b701509 tidied using sledgehammer
paulson
parents: 21404
diff changeset
    95
  by (metis dvd_mult_left dvd_refl prod.simps(2))
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    96
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    97
lemma primel_tl: "primel (x # xs) ==> primel xs"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    98
  apply (unfold primel_def)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
    99
  apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   100
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   101
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
   102
lemma primel_hd_tl: "(primel (x # xs)) = (prime x \<and> primel xs)"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   103
  apply (unfold primel_def)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   104
  apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   105
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   106
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
   107
lemma primes_eq: "prime p ==> prime q ==> p dvd q ==> p = q"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   108
  apply (unfold prime_def)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   109
  apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   110
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   111
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11468
diff changeset
   112
lemma primel_one_empty: "primel xs ==> prod xs = Suc 0 ==> xs = []"
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   113
  apply (cases xs)
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   114
   apply (simp_all add: primel_def prime_def)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   115
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   116
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
   117
lemma prime_g_one: "prime p ==> Suc 0 < p"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   118
  apply (unfold prime_def)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   119
  apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   120
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   121
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
   122
lemma prime_g_zero: "prime p ==> 0 < p"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   123
  apply (unfold prime_def)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   124
  apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   125
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   126
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   127
lemma primel_nempty_g_one:
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   128
    "primel xs \<Longrightarrow> xs \<noteq> [] \<Longrightarrow> Suc 0 < prod xs"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   129
  apply (induct xs)
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   130
   apply simp
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 41413
diff changeset
   131
  apply (fastforce simp: primel_def prime_def elim: one_less_mult)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   132
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   133
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   134
lemma primel_prod_gz: "primel xs ==> 0 < prod xs"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   135
  apply (induct xs)
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   136
   apply (auto simp: primel_def prime_def)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   137
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   138
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   139
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   140
subsection {* Sorting *}
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   141
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   142
lemma nondec_oinsert: "nondec xs \<Longrightarrow> nondec (oinsert x xs)"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   143
  apply (induct xs)
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   144
   apply simp
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   145
   apply (case_tac xs)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   146
    apply (simp_all cong del: list.weak_case_cong)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   147
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   148
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   149
lemma nondec_sort: "nondec (sort xs)"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   150
  apply (induct xs)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   151
   apply simp_all
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   152
  apply (erule nondec_oinsert)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   153
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   154
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   155
lemma x_less_y_oinsert: "x \<le> y ==> l = y # ys ==> x # l = oinsert x l"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   156
  apply simp_all
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   157
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   158
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   159
lemma nondec_sort_eq [rule_format]: "nondec xs \<longrightarrow> xs = sort xs"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   160
  apply (induct xs)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   161
   apply safe
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   162
    apply simp_all
15236
f289e8ba2bb3 Proofs needed to be updated because induction now preserves name of
nipkow
parents: 11701
diff changeset
   163
   apply (case_tac xs)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   164
    apply simp_all
15236
f289e8ba2bb3 Proofs needed to be updated because induction now preserves name of
nipkow
parents: 11701
diff changeset
   165
  apply (case_tac xs)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   166
   apply simp
15236
f289e8ba2bb3 Proofs needed to be updated because induction now preserves name of
nipkow
parents: 11701
diff changeset
   167
  apply (rule_tac y = aa and ys = list in x_less_y_oinsert)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   168
   apply simp_all
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   169
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   170
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   171
lemma oinsert_x_y: "oinsert x (oinsert y l) = oinsert y (oinsert x l)"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   172
  apply (induct l)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   173
  apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   174
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   175
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   176
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   177
subsection {* Permutation *}
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   178
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   179
lemma perm_primel [rule_format]: "xs <~~> ys ==> primel xs --> primel ys"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   180
  apply (unfold primel_def)
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   181
  apply (induct set: perm)
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
   182
     apply simp
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
   183
    apply simp
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
   184
   apply (simp (no_asm))
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
   185
   apply blast
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
   186
  apply blast
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   187
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   188
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   189
lemma perm_prod: "xs <~~> ys ==> prod xs = prod ys"
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   190
  apply (induct set: perm)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   191
     apply (simp_all add: mult_ac)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   192
  done
9944
2a705d1af4dc moved Primes, Fib, Factorization from HOL/ex
paulson
parents:
diff changeset
   193
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   194
lemma perm_subst_oinsert: "xs <~~> ys ==> oinsert a xs <~~> oinsert a ys"
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   195
  apply (induct set: perm)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   196
     apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   197
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   198
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   199
lemma perm_oinsert: "x # xs <~~> oinsert x xs"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   200
  apply (induct xs)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   201
   apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   202
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   203
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   204
lemma perm_sort: "xs <~~> sort xs"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   205
  apply (induct xs)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   206
  apply (auto intro: perm_oinsert elim: perm_subst_oinsert)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   207
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   208
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   209
lemma perm_sort_eq: "xs <~~> ys ==> sort xs = sort ys"
19670
2e4a143c73c5 prefer 'definition' over low-level defs;
wenzelm
parents: 16663
diff changeset
   210
  apply (induct set: perm)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   211
     apply (simp_all add: oinsert_x_y)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   212
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   213
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   214
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   215
subsection {* Existence *}
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   216
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   217
lemma ex_nondec_lemma:
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   218
    "primel xs ==> \<exists>ys. primel ys \<and> nondec ys \<and> prod ys = prod xs"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   219
  apply (blast intro: nondec_sort perm_prod perm_primel perm_sort perm_sym)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   220
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   221
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   222
lemma not_prime_ex_mk:
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
   223
  "Suc 0 < n \<and> \<not> prime n ==>
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11468
diff changeset
   224
    \<exists>m k. Suc 0 < m \<and> Suc 0 < k \<and> m < n \<and> k < n \<and> n = m * k"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   225
  apply (unfold prime_def dvd_def)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   226
  apply (auto intro: n_less_m_mult_n n_less_n_mult_m one_less_m one_less_k)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   227
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   228
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   229
lemma split_primel:
25687
f92c9dfa7681 split_primel: salvaged original proof after blow with sledghammer
wenzelm
parents: 25493
diff changeset
   230
  "primel xs \<Longrightarrow> primel ys \<Longrightarrow> \<exists>l. primel l \<and> prod l = prod xs * prod ys"
f92c9dfa7681 split_primel: salvaged original proof after blow with sledghammer
wenzelm
parents: 25493
diff changeset
   231
  apply (rule exI)
f92c9dfa7681 split_primel: salvaged original proof after blow with sledghammer
wenzelm
parents: 25493
diff changeset
   232
  apply safe
f92c9dfa7681 split_primel: salvaged original proof after blow with sledghammer
wenzelm
parents: 25493
diff changeset
   233
   apply (rule_tac [2] prod_append)
f92c9dfa7681 split_primel: salvaged original proof after blow with sledghammer
wenzelm
parents: 25493
diff changeset
   234
  apply (simp add: primel_append)
f92c9dfa7681 split_primel: salvaged original proof after blow with sledghammer
wenzelm
parents: 25493
diff changeset
   235
  done
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   236
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11468
diff changeset
   237
lemma factor_exists [rule_format]: "Suc 0 < n --> (\<exists>l. primel l \<and> prod l = n)"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   238
  apply (induct n rule: nat_less_induct)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   239
  apply (rule impI)
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
   240
  apply (case_tac "prime n")
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   241
   apply (rule exI)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   242
   apply (erule prime_primel)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   243
  apply (cut_tac n = n in not_prime_ex_mk)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   244
   apply (auto intro!: split_primel)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   245
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   246
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11468
diff changeset
   247
lemma nondec_factor_exists: "Suc 0 < n ==> \<exists>l. primel l \<and> nondec l \<and> prod l = n"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   248
  apply (erule factor_exists [THEN exE])
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   249
  apply (blast intro!: ex_nondec_lemma)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   250
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   251
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   252
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   253
subsection {* Uniqueness *}
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   254
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   255
lemma prime_dvd_mult_list [rule_format]:
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
   256
    "prime p ==> p dvd (prod xs) --> (\<exists>m. m:set xs \<and> p dvd m)"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   257
  apply (induct xs)
11364
01020b10c0a7 simplified a proof using new dvd rules
paulson
parents: 11049
diff changeset
   258
   apply (force simp add: prime_def)
01020b10c0a7 simplified a proof using new dvd rules
paulson
parents: 11049
diff changeset
   259
   apply (force dest: prime_dvd_mult)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   260
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   261
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   262
lemma hd_xs_dvd_prod:
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   263
  "primel (x # xs) ==> primel ys ==> prod (x # xs) = prod ys
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   264
    ==> \<exists>m. m \<in> set ys \<and> x dvd m"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   265
  apply (rule prime_dvd_mult_list)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   266
   apply (simp add: primel_hd_tl)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   267
  apply (erule hd_dvd_prod)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   268
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   269
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   270
lemma prime_dvd_eq: "primel (x # xs) ==> primel ys ==> m \<in> set ys ==> x dvd m ==> x = m"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   271
  apply (rule primes_eq)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   272
    apply (auto simp add: primel_def primel_hd_tl)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   273
  done
9944
2a705d1af4dc moved Primes, Fib, Factorization from HOL/ex
paulson
parents:
diff changeset
   274
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   275
lemma hd_xs_eq_prod:
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   276
  "primel (x # xs) ==>
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   277
    primel ys ==> prod (x # xs) = prod ys ==> x \<in> set ys"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   278
  apply (frule hd_xs_dvd_prod)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   279
    apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   280
  apply (drule prime_dvd_eq)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   281
     apply auto
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   282
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   283
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   284
lemma perm_primel_ex:
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   285
  "primel (x # xs) ==>
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   286
    primel ys ==> prod (x # xs) = prod ys ==> \<exists>l. ys <~~> (x # l)"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   287
  apply (rule exI)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   288
  apply (rule perm_remove)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   289
  apply (erule hd_xs_eq_prod)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   290
   apply simp_all
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   291
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   292
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   293
lemma primel_prod_less:
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   294
  "primel (x # xs) ==>
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   295
    primel ys ==> prod (x # xs) = prod ys ==> prod xs < prod ys"
26316
9e9e67e33557 removed redundant less_trans, less_linear, le_imp_less_or_eq, le_less_trans, less_le_trans (cf. Orderings.thy);
wenzelm
parents: 25687
diff changeset
   296
  by (metis less_asym linorder_neqE_nat mult_less_cancel2 nat_0_less_mult_iff
25180
16a99bc76717 avoid very slow metis invocation (saves 1min on 1.60 GHz machine);
wenzelm
parents: 25157
diff changeset
   297
    nat_less_le nat_mult_1 prime_def primel_hd_tl primel_prod_gz prod.simps(2))
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   298
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   299
lemma prod_one_empty:
16663
13e9c402308b prime is a predicate now.
nipkow
parents: 16417
diff changeset
   300
    "primel xs ==> p * prod xs = p ==> prime p ==> xs = []"
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   301
  apply (auto intro: primel_one_empty simp add: prime_def)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   302
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   303
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   304
lemma uniq_ex_aux:
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   305
  "\<forall>m. m < prod ys --> (\<forall>xs ys. primel xs \<and> primel ys \<and>
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   306
      prod xs = prod ys \<and> prod xs = m --> xs <~~> ys) ==>
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   307
    primel list ==> primel x ==> prod list = prod x ==> prod x < prod ys
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   308
    ==> x <~~> list"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   309
  apply simp
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   310
  done
9944
2a705d1af4dc moved Primes, Fib, Factorization from HOL/ex
paulson
parents:
diff changeset
   311
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   312
lemma factor_unique [rule_format]:
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   313
  "\<forall>xs ys. primel xs \<and> primel ys \<and> prod xs = prod ys \<and> prod xs = n
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   314
    --> xs <~~> ys"
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   315
  apply (induct n rule: nat_less_induct)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   316
  apply safe
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   317
  apply (case_tac xs)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   318
   apply (force intro: primel_one_empty)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   319
  apply (rule perm_primel_ex [THEN exE])
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   320
     apply simp_all
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   321
  apply (rule perm.trans [THEN perm_sym])
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   322
  apply assumption
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   323
  apply (rule perm.Cons)
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   324
  apply (case_tac "x = []")
25493
50d566776a26 simplified using sledgehammer
paulson
parents: 25180
diff changeset
   325
   apply (metis perm_prod perm_refl prime_primel primel_hd_tl primel_tl prod_one_empty)
50d566776a26 simplified using sledgehammer
paulson
parents: 25180
diff changeset
   326
  apply (metis nat_0_less_mult_iff nat_mult_eq_cancel1 perm_primel perm_prod primel_prod_gz primel_prod_less primel_tl prod.simps(2))
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   327
  done
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   328
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   329
lemma perm_nondec_unique:
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   330
    "xs <~~> ys ==> nondec xs ==> nondec ys ==> xs = ys"
23814
cdaa6b701509 tidied using sledgehammer
paulson
parents: 21404
diff changeset
   331
  by (metis nondec_sort_eq perm_sort_eq)
cdaa6b701509 tidied using sledgehammer
paulson
parents: 21404
diff changeset
   332
25493
50d566776a26 simplified using sledgehammer
paulson
parents: 25180
diff changeset
   333
theorem unique_prime_factorization [rule_format]:
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11468
diff changeset
   334
    "\<forall>n. Suc 0 < n --> (\<exists>!l. primel l \<and> nondec l \<and> prod l = n)"
25493
50d566776a26 simplified using sledgehammer
paulson
parents: 25180
diff changeset
   335
  by (metis factor_unique nondec_factor_exists perm_nondec_unique)
11049
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   336
7eef34adb852 HOL-NumberTheory: converted to new-style format and proper document setup;
wenzelm
parents: 9944
diff changeset
   337
end