src/HOL/Divides.ML
author oheimb
Tue, 04 Nov 1997 20:48:38 +0100
changeset 4133 0a08c2b9b1ed
parent 4089 96fba19bcbe2
child 4356 0dfd34f0d33d
permissions -rw-r--r--
added the, option_map, and case analysis theorems
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
     1
(*  Title:      HOL/Divides.ML
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
     2
    ID:         $Id$
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
     5
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
     6
The division operators div, mod and the divides relation "dvd"
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
     7
*)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
     8
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
     9
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    10
(** Less-then properties **)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    11
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    12
(*In ordinary notation: if 0<n and n<=m then m-n < m *)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    13
goal Arith.thy "!!m. [| 0<n; ~ m<n |] ==> m - n < m";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    14
by (subgoal_tac "0<n --> ~ m<n --> m - n < m" 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    15
by (Blast_tac 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    16
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    17
by (ALLGOALS(asm_simp_tac(simpset() addsimps [diff_less_Suc])));
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    18
qed "diff_less";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    19
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    20
val wf_less_trans = [eq_reflection, wf_pred_nat RS wf_trancl] MRS 
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    21
                    def_wfrec RS trans;
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    22
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    23
(*** Remainder ***)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    24
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    25
goal thy "(%m. m mod n) = wfrec (trancl pred_nat) \
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    26
             \                      (%f j. if j<n then j else f (j-n))";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    27
by (simp_tac (simpset() addsimps [mod_def]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    28
qed "mod_eq";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    29
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    30
goal thy "!!m. m<n ==> m mod n = m";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    31
by (rtac (mod_eq RS wf_less_trans) 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    32
by (Asm_simp_tac 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    33
qed "mod_less";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    34
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    35
goal thy "!!m. [| 0<n;  ~m<n |] ==> m mod n = (m-n) mod n";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    36
by (rtac (mod_eq RS wf_less_trans) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    37
by (asm_simp_tac (simpset() addsimps [diff_less, cut_apply, less_eq]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    38
qed "mod_geq";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    39
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    40
goal thy "m mod 1 = 0";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    41
by (induct_tac "m" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    42
by (ALLGOALS (asm_simp_tac (simpset() addsimps [mod_less, mod_geq])));
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    43
qed "mod_1";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    44
Addsimps [mod_1];
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    45
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    46
goal thy "!!n. 0<n ==> n mod n = 0";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    47
by (asm_simp_tac (simpset() addsimps [mod_less, mod_geq]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    48
qed "mod_self";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    49
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    50
goal thy "!!n. 0<n ==> (m+n) mod n = m mod n";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    51
by (subgoal_tac "(n + m) mod n = (n+m-n) mod n" 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    52
by (stac (mod_geq RS sym) 2);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    53
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [add_commute])));
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    54
qed "mod_eq_add";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    55
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    56
goal thy "!!k. [| 0<k; 0<n |] ==> (m mod n)*k = (m*k) mod (n*k)";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    57
by (res_inst_tac [("n","m")] less_induct 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    58
by (case_tac "na<n" 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    59
(*case na<n*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    60
by (asm_simp_tac (simpset() addsimps [mod_less]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    61
(*case n<=na*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    62
by (asm_simp_tac (simpset() addsimps [mod_geq, diff_less, zero_less_mult_iff, 
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    63
				     diff_mult_distrib]) 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    64
qed "mod_mult_distrib";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    65
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    66
goal thy "!!k. [| 0<k; 0<n |] ==> k*(m mod n) = (k*m) mod (k*n)";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    67
by (res_inst_tac [("n","m")] less_induct 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    68
by (case_tac "na<n" 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    69
(*case na<n*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    70
by (asm_simp_tac (simpset() addsimps [mod_less]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    71
(*case n<=na*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    72
by (asm_simp_tac (simpset() addsimps [mod_geq, diff_less, zero_less_mult_iff, 
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    73
				     diff_mult_distrib2]) 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    74
qed "mod_mult_distrib2";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    75
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    76
goal thy "!!n. 0<n ==> m*n mod n = 0";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    77
by (induct_tac "m" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    78
by (asm_simp_tac (simpset() addsimps [mod_less]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    79
by (dres_inst_tac [("m","m*n")] mod_eq_add 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    80
by (asm_full_simp_tac (simpset() addsimps [add_commute]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    81
qed "mod_mult_self_is_0";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    82
Addsimps [mod_mult_self_is_0];
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    83
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    84
(*** Quotient ***)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    85
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    86
goal thy "(%m. m div n) = wfrec (trancl pred_nat) \
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    87
                        \            (%f j. if j<n then 0 else Suc (f (j-n)))";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    88
by (simp_tac (simpset() addsimps [div_def]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    89
qed "div_eq";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    90
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    91
goal thy "!!m. m<n ==> m div n = 0";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    92
by (rtac (div_eq RS wf_less_trans) 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    93
by (Asm_simp_tac 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    94
qed "div_less";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    95
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    96
goal thy "!!M. [| 0<n;  ~m<n |] ==> m div n = Suc((m-n) div n)";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    97
by (rtac (div_eq RS wf_less_trans) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    98
by (asm_simp_tac (simpset() addsimps [diff_less, cut_apply, less_eq]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
    99
qed "div_geq";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   100
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   101
(*Main Result about quotient and remainder.*)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   102
goal thy "!!m. 0<n ==> (m div n)*n + m mod n = m";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   103
by (res_inst_tac [("n","m")] less_induct 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   104
by (rename_tac "k" 1);    (*Variable name used in line below*)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   105
by (case_tac "k<n" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   106
by (ALLGOALS (asm_simp_tac(simpset() addsimps ([add_assoc] @
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   107
                       [mod_less, mod_geq, div_less, div_geq,
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   108
                        add_diff_inverse, diff_less]))));
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   109
qed "mod_div_equality";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   110
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   111
goal thy "m div 1 = m";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   112
by (induct_tac "m" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   113
by (ALLGOALS (asm_simp_tac (simpset() addsimps [div_less, div_geq])));
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   114
qed "div_1";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   115
Addsimps [div_1];
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   116
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   117
goal thy "!!n. 0<n ==> n div n = 1";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   118
by (asm_simp_tac (simpset() addsimps [div_less, div_geq]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   119
qed "div_self";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   120
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   121
(* Monotonicity of div in first argument *)
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   122
goal thy "!!n. 0<k ==> ALL m. m <= n --> (m div k) <= (n div k)";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   123
by (res_inst_tac [("n","n")] less_induct 1);
3718
d78cf498a88c Minor tidying to use Clarify_tac, etc.
paulson
parents: 3496
diff changeset
   124
by (Clarify_tac 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   125
by (case_tac "na<k" 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   126
(* 1  case n<k *)
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   127
by (subgoal_tac "m<k" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   128
by (asm_simp_tac (simpset() addsimps [div_less]) 1);
3496
32e7edc609fd Simplified the new proofs about division
paulson
parents: 3484
diff changeset
   129
by (trans_tac 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   130
(* 2  case n >= k *)
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   131
by (case_tac "m<k" 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   132
(* 2.1  case m<k *)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   133
by (asm_simp_tac (simpset() addsimps [div_less]) 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   134
(* 2.2  case m>=k *)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   135
by (asm_simp_tac (simpset() addsimps [div_geq, diff_less, diff_le_mono]) 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   136
qed_spec_mp "div_le_mono";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   137
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   138
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   139
(* Antimonotonicity of div in second argument *)
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   140
goal thy "!!k m n. [| 0<m; m<=n |] ==> (k div n) <= (k div m)";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   141
by (subgoal_tac "0<n" 1);
3496
32e7edc609fd Simplified the new proofs about division
paulson
parents: 3484
diff changeset
   142
 by (trans_tac 2);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   143
by (res_inst_tac [("n","k")] less_induct 1);
3496
32e7edc609fd Simplified the new proofs about division
paulson
parents: 3484
diff changeset
   144
by (Simp_tac 1);
32e7edc609fd Simplified the new proofs about division
paulson
parents: 3484
diff changeset
   145
by (rename_tac "k" 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   146
by (case_tac "k<n" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   147
 by (asm_simp_tac (simpset() addsimps [div_less]) 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   148
by (subgoal_tac "~(k<m)" 1);
3496
32e7edc609fd Simplified the new proofs about division
paulson
parents: 3484
diff changeset
   149
 by (trans_tac 2);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   150
by (asm_simp_tac (simpset() addsimps [div_geq]) 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   151
by (subgoal_tac "(k-n) div n <= (k-m) div n" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   152
 by (best_tac (claset() addIs [le_trans] 
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   153
                       addss (simpset() addsimps [diff_less])) 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   154
by (REPEAT (eresolve_tac [div_le_mono,diff_le_mono2] 1));
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   155
qed "div_le_mono2";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   156
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   157
goal thy "!!m n. 0<n ==> m div n <= m";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   158
by (subgoal_tac "m div n <= m div 1" 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   159
by (Asm_full_simp_tac 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   160
by (rtac div_le_mono2 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   161
by (ALLGOALS trans_tac);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   162
qed "div_le_dividend";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   163
Addsimps [div_le_dividend];
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   164
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   165
(* Similar for "less than" *)
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   166
goal thy "!!m n. 1<n ==> (0 < m) --> (m div n < m)";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   167
by (res_inst_tac [("n","m")] less_induct 1);
3496
32e7edc609fd Simplified the new proofs about division
paulson
parents: 3484
diff changeset
   168
by (Simp_tac 1);
32e7edc609fd Simplified the new proofs about division
paulson
parents: 3484
diff changeset
   169
by (rename_tac "m" 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   170
by (case_tac "m<n" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   171
 by (asm_full_simp_tac (simpset() addsimps [div_less]) 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   172
by (subgoal_tac "0<n" 1);
3496
32e7edc609fd Simplified the new proofs about division
paulson
parents: 3484
diff changeset
   173
 by (trans_tac 2);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   174
by (asm_full_simp_tac (simpset() addsimps [div_geq]) 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   175
by (case_tac "n<m" 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   176
 by (subgoal_tac "(m-n) div n < (m-n)" 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   177
  by (REPEAT (ares_tac [impI,less_trans_Suc] 1));
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   178
  by (asm_full_simp_tac (simpset() addsimps [diff_less]) 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   179
 by (dres_inst_tac [("m","n")] less_imp_diff_positive 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   180
 by (asm_full_simp_tac (simpset() addsimps [diff_less]) 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   181
(* case n=m *)
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   182
by (subgoal_tac "m=n" 1);
3496
32e7edc609fd Simplified the new proofs about division
paulson
parents: 3484
diff changeset
   183
 by (trans_tac 2);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   184
by (asm_simp_tac (simpset() addsimps [div_less]) 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   185
qed_spec_mp "div_less_dividend";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   186
Addsimps [div_less_dividend];
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   187
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   188
(*** Further facts about mod (mainly for the mutilated chess board ***)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   189
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   190
goal thy
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   191
    "!!m n. 0<n ==> \
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   192
\           Suc(m) mod n = (if Suc(m mod n) = n then 0 else Suc(m mod n))";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   193
by (res_inst_tac [("n","m")] less_induct 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   194
by (excluded_middle_tac "Suc(na)<n" 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   195
(* case Suc(na) < n *)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   196
by (forward_tac [lessI RS less_trans] 2);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   197
by (asm_simp_tac (simpset() addsimps [mod_less, less_not_refl2 RS not_sym]) 2);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   198
(* case n <= Suc(na) *)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   199
by (asm_full_simp_tac (simpset() addsimps [not_less_iff_le, mod_geq]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   200
by (etac (le_imp_less_or_eq RS disjE) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   201
by (asm_simp_tac (simpset() addsimps [Suc_diff_n]) 1);
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   202
by (asm_full_simp_tac (simpset() addsimps [not_less_eq RS sym, 
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   203
                                          diff_less, mod_geq]) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   204
by (asm_simp_tac (simpset() addsimps [mod_less]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   205
qed "mod_Suc";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   206
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   207
goal thy "!!m n. 0<n ==> m mod n < n";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   208
by (res_inst_tac [("n","m")] less_induct 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   209
by (excluded_middle_tac "na<n" 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   210
(*case na<n*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   211
by (asm_simp_tac (simpset() addsimps [mod_less]) 2);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   212
(*case n le na*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   213
by (asm_full_simp_tac (simpset() addsimps [mod_geq, diff_less]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   214
qed "mod_less_divisor";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   215
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   216
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   217
(** Evens and Odds **)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   218
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   219
(*With less_zeroE, causes case analysis on b<2*)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   220
AddSEs [less_SucE];
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   221
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   222
goal thy "!!k b. b<2 ==> k mod 2 = b | k mod 2 = (if b=1 then 0 else 1)";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   223
by (subgoal_tac "k mod 2 < 2" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   224
by (asm_simp_tac (simpset() addsimps [mod_less_divisor]) 2);
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   225
by (asm_simp_tac (simpset() addsplits [expand_if]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   226
by (Blast_tac 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   227
qed "mod2_cases";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   228
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   229
goal thy "Suc(Suc(m)) mod 2 = m mod 2";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   230
by (subgoal_tac "m mod 2 < 2" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   231
by (asm_simp_tac (simpset() addsimps [mod_less_divisor]) 2);
3724
f33e301a89f5 Step_tac -> Safe_tac
paulson
parents: 3718
diff changeset
   232
by Safe_tac;
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   233
by (ALLGOALS (asm_simp_tac (simpset() addsimps [mod_Suc])));
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   234
qed "mod2_Suc_Suc";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   235
Addsimps [mod2_Suc_Suc];
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   236
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   237
goal thy "!!m. m mod 2 ~= 0 ==> m mod 2 = 1";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   238
by (subgoal_tac "m mod 2 < 2" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   239
by (asm_simp_tac (simpset() addsimps [mod_less_divisor]) 2);
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   240
by (safe_tac (claset() addSEs [lessE]));
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   241
by (ALLGOALS (blast_tac (claset() addIs [sym])));
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   242
qed "mod2_neq_0";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   243
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   244
goal thy "(m+m) mod 2 = 0";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   245
by (induct_tac "m" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   246
by (simp_tac (simpset() addsimps [mod_less]) 1);
3427
e7cef2081106 Removed a few redundant additions of simprules or classical rules
paulson
parents: 3366
diff changeset
   247
by (Asm_simp_tac 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   248
qed "mod2_add_self";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   249
Addsimps [mod2_add_self];
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   250
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   251
Delrules [less_SucE];
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   252
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   253
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   254
(*** More division laws ***)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   255
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   256
goal thy "!!n. 0<n ==> m*n div n = m";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   257
by (cut_inst_tac [("m", "m*n")] mod_div_equality 1);
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3427
diff changeset
   258
by (assume_tac 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   259
by (asm_full_simp_tac (simpset() addsimps [mod_mult_self_is_0]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   260
qed "div_mult_self_is_m";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   261
Addsimps [div_mult_self_is_m];
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   262
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   263
(*Cancellation law for division*)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   264
goal thy "!!k. [| 0<n; 0<k |] ==> (k*m) div (k*n) = m div n";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   265
by (res_inst_tac [("n","m")] less_induct 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   266
by (case_tac "na<n" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   267
by (asm_simp_tac (simpset() addsimps [div_less, zero_less_mult_iff, 
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   268
                                     mult_less_mono2]) 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   269
by (subgoal_tac "~ k*na < k*n" 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   270
by (asm_simp_tac
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   271
     (simpset() addsimps [zero_less_mult_iff, div_geq,
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   272
                         diff_mult_distrib2 RS sym, diff_less]) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   273
by (asm_full_simp_tac (simpset() addsimps [not_less_iff_le, 
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   274
                                          le_refl RS mult_le_mono]) 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   275
qed "div_cancel";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   276
Addsimps [div_cancel];
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   277
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   278
goal thy "!!k. [| 0<n; 0<k |] ==> (k*m) mod (k*n) = k * (m mod n)";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   279
by (res_inst_tac [("n","m")] less_induct 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   280
by (case_tac "na<n" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   281
by (asm_simp_tac (simpset() addsimps [mod_less, zero_less_mult_iff, 
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   282
                                     mult_less_mono2]) 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   283
by (subgoal_tac "~ k*na < k*n" 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   284
by (asm_simp_tac
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   285
     (simpset() addsimps [zero_less_mult_iff, mod_geq,
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   286
                         diff_mult_distrib2 RS sym, diff_less]) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   287
by (asm_full_simp_tac (simpset() addsimps [not_less_iff_le, 
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   288
                                          le_refl RS mult_le_mono]) 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   289
qed "mult_mod_distrib";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   290
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   291
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   292
(************************************************)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   293
(** Divides Relation                           **)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   294
(************************************************)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   295
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   296
goalw thy [dvd_def] "m dvd 0";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   297
by (blast_tac (claset() addIs [mult_0_right RS sym]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   298
qed "dvd_0_right";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   299
Addsimps [dvd_0_right];
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   300
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   301
goalw thy [dvd_def] "!!m. 0 dvd m ==> m = 0";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   302
by (fast_tac (claset() addss simpset()) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   303
qed "dvd_0_left";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   304
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   305
goalw thy [dvd_def] "1 dvd k";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   306
by (Simp_tac 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   307
qed "dvd_1_left";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   308
AddIffs [dvd_1_left];
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   309
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   310
goalw thy [dvd_def] "m dvd m";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   311
by (blast_tac (claset() addIs [mult_1_right RS sym]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   312
qed "dvd_refl";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   313
Addsimps [dvd_refl];
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   314
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   315
goalw thy [dvd_def] "!!m n p. [| m dvd n; n dvd p |] ==> m dvd p";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   316
by (blast_tac (claset() addIs [mult_assoc] ) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   317
qed "dvd_trans";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   318
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   319
goalw thy [dvd_def] "!!m n. [| m dvd n; n dvd m |] ==> m=n";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   320
by (fast_tac (claset() addDs [mult_eq_self_implies_10]
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   321
                     addss (simpset() addsimps [mult_assoc, mult_eq_1_iff])) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   322
qed "dvd_anti_sym";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   323
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   324
goalw thy [dvd_def] "!!k. [| k dvd m; k dvd n |] ==> k dvd (m + n)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   325
by (blast_tac (claset() addIs [add_mult_distrib2 RS sym]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   326
qed "dvd_add";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   327
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   328
goalw thy [dvd_def] "!!k. [| k dvd m; k dvd n |] ==> k dvd (m-n)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   329
by (blast_tac (claset() addIs [diff_mult_distrib2 RS sym]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   330
qed "dvd_diff";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   331
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   332
goal thy "!!k. [| k dvd (m-n); k dvd n; n<=m |] ==> k dvd m";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3427
diff changeset
   333
by (etac (not_less_iff_le RS iffD2 RS add_diff_inverse RS subst) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   334
by (blast_tac (claset() addIs [dvd_add]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   335
qed "dvd_diffD";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   336
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   337
goalw thy [dvd_def] "!!k. k dvd n ==> k dvd (m*n)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   338
by (blast_tac (claset() addIs [mult_left_commute]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   339
qed "dvd_mult";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   340
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   341
goal thy "!!k. k dvd m ==> k dvd (m*n)";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   342
by (stac mult_commute 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   343
by (etac dvd_mult 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   344
qed "dvd_mult2";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   345
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   346
(* k dvd (m*k) *)
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   347
AddIffs [dvd_refl RS dvd_mult, dvd_refl RS dvd_mult2];
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   348
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   349
goalw thy [dvd_def] "!!m. [| f dvd m; f dvd n; 0<n |] ==> f dvd (m mod n)";
3718
d78cf498a88c Minor tidying to use Clarify_tac, etc.
paulson
parents: 3496
diff changeset
   350
by (Clarify_tac 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   351
by (full_simp_tac (simpset() addsimps [zero_less_mult_iff]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   352
by (res_inst_tac 
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   353
    [("x", "(((k div ka)*ka + k mod ka) - ((f*k) div (f*ka)) * ka)")] 
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   354
    exI 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   355
by (asm_simp_tac (simpset() addsimps [diff_mult_distrib2, 
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   356
                                     mult_mod_distrib, add_mult_distrib2]) 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   357
qed "dvd_mod";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   358
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   359
goal thy "!!k. [| k dvd (m mod n); k dvd n; n~=0 |] ==> k dvd m";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   360
by (subgoal_tac "k dvd ((m div n)*n + m mod n)" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   361
by (asm_simp_tac (simpset() addsimps [dvd_add, dvd_mult]) 2);
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   362
by (asm_full_simp_tac (simpset() addsimps [mod_div_equality, zero_less_eq]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   363
qed "dvd_mod_imp_dvd";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   364
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   365
goalw thy [dvd_def]  "!!k m n. [| (k*m) dvd (k*n); 0<k |] ==> m dvd n";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   366
by (etac exE 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   367
by (asm_full_simp_tac (simpset() addsimps mult_ac) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   368
by (Blast_tac 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   369
qed "dvd_mult_cancel";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   370
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   371
goalw thy [dvd_def] "!!i j. [| i dvd m; j dvd n|] ==> (i*j) dvd (m*n)";
3718
d78cf498a88c Minor tidying to use Clarify_tac, etc.
paulson
parents: 3496
diff changeset
   372
by (Clarify_tac 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   373
by (res_inst_tac [("x","k*ka")] exI 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   374
by (asm_simp_tac (simpset() addsimps mult_ac) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   375
qed "mult_dvd_mono";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   376
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   377
goalw thy [dvd_def] "!!c. (i*j) dvd k ==> i dvd k";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   378
by (full_simp_tac (simpset() addsimps [mult_assoc]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   379
by (Blast_tac 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   380
qed "dvd_mult_left";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   381
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   382
goalw thy [dvd_def] "!!n. [| k dvd n; 0 < n |] ==> k <= n";
3718
d78cf498a88c Minor tidying to use Clarify_tac, etc.
paulson
parents: 3496
diff changeset
   383
by (Clarify_tac 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   384
by (ALLGOALS (full_simp_tac (simpset() addsimps [zero_less_mult_iff])));
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3427
diff changeset
   385
by (etac conjE 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3427
diff changeset
   386
by (rtac le_trans 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3427
diff changeset
   387
by (rtac (le_refl RS mult_le_mono) 2);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   388
by (etac Suc_leI 2);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   389
by (Simp_tac 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   390
qed "dvd_imp_le";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   391
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   392
goalw thy [dvd_def] "!!k. 0<k ==> (k dvd n) = (n mod k = 0)";
3724
f33e301a89f5 Step_tac -> Safe_tac
paulson
parents: 3718
diff changeset
   393
by Safe_tac;
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   394
by (stac mult_commute 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   395
by (Asm_simp_tac 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   396
by (eres_inst_tac [("t","n")] (mod_div_equality RS subst) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   397
by (asm_simp_tac (simpset() addsimps [mult_commute]) 1);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   398
by (Blast_tac 1);
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents:
diff changeset
   399
qed "dvd_eq_mod_eq_0";