src/HOL/Hoare/Arith2.thy
author wenzelm
Thu, 16 Feb 2012 22:54:40 +0100
changeset 46509 c4b2ec379fdd
parent 44890 22f665a2e91c
child 57442 2373b4c61111
permissions -rw-r--r--
more symbols; misc tuning;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1476
608483c2122a expanded tabs; incorporated Konrad's changes
clasohm
parents: 1374
diff changeset
     1
(*  Title:      HOL/Hoare/Arith2.thy
608483c2122a expanded tabs; incorporated Konrad's changes
clasohm
parents: 1374
diff changeset
     2
    Author:     Norbert Galm
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
     3
    Copyright   1995 TUM
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
     4
3372
6e472c8f0011 Replacement of "divides" by "dvd" from Divides.thy, and updating of proofs
paulson
parents: 1824
diff changeset
     5
More arithmetic.  Much of this duplicates ex/Primes.
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
     6
*)
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
     7
17278
f27456a2a975 converted to Isar theory format;
wenzelm
parents: 8791
diff changeset
     8
theory Arith2
f27456a2a975 converted to Isar theory format;
wenzelm
parents: 8791
diff changeset
     9
imports Main
f27456a2a975 converted to Isar theory format;
wenzelm
parents: 8791
diff changeset
    10
begin
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    11
38353
d98baa2cf589 modernized specifications;
wenzelm
parents: 35416
diff changeset
    12
definition "cd" :: "[nat, nat, nat] => bool"
d98baa2cf589 modernized specifications;
wenzelm
parents: 35416
diff changeset
    13
  where "cd x m n \<longleftrightarrow> x dvd m & x dvd n"
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    14
38353
d98baa2cf589 modernized specifications;
wenzelm
parents: 35416
diff changeset
    15
definition gcd :: "[nat, nat] => nat"
d98baa2cf589 modernized specifications;
wenzelm
parents: 35416
diff changeset
    16
  where "gcd m n = (SOME x. cd x m n & (!y.(cd y m n) --> y<=x))"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 4359
diff changeset
    17
38353
d98baa2cf589 modernized specifications;
wenzelm
parents: 35416
diff changeset
    18
primrec fac :: "nat => nat"
d98baa2cf589 modernized specifications;
wenzelm
parents: 35416
diff changeset
    19
where
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 4359
diff changeset
    20
  "fac 0 = Suc 0"
38353
d98baa2cf589 modernized specifications;
wenzelm
parents: 35416
diff changeset
    21
| "fac (Suc n) = Suc n * fac n"
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    22
19802
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    23
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    24
subsubsection {* cd *}
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    25
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    26
lemma cd_nnn: "0<n ==> cd n n n"
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    27
  apply (simp add: cd_def)
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    28
  done
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    29
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    30
lemma cd_le: "[| cd x m n; 0<m; 0<n |] ==> x<=m & x<=n"
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    31
  apply (unfold cd_def)
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    32
  apply (blast intro: dvd_imp_le)
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    33
  done
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    34
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    35
lemma cd_swap: "cd x m n = cd x n m"
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    36
  apply (unfold cd_def)
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    37
  apply blast
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    38
  done
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    39
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    40
lemma cd_diff_l: "n<=m ==> cd x m n = cd x (m-n) n"
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    41
  apply (unfold cd_def)
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 38353
diff changeset
    42
  apply (fastforce dest: dvd_diffD)
19802
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    43
  done
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    44
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    45
lemma cd_diff_r: "m<=n ==> cd x m n = cd x m (n-m)"
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    46
  apply (unfold cd_def)
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 38353
diff changeset
    47
  apply (fastforce dest: dvd_diffD)
19802
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    48
  done
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    49
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    50
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    51
subsubsection {* gcd *}
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    52
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    53
lemma gcd_nnn: "0<n ==> n = gcd n n"
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    54
  apply (unfold gcd_def)
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    55
  apply (frule cd_nnn)
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    56
  apply (rule some_equality [symmetric])
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    57
  apply (blast dest: cd_le)
33657
a4179bf442d1 renamed lemmas "anti_sym" -> "antisym"
nipkow
parents: 30042
diff changeset
    58
  apply (blast intro: le_antisym dest: cd_le)
19802
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    59
  done
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    60
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    61
lemma gcd_swap: "gcd m n = gcd n m"
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    62
  apply (simp add: gcd_def cd_swap)
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    63
  done
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    64
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    65
lemma gcd_diff_l: "n<=m ==> gcd m n = gcd (m-n) n"
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    66
  apply (unfold gcd_def)
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    67
  apply (subgoal_tac "n<=m ==> !x. cd x m n = cd x (m-n) n")
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    68
  apply simp
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    69
  apply (rule allI)
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    70
  apply (erule cd_diff_l)
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    71
  done
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    72
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    73
lemma gcd_diff_r: "m<=n ==> gcd m n = gcd m (n-m)"
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    74
  apply (unfold gcd_def)
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    75
  apply (subgoal_tac "m<=n ==> !x. cd x m n = cd x m (n-m) ")
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    76
  apply simp
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    77
  apply (rule allI)
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    78
  apply (erule cd_diff_r)
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    79
  done
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    80
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    81
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    82
subsubsection {* pow *}
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    83
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    84
lemma sq_pow_div2 [simp]:
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    85
    "m mod 2 = 0 ==> ((n::nat)*n)^(m div 2) = n^m"
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    86
  apply (simp add: power2_eq_square [symmetric] power_mult [symmetric] mult_div_cancel)
c2860c37e574 removed obsolete ML files;
wenzelm
parents: 17278
diff changeset
    87
  done
17278
f27456a2a975 converted to Isar theory format;
wenzelm
parents: 8791
diff changeset
    88
1335
5e1c0540f285 New directory.
nipkow
parents:
diff changeset
    89
end