src/ZF/ArithSimp.thy
author paulson
Tue, 09 Jul 2002 23:05:26 +0200
changeset 13328 703de709a64b
parent 13259 01fa0c8dbc92
child 13356 c9cfe1638bf2
permissions -rw-r--r--
better document preparation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9548
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents:
diff changeset
     1
(*  Title:      ZF/ArithSimp.ML
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents:
diff changeset
     2
    ID:         $Id$
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents:
diff changeset
     4
    Copyright   2000  University of Cambridge
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents:
diff changeset
     5
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents:
diff changeset
     6
*)
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents:
diff changeset
     7
13328
703de709a64b better document preparation
paulson
parents: 13259
diff changeset
     8
header{*Arithmetic with simplification*}
703de709a64b better document preparation
paulson
parents: 13259
diff changeset
     9
9548
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents:
diff changeset
    10
theory ArithSimp = Arith
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents:
diff changeset
    11
files "arith_data.ML":
13259
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    12
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    13
(*** Difference ***)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    14
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    15
lemma diff_self_eq_0: "m #- m = 0"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    16
apply (subgoal_tac "natify (m) #- natify (m) = 0")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    17
apply (rule_tac [2] natify_in_nat [THEN nat_induct], auto)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    18
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    19
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    20
(**Addition is the inverse of subtraction**)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    21
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    22
(*We need m:nat even if we replace the RHS by natify(m), for consider e.g.
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    23
  n=2, m=omega; then n + (m-n) = 2 + (0-2) = 2 ~= 0 = natify(m).*)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    24
lemma add_diff_inverse: "[| n le m;  m:nat |] ==> n #+ (m#-n) = m"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    25
apply (frule lt_nat_in_nat, erule nat_succI)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    26
apply (erule rev_mp)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    27
apply (rule_tac m = "m" and n = "n" in diff_induct, auto)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    28
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    29
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    30
lemma add_diff_inverse2: "[| n le m;  m:nat |] ==> (m#-n) #+ n = m"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    31
apply (frule lt_nat_in_nat, erule nat_succI)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    32
apply (simp (no_asm_simp) add: add_commute add_diff_inverse)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    33
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    34
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    35
(*Proof is IDENTICAL to that of add_diff_inverse*)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    36
lemma diff_succ: "[| n le m;  m:nat |] ==> succ(m) #- n = succ(m#-n)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    37
apply (frule lt_nat_in_nat, erule nat_succI)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    38
apply (erule rev_mp)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    39
apply (rule_tac m = "m" and n = "n" in diff_induct)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    40
apply (simp_all (no_asm_simp))
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    41
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    42
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    43
lemma zero_less_diff [simp]:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    44
     "[| m: nat; n: nat |] ==> 0 < (n #- m)   <->   m<n"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    45
apply (rule_tac m = "m" and n = "n" in diff_induct)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    46
apply (simp_all (no_asm_simp))
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    47
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    48
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    49
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    50
(** Difference distributes over multiplication **)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    51
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    52
lemma diff_mult_distrib: "(m #- n) #* k = (m #* k) #- (n #* k)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    53
apply (subgoal_tac " (natify (m) #- natify (n)) #* natify (k) = (natify (m) #* natify (k)) #- (natify (n) #* natify (k))")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    54
apply (rule_tac [2] m = "natify (m) " and n = "natify (n) " in diff_induct)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    55
apply (simp_all add: diff_cancel)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    56
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    57
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    58
lemma diff_mult_distrib2: "k #* (m #- n) = (k #* m) #- (k #* n)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    59
apply (simp (no_asm) add: mult_commute [of k] diff_mult_distrib)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    60
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    61
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    62
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    63
(*** Remainder ***)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    64
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    65
(*We need m:nat even with natify*)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    66
lemma div_termination: "[| 0<n;  n le m;  m:nat |] ==> m #- n < m"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    67
apply (frule lt_nat_in_nat, erule nat_succI)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    68
apply (erule rev_mp)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    69
apply (erule rev_mp)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    70
apply (rule_tac m = "m" and n = "n" in diff_induct)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    71
apply (simp_all (no_asm_simp) add: diff_le_self)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    72
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    73
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    74
(*for mod and div*)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    75
lemmas div_rls = 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    76
    nat_typechecks Ord_transrec_type apply_funtype 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    77
    div_termination [THEN ltD]
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    78
    nat_into_Ord not_lt_iff_le [THEN iffD1]
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    79
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    80
lemma raw_mod_type: "[| m:nat;  n:nat |] ==> raw_mod (m, n) : nat"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    81
apply (unfold raw_mod_def)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    82
apply (rule Ord_transrec_type)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    83
apply (auto simp add: nat_into_Ord [THEN Ord_0_lt_iff])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    84
apply (blast intro: div_rls) 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    85
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    86
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    87
lemma mod_type [TC,iff]: "m mod n : nat"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    88
apply (unfold mod_def)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    89
apply (simp (no_asm) add: mod_def raw_mod_type)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    90
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    91
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    92
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    93
(** Aribtrary definitions for division by zero.  Useful to simplify 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    94
    certain equations **)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    95
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    96
lemma DIVISION_BY_ZERO_DIV: "a div 0 = 0"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    97
apply (unfold div_def)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    98
apply (rule raw_div_def [THEN def_transrec, THEN trans])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
    99
apply (simp (no_asm_simp))
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   100
done  (*NOT for adding to default simpset*)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   101
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   102
lemma DIVISION_BY_ZERO_MOD: "a mod 0 = natify(a)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   103
apply (unfold mod_def)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   104
apply (rule raw_mod_def [THEN def_transrec, THEN trans])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   105
apply (simp (no_asm_simp))
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   106
done  (*NOT for adding to default simpset*)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   107
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   108
lemma raw_mod_less: "m<n ==> raw_mod (m,n) = m"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   109
apply (rule raw_mod_def [THEN def_transrec, THEN trans])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   110
apply (simp (no_asm_simp) add: div_termination [THEN ltD])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   111
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   112
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   113
lemma mod_less [simp]: "[| m<n; n : nat |] ==> m mod n = m"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   114
apply (frule lt_nat_in_nat, assumption)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   115
apply (simp (no_asm_simp) add: mod_def raw_mod_less)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   116
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   117
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   118
lemma raw_mod_geq:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   119
     "[| 0<n; n le m;  m:nat |] ==> raw_mod (m, n) = raw_mod (m#-n, n)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   120
apply (frule lt_nat_in_nat, erule nat_succI)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   121
apply (rule raw_mod_def [THEN def_transrec, THEN trans])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   122
apply (simp add: div_termination [THEN ltD] not_lt_iff_le [THEN iffD2], blast)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   123
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   124
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   125
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   126
lemma mod_geq: "[| n le m;  m:nat |] ==> m mod n = (m#-n) mod n"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   127
apply (frule lt_nat_in_nat, erule nat_succI)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   128
apply (case_tac "n=0")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   129
 apply (simp add: DIVISION_BY_ZERO_MOD)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   130
apply (simp add: mod_def raw_mod_geq nat_into_Ord [THEN Ord_0_lt_iff])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   131
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   132
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   133
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   134
(*** Division ***)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   135
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   136
lemma raw_div_type: "[| m:nat;  n:nat |] ==> raw_div (m, n) : nat"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   137
apply (unfold raw_div_def)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   138
apply (rule Ord_transrec_type)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   139
apply (auto simp add: nat_into_Ord [THEN Ord_0_lt_iff])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   140
apply (blast intro: div_rls) 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   141
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   142
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   143
lemma div_type [TC,iff]: "m div n : nat"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   144
apply (unfold div_def)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   145
apply (simp (no_asm) add: div_def raw_div_type)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   146
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   147
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   148
lemma raw_div_less: "m<n ==> raw_div (m,n) = 0"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   149
apply (rule raw_div_def [THEN def_transrec, THEN trans])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   150
apply (simp (no_asm_simp) add: div_termination [THEN ltD])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   151
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   152
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   153
lemma div_less [simp]: "[| m<n; n : nat |] ==> m div n = 0"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   154
apply (frule lt_nat_in_nat, assumption)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   155
apply (simp (no_asm_simp) add: div_def raw_div_less)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   156
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   157
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   158
lemma raw_div_geq: "[| 0<n;  n le m;  m:nat |] ==> raw_div(m,n) = succ(raw_div(m#-n, n))"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   159
apply (subgoal_tac "n ~= 0")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   160
prefer 2 apply blast
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   161
apply (frule lt_nat_in_nat, erule nat_succI)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   162
apply (rule raw_div_def [THEN def_transrec, THEN trans])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   163
apply (simp add: div_termination [THEN ltD] not_lt_iff_le [THEN iffD2] ) 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   164
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   165
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   166
lemma div_geq [simp]:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   167
     "[| 0<n;  n le m;  m:nat |] ==> m div n = succ ((m#-n) div n)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   168
apply (frule lt_nat_in_nat, erule nat_succI)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   169
apply (simp (no_asm_simp) add: div_def raw_div_geq)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   170
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   171
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   172
declare div_less [simp] div_geq [simp]
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   173
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   174
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   175
(*A key result*)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   176
lemma mod_div_lemma: "[| m: nat;  n: nat |] ==> (m div n)#*n #+ m mod n = m"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   177
apply (case_tac "n=0")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   178
 apply (simp add: DIVISION_BY_ZERO_MOD)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   179
apply (simp add: nat_into_Ord [THEN Ord_0_lt_iff])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   180
apply (erule complete_induct)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   181
apply (case_tac "x<n")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   182
txt{*case x<n*}
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   183
apply (simp (no_asm_simp))
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   184
txt{*case n le x*}
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   185
apply (simp add: not_lt_iff_le add_assoc mod_geq div_termination [THEN ltD] add_diff_inverse)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   186
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   187
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   188
lemma mod_div_equality_natify: "(m div n)#*n #+ m mod n = natify(m)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   189
apply (subgoal_tac " (natify (m) div natify (n))#*natify (n) #+ natify (m) mod natify (n) = natify (m) ")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   190
apply force 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   191
apply (subst mod_div_lemma, auto)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   192
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   193
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   194
lemma mod_div_equality: "m: nat ==> (m div n)#*n #+ m mod n = m"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   195
apply (simp (no_asm_simp) add: mod_div_equality_natify)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   196
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   197
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   198
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   199
(*** Further facts about mod (mainly for mutilated chess board) ***)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   200
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   201
lemma mod_succ_lemma:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   202
     "[| 0<n;  m:nat;  n:nat |]  
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   203
      ==> succ(m) mod n = (if succ(m mod n) = n then 0 else succ(m mod n))"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   204
apply (erule complete_induct)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   205
apply (case_tac "succ (x) <n")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   206
txt{* case succ(x) < n *}
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   207
 apply (simp (no_asm_simp) add: nat_le_refl [THEN lt_trans] succ_neq_self)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   208
 apply (simp add: ltD [THEN mem_imp_not_eq])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   209
txt{* case n le succ(x) *}
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   210
apply (simp add: mod_geq not_lt_iff_le)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   211
apply (erule leE)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   212
 apply (simp (no_asm_simp) add: mod_geq div_termination [THEN ltD] diff_succ)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   213
txt{*equality case*}
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   214
apply (simp add: diff_self_eq_0)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   215
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   216
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   217
lemma mod_succ:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   218
  "n:nat ==> succ(m) mod n = (if succ(m mod n) = n then 0 else succ(m mod n))"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   219
apply (case_tac "n=0")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   220
 apply (simp (no_asm_simp) add: natify_succ DIVISION_BY_ZERO_MOD)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   221
apply (subgoal_tac "natify (succ (m)) mod n = (if succ (natify (m) mod n) = n then 0 else succ (natify (m) mod n))")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   222
 prefer 2
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   223
 apply (subst natify_succ)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   224
 apply (rule mod_succ_lemma)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   225
  apply (auto simp del: natify_succ simp add: nat_into_Ord [THEN Ord_0_lt_iff])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   226
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   227
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   228
lemma mod_less_divisor: "[| 0<n;  n:nat |] ==> m mod n < n"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   229
apply (subgoal_tac "natify (m) mod n < n")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   230
apply (rule_tac [2] i = "natify (m) " in complete_induct)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   231
apply (case_tac [3] "x<n", auto) 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   232
txt{* case n le x*}
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   233
apply (simp add: mod_geq not_lt_iff_le div_termination [THEN ltD])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   234
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   235
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   236
lemma mod_1_eq [simp]: "m mod 1 = 0"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   237
by (cut_tac n = "1" in mod_less_divisor, auto)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   238
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   239
lemma mod2_cases: "b<2 ==> k mod 2 = b | k mod 2 = (if b=1 then 0 else 1)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   240
apply (subgoal_tac "k mod 2: 2")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   241
 prefer 2 apply (simp add: mod_less_divisor [THEN ltD])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   242
apply (drule ltD, auto)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   243
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   244
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   245
lemma mod2_succ_succ [simp]: "succ(succ(m)) mod 2 = m mod 2"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   246
apply (subgoal_tac "m mod 2: 2")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   247
 prefer 2 apply (simp add: mod_less_divisor [THEN ltD])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   248
apply (auto simp add: mod_succ)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   249
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   250
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   251
lemma mod2_add_more [simp]: "(m#+m#+n) mod 2 = n mod 2"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   252
apply (subgoal_tac " (natify (m) #+natify (m) #+n) mod 2 = n mod 2")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   253
apply (rule_tac [2] n = "natify (m) " in nat_induct)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   254
apply auto
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   255
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   256
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   257
lemma mod2_add_self [simp]: "(m#+m) mod 2 = 0"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   258
by (cut_tac n = "0" in mod2_add_more, auto)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   259
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   260
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   261
(**** Additional theorems about "le" ****)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   262
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   263
lemma add_le_self: "m:nat ==> m le (m #+ n)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   264
apply (simp (no_asm_simp))
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   265
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   266
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   267
lemma add_le_self2: "m:nat ==> m le (n #+ m)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   268
apply (simp (no_asm_simp))
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   269
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   270
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   271
(*** Monotonicity of Multiplication ***)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   272
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   273
lemma mult_le_mono1: "[| i le j; j:nat |] ==> (i#*k) le (j#*k)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   274
apply (subgoal_tac "natify (i) #*natify (k) le j#*natify (k) ")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   275
apply (frule_tac [2] lt_nat_in_nat)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   276
apply (rule_tac [3] n = "natify (k) " in nat_induct)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   277
apply (simp_all add: add_le_mono)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   278
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   279
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   280
(* le monotonicity, BOTH arguments*)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   281
lemma mult_le_mono: "[| i le j; k le l; j:nat; l:nat |] ==> i#*k le j#*l"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   282
apply (rule mult_le_mono1 [THEN le_trans], assumption+)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   283
apply (subst mult_commute, subst mult_commute, rule mult_le_mono1, assumption+)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   284
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   285
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   286
(*strict, in 1st argument; proof is by induction on k>0.
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   287
  I can't see how to relax the typing conditions.*)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   288
lemma mult_lt_mono2: "[| i<j; 0<k; j:nat; k:nat |] ==> k#*i < k#*j"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   289
apply (erule zero_lt_natE)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   290
apply (frule_tac [2] lt_nat_in_nat)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   291
apply (simp_all (no_asm_simp))
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   292
apply (induct_tac "x")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   293
apply (simp_all (no_asm_simp) add: add_lt_mono)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   294
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   295
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   296
lemma mult_lt_mono1: "[| i<j; 0<k; j:nat; k:nat |] ==> i#*k < j#*k"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   297
apply (simp (no_asm_simp) add: mult_lt_mono2 mult_commute [of _ k])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   298
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   299
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   300
lemma add_eq_0_iff [iff]: "m#+n = 0 <-> natify(m)=0 & natify(n)=0"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   301
apply (subgoal_tac "natify (m) #+ natify (n) = 0 <-> natify (m) =0 & natify (n) =0")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   302
apply (rule_tac [2] n = "natify (m) " in natE)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   303
 apply (rule_tac [4] n = "natify (n) " in natE)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   304
apply auto
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   305
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   306
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   307
lemma zero_lt_mult_iff [iff]: "0 < m#*n <-> 0 < natify(m) & 0 < natify(n)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   308
apply (subgoal_tac "0 < natify (m) #*natify (n) <-> 0 < natify (m) & 0 < natify (n) ")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   309
apply (rule_tac [2] n = "natify (m) " in natE)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   310
 apply (rule_tac [4] n = "natify (n) " in natE)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   311
  apply (rule_tac [3] n = "natify (n) " in natE)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   312
apply auto
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   313
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   314
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   315
lemma mult_eq_1_iff [iff]: "m#*n = 1 <-> natify(m)=1 & natify(n)=1"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   316
apply (subgoal_tac "natify (m) #* natify (n) = 1 <-> natify (m) =1 & natify (n) =1")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   317
apply (rule_tac [2] n = "natify (m) " in natE)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   318
 apply (rule_tac [4] n = "natify (n) " in natE)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   319
apply auto
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   320
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   321
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   322
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   323
lemma mult_is_zero: "[|m: nat; n: nat|] ==> (m #* n = 0) <-> (m = 0 | n = 0)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   324
apply auto
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   325
apply (erule natE)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   326
apply (erule_tac [2] natE, auto)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   327
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   328
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   329
lemma mult_is_zero_natify [iff]:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   330
     "(m #* n = 0) <-> (natify(m) = 0 | natify(n) = 0)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   331
apply (cut_tac m = "natify (m) " and n = "natify (n) " in mult_is_zero)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   332
apply auto
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   333
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   334
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   335
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   336
(** Cancellation laws for common factors in comparisons **)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   337
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   338
lemma mult_less_cancel_lemma:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   339
     "[| k: nat; m: nat; n: nat |] ==> (m#*k < n#*k) <-> (0<k & m<n)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   340
apply (safe intro!: mult_lt_mono1)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   341
apply (erule natE, auto)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   342
apply (rule not_le_iff_lt [THEN iffD1])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   343
apply (drule_tac [3] not_le_iff_lt [THEN [2] rev_iffD2])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   344
prefer 5 apply (blast intro: mult_le_mono1, auto)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   345
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   346
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   347
lemma mult_less_cancel2 [simp]:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   348
     "(m#*k < n#*k) <-> (0 < natify(k) & natify(m) < natify(n))"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   349
apply (rule iff_trans)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   350
apply (rule_tac [2] mult_less_cancel_lemma, auto)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   351
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   352
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   353
lemma mult_less_cancel1 [simp]:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   354
     "(k#*m < k#*n) <-> (0 < natify(k) & natify(m) < natify(n))"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   355
apply (simp (no_asm) add: mult_less_cancel2 mult_commute [of k])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   356
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   357
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   358
lemma mult_le_cancel2 [simp]: "(m#*k le n#*k) <-> (0 < natify(k) --> natify(m) le natify(n))"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   359
apply (simp (no_asm_simp) add: not_lt_iff_le [THEN iff_sym])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   360
apply auto
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   361
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   362
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   363
lemma mult_le_cancel1 [simp]: "(k#*m le k#*n) <-> (0 < natify(k) --> natify(m) le natify(n))"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   364
apply (simp (no_asm_simp) add: not_lt_iff_le [THEN iff_sym])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   365
apply auto
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   366
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   367
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   368
lemma mult_le_cancel_le1: "k : nat ==> k #* m le k \<longleftrightarrow> (0 < k \<longrightarrow> natify(m) le 1)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   369
by (cut_tac k = "k" and m = "m" and n = "1" in mult_le_cancel1, auto)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   370
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   371
lemma Ord_eq_iff_le: "[| Ord(m); Ord(n) |] ==> m=n <-> (m le n & n le m)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   372
by (blast intro: le_anti_sym)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   373
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   374
lemma mult_cancel2_lemma:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   375
     "[| k: nat; m: nat; n: nat |] ==> (m#*k = n#*k) <-> (m=n | k=0)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   376
apply (simp (no_asm_simp) add: Ord_eq_iff_le [of "m#*k"] Ord_eq_iff_le [of m])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   377
apply (auto simp add: Ord_0_lt_iff)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   378
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   379
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   380
lemma mult_cancel2 [simp]:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   381
     "(m#*k = n#*k) <-> (natify(m) = natify(n) | natify(k) = 0)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   382
apply (rule iff_trans)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   383
apply (rule_tac [2] mult_cancel2_lemma, auto)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   384
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   385
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   386
lemma mult_cancel1 [simp]:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   387
     "(k#*m = k#*n) <-> (natify(m) = natify(n) | natify(k) = 0)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   388
apply (simp (no_asm) add: mult_cancel2 mult_commute [of k])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   389
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   390
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   391
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   392
(** Cancellation law for division **)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   393
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   394
lemma div_cancel_raw:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   395
     "[| 0<n; 0<k; k:nat; m:nat; n:nat |] ==> (k#*m) div (k#*n) = m div n"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   396
apply (erule_tac i = "m" in complete_induct)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   397
apply (case_tac "x<n")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   398
 apply (simp add: div_less zero_lt_mult_iff mult_lt_mono2)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   399
apply (simp add: not_lt_iff_le zero_lt_mult_iff le_refl [THEN mult_le_mono]
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   400
          div_geq diff_mult_distrib2 [symmetric] div_termination [THEN ltD])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   401
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   402
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   403
lemma div_cancel:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   404
     "[| 0 < natify(n);  0 < natify(k) |] ==> (k#*m) div (k#*n) = m div n"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   405
apply (cut_tac k = "natify (k) " and m = "natify (m)" and n = "natify (n)" 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   406
       in div_cancel_raw)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   407
apply auto
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   408
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   409
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   410
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   411
(** Distributive law for remainder (mod) **)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   412
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   413
lemma mult_mod_distrib_raw:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   414
     "[| k:nat; m:nat; n:nat |] ==> (k#*m) mod (k#*n) = k #* (m mod n)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   415
apply (case_tac "k=0")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   416
 apply (simp add: DIVISION_BY_ZERO_MOD)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   417
apply (case_tac "n=0")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   418
 apply (simp add: DIVISION_BY_ZERO_MOD)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   419
apply (simp add: nat_into_Ord [THEN Ord_0_lt_iff])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   420
apply (erule_tac i = "m" in complete_induct)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   421
apply (case_tac "x<n")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   422
 apply (simp (no_asm_simp) add: mod_less zero_lt_mult_iff mult_lt_mono2)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   423
apply (simp add: not_lt_iff_le zero_lt_mult_iff le_refl [THEN mult_le_mono] 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   424
         mod_geq diff_mult_distrib2 [symmetric] div_termination [THEN ltD])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   425
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   426
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   427
lemma mod_mult_distrib2: "k #* (m mod n) = (k#*m) mod (k#*n)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   428
apply (cut_tac k = "natify (k) " and m = "natify (m)" and n = "natify (n)" 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   429
       in mult_mod_distrib_raw)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   430
apply auto
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   431
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   432
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   433
lemma mult_mod_distrib: "(m mod n) #* k = (m#*k) mod (n#*k)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   434
apply (simp (no_asm) add: mult_commute mod_mult_distrib2)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   435
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   436
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   437
lemma mod_add_self2_raw: "n \<in> nat ==> (m #+ n) mod n = m mod n"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   438
apply (subgoal_tac " (n #+ m) mod n = (n #+ m #- n) mod n")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   439
apply (simp add: add_commute) 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   440
apply (subst mod_geq [symmetric], auto) 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   441
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   442
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   443
lemma mod_add_self2 [simp]: "(m #+ n) mod n = m mod n"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   444
apply (cut_tac n = "natify (n) " in mod_add_self2_raw)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   445
apply auto
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   446
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   447
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   448
lemma mod_add_self1 [simp]: "(n#+m) mod n = m mod n"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   449
apply (simp (no_asm_simp) add: add_commute mod_add_self2)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   450
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   451
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   452
lemma mod_mult_self1_raw: "k \<in> nat ==> (m #+ k#*n) mod n = m mod n"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   453
apply (erule nat_induct)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   454
apply (simp_all (no_asm_simp) add: add_left_commute [of _ n])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   455
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   456
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   457
lemma mod_mult_self1 [simp]: "(m #+ k#*n) mod n = m mod n"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   458
apply (cut_tac k = "natify (k) " in mod_mult_self1_raw)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   459
apply auto
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   460
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   461
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   462
lemma mod_mult_self2 [simp]: "(m #+ n#*k) mod n = m mod n"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   463
apply (simp (no_asm) add: mult_commute mod_mult_self1)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   464
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   465
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   466
(*Lemma for gcd*)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   467
lemma mult_eq_self_implies_10: "m = m#*n ==> natify(n)=1 | m=0"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   468
apply (subgoal_tac "m: nat")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   469
 prefer 2 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   470
 apply (erule ssubst)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   471
 apply simp  
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   472
apply (rule disjCI)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   473
apply (drule sym)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   474
apply (rule Ord_linear_lt [of "natify(n)" 1])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   475
apply simp_all  
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   476
 apply (subgoal_tac "m #* n = 0", simp) 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   477
 apply (subst mult_natify2 [symmetric])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   478
 apply (simp del: mult_natify2)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   479
apply (drule nat_into_Ord [THEN Ord_0_lt, THEN [2] mult_lt_mono2], auto)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   480
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   481
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   482
lemma less_imp_succ_add [rule_format]:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   483
     "[| m<n; n: nat |] ==> EX k: nat. n = succ(m#+k)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   484
apply (frule lt_nat_in_nat, assumption)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   485
apply (erule rev_mp)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   486
apply (induct_tac "n")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   487
apply (simp_all (no_asm) add: le_iff)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   488
apply (blast elim!: leE intro!: add_0_right [symmetric] add_succ_right [symmetric])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   489
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   490
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   491
lemma less_iff_succ_add:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   492
     "[| m: nat; n: nat |] ==> (m<n) <-> (EX k: nat. n = succ(m#+k))"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   493
by (auto intro: less_imp_succ_add)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   494
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   495
(* on nat *)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   496
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   497
lemma diff_is_0_lemma:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   498
     "[| m: nat; n: nat |] ==> m #- n = 0 <-> m le n"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   499
apply (rule_tac m = "m" and n = "n" in diff_induct, simp_all)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   500
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   501
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   502
lemma diff_is_0_iff: "m #- n = 0 <-> natify(m) le natify(n)"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   503
by (simp add: diff_is_0_lemma [symmetric])
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   504
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   505
lemma nat_lt_imp_diff_eq_0:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   506
     "[| a:nat; b:nat; a<b |] ==> a #- b = 0"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   507
by (simp add: diff_is_0_iff le_iff) 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   508
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   509
lemma nat_diff_split:
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   510
     "[| a:nat; b:nat |] ==>  
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   511
      (P(a #- b)) <-> ((a < b -->P(0)) & (ALL d:nat. a = b #+ d --> P(d)))"
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   512
apply (case_tac "a < b")
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   513
 apply (force simp add: nat_lt_imp_diff_eq_0)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   514
apply (rule iffI, simp_all) 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   515
 apply clarify 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   516
 apply (rotate_tac -1) 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   517
 apply simp 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   518
apply (drule_tac x="a#-b" in bspec)
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   519
apply (simp_all add: Ordinal.not_lt_iff_le add_diff_inverse) 
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   520
done
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   521
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   522
ML
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   523
{*
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   524
val diff_self_eq_0 = thm "diff_self_eq_0";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   525
val add_diff_inverse = thm "add_diff_inverse";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   526
val add_diff_inverse2 = thm "add_diff_inverse2";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   527
val diff_succ = thm "diff_succ";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   528
val zero_less_diff = thm "zero_less_diff";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   529
val diff_mult_distrib = thm "diff_mult_distrib";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   530
val diff_mult_distrib2 = thm "diff_mult_distrib2";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   531
val div_termination = thm "div_termination";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   532
val raw_mod_type = thm "raw_mod_type";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   533
val mod_type = thm "mod_type";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   534
val DIVISION_BY_ZERO_DIV = thm "DIVISION_BY_ZERO_DIV";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   535
val DIVISION_BY_ZERO_MOD = thm "DIVISION_BY_ZERO_MOD";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   536
val raw_mod_less = thm "raw_mod_less";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   537
val mod_less = thm "mod_less";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   538
val raw_mod_geq = thm "raw_mod_geq";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   539
val mod_geq = thm "mod_geq";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   540
val raw_div_type = thm "raw_div_type";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   541
val div_type = thm "div_type";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   542
val raw_div_less = thm "raw_div_less";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   543
val div_less = thm "div_less";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   544
val raw_div_geq = thm "raw_div_geq";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   545
val div_geq = thm "div_geq";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   546
val mod_div_equality_natify = thm "mod_div_equality_natify";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   547
val mod_div_equality = thm "mod_div_equality";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   548
val mod_succ = thm "mod_succ";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   549
val mod_less_divisor = thm "mod_less_divisor";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   550
val mod_1_eq = thm "mod_1_eq";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   551
val mod2_cases = thm "mod2_cases";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   552
val mod2_succ_succ = thm "mod2_succ_succ";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   553
val mod2_add_more = thm "mod2_add_more";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   554
val mod2_add_self = thm "mod2_add_self";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   555
val add_le_self = thm "add_le_self";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   556
val add_le_self2 = thm "add_le_self2";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   557
val mult_le_mono1 = thm "mult_le_mono1";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   558
val mult_le_mono = thm "mult_le_mono";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   559
val mult_lt_mono2 = thm "mult_lt_mono2";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   560
val mult_lt_mono1 = thm "mult_lt_mono1";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   561
val add_eq_0_iff = thm "add_eq_0_iff";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   562
val zero_lt_mult_iff = thm "zero_lt_mult_iff";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   563
val mult_eq_1_iff = thm "mult_eq_1_iff";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   564
val mult_is_zero = thm "mult_is_zero";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   565
val mult_is_zero_natify = thm "mult_is_zero_natify";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   566
val mult_less_cancel2 = thm "mult_less_cancel2";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   567
val mult_less_cancel1 = thm "mult_less_cancel1";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   568
val mult_le_cancel2 = thm "mult_le_cancel2";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   569
val mult_le_cancel1 = thm "mult_le_cancel1";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   570
val mult_le_cancel_le1 = thm "mult_le_cancel_le1";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   571
val Ord_eq_iff_le = thm "Ord_eq_iff_le";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   572
val mult_cancel2 = thm "mult_cancel2";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   573
val mult_cancel1 = thm "mult_cancel1";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   574
val div_cancel_raw = thm "div_cancel_raw";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   575
val div_cancel = thm "div_cancel";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   576
val mult_mod_distrib_raw = thm "mult_mod_distrib_raw";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   577
val mod_mult_distrib2 = thm "mod_mult_distrib2";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   578
val mult_mod_distrib = thm "mult_mod_distrib";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   579
val mod_add_self2_raw = thm "mod_add_self2_raw";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   580
val mod_add_self2 = thm "mod_add_self2";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   581
val mod_add_self1 = thm "mod_add_self1";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   582
val mod_mult_self1_raw = thm "mod_mult_self1_raw";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   583
val mod_mult_self1 = thm "mod_mult_self1";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   584
val mod_mult_self2 = thm "mod_mult_self2";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   585
val mult_eq_self_implies_10 = thm "mult_eq_self_implies_10";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   586
val less_imp_succ_add = thm "less_imp_succ_add";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   587
val less_iff_succ_add = thm "less_iff_succ_add";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   588
val diff_is_0_iff = thm "diff_is_0_iff";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   589
val nat_lt_imp_diff_eq_0 = thm "nat_lt_imp_diff_eq_0";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   590
val nat_diff_split = thm "nat_diff_split";
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   591
*}
01fa0c8dbc92 conversion of many files to Isar format
paulson
parents: 9548
diff changeset
   592
9548
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents:
diff changeset
   593
end