src/HOL/NatDef.ML
author wenzelm
Wed, 29 Aug 2001 21:17:24 +0200
changeset 11506 244a02a2968b
parent 11464 ddea204de5bc
child 11655 923e4d0d36d5
permissions -rw-r--r--
avoid ML bindings;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/NatDef.ML
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
     2
    ID:         $Id$
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
     3
    Author:     Tobias Nipkow, Cambridge University Computer Laboratory
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
     4
    Copyright   1991  University of Cambridge
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
     5
*)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
     6
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 11461
diff changeset
     7
Addsimps [One_def];
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 11461
diff changeset
     8
11326
680ebd093cfe Representing set for type nat is now defined via "inductive".
berghofe
parents: 11135
diff changeset
     9
val rew = rewrite_rule [symmetric Nat_def];
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    10
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    11
(*** Induction ***)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    12
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
    13
val prems = Goalw [Zero_def,Suc_def]
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    14
    "[| P(0);   \
3040
7d48671753da Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents: 3023
diff changeset
    15
\       !!n. P(n) ==> P(Suc(n)) |]  ==> P(n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    16
by (rtac (Rep_Nat_inverse RS subst) 1);   (*types force good instantiation*)
11326
680ebd093cfe Representing set for type nat is now defined via "inductive".
berghofe
parents: 11135
diff changeset
    17
by (rtac (Rep_Nat RS rew Nat'.induct) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    18
by (REPEAT (ares_tac prems 1
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    19
     ORELSE eresolve_tac [Abs_Nat_inverse RS subst] 1));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    20
qed "nat_induct";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    21
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    22
(*Perform induction on n. *)
5187
55f07169cf5f Removed nat_case, nat_rec, and natE (now provided by datatype
berghofe
parents: 5148
diff changeset
    23
fun nat_ind_tac a i = 
55f07169cf5f Removed nat_case, nat_rec, and natE (now provided by datatype
berghofe
parents: 5148
diff changeset
    24
  res_inst_tac [("n",a)] nat_induct i  THEN  rename_last_tac a [""] (i+1);
3040
7d48671753da Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents: 3023
diff changeset
    25
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    26
(*A special form of induction for reasoning about m<n and m-n*)
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
    27
val prems = Goal
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    28
    "[| !!x. P x 0;  \
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    29
\       !!y. P 0 (Suc y);  \
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    30
\       !!x y. [| P x y |] ==> P (Suc x) (Suc y)  \
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    31
\    |] ==> P m n";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    32
by (res_inst_tac [("x","m")] spec 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    33
by (nat_ind_tac "n" 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    34
by (rtac allI 2);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    35
by (nat_ind_tac "x" 2);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    36
by (REPEAT (ares_tac (prems@[allI]) 1 ORELSE etac spec 1));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    37
qed "diff_induct";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    38
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    39
(*** Isomorphisms: Abs_Nat and Rep_Nat ***)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    40
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    41
(*We can't take these properties as axioms, or take Abs_Nat==Inv(Rep_Nat),
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    42
  since we assume the isomorphism equations will one day be given by Isabelle*)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    43
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
    44
Goal "inj(Rep_Nat)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    45
by (rtac inj_inverseI 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    46
by (rtac Rep_Nat_inverse 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    47
qed "inj_Rep_Nat";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    48
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
    49
Goal "inj_on Abs_Nat Nat";
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4821
diff changeset
    50
by (rtac inj_on_inverseI 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    51
by (etac Abs_Nat_inverse 1);
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4821
diff changeset
    52
qed "inj_on_Abs_Nat";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    53
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    54
(*** Distinctness of constructors ***)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    55
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
    56
Goalw [Zero_def,Suc_def] "Suc(m) ~= 0";
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4821
diff changeset
    57
by (rtac (inj_on_Abs_Nat RS inj_on_contraD) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    58
by (rtac Suc_Rep_not_Zero_Rep 1);
11326
680ebd093cfe Representing set for type nat is now defined via "inductive".
berghofe
parents: 11135
diff changeset
    59
by (REPEAT (resolve_tac [Rep_Nat, rew Nat'.Suc_RepI, rew Nat'.Zero_RepI] 1));
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    60
qed "Suc_not_Zero";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    61
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    62
bind_thm ("Zero_not_Suc", Suc_not_Zero RS not_sym);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    63
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    64
AddIffs [Suc_not_Zero,Zero_not_Suc];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    65
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    66
bind_thm ("Suc_neq_Zero", (Suc_not_Zero RS notE));
9108
9fff97d29837 bind_thm(s);
wenzelm
parents: 8942
diff changeset
    67
bind_thm ("Zero_neq_Suc", sym RS Suc_neq_Zero);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    68
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    69
(** Injectiveness of Suc **)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    70
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
    71
Goalw [Suc_def] "inj(Suc)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    72
by (rtac injI 1);
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4821
diff changeset
    73
by (dtac (inj_on_Abs_Nat RS inj_onD) 1);
11326
680ebd093cfe Representing set for type nat is now defined via "inductive".
berghofe
parents: 11135
diff changeset
    74
by (REPEAT (resolve_tac [Rep_Nat, rew Nat'.Suc_RepI] 1));
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    75
by (dtac (inj_Suc_Rep RS injD) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    76
by (etac (inj_Rep_Nat RS injD) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    77
qed "inj_Suc";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    78
9108
9fff97d29837 bind_thm(s);
wenzelm
parents: 8942
diff changeset
    79
bind_thm ("Suc_inject", inj_Suc RS injD);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    80
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
    81
Goal "(Suc(m)=Suc(n)) = (m=n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    82
by (EVERY1 [rtac iffI, etac Suc_inject, etac arg_cong]); 
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    83
qed "Suc_Suc_eq";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    84
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    85
AddIffs [Suc_Suc_eq];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    86
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
    87
Goal "n ~= Suc(n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    88
by (nat_ind_tac "n" 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    89
by (ALLGOALS Asm_simp_tac);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    90
qed "n_not_Suc_n";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    91
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    92
bind_thm ("Suc_n_not_n", n_not_Suc_n RS not_sym);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    93
11461
ffeac9aa1967 removed an unsuitable default simprule
paulson
parents: 11338
diff changeset
    94
Goal "(ALL x. x = (0::nat)) = False";
11338
779d289255f7 added nat_not_singleton (also to simpset)
oheimb
parents: 11326
diff changeset
    95
by Auto_tac;
779d289255f7 added nat_not_singleton (also to simpset)
oheimb
parents: 11326
diff changeset
    96
qed "nat_not_singleton";
779d289255f7 added nat_not_singleton (also to simpset)
oheimb
parents: 11326
diff changeset
    97
5187
55f07169cf5f Removed nat_case, nat_rec, and natE (now provided by datatype
berghofe
parents: 5148
diff changeset
    98
(*** Basic properties of "less than" ***)
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    99
11135
8fd0dea26286 moved wf_less from Nat.ML to NatDef.ML
oheimb
parents: 10850
diff changeset
   100
Goalw [wf_def, pred_nat_def] "wf pred_nat";
3718
d78cf498a88c Minor tidying to use Clarify_tac, etc.
paulson
parents: 3563
diff changeset
   101
by (Clarify_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   102
by (nat_ind_tac "x" 1);
3236
882e125ed7da New pattern-matching definition of pred_nat
paulson
parents: 3143
diff changeset
   103
by (ALLGOALS Blast_tac);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   104
qed "wf_pred_nat";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   105
11135
8fd0dea26286 moved wf_less from Nat.ML to NatDef.ML
oheimb
parents: 10850
diff changeset
   106
Goalw [less_def] "wf {(x,y::nat). x<y}"; 
8fd0dea26286 moved wf_less from Nat.ML to NatDef.ML
oheimb
parents: 10850
diff changeset
   107
by (rtac (wf_pred_nat RS wf_trancl RS wf_subset) 1);
8fd0dea26286 moved wf_less from Nat.ML to NatDef.ML
oheimb
parents: 10850
diff changeset
   108
by (Blast_tac 1); 
8fd0dea26286 moved wf_less from Nat.ML to NatDef.ML
oheimb
parents: 10850
diff changeset
   109
qed "wf_less";
8fd0dea26286 moved wf_less from Nat.ML to NatDef.ML
oheimb
parents: 10850
diff changeset
   110
3378
11f4884a071a Moved "less_eq" to NatDef from Arith
paulson
parents: 3355
diff changeset
   111
(*Used in TFL/post.sml*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   112
Goalw [less_def] "(m,n) : pred_nat^+ = (m<n)";
3378
11f4884a071a Moved "less_eq" to NatDef from Arith
paulson
parents: 3355
diff changeset
   113
by (rtac refl 1);
11f4884a071a Moved "less_eq" to NatDef from Arith
paulson
parents: 3355
diff changeset
   114
qed "less_eq";
11f4884a071a Moved "less_eq" to NatDef from Arith
paulson
parents: 3355
diff changeset
   115
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   116
(** Introduction properties **)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   117
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   118
Goalw [less_def] "[| i<j;  j<k |] ==> i<(k::nat)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   119
by (rtac (trans_trancl RS transD) 1);
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   120
by (assume_tac 1);
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   121
by (assume_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   122
qed "less_trans";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   123
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   124
Goalw [less_def, pred_nat_def] "n < Suc(n)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   125
by (simp_tac (simpset() addsimps [r_into_trancl]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   126
qed "lessI";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   127
AddIffs [lessI];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   128
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   129
(* i<j ==> i<Suc(j) *)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   130
bind_thm("less_SucI", lessI RSN (2, less_trans));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   131
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   132
Goal "0 < Suc(n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   133
by (nat_ind_tac "n" 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   134
by (rtac lessI 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   135
by (etac less_trans 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   136
by (rtac lessI 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   137
qed "zero_less_Suc";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   138
AddIffs [zero_less_Suc];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   139
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   140
(** Elimination properties **)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   141
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   142
Goalw [less_def] "n<m ==> ~ m<(n::nat)";
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   143
by (blast_tac (claset() addIs [wf_pred_nat, wf_trancl RS wf_asym])1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   144
qed "less_not_sym";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   145
5474
a2109bb8ce2b well-formed asym rules; also adds less_irrefl, le_refl since order_refl
paulson
parents: 5354
diff changeset
   146
(* [| n<m; ~P ==> m<n |] ==> P *)
10231
178a272bceeb renaming of contrapos rules
paulson
parents: 10202
diff changeset
   147
bind_thm ("less_asym", less_not_sym RS contrapos_np);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   148
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   149
Goalw [less_def] "~ n<(n::nat)";
9160
7a98dbf3e579 using the new theorem wf_not_refl; tidied
paulson
parents: 9108
diff changeset
   150
by (rtac (wf_pred_nat RS wf_trancl RS wf_not_refl) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   151
qed "less_not_refl";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   152
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   153
(* n<n ==> R *)
9160
7a98dbf3e579 using the new theorem wf_not_refl; tidied
paulson
parents: 9108
diff changeset
   154
bind_thm ("less_irrefl", less_not_refl RS notE);
5474
a2109bb8ce2b well-formed asym rules; also adds less_irrefl, le_refl since order_refl
paulson
parents: 5354
diff changeset
   155
AddSEs [less_irrefl];
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   156
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   157
Goal "n<m ==> m ~= (n::nat)";
5474
a2109bb8ce2b well-formed asym rules; also adds less_irrefl, le_refl since order_refl
paulson
parents: 5354
diff changeset
   158
by (Blast_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   159
qed "less_not_refl2";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   160
5354
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   161
(* s < t ==> s ~= t *)
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   162
bind_thm ("less_not_refl3", less_not_refl2 RS not_sym);
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   163
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   164
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   165
val major::prems = Goalw [less_def, pred_nat_def]
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   166
    "[| i<k;  k=Suc(i) ==> P;  !!j. [| i<j;  k=Suc(j) |] ==> P \
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   167
\    |] ==> P";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   168
by (rtac (major RS tranclE) 1);
3236
882e125ed7da New pattern-matching definition of pred_nat
paulson
parents: 3143
diff changeset
   169
by (ALLGOALS Full_simp_tac); 
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   170
by (REPEAT_FIRST (bound_hyp_subst_tac ORELSE'
3236
882e125ed7da New pattern-matching definition of pred_nat
paulson
parents: 3143
diff changeset
   171
                  eresolve_tac (prems@[asm_rl, Pair_inject])));
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   172
qed "lessE";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   173
8942
6aad5381ba83 added type constraint ::nat because 0 is now overloaded
paulson
parents: 8741
diff changeset
   174
Goal "~ n < (0::nat)";
6aad5381ba83 added type constraint ::nat because 0 is now overloaded
paulson
parents: 8741
diff changeset
   175
by (blast_tac (claset() addEs [lessE]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   176
qed "not_less0";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   177
AddIffs [not_less0];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   178
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   179
(* n<0 ==> R *)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   180
bind_thm ("less_zeroE", not_less0 RS notE);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   181
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   182
val [major,less,eq] = Goal
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   183
    "[| m < Suc(n);  m<n ==> P;  m=n ==> P |] ==> P";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   184
by (rtac (major RS lessE) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   185
by (rtac eq 1);
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   186
by (Blast_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   187
by (rtac less 1);
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   188
by (Blast_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   189
qed "less_SucE";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   190
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   191
Goal "(m < Suc(n)) = (m < n | m = n)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   192
by (blast_tac (claset() addSEs [less_SucE] addIs [less_trans]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   193
qed "less_Suc_eq";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   194
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   195
Goal "(n<1) = (n=0)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   196
by (simp_tac (simpset() addsimps [less_Suc_eq]) 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   197
qed "less_one";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   198
AddIffs [less_one];
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   199
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   200
Goal "m<n ==> Suc(m) < Suc(n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   201
by (etac rev_mp 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   202
by (nat_ind_tac "n" 1);
5474
a2109bb8ce2b well-formed asym rules; also adds less_irrefl, le_refl since order_refl
paulson
parents: 5354
diff changeset
   203
by (ALLGOALS (fast_tac (claset() addEs [less_trans, lessE])));
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   204
qed "Suc_mono";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   205
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   206
(*"Less than" is a linear ordering*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   207
Goal "m<n | m=n | n<(m::nat)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   208
by (nat_ind_tac "m" 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   209
by (nat_ind_tac "n" 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   210
by (rtac (refl RS disjI1 RS disjI2) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   211
by (rtac (zero_less_Suc RS disjI1) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   212
by (blast_tac (claset() addIs [Suc_mono, less_SucI] addEs [lessE]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   213
qed "less_linear";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   214
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   215
Goal "!!m::nat. (m ~= n) = (m<n | n<m)";
4737
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   216
by (cut_facts_tac [less_linear] 1);
5500
7e0ed3e31590 new theorem less_Suc_eq_le and le_simps
paulson
parents: 5478
diff changeset
   217
by (Blast_tac 1);
4737
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   218
qed "nat_neq_iff";
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   219
7030
53934985426a getting rid of qed_goal
paulson
parents: 6115
diff changeset
   220
val [major,eqCase,lessCase] = Goal 
53934985426a getting rid of qed_goal
paulson
parents: 6115
diff changeset
   221
   "[| (m::nat)<n ==> P n m; m=n ==> P n m; n<m ==> P n m |] ==> P n m";
53934985426a getting rid of qed_goal
paulson
parents: 6115
diff changeset
   222
by (rtac (less_linear RS disjE) 1);
53934985426a getting rid of qed_goal
paulson
parents: 6115
diff changeset
   223
by (etac disjE 2);
53934985426a getting rid of qed_goal
paulson
parents: 6115
diff changeset
   224
by (etac lessCase 1);
53934985426a getting rid of qed_goal
paulson
parents: 6115
diff changeset
   225
by (etac (sym RS eqCase) 1);
53934985426a getting rid of qed_goal
paulson
parents: 6115
diff changeset
   226
by (etac major 1);
53934985426a getting rid of qed_goal
paulson
parents: 6115
diff changeset
   227
qed "nat_less_cases";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   228
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   229
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   230
(** Inductive (?) properties **)
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   231
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   232
Goal "[| m<n; Suc m ~= n |] ==> Suc(m) < n";
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   233
by (full_simp_tac (simpset() addsimps [nat_neq_iff]) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   234
by (blast_tac (claset() addSEs [less_irrefl, less_SucE] addEs [less_asym]) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   235
qed "Suc_lessI";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   236
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   237
Goal "Suc(m) < n ==> m<n";
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   238
by (etac rev_mp 1);
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   239
by (nat_ind_tac "n" 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   240
by (ALLGOALS (fast_tac (claset() addSIs [lessI RS less_SucI]
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   241
                                 addEs  [less_trans, lessE])));
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   242
qed "Suc_lessD";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   243
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   244
val [major,minor] = Goal 
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   245
    "[| Suc(i)<k;  !!j. [| i<j;  k=Suc(j) |] ==> P \
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   246
\    |] ==> P";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   247
by (rtac (major RS lessE) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   248
by (etac (lessI RS minor) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   249
by (etac (Suc_lessD RS minor) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   250
by (assume_tac 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   251
qed "Suc_lessE";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   252
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   253
Goal "Suc(m) < Suc(n) ==> m<n";
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   254
by (blast_tac (claset() addEs [lessE, make_elim Suc_lessD]) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   255
qed "Suc_less_SucD";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   256
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   257
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   258
Goal "(Suc(m) < Suc(n)) = (m<n)";
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   259
by (EVERY1 [rtac iffI, etac Suc_less_SucD, etac Suc_mono]);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   260
qed "Suc_less_eq";
8555
17325ee838ab Suc_less_eq now with AddIffs. How could this have been overlooked?
paulson
parents: 7064
diff changeset
   261
AddIffs [Suc_less_eq];
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   262
6109
82b50115564c Simplified arithmetic.
nipkow
parents: 6075
diff changeset
   263
(*Goal "~(Suc(n) < n)";
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   264
by (blast_tac (claset() addEs [Suc_lessD RS less_irrefl]) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   265
qed "not_Suc_n_less_n";
6109
82b50115564c Simplified arithmetic.
nipkow
parents: 6075
diff changeset
   266
Addsimps [not_Suc_n_less_n];*)
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   267
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   268
Goal "i<j ==> j<k --> Suc i < k";
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   269
by (nat_ind_tac "k" 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   270
by (ALLGOALS (asm_simp_tac (simpset())));
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   271
by (asm_simp_tac (simpset() addsimps [less_Suc_eq]) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   272
by (blast_tac (claset() addDs [Suc_lessD]) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   273
qed_spec_mp "less_trans_Suc";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   274
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   275
(*Can be used with less_Suc_eq to get n=m | n<m *)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   276
Goal "(~ m < n) = (n < Suc(m))";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   277
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   278
by (ALLGOALS Asm_simp_tac);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   279
qed "not_less_eq";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   280
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   281
(*Complete induction, aka course-of-values induction*)
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   282
val prems = Goalw [less_def]
9160
7a98dbf3e579 using the new theorem wf_not_refl; tidied
paulson
parents: 9108
diff changeset
   283
    "[| !!n. [| ALL m::nat. m<n --> P(m) |] ==> P(n) |]  ==>  P(n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   284
by (wf_ind_tac "n" [wf_pred_nat RS wf_trancl] 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   285
by (eresolve_tac prems 1);
9870
2374ba026fc6 less_induct -> nat_less_induct
nipkow
parents: 9160
diff changeset
   286
qed "nat_less_induct";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   287
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   288
(*** Properties of <= ***)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   289
5500
7e0ed3e31590 new theorem less_Suc_eq_le and le_simps
paulson
parents: 5478
diff changeset
   290
(*Was le_eq_less_Suc, but this orientation is more useful*)
7e0ed3e31590 new theorem less_Suc_eq_le and le_simps
paulson
parents: 5478
diff changeset
   291
Goalw [le_def] "(m < Suc n) = (m <= n)";
7e0ed3e31590 new theorem less_Suc_eq_le and le_simps
paulson
parents: 5478
diff changeset
   292
by (rtac (not_less_eq RS sym) 1);
7e0ed3e31590 new theorem less_Suc_eq_le and le_simps
paulson
parents: 5478
diff changeset
   293
qed "less_Suc_eq_le";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   294
3343
45986997f1fe Renamed lessD to Suc_leI
paulson
parents: 3308
diff changeset
   295
(*  m<=n ==> m < Suc n  *)
5500
7e0ed3e31590 new theorem less_Suc_eq_le and le_simps
paulson
parents: 5478
diff changeset
   296
bind_thm ("le_imp_less_Suc", less_Suc_eq_le RS iffD2);
3343
45986997f1fe Renamed lessD to Suc_leI
paulson
parents: 3308
diff changeset
   297
8942
6aad5381ba83 added type constraint ::nat because 0 is now overloaded
paulson
parents: 8741
diff changeset
   298
Goalw [le_def] "(0::nat) <= n";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   299
by (rtac not_less0 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   300
qed "le0";
6075
c148037f53c6 Remoaved a few now redundant rewrite rules.
nipkow
parents: 5983
diff changeset
   301
AddIffs [le0];
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   302
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   303
Goalw [le_def] "~ Suc n <= n";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   304
by (Simp_tac 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   305
qed "Suc_n_not_le_n";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   306
8942
6aad5381ba83 added type constraint ::nat because 0 is now overloaded
paulson
parents: 8741
diff changeset
   307
Goalw [le_def] "!!i::nat. (i <= 0) = (i = 0)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   308
by (nat_ind_tac "i" 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   309
by (ALLGOALS Asm_simp_tac);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   310
qed "le_0_eq";
4614
122015efd4e1 New AddIffs le_0_eq and neq0_conv
paulson
parents: 4599
diff changeset
   311
AddIffs [le_0_eq];
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   312
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   313
Goal "(m <= Suc(n)) = (m<=n | m = Suc n)";
5500
7e0ed3e31590 new theorem less_Suc_eq_le and le_simps
paulson
parents: 5478
diff changeset
   314
by (simp_tac (simpset() delsimps [less_Suc_eq_le]
7e0ed3e31590 new theorem less_Suc_eq_le and le_simps
paulson
parents: 5478
diff changeset
   315
			addsimps [less_Suc_eq_le RS sym, less_Suc_eq]) 1);
3355
0d955bcf8e0a New theorem le_Suc_eq
paulson
parents: 3343
diff changeset
   316
qed "le_Suc_eq";
0d955bcf8e0a New theorem le_Suc_eq
paulson
parents: 3343
diff changeset
   317
4614
122015efd4e1 New AddIffs le_0_eq and neq0_conv
paulson
parents: 4599
diff changeset
   318
(* [| m <= Suc n;  m <= n ==> R;  m = Suc n ==> R |] ==> R *)
122015efd4e1 New AddIffs le_0_eq and neq0_conv
paulson
parents: 4599
diff changeset
   319
bind_thm ("le_SucE", le_Suc_eq RS iffD1 RS disjE);
122015efd4e1 New AddIffs le_0_eq and neq0_conv
paulson
parents: 4599
diff changeset
   320
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   321
Goalw [le_def] "~n<m ==> m<=(n::nat)";
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   322
by (assume_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   323
qed "leI";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   324
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   325
Goalw [le_def] "m<=n ==> ~ n < (m::nat)";
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5187
diff changeset
   326
by (assume_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   327
qed "leD";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   328
9108
9fff97d29837 bind_thm(s);
wenzelm
parents: 8942
diff changeset
   329
bind_thm ("leE", make_elim leD);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   330
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   331
Goal "(~n<m) = (m<=(n::nat))";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   332
by (blast_tac (claset() addIs [leI] addEs [leE]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   333
qed "not_less_iff_le";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   334
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   335
Goalw [le_def] "~ m <= n ==> n<(m::nat)";
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   336
by (Blast_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   337
qed "not_leE";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   338
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   339
Goalw [le_def] "(~n<=m) = (m<(n::nat))";
4599
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   340
by (Simp_tac 1);
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   341
qed "not_le_iff_less";
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   342
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   343
Goalw [le_def] "m < n ==> Suc(m) <= n";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   344
by (simp_tac (simpset() addsimps [less_Suc_eq]) 1);
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   345
by (blast_tac (claset() addSEs [less_irrefl,less_asym]) 1);
3343
45986997f1fe Renamed lessD to Suc_leI
paulson
parents: 3308
diff changeset
   346
qed "Suc_leI";  (*formerly called lessD*)
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   347
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   348
Goalw [le_def] "Suc(m) <= n ==> m <= n";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   349
by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   350
qed "Suc_leD";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   351
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   352
(* stronger version of Suc_leD *)
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5143
diff changeset
   353
Goalw [le_def] "Suc m <= n ==> m < n";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   354
by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   355
by (cut_facts_tac [less_linear] 1);
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   356
by (Blast_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   357
qed "Suc_le_lessD";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   358
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   359
Goal "(Suc m <= n) = (m < n)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   360
by (blast_tac (claset() addIs [Suc_leI, Suc_le_lessD]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   361
qed "Suc_le_eq";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   362
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   363
Goalw [le_def] "m <= n ==> m <= Suc n";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   364
by (blast_tac (claset() addDs [Suc_lessD]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   365
qed "le_SucI";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   366
6109
82b50115564c Simplified arithmetic.
nipkow
parents: 6075
diff changeset
   367
(*bind_thm ("le_Suc", not_Suc_n_less_n RS leI);*)
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   368
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   369
Goalw [le_def] "m < n ==> m <= (n::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   370
by (blast_tac (claset() addEs [less_asym]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   371
qed "less_imp_le";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   372
5591
paulson
parents: 5500
diff changeset
   373
(*For instance, (Suc m < Suc n)  =   (Suc m <= n)  =  (m<n) *)
9108
9fff97d29837 bind_thm(s);
wenzelm
parents: 8942
diff changeset
   374
bind_thms ("le_simps", [less_imp_le, less_Suc_eq_le, Suc_le_eq]);
5591
paulson
parents: 5500
diff changeset
   375
5354
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   376
3343
45986997f1fe Renamed lessD to Suc_leI
paulson
parents: 3308
diff changeset
   377
(** Equivalence of m<=n and  m<n | m=n **)
45986997f1fe Renamed lessD to Suc_leI
paulson
parents: 3308
diff changeset
   378
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   379
Goalw [le_def] "m <= n ==> m < n | m=(n::nat)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   380
by (cut_facts_tac [less_linear] 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   381
by (blast_tac (claset() addEs [less_irrefl,less_asym]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   382
qed "le_imp_less_or_eq";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   383
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   384
Goalw [le_def] "m<n | m=n ==> m <=(n::nat)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   385
by (cut_facts_tac [less_linear] 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   386
by (blast_tac (claset() addSEs [less_irrefl] addEs [less_asym]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   387
qed "less_or_eq_imp_le";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   388
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   389
Goal "(m <= (n::nat)) = (m < n | m=n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   390
by (REPEAT(ares_tac [iffI,less_or_eq_imp_le,le_imp_less_or_eq] 1));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   391
qed "le_eq_less_or_eq";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   392
4635
c448e09d0fca New theorem eq_imp_le
paulson
parents: 4614
diff changeset
   393
(*Useful with Blast_tac.   m=n ==> m<=n *)
c448e09d0fca New theorem eq_imp_le
paulson
parents: 4614
diff changeset
   394
bind_thm ("eq_imp_le", disjI2 RS less_or_eq_imp_le);
c448e09d0fca New theorem eq_imp_le
paulson
parents: 4614
diff changeset
   395
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   396
Goal "n <= (n::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   397
by (simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   398
qed "le_refl";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   399
5354
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   400
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   401
Goal "[| i <= j; j < k |] ==> i < (k::nat)";
4468
paulson
parents: 4423
diff changeset
   402
by (blast_tac (claset() addSDs [le_imp_less_or_eq]
paulson
parents: 4423
diff changeset
   403
	                addIs [less_trans]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   404
qed "le_less_trans";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   405
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   406
Goal "[| i < j; j <= k |] ==> i < (k::nat)";
4468
paulson
parents: 4423
diff changeset
   407
by (blast_tac (claset() addSDs [le_imp_less_or_eq]
paulson
parents: 4423
diff changeset
   408
	                addIs [less_trans]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   409
qed "less_le_trans";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   410
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   411
Goal "[| i <= j; j <= k |] ==> i <= (k::nat)";
4468
paulson
parents: 4423
diff changeset
   412
by (blast_tac (claset() addSDs [le_imp_less_or_eq]
paulson
parents: 4423
diff changeset
   413
	                addIs [less_or_eq_imp_le, less_trans]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   414
qed "le_trans";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   415
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   416
Goal "[| m <= n; n <= m |] ==> m = (n::nat)";
4468
paulson
parents: 4423
diff changeset
   417
(*order_less_irrefl could make this proof fail*)
paulson
parents: 4423
diff changeset
   418
by (blast_tac (claset() addSDs [le_imp_less_or_eq]
paulson
parents: 4423
diff changeset
   419
	                addSEs [less_irrefl] addEs [less_asym]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   420
qed "le_anti_sym";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   421
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   422
Goal "(Suc(n) <= Suc(m)) = (n <= m)";
5500
7e0ed3e31590 new theorem less_Suc_eq_le and le_simps
paulson
parents: 5478
diff changeset
   423
by (simp_tac (simpset() addsimps le_simps) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   424
qed "Suc_le_mono";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   425
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   426
AddIffs [Suc_le_mono];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   427
5500
7e0ed3e31590 new theorem less_Suc_eq_le and le_simps
paulson
parents: 5478
diff changeset
   428
(* Axiom 'order_less_le' of class 'order': *)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   429
Goal "(m::nat) < n = (m <= n & m ~= n)";
4737
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   430
by (simp_tac (simpset() addsimps [le_def, nat_neq_iff]) 1);
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   431
by (blast_tac (claset() addSEs [less_asym]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   432
qed "nat_less_le";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   433
5354
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   434
(* [| m <= n; m ~= n |] ==> m < n *)
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   435
bind_thm ("le_neq_implies_less", [nat_less_le, conjI] MRS iffD2);
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   436
4640
ac6cf9f18653 Congruence rules use == in premises now.
nipkow
parents: 4635
diff changeset
   437
(* Axiom 'linorder_linear' of class 'linorder': *)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   438
Goal "(m::nat) <= n | n <= m";
4640
ac6cf9f18653 Congruence rules use == in premises now.
nipkow
parents: 4635
diff changeset
   439
by (simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1);
ac6cf9f18653 Congruence rules use == in premises now.
nipkow
parents: 4635
diff changeset
   440
by (cut_facts_tac [less_linear] 1);
5132
24f992a25adc isatool expandshort;
wenzelm
parents: 5069
diff changeset
   441
by (Blast_tac 1);
4640
ac6cf9f18653 Congruence rules use == in premises now.
nipkow
parents: 4635
diff changeset
   442
qed "nat_le_linear";
ac6cf9f18653 Congruence rules use == in premises now.
nipkow
parents: 4635
diff changeset
   443
5354
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   444
Goal "~ n < m ==> (n < Suc m) = (n = m)";
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   445
by (blast_tac (claset() addSEs [less_SucE]) 1);
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   446
qed "not_less_less_Suc_eq";
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   447
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   448
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   449
(*Rewrite (n < Suc m) to (n=m) if  ~ n<m or m<=n hold.
da63d9b35caf new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents: 5316
diff changeset
   450
  Not suitable as default simprules because they often lead to looping*)
9108
9fff97d29837 bind_thm(s);
wenzelm
parents: 8942
diff changeset
   451
bind_thms ("not_less_simps", [not_less_less_Suc_eq, leD RS not_less_less_Suc_eq]);
4640
ac6cf9f18653 Congruence rules use == in premises now.
nipkow
parents: 4635
diff changeset
   452
10706
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   453
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   454
(** Re-orientation of the equations 0=x and Suc n = x. *
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   455
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   456
  The condition "True" is a hack to prevent looping for e.g. Suc m = Suc n.
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   457
  Conditional rewrite rules are tried after unconditional ones.
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   458
**)
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   459
10711
a9f6994fb906 generalized the re-orientation 0f 0=... to all types
paulson
parents: 10706
diff changeset
   460
(*Polymorphic, not just for "nat"*)
a9f6994fb906 generalized the re-orientation 0f 0=... to all types
paulson
parents: 10706
diff changeset
   461
Goal "True ==> (0 = x) = (x = 0)";
10706
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   462
by Auto_tac;  
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   463
qed "zero_reorient";
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   464
Addsimps [zero_reorient];
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   465
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   466
Goal "True ==> (1 = x) = (x = 1)";
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   467
by Auto_tac;  
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   468
qed "one_reorient";
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   469
Addsimps [one_reorient];
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   470
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   471
Goal "True ==> (2 = x) = (x = 2)";
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   472
by Auto_tac;  
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   473
qed "two_reorient";
f02834001fca re-orienting equations with 0, 1, 2 on the lhs
paulson
parents: 10231
diff changeset
   474
Addsimps [two_reorient];