src/HOL/Divides_lemmas.ML
author nipkow
Fri, 17 May 2002 08:53:40 +0200
changeset 13156 4597080b1947
child 13517 42efec18f5b2
permissions -rw-r--r--
Used to be Divides.ML
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13156
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/Divides.ML
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
     2
    ID:         $Id$
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
     5
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
     6
The division operators div, mod and the divides relation "dvd"
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
     7
*)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
     8
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
     9
(* ML legacy bindings *)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    10
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    11
val div_def = thm "div_def";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    12
val mod_def = thm "mod_def";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    13
val dvd_def = thm "dvd_def";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    14
val quorem_def = thm "quorem_def";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    15
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    16
structure Divides =
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    17
struct
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    18
 val div_def = div_def
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    19
 val mod_def = mod_def
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    20
 val dvd_def = dvd_def
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    21
 val quorem_def = quorem_def
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    22
end;
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    23
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    24
(** Less-then properties **)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    25
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    26
bind_thm ("wf_less_trans", [eq_reflection, wf_pred_nat RS wf_trancl] MRS 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    27
                    def_wfrec RS trans);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    28
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    29
Goal "(%m. m mod n) = wfrec (trancl pred_nat) \
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    30
\                           (%f j. if j<n | n=0 then j else f (j-n))";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    31
by (simp_tac (simpset() addsimps [mod_def]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    32
qed "mod_eq";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    33
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    34
Goal "(%m. m div n) = wfrec (trancl pred_nat) \
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    35
\            (%f j. if j<n | n=0 then 0 else Suc (f (j-n)))";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    36
by (simp_tac (simpset() addsimps [div_def]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    37
qed "div_eq";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    38
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    39
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    40
(** Aribtrary definitions for division by zero.  Useful to simplify 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    41
    certain equations **)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    42
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    43
Goal "a div 0 = (0::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    44
by (rtac (div_eq RS wf_less_trans) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    45
by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    46
qed "DIVISION_BY_ZERO_DIV";  (*NOT for adding to default simpset*)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    47
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    48
Goal "a mod 0 = (a::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    49
by (rtac (mod_eq RS wf_less_trans) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    50
by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    51
qed "DIVISION_BY_ZERO_MOD";  (*NOT for adding to default simpset*)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    52
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    53
fun div_undefined_case_tac s i =
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    54
  case_tac s i THEN 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    55
  Full_simp_tac (i+1) THEN
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    56
  asm_simp_tac (simpset() addsimps [DIVISION_BY_ZERO_DIV, 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    57
				    DIVISION_BY_ZERO_MOD]) i;
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    58
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    59
(*** Remainder ***)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    60
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    61
Goal "m<n ==> m mod n = (m::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    62
by (rtac (mod_eq RS wf_less_trans) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    63
by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    64
qed "mod_less";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    65
Addsimps [mod_less];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    66
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    67
Goal "~ m < (n::nat) ==> m mod n = (m-n) mod n";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    68
by (div_undefined_case_tac "n=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    69
by (rtac (mod_eq RS wf_less_trans) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    70
by (asm_simp_tac (simpset() addsimps [diff_less, cut_apply, less_eq]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    71
qed "mod_geq";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    72
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    73
(*Avoids the ugly ~m<n above*)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    74
Goal "(n::nat) <= m ==> m mod n = (m-n) mod n";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    75
by (asm_simp_tac (simpset() addsimps [mod_geq, not_less_iff_le]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    76
qed "le_mod_geq";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    77
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    78
Goal "m mod (n::nat) = (if m<n then m else (m-n) mod n)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    79
by (asm_simp_tac (simpset() addsimps [mod_geq]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    80
qed "mod_if";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    81
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    82
Goal "m mod Suc 0 = 0";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    83
by (induct_tac "m" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    84
by (ALLGOALS (asm_simp_tac (simpset() addsimps [mod_geq])));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    85
qed "mod_1";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    86
Addsimps [mod_1];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    87
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    88
Goal "n mod n = (0::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    89
by (div_undefined_case_tac "n=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    90
by (asm_simp_tac (simpset() addsimps [mod_geq]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    91
qed "mod_self";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    92
Addsimps [mod_self];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    93
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    94
Goal "(m+n) mod n = m mod (n::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    95
by (subgoal_tac "(n + m) mod n = (n+m-n) mod n" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    96
by (stac (mod_geq RS sym) 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    97
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [add_commute])));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    98
qed "mod_add_self2";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
    99
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   100
Goal "(n+m) mod n = m mod (n::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   101
by (asm_simp_tac (simpset() addsimps [add_commute, mod_add_self2]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   102
qed "mod_add_self1";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   103
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   104
Addsimps [mod_add_self1, mod_add_self2];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   105
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   106
Goal "(m + k*n) mod n = m mod (n::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   107
by (induct_tac "k" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   108
by (ALLGOALS
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   109
    (asm_simp_tac 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   110
     (simpset() addsimps [read_instantiate [("y","n")] add_left_commute])));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   111
qed "mod_mult_self1";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   112
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   113
Goal "(m + n*k) mod n = m mod (n::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   114
by (asm_simp_tac (simpset() addsimps [mult_commute, mod_mult_self1]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   115
qed "mod_mult_self2";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   116
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   117
Addsimps [mod_mult_self1, mod_mult_self2];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   118
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   119
Goal "(m mod n) * (k::nat) = (m*k) mod (n*k)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   120
by (div_undefined_case_tac "n=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   121
by (div_undefined_case_tac "k=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   122
by (induct_thm_tac nat_less_induct "m" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   123
by (stac mod_if 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   124
by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   125
by (asm_simp_tac (simpset() addsimps [mod_geq, 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   126
				      diff_less, diff_mult_distrib]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   127
qed "mod_mult_distrib";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   128
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   129
Goal "(k::nat) * (m mod n) = (k*m) mod (k*n)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   130
by (asm_simp_tac 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   131
    (simpset() addsimps [read_instantiate [("m","k")] mult_commute, 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   132
			 mod_mult_distrib]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   133
qed "mod_mult_distrib2";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   134
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   135
Goal "(m*n) mod n = (0::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   136
by (div_undefined_case_tac "n=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   137
by (induct_tac "m" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   138
by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   139
by (rename_tac "k" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   140
by (cut_inst_tac [("m","k*n"),("n","n")] mod_add_self2 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   141
by (asm_full_simp_tac (simpset() addsimps [add_commute]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   142
qed "mod_mult_self_is_0";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   143
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   144
Goal "(n*m) mod n = (0::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   145
by (simp_tac (simpset() addsimps [mult_commute, mod_mult_self_is_0]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   146
qed "mod_mult_self1_is_0";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   147
Addsimps [mod_mult_self_is_0, mod_mult_self1_is_0];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   148
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   149
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   150
(*** Quotient ***)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   151
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   152
Goal "m<n ==> m div n = (0::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   153
by (rtac (div_eq RS wf_less_trans) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   154
by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   155
qed "div_less";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   156
Addsimps [div_less];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   157
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   158
Goal "[| 0<n;  ~m<n |] ==> m div n = Suc((m-n) div n)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   159
by (rtac (div_eq RS wf_less_trans) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   160
by (asm_simp_tac (simpset() addsimps [diff_less, cut_apply, less_eq]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   161
qed "div_geq";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   162
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   163
(*Avoids the ugly ~m<n above*)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   164
Goal "[| 0<n;  n<=m |] ==> m div n = Suc((m-n) div n)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   165
by (asm_simp_tac (simpset() addsimps [div_geq, not_less_iff_le]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   166
qed "le_div_geq";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   167
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   168
Goal "0<n ==> m div n = (if m<n then 0 else Suc((m-n) div n))";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   169
by (asm_simp_tac (simpset() addsimps [div_geq]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   170
qed "div_if";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   171
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   172
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   173
(*Main Result about quotient and remainder.*)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   174
Goal "(m div n)*n + m mod n = (m::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   175
by (div_undefined_case_tac "n=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   176
by (induct_thm_tac nat_less_induct "m" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   177
by (stac mod_if 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   178
by (ALLGOALS (asm_simp_tac 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   179
	      (simpset() addsimps [add_assoc, div_geq,
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   180
				   add_diff_inverse, diff_less])));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   181
qed "mod_div_equality";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   182
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   183
(* a simple rearrangement of mod_div_equality: *)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   184
Goal "(n::nat) * (m div n) = m - (m mod n)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   185
by (cut_inst_tac [("m","m"),("n","n")] mod_div_equality 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   186
by (full_simp_tac (simpset() addsimps mult_ac) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   187
by (arith_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   188
qed "mult_div_cancel";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   189
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   190
Goal "0<n ==> m mod n < (n::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   191
by (induct_thm_tac nat_less_induct "m" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   192
by (case_tac "na<n" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   193
(*case n le na*)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   194
by (asm_full_simp_tac (simpset() addsimps [mod_geq, diff_less]) 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   195
(*case na<n*)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   196
by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   197
qed "mod_less_divisor";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   198
Addsimps [mod_less_divisor];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   199
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   200
(*** More division laws ***)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   201
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   202
Goal "0<n ==> (m*n) div n = (m::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   203
by (cut_inst_tac [("m", "m*n"),("n","n")] mod_div_equality 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   204
by Auto_tac;
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   205
qed "div_mult_self_is_m";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   206
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   207
Goal "0<n ==> (n*m) div n = (m::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   208
by (asm_simp_tac (simpset() addsimps [mult_commute, div_mult_self_is_m]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   209
qed "div_mult_self1_is_m";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   210
Addsimps [div_mult_self_is_m, div_mult_self1_is_m];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   211
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   212
(*mod_mult_distrib2 above is the counterpart for remainder*)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   213
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   214
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   215
(*** Proving facts about div and mod using quorem ***)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   216
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   217
Goal "[| b*q' + r'  <= b*q + r;  0 < b;  r < b |] \
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   218
\     ==> q' <= (q::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   219
by (rtac leI 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   220
by (stac less_iff_Suc_add 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   221
by (auto_tac (claset(), simpset() addsimps [add_mult_distrib2]));   
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   222
qed "unique_quotient_lemma";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   223
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   224
Goal "[| quorem ((a,b), (q,r));  quorem ((a,b), (q',r'));  0 < b |] \
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   225
\     ==> q = q'";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   226
by (asm_full_simp_tac 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   227
    (simpset() addsimps split_ifs @ [Divides.quorem_def]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   228
by Auto_tac;  
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   229
by (REPEAT 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   230
    (blast_tac (claset() addIs [order_antisym]
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   231
			 addDs [order_eq_refl RS unique_quotient_lemma, 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   232
				sym]) 1));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   233
qed "unique_quotient";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   234
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   235
Goal "[| quorem ((a,b), (q,r));  quorem ((a,b), (q',r'));  0 < b |] \
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   236
\     ==> r = r'";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   237
by (subgoal_tac "q = q'" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   238
by (blast_tac (claset() addIs [unique_quotient]) 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   239
by (asm_full_simp_tac (simpset() addsimps [Divides.quorem_def]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   240
qed "unique_remainder";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   241
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   242
Goal "0 < b ==> quorem ((a, b), (a div b, a mod b))";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   243
by (cut_inst_tac [("m","a"),("n","b")] mod_div_equality 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   244
by (auto_tac
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   245
    (claset() addEs [sym],
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   246
     simpset() addsimps mult_ac@[Divides.quorem_def]));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   247
qed "quorem_div_mod";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   248
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   249
Goal "[| quorem((a,b),(q,r));  0 < b |] ==> a div b = q";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   250
by (asm_simp_tac (simpset() addsimps [quorem_div_mod RS unique_quotient]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   251
qed "quorem_div";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   252
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   253
Goal "[| quorem((a,b),(q,r));  0 < b |] ==> a mod b = r";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   254
by (asm_simp_tac (simpset() addsimps [quorem_div_mod RS unique_remainder]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   255
qed "quorem_mod";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   256
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   257
(** A dividend of zero **)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   258
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   259
Goal "0 div m = (0::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   260
by (div_undefined_case_tac "m=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   261
by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   262
qed "div_0"; 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   263
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   264
Goal "0 mod m = (0::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   265
by (div_undefined_case_tac "m=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   266
by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   267
qed "mod_0"; 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   268
Addsimps [div_0, mod_0];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   269
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   270
(** proving (a*b) div c = a * (b div c) + a * (b mod c) **)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   271
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   272
Goal "[| quorem((b,c),(q,r));  0 < c |] \
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   273
\     ==> quorem ((a*b, c), (a*q + a*r div c, a*r mod c))";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   274
by (cut_inst_tac [("m", "a*r"), ("n","c")] mod_div_equality 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   275
by (auto_tac
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   276
    (claset(),
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   277
     simpset() addsimps split_ifs@mult_ac@
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   278
                        [Divides.quorem_def, add_mult_distrib2]));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   279
val lemma = result();
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   280
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   281
Goal "(a*b) div c = a*(b div c) + a*(b mod c) div (c::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   282
by (div_undefined_case_tac "c = 0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   283
by (blast_tac (claset() addIs [quorem_div_mod RS lemma RS quorem_div]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   284
qed "div_mult1_eq";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   285
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   286
Goal "(a*b) mod c = a*(b mod c) mod (c::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   287
by (div_undefined_case_tac "c = 0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   288
by (blast_tac (claset() addIs [quorem_div_mod RS lemma RS quorem_mod]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   289
qed "mod_mult1_eq";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   290
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   291
Goal "(a*b) mod (c::nat) = ((a mod c) * b) mod c";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   292
by (rtac trans 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   293
by (res_inst_tac [("s","b*a mod c")] trans 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   294
by (rtac mod_mult1_eq 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   295
by (ALLGOALS (simp_tac (simpset() addsimps [mult_commute])));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   296
qed "mod_mult1_eq'";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   297
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   298
Goal "(a*b) mod (c::nat) = ((a mod c) * (b mod c)) mod c";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   299
by (rtac (mod_mult1_eq' RS trans) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   300
by (rtac mod_mult1_eq 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   301
qed "mod_mult_distrib_mod";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   302
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   303
(** proving (a+b) div c = a div c + b div c + ((a mod c + b mod c) div c) **)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   304
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   305
Goal "[| quorem((a,c),(aq,ar));  quorem((b,c),(bq,br));  0 < c |] \
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   306
\     ==> quorem ((a+b, c), (aq + bq + (ar+br) div c, (ar+br) mod c))";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   307
by (cut_inst_tac [("m", "ar+br"), ("n","c")] mod_div_equality 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   308
by (auto_tac
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   309
    (claset(),
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   310
     simpset() addsimps split_ifs@mult_ac@
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   311
                        [Divides.quorem_def, add_mult_distrib2]));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   312
val lemma = result();
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   313
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   314
(*NOT suitable for rewriting: the RHS has an instance of the LHS*)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   315
Goal "(a+b) div (c::nat) = a div c + b div c + ((a mod c + b mod c) div c)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   316
by (div_undefined_case_tac "c = 0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   317
by (blast_tac (claset() addIs [[quorem_div_mod,quorem_div_mod]
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   318
			       MRS lemma RS quorem_div]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   319
qed "div_add1_eq";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   320
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   321
Goal "(a+b) mod (c::nat) = (a mod c + b mod c) mod c";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   322
by (div_undefined_case_tac "c = 0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   323
by (blast_tac (claset() addIs [[quorem_div_mod,quorem_div_mod]
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   324
			       MRS lemma RS quorem_mod]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   325
qed "mod_add1_eq";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   326
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   327
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   328
(*** proving  a div (b*c) = (a div b) div c ***)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   329
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   330
(** first, a lemma to bound the remainder **)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   331
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   332
Goal "[| (0::nat) < c; r < b |] ==> b * (q mod c) + r < b * c";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   333
by (cut_inst_tac [("m","q"),("n","c")] mod_less_divisor 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   334
by (dres_inst_tac [("m","q mod c")] less_imp_Suc_add 2); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   335
by Auto_tac;  
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   336
by (eres_inst_tac [("P","%x. ?lhs < ?rhs x")] ssubst 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   337
by (asm_simp_tac (simpset() addsimps [add_mult_distrib2]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   338
val mod_lemma = result();
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   339
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   340
Goal "[| quorem ((a,b), (q,r));  0 < b;  0 < c |] \
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   341
\     ==> quorem ((a, b*c), (q div c, b*(q mod c) + r))";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   342
by (cut_inst_tac [("m", "q"), ("n","c")] mod_div_equality 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   343
by (auto_tac  
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   344
    (claset(),
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   345
     simpset() addsimps mult_ac@
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   346
                        [Divides.quorem_def, add_mult_distrib2 RS sym,
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   347
			 mod_lemma]));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   348
val lemma = result();
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   349
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   350
Goal "a div (b*c) = (a div b) div (c::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   351
by (div_undefined_case_tac "b=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   352
by (div_undefined_case_tac "c=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   353
by (force_tac (claset(),
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   354
	       simpset() addsimps [quorem_div_mod RS lemma RS quorem_div]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   355
qed "div_mult2_eq";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   356
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   357
Goal "a mod (b*c) = b*(a div b mod c) + a mod (b::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   358
by (div_undefined_case_tac "b=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   359
by (div_undefined_case_tac "c=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   360
by (cut_inst_tac [("m", "a"), ("n","b")] mod_div_equality 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   361
by (auto_tac (claset(),
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   362
	       simpset() addsimps [mult_commute, 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   363
				   quorem_div_mod RS lemma RS quorem_mod]));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   364
qed "mod_mult2_eq";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   365
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   366
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   367
(*** Cancellation of common factors in "div" ***)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   368
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   369
Goal "[| (0::nat) < b;  0 < c |] ==> (c*a) div (c*b) = a div b";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   370
by (stac div_mult2_eq 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   371
by Auto_tac;
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   372
val lemma1 = result();
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   373
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   374
Goal "(0::nat) < c ==> (c*a) div (c*b) = a div b";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   375
by (div_undefined_case_tac "b = 0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   376
by (auto_tac
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   377
    (claset(), 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   378
     simpset() addsimps [read_instantiate [("x", "b")] linorder_neq_iff, 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   379
			 lemma1, lemma2]));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   380
qed "div_mult_mult1";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   381
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   382
Goal "(0::nat) < c ==> (a*c) div (b*c) = a div b";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   383
by (dtac div_mult_mult1 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   384
by (auto_tac (claset(), simpset() addsimps [mult_commute]));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   385
qed "div_mult_mult2";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   386
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   387
Addsimps [div_mult_mult1, div_mult_mult2];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   388
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   389
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   390
(*** Distribution of factors over "mod"
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   391
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   392
Could prove these as in Integ/IntDiv.ML, but we already have
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   393
mod_mult_distrib and mod_mult_distrib2 above!
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   394
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   395
Goal "(c*a) mod (c*b) = (c::nat) * (a mod b)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   396
qed "mod_mult_mult1";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   397
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   398
Goal "(a*c) mod (b*c) = (a mod b) * (c::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   399
qed "mod_mult_mult2";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   400
 ***)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   401
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   402
(*** Further facts about div and mod ***)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   403
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   404
Goal "m div Suc 0 = m";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   405
by (induct_tac "m" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   406
by (ALLGOALS (asm_simp_tac (simpset() addsimps [div_geq])));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   407
qed "div_1";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   408
Addsimps [div_1];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   409
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   410
Goal "0<n ==> n div n = (1::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   411
by (asm_simp_tac (simpset() addsimps [div_geq]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   412
qed "div_self";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   413
Addsimps [div_self];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   414
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   415
Goal "0<n ==> (m+n) div n = Suc (m div n)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   416
by (subgoal_tac "(n + m) div n = Suc ((n+m-n) div n)" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   417
by (stac (div_geq RS sym) 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   418
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [add_commute])));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   419
qed "div_add_self2";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   420
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   421
Goal "0<n ==> (n+m) div n = Suc (m div n)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   422
by (asm_simp_tac (simpset() addsimps [add_commute, div_add_self2]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   423
qed "div_add_self1";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   424
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   425
Goal "!!n::nat. 0<n ==> (m + k*n) div n = k + m div n";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   426
by (stac div_add1_eq 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   427
by (stac div_mult1_eq 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   428
by (Asm_simp_tac 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   429
qed "div_mult_self1";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   430
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   431
Goal "0<n ==> (m + n*k) div n = k + m div (n::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   432
by (asm_simp_tac (simpset() addsimps [mult_commute, div_mult_self1]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   433
qed "div_mult_self2";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   434
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   435
Addsimps [div_mult_self1, div_mult_self2];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   436
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   437
(* Monotonicity of div in first argument *)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   438
Goal "ALL m::nat. m <= n --> (m div k) <= (n div k)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   439
by (div_undefined_case_tac "k=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   440
by (induct_thm_tac nat_less_induct "n" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   441
by (Clarify_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   442
by (case_tac "n<k" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   443
(* 1  case n<k *)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   444
by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   445
(* 2  case n >= k *)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   446
by (case_tac "m<k" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   447
(* 2.1  case m<k *)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   448
by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   449
(* 2.2  case m>=k *)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   450
by (asm_simp_tac (simpset() addsimps [div_geq, diff_less, diff_le_mono]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   451
qed_spec_mp "div_le_mono";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   452
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   453
(* Antimonotonicity of div in second argument *)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   454
Goal "!!m::nat. [| 0<m; m<=n |] ==> (k div n) <= (k div m)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   455
by (subgoal_tac "0<n" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   456
 by (Asm_simp_tac 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   457
by (induct_thm_tac nat_less_induct "k" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   458
by (rename_tac "k" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   459
by (case_tac "k<n" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   460
 by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   461
by (subgoal_tac "~(k<m)" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   462
 by (Asm_simp_tac 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   463
by (asm_simp_tac (simpset() addsimps [div_geq]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   464
by (subgoal_tac "(k-n) div n <= (k-m) div n" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   465
 by (REPEAT (ares_tac [div_le_mono,diff_le_mono2] 2));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   466
by (rtac le_trans 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   467
by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   468
by (asm_simp_tac (simpset() addsimps [diff_less]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   469
qed "div_le_mono2";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   470
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   471
Goal "m div n <= (m::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   472
by (div_undefined_case_tac "n=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   473
by (subgoal_tac "m div n <= m div 1" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   474
by (Asm_full_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   475
by (rtac div_le_mono2 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   476
by (ALLGOALS Asm_simp_tac);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   477
qed "div_le_dividend";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   478
Addsimps [div_le_dividend];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   479
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   480
(* Similar for "less than" *)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   481
Goal "!!n::nat. 1<n ==> (0 < m) --> (m div n < m)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   482
by (induct_thm_tac nat_less_induct "m" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   483
by (rename_tac "m" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   484
by (case_tac "m<n" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   485
 by (Asm_full_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   486
by (subgoal_tac "0<n" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   487
 by (Asm_simp_tac 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   488
by (asm_full_simp_tac (simpset() addsimps [div_geq]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   489
by (case_tac "n<m" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   490
 by (subgoal_tac "(m-n) div n < (m-n)" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   491
  by (REPEAT (ares_tac [impI,less_trans_Suc] 1));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   492
  by (asm_full_simp_tac (simpset() addsimps [diff_less]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   493
 by (asm_full_simp_tac (simpset() addsimps [diff_less]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   494
(* case n=m *)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   495
by (subgoal_tac "m=n" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   496
 by (Asm_simp_tac 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   497
by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   498
qed_spec_mp "div_less_dividend";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   499
Addsimps [div_less_dividend];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   500
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   501
(*** Further facts about mod (mainly for the mutilated chess board ***)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   502
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   503
Goal "Suc(m) mod n = (if Suc(m mod n) = n then 0 else Suc(m mod n))";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   504
by (div_undefined_case_tac "n=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   505
by (induct_thm_tac nat_less_induct "m" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   506
by (case_tac "Suc(na)<n" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   507
(* case Suc(na) < n *)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   508
by (forward_tac [lessI RS less_trans] 1 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   509
    THEN asm_simp_tac (simpset() addsimps [less_not_refl3]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   510
(* case n <= Suc(na) *)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   511
by (asm_full_simp_tac (simpset() addsimps [not_less_iff_le, le_Suc_eq, 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   512
					   mod_geq]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   513
by (auto_tac (claset(), 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   514
	      simpset() addsimps [Suc_diff_le, diff_less, le_mod_geq]));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   515
qed "mod_Suc";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   516
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   517
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   518
(************************************************)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   519
(** Divides Relation                           **)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   520
(************************************************)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   521
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   522
Goalw [dvd_def] "n = m * k ==> m dvd n";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   523
by (Blast_tac 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   524
qed "dvdI";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   525
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   526
Goalw [dvd_def] "!!P. [|m dvd n;  !!k. n = m*k ==> P|] ==> P";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   527
by (Blast_tac 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   528
qed "dvdE";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   529
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   530
Goalw [dvd_def] "m dvd (0::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   531
by (blast_tac (claset() addIs [mult_0_right RS sym]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   532
qed "dvd_0_right";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   533
AddIffs [dvd_0_right];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   534
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   535
Goalw [dvd_def] "0 dvd m ==> m = (0::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   536
by Auto_tac;
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   537
qed "dvd_0_left";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   538
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   539
Goal "(0 dvd (m::nat)) = (m = 0)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   540
by (blast_tac (claset() addIs [dvd_0_left]) 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   541
qed "dvd_0_left_iff";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   542
AddIffs [dvd_0_left_iff];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   543
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   544
Goalw [dvd_def] "Suc 0 dvd k";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   545
by (Simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   546
qed "dvd_1_left";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   547
AddIffs [dvd_1_left];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   548
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   549
Goal "(m dvd Suc 0) = (m = Suc 0)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   550
by (simp_tac (simpset() addsimps [dvd_def]) 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   551
qed "dvd_1_iff_1";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   552
Addsimps [dvd_1_iff_1];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   553
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   554
Goalw [dvd_def] "m dvd (m::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   555
by (blast_tac (claset() addIs [mult_1_right RS sym]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   556
qed "dvd_refl";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   557
Addsimps [dvd_refl];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   558
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   559
Goalw [dvd_def] "[| m dvd n; n dvd p |] ==> m dvd (p::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   560
by (blast_tac (claset() addIs [mult_assoc] ) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   561
qed "dvd_trans";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   562
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   563
Goalw [dvd_def] "[| m dvd n; n dvd m |] ==> m = (n::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   564
by (force_tac (claset() addDs [mult_eq_self_implies_10],
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   565
	       simpset() addsimps [mult_assoc, mult_eq_1_iff]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   566
qed "dvd_anti_sym";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   567
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   568
Goalw [dvd_def] "[| k dvd m; k dvd n |] ==> k dvd (m+n :: nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   569
by (blast_tac (claset() addIs [add_mult_distrib2 RS sym]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   570
qed "dvd_add";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   571
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   572
Goalw [dvd_def] "[| k dvd m; k dvd n |] ==> k dvd (m-n :: nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   573
by (blast_tac (claset() addIs [diff_mult_distrib2 RS sym]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   574
qed "dvd_diff";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   575
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   576
Goal "[| k dvd m-n; k dvd n; n<=m |] ==> k dvd (m::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   577
by (etac (not_less_iff_le RS iffD2 RS add_diff_inverse RS subst) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   578
by (blast_tac (claset() addIs [dvd_add]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   579
qed "dvd_diffD";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   580
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   581
Goal "[| k dvd m-n; k dvd m; n<=m |] ==> k dvd (n::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   582
by (dres_inst_tac [("m","m")] dvd_diff 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   583
by Auto_tac;  
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   584
qed "dvd_diffD1";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   585
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   586
Goalw [dvd_def] "k dvd n ==> k dvd (m*n :: nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   587
by (blast_tac (claset() addIs [mult_left_commute]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   588
qed "dvd_mult";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   589
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   590
Goal "k dvd m ==> k dvd (m*n :: nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   591
by (stac mult_commute 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   592
by (etac dvd_mult 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   593
qed "dvd_mult2";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   594
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   595
(* k dvd (m*k) *)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   596
AddIffs [dvd_refl RS dvd_mult, dvd_refl RS dvd_mult2];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   597
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   598
Goal "(k dvd n + k) = (k dvd (n::nat))";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   599
by (rtac iffI 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   600
by (etac dvd_add 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   601
by (rtac dvd_refl 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   602
by (subgoal_tac "n = (n+k)-k" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   603
by  (Simp_tac 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   604
by (etac ssubst 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   605
by (etac dvd_diff 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   606
by (rtac dvd_refl 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   607
qed "dvd_reduce";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   608
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   609
Goalw [dvd_def] "!!n::nat. [| f dvd m; f dvd n |] ==> f dvd m mod n";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   610
by (div_undefined_case_tac "n=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   611
by Auto_tac; 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   612
by (blast_tac (claset() addIs [mod_mult_distrib2 RS sym]) 1);  
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   613
qed "dvd_mod";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   614
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   615
Goal "[| (k::nat) dvd m mod n;  k dvd n |] ==> k dvd m";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   616
by (subgoal_tac "k dvd (m div n)*n + m mod n" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   617
by (asm_simp_tac (simpset() addsimps [dvd_add, dvd_mult]) 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   618
by (asm_full_simp_tac (simpset() addsimps [mod_div_equality]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   619
qed "dvd_mod_imp_dvd";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   620
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   621
Goal "k dvd n ==> ((k::nat) dvd m mod n) = (k dvd m)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   622
by (blast_tac (claset() addIs [dvd_mod_imp_dvd, dvd_mod]) 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   623
qed "dvd_mod_iff";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   624
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   625
Goalw [dvd_def]  "!!k::nat. [| k*m dvd k*n; 0<k |] ==> m dvd n";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   626
by (etac exE 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   627
by (asm_full_simp_tac (simpset() addsimps mult_ac) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   628
qed "dvd_mult_cancel";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   629
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   630
Goal "0<m ==> (m*n dvd m) = (n = (1::nat))";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   631
by Auto_tac;  
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   632
by (subgoal_tac "m*n dvd m*1" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   633
by (dtac dvd_mult_cancel 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   634
by Auto_tac;  
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   635
qed "dvd_mult_cancel1";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   636
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   637
Goal "0<m ==> (n*m dvd m) = (n = (1::nat))";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   638
by (stac mult_commute 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   639
by (etac dvd_mult_cancel1 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   640
qed "dvd_mult_cancel2";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   641
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   642
Goalw [dvd_def] "[| i dvd m; j dvd n|] ==> i*j dvd (m*n :: nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   643
by (Clarify_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   644
by (res_inst_tac [("x","k*ka")] exI 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   645
by (asm_simp_tac (simpset() addsimps mult_ac) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   646
qed "mult_dvd_mono";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   647
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   648
Goalw [dvd_def] "(i*j :: nat) dvd k ==> i dvd k";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   649
by (full_simp_tac (simpset() addsimps [mult_assoc]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   650
by (Blast_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   651
qed "dvd_mult_left";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   652
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   653
Goalw [dvd_def] "(i*j :: nat) dvd k ==> j dvd k";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   654
by (Clarify_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   655
by (res_inst_tac [("x","i*k")] exI 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   656
by (simp_tac (simpset() addsimps mult_ac) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   657
qed "dvd_mult_right";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   658
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   659
Goalw [dvd_def] "[| k dvd n; 0 < n |] ==> k <= (n::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   660
by (Clarify_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   661
by (ALLGOALS (full_simp_tac (simpset() addsimps [zero_less_mult_iff])));
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   662
by (etac conjE 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   663
by (rtac le_trans 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   664
by (rtac (le_refl RS mult_le_mono) 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   665
by (etac Suc_leI 2);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   666
by (Simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   667
qed "dvd_imp_le";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   668
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   669
Goalw [dvd_def] "!!k::nat. (k dvd n) = (n mod k = 0)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   670
by (div_undefined_case_tac "k=0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   671
by Safe_tac;
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   672
by (asm_simp_tac (simpset() addsimps [mult_commute]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   673
by (res_inst_tac [("t","n"),("n1","k")] (mod_div_equality RS subst) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   674
by (stac mult_commute 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   675
by (Asm_simp_tac 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   676
qed "dvd_eq_mod_eq_0";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   677
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   678
Goal "n dvd m ==> n * (m div n) = (m::nat)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   679
by (subgoal_tac "m mod n = 0" 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   680
 by (asm_full_simp_tac (simpset() addsimps [mult_div_cancel]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   681
by (asm_full_simp_tac (HOL_basic_ss addsimps [dvd_eq_mod_eq_0]) 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   682
qed "dvd_mult_div_cancel";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   683
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   684
Goal "(m mod d = 0) = (EX q::nat. m = d*q)";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   685
by (auto_tac (claset(), 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   686
     simpset() addsimps [dvd_eq_mod_eq_0 RS sym, dvd_def]));  
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   687
qed "mod_eq_0_iff";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   688
AddSDs [mod_eq_0_iff RS iffD1];
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   689
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   690
(*Loses information, namely we also have r<d provided d is nonzero*)
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   691
Goal "(m mod d = r) ==> EX q::nat. m = r + q*d";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   692
by (cut_inst_tac [("m","m")] mod_div_equality 1);
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   693
by (full_simp_tac (simpset() addsimps add_ac) 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   694
by (blast_tac (claset() addIs [sym]) 1); 
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   695
qed "mod_eqD";
4597080b1947 Used to be Divides.ML
nipkow
parents:
diff changeset
   696