src/HOL/NatDef.ML
author oheimb
Wed Jan 31 10:15:55 2001 +0100 (2001-01-31)
changeset 11008 f7333f055ef6
parent 10850 e1a793957a8f
child 11135 8fd0dea26286
permissions -rw-r--r--
improved theory reference in comment
nipkow@2608
     1
(*  Title:      HOL/NatDef.ML
nipkow@2608
     2
    ID:         $Id$
nipkow@2608
     3
    Author:     Tobias Nipkow, Cambridge University Computer Laboratory
nipkow@2608
     4
    Copyright   1991  University of Cambridge
nipkow@2608
     5
*)
nipkow@2608
     6
nipkow@10832
     7
Goal "mono(%X. {Zero_Rep} Un Suc_Rep`X)";
nipkow@2608
     8
by (REPEAT (ares_tac [monoI, subset_refl, image_mono, Un_mono] 1));
nipkow@2608
     9
qed "Nat_fun_mono";
nipkow@2608
    10
nipkow@10186
    11
bind_thm ("Nat_unfold", Nat_fun_mono RS (Nat_def RS def_lfp_unfold));
nipkow@2608
    12
nipkow@2608
    13
(* Zero is a natural number -- this also justifies the type definition*)
wenzelm@5069
    14
Goal "Zero_Rep: Nat";
nipkow@2608
    15
by (stac Nat_unfold 1);
nipkow@2608
    16
by (rtac (singletonI RS UnI1) 1);
nipkow@2608
    17
qed "Zero_RepI";
nipkow@2608
    18
paulson@5316
    19
Goal "i: Nat ==> Suc_Rep(i) : Nat";
nipkow@2608
    20
by (stac Nat_unfold 1);
nipkow@2608
    21
by (rtac (imageI RS UnI2) 1);
paulson@5316
    22
by (assume_tac 1);
nipkow@2608
    23
qed "Suc_RepI";
nipkow@2608
    24
nipkow@2608
    25
(*** Induction ***)
nipkow@2608
    26
paulson@5316
    27
val major::prems = Goal
nipkow@2608
    28
    "[| i: Nat;  P(Zero_Rep);   \
nipkow@2608
    29
\       !!j. [| j: Nat; P(j) |] ==> P(Suc_Rep(j)) |]  ==> P(i)";
nipkow@10202
    30
by (rtac ([Nat_def, Nat_fun_mono, major] MRS def_lfp_induct) 1);
wenzelm@4089
    31
by (blast_tac (claset() addIs prems) 1);
nipkow@2608
    32
qed "Nat_induct";
nipkow@2608
    33
paulson@5316
    34
val prems = Goalw [Zero_def,Suc_def]
nipkow@2608
    35
    "[| P(0);   \
nipkow@3040
    36
\       !!n. P(n) ==> P(Suc(n)) |]  ==> P(n)";
nipkow@2608
    37
by (rtac (Rep_Nat_inverse RS subst) 1);   (*types force good instantiation*)
nipkow@2608
    38
by (rtac (Rep_Nat RS Nat_induct) 1);
nipkow@2608
    39
by (REPEAT (ares_tac prems 1
nipkow@2608
    40
     ORELSE eresolve_tac [Abs_Nat_inverse RS subst] 1));
nipkow@2608
    41
qed "nat_induct";
nipkow@2608
    42
nipkow@2608
    43
(*Perform induction on n. *)
berghofe@5187
    44
fun nat_ind_tac a i = 
berghofe@5187
    45
  res_inst_tac [("n",a)] nat_induct i  THEN  rename_last_tac a [""] (i+1);
nipkow@3040
    46
nipkow@2608
    47
(*A special form of induction for reasoning about m<n and m-n*)
paulson@5316
    48
val prems = Goal
nipkow@2608
    49
    "[| !!x. P x 0;  \
nipkow@2608
    50
\       !!y. P 0 (Suc y);  \
nipkow@2608
    51
\       !!x y. [| P x y |] ==> P (Suc x) (Suc y)  \
nipkow@2608
    52
\    |] ==> P m n";
nipkow@2608
    53
by (res_inst_tac [("x","m")] spec 1);
nipkow@2608
    54
by (nat_ind_tac "n" 1);
nipkow@2608
    55
by (rtac allI 2);
nipkow@2608
    56
by (nat_ind_tac "x" 2);
nipkow@2608
    57
by (REPEAT (ares_tac (prems@[allI]) 1 ORELSE etac spec 1));
nipkow@2608
    58
qed "diff_induct";
nipkow@2608
    59
nipkow@2608
    60
(*** Isomorphisms: Abs_Nat and Rep_Nat ***)
nipkow@2608
    61
nipkow@2608
    62
(*We can't take these properties as axioms, or take Abs_Nat==Inv(Rep_Nat),
nipkow@2608
    63
  since we assume the isomorphism equations will one day be given by Isabelle*)
nipkow@2608
    64
wenzelm@5069
    65
Goal "inj(Rep_Nat)";
nipkow@2608
    66
by (rtac inj_inverseI 1);
nipkow@2608
    67
by (rtac Rep_Nat_inverse 1);
nipkow@2608
    68
qed "inj_Rep_Nat";
nipkow@2608
    69
wenzelm@5069
    70
Goal "inj_on Abs_Nat Nat";
nipkow@4830
    71
by (rtac inj_on_inverseI 1);
nipkow@2608
    72
by (etac Abs_Nat_inverse 1);
nipkow@4830
    73
qed "inj_on_Abs_Nat";
nipkow@2608
    74
nipkow@2608
    75
(*** Distinctness of constructors ***)
nipkow@2608
    76
wenzelm@5069
    77
Goalw [Zero_def,Suc_def] "Suc(m) ~= 0";
nipkow@4830
    78
by (rtac (inj_on_Abs_Nat RS inj_on_contraD) 1);
nipkow@2608
    79
by (rtac Suc_Rep_not_Zero_Rep 1);
nipkow@2608
    80
by (REPEAT (resolve_tac [Rep_Nat, Suc_RepI, Zero_RepI] 1));
nipkow@2608
    81
qed "Suc_not_Zero";
nipkow@2608
    82
nipkow@2608
    83
bind_thm ("Zero_not_Suc", Suc_not_Zero RS not_sym);
nipkow@2608
    84
nipkow@2608
    85
AddIffs [Suc_not_Zero,Zero_not_Suc];
nipkow@2608
    86
nipkow@2608
    87
bind_thm ("Suc_neq_Zero", (Suc_not_Zero RS notE));
wenzelm@9108
    88
bind_thm ("Zero_neq_Suc", sym RS Suc_neq_Zero);
nipkow@2608
    89
nipkow@2608
    90
(** Injectiveness of Suc **)
nipkow@2608
    91
wenzelm@5069
    92
Goalw [Suc_def] "inj(Suc)";
nipkow@2608
    93
by (rtac injI 1);
nipkow@4830
    94
by (dtac (inj_on_Abs_Nat RS inj_onD) 1);
nipkow@2608
    95
by (REPEAT (resolve_tac [Rep_Nat, Suc_RepI] 1));
nipkow@2608
    96
by (dtac (inj_Suc_Rep RS injD) 1);
nipkow@2608
    97
by (etac (inj_Rep_Nat RS injD) 1);
nipkow@2608
    98
qed "inj_Suc";
nipkow@2608
    99
wenzelm@9108
   100
bind_thm ("Suc_inject", inj_Suc RS injD);
nipkow@2608
   101
wenzelm@5069
   102
Goal "(Suc(m)=Suc(n)) = (m=n)";
nipkow@2608
   103
by (EVERY1 [rtac iffI, etac Suc_inject, etac arg_cong]); 
nipkow@2608
   104
qed "Suc_Suc_eq";
nipkow@2608
   105
nipkow@2608
   106
AddIffs [Suc_Suc_eq];
nipkow@2608
   107
wenzelm@5069
   108
Goal "n ~= Suc(n)";
nipkow@2608
   109
by (nat_ind_tac "n" 1);
nipkow@2608
   110
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   111
qed "n_not_Suc_n";
nipkow@2608
   112
nipkow@2608
   113
bind_thm ("Suc_n_not_n", n_not_Suc_n RS not_sym);
nipkow@2608
   114
berghofe@5187
   115
(*** Basic properties of "less than" ***)
nipkow@2608
   116
wenzelm@5069
   117
Goalw [wf_def, pred_nat_def] "wf(pred_nat)";
paulson@3718
   118
by (Clarify_tac 1);
nipkow@2608
   119
by (nat_ind_tac "x" 1);
paulson@3236
   120
by (ALLGOALS Blast_tac);
nipkow@2608
   121
qed "wf_pred_nat";
nipkow@2608
   122
paulson@3378
   123
(*Used in TFL/post.sml*)
wenzelm@5069
   124
Goalw [less_def] "(m,n) : pred_nat^+ = (m<n)";
paulson@3378
   125
by (rtac refl 1);
paulson@3378
   126
qed "less_eq";
paulson@3378
   127
nipkow@2608
   128
(** Introduction properties **)
nipkow@2608
   129
paulson@5316
   130
Goalw [less_def] "[| i<j;  j<k |] ==> i<(k::nat)";
nipkow@2608
   131
by (rtac (trans_trancl RS transD) 1);
paulson@5316
   132
by (assume_tac 1);
paulson@5316
   133
by (assume_tac 1);
nipkow@2608
   134
qed "less_trans";
nipkow@2608
   135
wenzelm@5069
   136
Goalw [less_def, pred_nat_def] "n < Suc(n)";
wenzelm@4089
   137
by (simp_tac (simpset() addsimps [r_into_trancl]) 1);
nipkow@2608
   138
qed "lessI";
nipkow@2608
   139
AddIffs [lessI];
nipkow@2608
   140
nipkow@2608
   141
(* i<j ==> i<Suc(j) *)
nipkow@2608
   142
bind_thm("less_SucI", lessI RSN (2, less_trans));
nipkow@2608
   143
wenzelm@5069
   144
Goal "0 < Suc(n)";
nipkow@2608
   145
by (nat_ind_tac "n" 1);
nipkow@2608
   146
by (rtac lessI 1);
nipkow@2608
   147
by (etac less_trans 1);
nipkow@2608
   148
by (rtac lessI 1);
nipkow@2608
   149
qed "zero_less_Suc";
nipkow@2608
   150
AddIffs [zero_less_Suc];
nipkow@2608
   151
nipkow@2608
   152
(** Elimination properties **)
nipkow@2608
   153
paulson@5316
   154
Goalw [less_def] "n<m ==> ~ m<(n::nat)";
paulson@5316
   155
by (blast_tac (claset() addIs [wf_pred_nat, wf_trancl RS wf_asym])1);
nipkow@2608
   156
qed "less_not_sym";
nipkow@2608
   157
paulson@5474
   158
(* [| n<m; ~P ==> m<n |] ==> P *)
paulson@10231
   159
bind_thm ("less_asym", less_not_sym RS contrapos_np);
nipkow@2608
   160
wenzelm@5069
   161
Goalw [less_def] "~ n<(n::nat)";
paulson@9160
   162
by (rtac (wf_pred_nat RS wf_trancl RS wf_not_refl) 1);
nipkow@2608
   163
qed "less_not_refl";
nipkow@2608
   164
nipkow@2608
   165
(* n<n ==> R *)
paulson@9160
   166
bind_thm ("less_irrefl", less_not_refl RS notE);
paulson@5474
   167
AddSEs [less_irrefl];
nipkow@2608
   168
paulson@5143
   169
Goal "n<m ==> m ~= (n::nat)";
paulson@5474
   170
by (Blast_tac 1);
nipkow@2608
   171
qed "less_not_refl2";
nipkow@2608
   172
paulson@5354
   173
(* s < t ==> s ~= t *)
paulson@5354
   174
bind_thm ("less_not_refl3", less_not_refl2 RS not_sym);
paulson@5354
   175
nipkow@2608
   176
paulson@5316
   177
val major::prems = Goalw [less_def, pred_nat_def]
nipkow@2608
   178
    "[| i<k;  k=Suc(i) ==> P;  !!j. [| i<j;  k=Suc(j) |] ==> P \
nipkow@2608
   179
\    |] ==> P";
nipkow@2608
   180
by (rtac (major RS tranclE) 1);
paulson@3236
   181
by (ALLGOALS Full_simp_tac); 
nipkow@2608
   182
by (REPEAT_FIRST (bound_hyp_subst_tac ORELSE'
paulson@3236
   183
                  eresolve_tac (prems@[asm_rl, Pair_inject])));
nipkow@2608
   184
qed "lessE";
nipkow@2608
   185
paulson@8942
   186
Goal "~ n < (0::nat)";
paulson@8942
   187
by (blast_tac (claset() addEs [lessE]) 1);
nipkow@2608
   188
qed "not_less0";
nipkow@2608
   189
AddIffs [not_less0];
nipkow@2608
   190
nipkow@2608
   191
(* n<0 ==> R *)
nipkow@2608
   192
bind_thm ("less_zeroE", not_less0 RS notE);
nipkow@2608
   193
paulson@5316
   194
val [major,less,eq] = Goal
nipkow@2608
   195
    "[| m < Suc(n);  m<n ==> P;  m=n ==> P |] ==> P";
nipkow@2608
   196
by (rtac (major RS lessE) 1);
nipkow@2608
   197
by (rtac eq 1);
paulson@2891
   198
by (Blast_tac 1);
nipkow@2608
   199
by (rtac less 1);
paulson@2891
   200
by (Blast_tac 1);
nipkow@2608
   201
qed "less_SucE";
nipkow@2608
   202
wenzelm@5069
   203
Goal "(m < Suc(n)) = (m < n | m = n)";
wenzelm@4089
   204
by (blast_tac (claset() addSEs [less_SucE] addIs [less_trans]) 1);
nipkow@2608
   205
qed "less_Suc_eq";
nipkow@2608
   206
wenzelm@5069
   207
Goal "(n<1) = (n=0)";
wenzelm@4089
   208
by (simp_tac (simpset() addsimps [less_Suc_eq]) 1);
nipkow@3484
   209
qed "less_one";
nipkow@3484
   210
AddIffs [less_one];
nipkow@3484
   211
paulson@5143
   212
Goal "m<n ==> Suc(m) < Suc(n)";
nipkow@2608
   213
by (etac rev_mp 1);
nipkow@2608
   214
by (nat_ind_tac "n" 1);
paulson@5474
   215
by (ALLGOALS (fast_tac (claset() addEs [less_trans, lessE])));
nipkow@2608
   216
qed "Suc_mono";
nipkow@2608
   217
nipkow@2608
   218
(*"Less than" is a linear ordering*)
wenzelm@5069
   219
Goal "m<n | m=n | n<(m::nat)";
nipkow@2608
   220
by (nat_ind_tac "m" 1);
nipkow@2608
   221
by (nat_ind_tac "n" 1);
nipkow@2608
   222
by (rtac (refl RS disjI1 RS disjI2) 1);
nipkow@2608
   223
by (rtac (zero_less_Suc RS disjI1) 1);
wenzelm@4089
   224
by (blast_tac (claset() addIs [Suc_mono, less_SucI] addEs [lessE]) 1);
nipkow@2608
   225
qed "less_linear";
nipkow@2608
   226
wenzelm@5069
   227
Goal "!!m::nat. (m ~= n) = (m<n | n<m)";
paulson@4737
   228
by (cut_facts_tac [less_linear] 1);
paulson@5500
   229
by (Blast_tac 1);
paulson@4737
   230
qed "nat_neq_iff";
paulson@4737
   231
paulson@7030
   232
val [major,eqCase,lessCase] = Goal 
paulson@7030
   233
   "[| (m::nat)<n ==> P n m; m=n ==> P n m; n<m ==> P n m |] ==> P n m";
paulson@7030
   234
by (rtac (less_linear RS disjE) 1);
paulson@7030
   235
by (etac disjE 2);
paulson@7030
   236
by (etac lessCase 1);
paulson@7030
   237
by (etac (sym RS eqCase) 1);
paulson@7030
   238
by (etac major 1);
paulson@7030
   239
qed "nat_less_cases";
nipkow@2608
   240
paulson@4745
   241
paulson@4745
   242
(** Inductive (?) properties **)
paulson@4745
   243
paulson@5143
   244
Goal "[| m<n; Suc m ~= n |] ==> Suc(m) < n";
paulson@4745
   245
by (full_simp_tac (simpset() addsimps [nat_neq_iff]) 1);
paulson@4745
   246
by (blast_tac (claset() addSEs [less_irrefl, less_SucE] addEs [less_asym]) 1);
paulson@4745
   247
qed "Suc_lessI";
paulson@4745
   248
paulson@5316
   249
Goal "Suc(m) < n ==> m<n";
paulson@5316
   250
by (etac rev_mp 1);
paulson@4745
   251
by (nat_ind_tac "n" 1);
paulson@4745
   252
by (ALLGOALS (fast_tac (claset() addSIs [lessI RS less_SucI]
paulson@4745
   253
                                 addEs  [less_trans, lessE])));
paulson@4745
   254
qed "Suc_lessD";
paulson@4745
   255
paulson@5316
   256
val [major,minor] = Goal 
paulson@4745
   257
    "[| Suc(i)<k;  !!j. [| i<j;  k=Suc(j) |] ==> P \
paulson@4745
   258
\    |] ==> P";
paulson@4745
   259
by (rtac (major RS lessE) 1);
paulson@4745
   260
by (etac (lessI RS minor) 1);
paulson@4745
   261
by (etac (Suc_lessD RS minor) 1);
paulson@4745
   262
by (assume_tac 1);
paulson@4745
   263
qed "Suc_lessE";
paulson@4745
   264
paulson@5143
   265
Goal "Suc(m) < Suc(n) ==> m<n";
paulson@4745
   266
by (blast_tac (claset() addEs [lessE, make_elim Suc_lessD]) 1);
paulson@4745
   267
qed "Suc_less_SucD";
paulson@4745
   268
paulson@4745
   269
wenzelm@5069
   270
Goal "(Suc(m) < Suc(n)) = (m<n)";
paulson@4745
   271
by (EVERY1 [rtac iffI, etac Suc_less_SucD, etac Suc_mono]);
paulson@4745
   272
qed "Suc_less_eq";
paulson@8555
   273
AddIffs [Suc_less_eq];
paulson@4745
   274
nipkow@6109
   275
(*Goal "~(Suc(n) < n)";
paulson@4745
   276
by (blast_tac (claset() addEs [Suc_lessD RS less_irrefl]) 1);
paulson@4745
   277
qed "not_Suc_n_less_n";
nipkow@6109
   278
Addsimps [not_Suc_n_less_n];*)
paulson@4745
   279
paulson@5143
   280
Goal "i<j ==> j<k --> Suc i < k";
paulson@4745
   281
by (nat_ind_tac "k" 1);
paulson@4745
   282
by (ALLGOALS (asm_simp_tac (simpset())));
paulson@4745
   283
by (asm_simp_tac (simpset() addsimps [less_Suc_eq]) 1);
paulson@4745
   284
by (blast_tac (claset() addDs [Suc_lessD]) 1);
paulson@4745
   285
qed_spec_mp "less_trans_Suc";
paulson@4745
   286
nipkow@2608
   287
(*Can be used with less_Suc_eq to get n=m | n<m *)
wenzelm@5069
   288
Goal "(~ m < n) = (n < Suc(m))";
nipkow@2608
   289
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
nipkow@2608
   290
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   291
qed "not_less_eq";
nipkow@2608
   292
nipkow@2608
   293
(*Complete induction, aka course-of-values induction*)
paulson@5316
   294
val prems = Goalw [less_def]
paulson@9160
   295
    "[| !!n. [| ALL m::nat. m<n --> P(m) |] ==> P(n) |]  ==>  P(n)";
nipkow@2608
   296
by (wf_ind_tac "n" [wf_pred_nat RS wf_trancl] 1);
nipkow@2608
   297
by (eresolve_tac prems 1);
nipkow@9870
   298
qed "nat_less_induct";
nipkow@2608
   299
nipkow@2608
   300
(*** Properties of <= ***)
nipkow@2608
   301
paulson@5500
   302
(*Was le_eq_less_Suc, but this orientation is more useful*)
paulson@5500
   303
Goalw [le_def] "(m < Suc n) = (m <= n)";
paulson@5500
   304
by (rtac (not_less_eq RS sym) 1);
paulson@5500
   305
qed "less_Suc_eq_le";
nipkow@2608
   306
paulson@3343
   307
(*  m<=n ==> m < Suc n  *)
paulson@5500
   308
bind_thm ("le_imp_less_Suc", less_Suc_eq_le RS iffD2);
paulson@3343
   309
paulson@8942
   310
Goalw [le_def] "(0::nat) <= n";
nipkow@2608
   311
by (rtac not_less0 1);
nipkow@2608
   312
qed "le0";
nipkow@6075
   313
AddIffs [le0];
nipkow@2608
   314
wenzelm@5069
   315
Goalw [le_def] "~ Suc n <= n";
nipkow@2608
   316
by (Simp_tac 1);
nipkow@2608
   317
qed "Suc_n_not_le_n";
nipkow@2608
   318
paulson@8942
   319
Goalw [le_def] "!!i::nat. (i <= 0) = (i = 0)";
nipkow@2608
   320
by (nat_ind_tac "i" 1);
nipkow@2608
   321
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   322
qed "le_0_eq";
paulson@4614
   323
AddIffs [le_0_eq];
nipkow@2608
   324
paulson@5143
   325
Goal "(m <= Suc(n)) = (m<=n | m = Suc n)";
paulson@5500
   326
by (simp_tac (simpset() delsimps [less_Suc_eq_le]
paulson@5500
   327
			addsimps [less_Suc_eq_le RS sym, less_Suc_eq]) 1);
paulson@3355
   328
qed "le_Suc_eq";
paulson@3355
   329
paulson@4614
   330
(* [| m <= Suc n;  m <= n ==> R;  m = Suc n ==> R |] ==> R *)
paulson@4614
   331
bind_thm ("le_SucE", le_Suc_eq RS iffD1 RS disjE);
paulson@4614
   332
paulson@5316
   333
Goalw [le_def] "~n<m ==> m<=(n::nat)";
paulson@5316
   334
by (assume_tac 1);
nipkow@2608
   335
qed "leI";
nipkow@2608
   336
paulson@5316
   337
Goalw [le_def] "m<=n ==> ~ n < (m::nat)";
paulson@5316
   338
by (assume_tac 1);
nipkow@2608
   339
qed "leD";
nipkow@2608
   340
wenzelm@9108
   341
bind_thm ("leE", make_elim leD);
nipkow@2608
   342
wenzelm@5069
   343
Goal "(~n<m) = (m<=(n::nat))";
wenzelm@4089
   344
by (blast_tac (claset() addIs [leI] addEs [leE]) 1);
nipkow@2608
   345
qed "not_less_iff_le";
nipkow@2608
   346
paulson@5143
   347
Goalw [le_def] "~ m <= n ==> n<(m::nat)";
paulson@2891
   348
by (Blast_tac 1);
nipkow@2608
   349
qed "not_leE";
nipkow@2608
   350
wenzelm@5069
   351
Goalw [le_def] "(~n<=m) = (m<(n::nat))";
paulson@4599
   352
by (Simp_tac 1);
paulson@4599
   353
qed "not_le_iff_less";
paulson@4599
   354
paulson@5143
   355
Goalw [le_def] "m < n ==> Suc(m) <= n";
wenzelm@4089
   356
by (simp_tac (simpset() addsimps [less_Suc_eq]) 1);
wenzelm@4089
   357
by (blast_tac (claset() addSEs [less_irrefl,less_asym]) 1);
paulson@3343
   358
qed "Suc_leI";  (*formerly called lessD*)
nipkow@2608
   359
paulson@5143
   360
Goalw [le_def] "Suc(m) <= n ==> m <= n";
wenzelm@4089
   361
by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq]) 1);
nipkow@2608
   362
qed "Suc_leD";
nipkow@2608
   363
nipkow@2608
   364
(* stronger version of Suc_leD *)
paulson@5148
   365
Goalw [le_def] "Suc m <= n ==> m < n";
wenzelm@4089
   366
by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq]) 1);
nipkow@2608
   367
by (cut_facts_tac [less_linear] 1);
paulson@2891
   368
by (Blast_tac 1);
nipkow@2608
   369
qed "Suc_le_lessD";
nipkow@2608
   370
wenzelm@5069
   371
Goal "(Suc m <= n) = (m < n)";
wenzelm@4089
   372
by (blast_tac (claset() addIs [Suc_leI, Suc_le_lessD]) 1);
nipkow@2608
   373
qed "Suc_le_eq";
nipkow@2608
   374
paulson@5143
   375
Goalw [le_def] "m <= n ==> m <= Suc n";
wenzelm@4089
   376
by (blast_tac (claset() addDs [Suc_lessD]) 1);
nipkow@2608
   377
qed "le_SucI";
nipkow@2608
   378
nipkow@6109
   379
(*bind_thm ("le_Suc", not_Suc_n_less_n RS leI);*)
nipkow@2608
   380
paulson@5143
   381
Goalw [le_def] "m < n ==> m <= (n::nat)";
wenzelm@4089
   382
by (blast_tac (claset() addEs [less_asym]) 1);
nipkow@2608
   383
qed "less_imp_le";
nipkow@2608
   384
paulson@5591
   385
(*For instance, (Suc m < Suc n)  =   (Suc m <= n)  =  (m<n) *)
wenzelm@9108
   386
bind_thms ("le_simps", [less_imp_le, less_Suc_eq_le, Suc_le_eq]);
paulson@5591
   387
paulson@5354
   388
paulson@3343
   389
(** Equivalence of m<=n and  m<n | m=n **)
paulson@3343
   390
paulson@5143
   391
Goalw [le_def] "m <= n ==> m < n | m=(n::nat)";
nipkow@2608
   392
by (cut_facts_tac [less_linear] 1);
wenzelm@4089
   393
by (blast_tac (claset() addEs [less_irrefl,less_asym]) 1);
nipkow@2608
   394
qed "le_imp_less_or_eq";
nipkow@2608
   395
paulson@5143
   396
Goalw [le_def] "m<n | m=n ==> m <=(n::nat)";
nipkow@2608
   397
by (cut_facts_tac [less_linear] 1);
wenzelm@4089
   398
by (blast_tac (claset() addSEs [less_irrefl] addEs [less_asym]) 1);
nipkow@2608
   399
qed "less_or_eq_imp_le";
nipkow@2608
   400
wenzelm@5069
   401
Goal "(m <= (n::nat)) = (m < n | m=n)";
nipkow@2608
   402
by (REPEAT(ares_tac [iffI,less_or_eq_imp_le,le_imp_less_or_eq] 1));
nipkow@2608
   403
qed "le_eq_less_or_eq";
nipkow@2608
   404
paulson@4635
   405
(*Useful with Blast_tac.   m=n ==> m<=n *)
paulson@4635
   406
bind_thm ("eq_imp_le", disjI2 RS less_or_eq_imp_le);
paulson@4635
   407
wenzelm@5069
   408
Goal "n <= (n::nat)";
wenzelm@4089
   409
by (simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1);
nipkow@2608
   410
qed "le_refl";
nipkow@2608
   411
paulson@5354
   412
paulson@5143
   413
Goal "[| i <= j; j < k |] ==> i < (k::nat)";
paulson@4468
   414
by (blast_tac (claset() addSDs [le_imp_less_or_eq]
paulson@4468
   415
	                addIs [less_trans]) 1);
nipkow@2608
   416
qed "le_less_trans";
nipkow@2608
   417
paulson@5143
   418
Goal "[| i < j; j <= k |] ==> i < (k::nat)";
paulson@4468
   419
by (blast_tac (claset() addSDs [le_imp_less_or_eq]
paulson@4468
   420
	                addIs [less_trans]) 1);
nipkow@2608
   421
qed "less_le_trans";
nipkow@2608
   422
paulson@5143
   423
Goal "[| i <= j; j <= k |] ==> i <= (k::nat)";
paulson@4468
   424
by (blast_tac (claset() addSDs [le_imp_less_or_eq]
paulson@4468
   425
	                addIs [less_or_eq_imp_le, less_trans]) 1);
nipkow@2608
   426
qed "le_trans";
nipkow@2608
   427
paulson@5143
   428
Goal "[| m <= n; n <= m |] ==> m = (n::nat)";
paulson@4468
   429
(*order_less_irrefl could make this proof fail*)
paulson@4468
   430
by (blast_tac (claset() addSDs [le_imp_less_or_eq]
paulson@4468
   431
	                addSEs [less_irrefl] addEs [less_asym]) 1);
nipkow@2608
   432
qed "le_anti_sym";
nipkow@2608
   433
wenzelm@5069
   434
Goal "(Suc(n) <= Suc(m)) = (n <= m)";
paulson@5500
   435
by (simp_tac (simpset() addsimps le_simps) 1);
nipkow@2608
   436
qed "Suc_le_mono";
nipkow@2608
   437
nipkow@2608
   438
AddIffs [Suc_le_mono];
nipkow@2608
   439
paulson@5500
   440
(* Axiom 'order_less_le' of class 'order': *)
wenzelm@5069
   441
Goal "(m::nat) < n = (m <= n & m ~= n)";
paulson@4737
   442
by (simp_tac (simpset() addsimps [le_def, nat_neq_iff]) 1);
paulson@4737
   443
by (blast_tac (claset() addSEs [less_asym]) 1);
nipkow@2608
   444
qed "nat_less_le";
nipkow@2608
   445
paulson@5354
   446
(* [| m <= n; m ~= n |] ==> m < n *)
paulson@5354
   447
bind_thm ("le_neq_implies_less", [nat_less_le, conjI] MRS iffD2);
paulson@5354
   448
nipkow@4640
   449
(* Axiom 'linorder_linear' of class 'linorder': *)
wenzelm@5069
   450
Goal "(m::nat) <= n | n <= m";
nipkow@4640
   451
by (simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1);
nipkow@4640
   452
by (cut_facts_tac [less_linear] 1);
wenzelm@5132
   453
by (Blast_tac 1);
nipkow@4640
   454
qed "nat_le_linear";
nipkow@4640
   455
paulson@5354
   456
Goal "~ n < m ==> (n < Suc m) = (n = m)";
paulson@5354
   457
by (blast_tac (claset() addSEs [less_SucE]) 1);
paulson@5354
   458
qed "not_less_less_Suc_eq";
paulson@5354
   459
paulson@5354
   460
paulson@5354
   461
(*Rewrite (n < Suc m) to (n=m) if  ~ n<m or m<=n hold.
paulson@5354
   462
  Not suitable as default simprules because they often lead to looping*)
wenzelm@9108
   463
bind_thms ("not_less_simps", [not_less_less_Suc_eq, leD RS not_less_less_Suc_eq]);
nipkow@4640
   464
paulson@10706
   465
paulson@10706
   466
(** Re-orientation of the equations 0=x and Suc n = x. *
paulson@10706
   467
paulson@10706
   468
  The condition "True" is a hack to prevent looping for e.g. Suc m = Suc n.
paulson@10706
   469
  Conditional rewrite rules are tried after unconditional ones.
paulson@10706
   470
**)
paulson@10706
   471
paulson@10711
   472
(*Polymorphic, not just for "nat"*)
paulson@10711
   473
Goal "True ==> (0 = x) = (x = 0)";
paulson@10706
   474
by Auto_tac;  
paulson@10706
   475
qed "zero_reorient";
paulson@10706
   476
Addsimps [zero_reorient];
paulson@10706
   477
paulson@10706
   478
Goal "True ==> (1 = x) = (x = 1)";
paulson@10706
   479
by Auto_tac;  
paulson@10706
   480
qed "one_reorient";
paulson@10706
   481
Addsimps [one_reorient];
paulson@10706
   482
paulson@10706
   483
Goal "True ==> (2 = x) = (x = 2)";
paulson@10706
   484
by Auto_tac;  
paulson@10706
   485
qed "two_reorient";
paulson@10706
   486
Addsimps [two_reorient];