src/HOL/NatDef.ML
author paulson
Wed, 15 Jul 1998 10:15:13 +0200
changeset 5143 b94cd208f073
parent 5132 24f992a25adc
child 5148 74919e8f221c
permissions -rw-r--r--
Removal of leading "\!\!..." from most Goal commands
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
4737
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
     5
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
     6
Blast_tac proofs here can get PROOF FAILED of Ord theorems like order_refl
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
     7
and order_less_irrefl.  We do not add the "nat" versions to the basic claset
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
     8
because the type will be promoted to type class "order".
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
     9
*)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    10
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
    11
Goal "mono(%X. {Zero_Rep} Un (Suc_Rep``X))";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    12
by (REPEAT (ares_tac [monoI, subset_refl, image_mono, Un_mono] 1));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    13
qed "Nat_fun_mono";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    14
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    15
val Nat_unfold = Nat_fun_mono RS (Nat_def RS def_lfp_Tarski);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    16
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    17
(* Zero is a natural number -- this also justifies the type definition*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
    18
Goal "Zero_Rep: Nat";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    19
by (stac Nat_unfold 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    20
by (rtac (singletonI RS UnI1) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    21
qed "Zero_RepI";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    22
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    23
val prems = goal thy "i: Nat ==> Suc_Rep(i) : Nat";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    24
by (stac Nat_unfold 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    25
by (rtac (imageI RS UnI2) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    26
by (resolve_tac prems 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    27
qed "Suc_RepI";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    28
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    29
(*** Induction ***)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    30
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    31
val major::prems = goal thy
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    32
    "[| i: Nat;  P(Zero_Rep);   \
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    33
\       !!j. [| j: Nat; P(j) |] ==> P(Suc_Rep(j)) |]  ==> P(i)";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    34
by (rtac ([Nat_def, Nat_fun_mono, major] MRS def_induct) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
    35
by (blast_tac (claset() addIs prems) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    36
qed "Nat_induct";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    37
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    38
val prems = goalw thy [Zero_def,Suc_def]
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    39
    "[| P(0);   \
3040
7d48671753da Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents: 3023
diff changeset
    40
\       !!n. P(n) ==> P(Suc(n)) |]  ==> P(n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    41
by (rtac (Rep_Nat_inverse RS subst) 1);   (*types force good instantiation*)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    42
by (rtac (Rep_Nat RS Nat_induct) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    43
by (REPEAT (ares_tac prems 1
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    44
     ORELSE eresolve_tac [Abs_Nat_inverse RS subst] 1));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    45
qed "nat_induct";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    46
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    47
(*Perform induction on n. *)
3563
c4f13747489f Uses new version of Datatype.occs_in_prems
paulson
parents: 3484
diff changeset
    48
local fun raw_nat_ind_tac a i = 
c4f13747489f Uses new version of Datatype.occs_in_prems
paulson
parents: 3484
diff changeset
    49
    res_inst_tac [("n",a)] nat_induct i  THEN  rename_last_tac a [""] (i+1)
c4f13747489f Uses new version of Datatype.occs_in_prems
paulson
parents: 3484
diff changeset
    50
in
c4f13747489f Uses new version of Datatype.occs_in_prems
paulson
parents: 3484
diff changeset
    51
val nat_ind_tac = Datatype.occs_in_prems raw_nat_ind_tac
c4f13747489f Uses new version of Datatype.occs_in_prems
paulson
parents: 3484
diff changeset
    52
end;
3040
7d48671753da Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents: 3023
diff changeset
    53
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    54
(*A special form of induction for reasoning about m<n and m-n*)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    55
val prems = goal thy
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    56
    "[| !!x. P x 0;  \
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    57
\       !!y. P 0 (Suc y);  \
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    58
\       !!x y. [| P x y |] ==> P (Suc x) (Suc y)  \
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    59
\    |] ==> P m n";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    60
by (res_inst_tac [("x","m")] spec 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    61
by (nat_ind_tac "n" 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    62
by (rtac allI 2);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    63
by (nat_ind_tac "x" 2);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    64
by (REPEAT (ares_tac (prems@[allI]) 1 ORELSE etac spec 1));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    65
qed "diff_induct";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    66
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    67
(*Case analysis on the natural numbers*)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    68
val prems = goal thy 
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    69
    "[| n=0 ==> P;  !!x. n = Suc(x) ==> P |] ==> P";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    70
by (subgoal_tac "n=0 | (EX x. n = Suc(x))" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
    71
by (fast_tac (claset() addSEs prems) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    72
by (nat_ind_tac "n" 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    73
by (rtac (refl RS disjI1) 1);
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
    74
by (Blast_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    75
qed "natE";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    76
3282
c31e6239d4c9 Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents: 3236
diff changeset
    77
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    78
(*** Isomorphisms: Abs_Nat and Rep_Nat ***)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    79
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    80
(*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
    81
  since we assume the isomorphism equations will one day be given by Isabelle*)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    82
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
    83
Goal "inj(Rep_Nat)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    84
by (rtac inj_inverseI 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    85
by (rtac Rep_Nat_inverse 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    86
qed "inj_Rep_Nat";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    87
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
    88
Goal "inj_on Abs_Nat Nat";
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4821
diff changeset
    89
by (rtac inj_on_inverseI 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    90
by (etac Abs_Nat_inverse 1);
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4821
diff changeset
    91
qed "inj_on_Abs_Nat";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    92
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    93
(*** Distinctness of constructors ***)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    94
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
    95
Goalw [Zero_def,Suc_def] "Suc(m) ~= 0";
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4821
diff changeset
    96
by (rtac (inj_on_Abs_Nat RS inj_on_contraD) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    97
by (rtac Suc_Rep_not_Zero_Rep 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    98
by (REPEAT (resolve_tac [Rep_Nat, Suc_RepI, Zero_RepI] 1));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
    99
qed "Suc_not_Zero";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   100
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   101
bind_thm ("Zero_not_Suc", Suc_not_Zero RS not_sym);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   102
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   103
AddIffs [Suc_not_Zero,Zero_not_Suc];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   104
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   105
bind_thm ("Suc_neq_Zero", (Suc_not_Zero RS notE));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   106
val Zero_neq_Suc = sym RS Suc_neq_Zero;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   107
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   108
(** Injectiveness of Suc **)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   109
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   110
Goalw [Suc_def] "inj(Suc)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   111
by (rtac injI 1);
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4821
diff changeset
   112
by (dtac (inj_on_Abs_Nat RS inj_onD) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   113
by (REPEAT (resolve_tac [Rep_Nat, Suc_RepI] 1));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   114
by (dtac (inj_Suc_Rep RS injD) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   115
by (etac (inj_Rep_Nat RS injD) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   116
qed "inj_Suc";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   117
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   118
val Suc_inject = inj_Suc RS injD;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   119
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   120
Goal "(Suc(m)=Suc(n)) = (m=n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   121
by (EVERY1 [rtac iffI, etac Suc_inject, etac arg_cong]); 
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   122
qed "Suc_Suc_eq";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   123
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   124
AddIffs [Suc_Suc_eq];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   125
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   126
Goal "n ~= Suc(n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   127
by (nat_ind_tac "n" 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   128
by (ALLGOALS Asm_simp_tac);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   129
qed "n_not_Suc_n";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   130
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   131
bind_thm ("Suc_n_not_n", n_not_Suc_n RS not_sym);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   132
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   133
Goal "n ~= 0 ==> EX m. n = Suc m";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3378
diff changeset
   134
by (rtac natE 1);
3236
882e125ed7da New pattern-matching definition of pred_nat
paulson
parents: 3143
diff changeset
   135
by (REPEAT (Blast_tac 1));
882e125ed7da New pattern-matching definition of pred_nat
paulson
parents: 3143
diff changeset
   136
qed "not0_implies_Suc";
882e125ed7da New pattern-matching definition of pred_nat
paulson
parents: 3143
diff changeset
   137
882e125ed7da New pattern-matching definition of pred_nat
paulson
parents: 3143
diff changeset
   138
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   139
(*** nat_case -- the selection operator for nat ***)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   140
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   141
Goalw [nat_case_def] "nat_case a f 0 = a";
4535
f24cebc299e4 added select_equality to the implicit claset
oheimb
parents: 4468
diff changeset
   142
by (Blast_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   143
qed "nat_case_0";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   144
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   145
Goalw [nat_case_def] "nat_case a f (Suc k) = f(k)";
4535
f24cebc299e4 added select_equality to the implicit claset
oheimb
parents: 4468
diff changeset
   146
by (Blast_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   147
qed "nat_case_Suc";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   148
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   149
Goalw [wf_def, pred_nat_def] "wf(pred_nat)";
3718
d78cf498a88c Minor tidying to use Clarify_tac, etc.
paulson
parents: 3563
diff changeset
   150
by (Clarify_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   151
by (nat_ind_tac "x" 1);
3236
882e125ed7da New pattern-matching definition of pred_nat
paulson
parents: 3143
diff changeset
   152
by (ALLGOALS Blast_tac);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   153
qed "wf_pred_nat";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   154
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   155
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   156
(*** nat_rec -- by wf recursion on pred_nat ***)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   157
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   158
(* The unrolling rule for nat_rec *)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   159
Goal
4821
bfbaea156f43 Modifications due to improved simplifier.
nipkow
parents: 4745
diff changeset
   160
   "nat_rec c d = wfrec pred_nat (%f. nat_case c (%m. d m (f m)))";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   161
  by (simp_tac (HOL_ss addsimps [nat_rec_def]) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   162
bind_thm("nat_rec_unfold", wf_pred_nat RS 
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   163
                            ((result() RS eq_reflection) RS def_wfrec));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   164
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   165
(*---------------------------------------------------------------------------
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   166
 * Old:
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   167
 * bind_thm ("nat_rec_unfold", (wf_pred_nat RS (nat_rec_def RS def_wfrec))); 
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   168
 *---------------------------------------------------------------------------*)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   169
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   170
(** conversion rules **)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   171
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   172
Goal "nat_rec c h 0 = c";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   173
by (rtac (nat_rec_unfold RS trans) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   174
by (simp_tac (simpset() addsimps [nat_case_0]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   175
qed "nat_rec_0";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   176
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   177
Goal "nat_rec c h (Suc n) = h n (nat_rec c h n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   178
by (rtac (nat_rec_unfold RS trans) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   179
by (simp_tac (simpset() addsimps [nat_case_Suc, pred_nat_def, cut_apply]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   180
qed "nat_rec_Suc";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   181
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   182
(*These 2 rules ease the use of primitive recursion.  NOTE USE OF == *)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   183
val [rew] = goal thy
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   184
    "[| !!n. f(n) == nat_rec c h n |] ==> f(0) = c";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   185
by (rewtac rew);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   186
by (rtac nat_rec_0 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   187
qed "def_nat_rec_0";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   188
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   189
val [rew] = goal thy
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   190
    "[| !!n. f(n) == nat_rec c h n |] ==> f(Suc(n)) = h n (f n)";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   191
by (rewtac rew);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   192
by (rtac nat_rec_Suc 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   193
qed "def_nat_rec_Suc";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   194
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   195
fun nat_recs def =
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   196
      [standard (def RS def_nat_rec_0),
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   197
       standard (def RS def_nat_rec_Suc)];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   198
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   199
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   200
(*** Basic properties of "less than" ***)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   201
3378
11f4884a071a Moved "less_eq" to NatDef from Arith
paulson
parents: 3355
diff changeset
   202
(*Used in TFL/post.sml*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   203
Goalw [less_def] "(m,n) : pred_nat^+ = (m<n)";
3378
11f4884a071a Moved "less_eq" to NatDef from Arith
paulson
parents: 3355
diff changeset
   204
by (rtac refl 1);
11f4884a071a Moved "less_eq" to NatDef from Arith
paulson
parents: 3355
diff changeset
   205
qed "less_eq";
11f4884a071a Moved "less_eq" to NatDef from Arith
paulson
parents: 3355
diff changeset
   206
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   207
(** Introduction properties **)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   208
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   209
val prems = goalw thy [less_def] "[| i<j;  j<k |] ==> i<(k::nat)";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   210
by (rtac (trans_trancl RS transD) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   211
by (resolve_tac prems 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   212
by (resolve_tac prems 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   213
qed "less_trans";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   214
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   215
Goalw [less_def, pred_nat_def] "n < Suc(n)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   216
by (simp_tac (simpset() addsimps [r_into_trancl]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   217
qed "lessI";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   218
AddIffs [lessI];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   219
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   220
(* i<j ==> i<Suc(j) *)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   221
bind_thm("less_SucI", lessI RSN (2, less_trans));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   222
Addsimps [less_SucI];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   223
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   224
Goal "0 < Suc(n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   225
by (nat_ind_tac "n" 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   226
by (rtac lessI 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   227
by (etac less_trans 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   228
by (rtac lessI 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   229
qed "zero_less_Suc";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   230
AddIffs [zero_less_Suc];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   231
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   232
(** Elimination properties **)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   233
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   234
val prems = goalw thy [less_def] "n<m ==> ~ m<(n::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   235
by (blast_tac (claset() addIs ([wf_pred_nat, wf_trancl RS wf_asym]@prems))1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   236
qed "less_not_sym";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   237
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   238
(* [| n<m; m<n |] ==> R *)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   239
bind_thm ("less_asym", (less_not_sym RS notE));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   240
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   241
Goalw [less_def] "~ n<(n::nat)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   242
by (rtac notI 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   243
by (etac (wf_pred_nat RS wf_trancl RS wf_irrefl) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   244
qed "less_not_refl";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   245
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   246
(* n<n ==> R *)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   247
bind_thm ("less_irrefl", (less_not_refl RS notE));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   248
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   249
Goal "n<m ==> m ~= (n::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   250
by (blast_tac (claset() addSEs [less_irrefl]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   251
qed "less_not_refl2";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   252
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   253
3236
882e125ed7da New pattern-matching definition of pred_nat
paulson
parents: 3143
diff changeset
   254
val major::prems = goalw thy [less_def, pred_nat_def]
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   255
    "[| i<k;  k=Suc(i) ==> P;  !!j. [| i<j;  k=Suc(j) |] ==> P \
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   256
\    |] ==> P";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   257
by (rtac (major RS tranclE) 1);
3236
882e125ed7da New pattern-matching definition of pred_nat
paulson
parents: 3143
diff changeset
   258
by (ALLGOALS Full_simp_tac); 
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   259
by (REPEAT_FIRST (bound_hyp_subst_tac ORELSE'
3236
882e125ed7da New pattern-matching definition of pred_nat
paulson
parents: 3143
diff changeset
   260
                  eresolve_tac (prems@[asm_rl, Pair_inject])));
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   261
qed "lessE";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   262
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   263
Goal "~ n<0";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   264
by (rtac notI 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   265
by (etac lessE 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   266
by (etac Zero_neq_Suc 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   267
by (etac Zero_neq_Suc 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   268
qed "not_less0";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   269
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   270
AddIffs [not_less0];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   271
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   272
(* n<0 ==> R *)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   273
bind_thm ("less_zeroE", not_less0 RS notE);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   274
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   275
val [major,less,eq] = goal thy
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   276
    "[| m < Suc(n);  m<n ==> P;  m=n ==> P |] ==> P";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   277
by (rtac (major RS lessE) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   278
by (rtac eq 1);
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   279
by (Blast_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   280
by (rtac less 1);
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   281
by (Blast_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   282
qed "less_SucE";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   283
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   284
Goal "(m < Suc(n)) = (m < n | m = n)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   285
by (blast_tac (claset() addSEs [less_SucE] addIs [less_trans]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   286
qed "less_Suc_eq";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   287
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   288
Goal "(n<1) = (n=0)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   289
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
   290
qed "less_one";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   291
AddIffs [less_one];
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   292
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   293
val prems = goal thy "m<n ==> n ~= 0";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   294
by (res_inst_tac [("n","n")] natE 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   295
by (cut_facts_tac prems 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   296
by (ALLGOALS Asm_full_simp_tac);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   297
qed "gr_implies_not0";
4356
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4153
diff changeset
   298
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   299
Goal "(n ~= 0) = (0 < n)";
4423
a129b817b58a expandshort;
wenzelm
parents: 4356
diff changeset
   300
by (rtac natE 1);
4737
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   301
by (Blast_tac 1);
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   302
by (Blast_tac 1);
4356
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4153
diff changeset
   303
qed "neq0_conv";
4614
122015efd4e1 New AddIffs le_0_eq and neq0_conv
paulson
parents: 4599
diff changeset
   304
AddIffs [neq0_conv];
122015efd4e1 New AddIffs le_0_eq and neq0_conv
paulson
parents: 4599
diff changeset
   305
4635
c448e09d0fca New theorem eq_imp_le
paulson
parents: 4614
diff changeset
   306
(*This theorem is useful with blast_tac: (n=0 ==> False) ==> 0<n *)
c448e09d0fca New theorem eq_imp_le
paulson
parents: 4614
diff changeset
   307
bind_thm ("gr0I", [neq0_conv, notI] MRS iffD1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   308
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   309
Goal "(~(0 < n)) = (n=0)";
4423
a129b817b58a expandshort;
wenzelm
parents: 4356
diff changeset
   310
by (rtac iffI 1);
a129b817b58a expandshort;
wenzelm
parents: 4356
diff changeset
   311
 by (etac swap 1);
a129b817b58a expandshort;
wenzelm
parents: 4356
diff changeset
   312
 by (ALLGOALS Asm_full_simp_tac);
4356
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4153
diff changeset
   313
qed "not_gr0";
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4153
diff changeset
   314
Addsimps [not_gr0];
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4153
diff changeset
   315
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   316
Goal "m<n ==> 0 < n";
4356
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4153
diff changeset
   317
by (dtac gr_implies_not0 1);
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4153
diff changeset
   318
by (Asm_full_simp_tac 1);
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4153
diff changeset
   319
qed "gr_implies_gr0";
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4153
diff changeset
   320
Addsimps [gr_implies_gr0];
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4153
diff changeset
   321
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   322
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   323
Goal "m<n ==> Suc(m) < Suc(n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   324
by (etac rev_mp 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   325
by (nat_ind_tac "n" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   326
by (ALLGOALS (fast_tac (claset() addEs  [less_trans, lessE])));
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   327
qed "Suc_mono";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   328
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   329
(*"Less than" is a linear ordering*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   330
Goal "m<n | m=n | n<(m::nat)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   331
by (nat_ind_tac "m" 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   332
by (nat_ind_tac "n" 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   333
by (rtac (refl RS disjI1 RS disjI2) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   334
by (rtac (zero_less_Suc RS disjI1) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   335
by (blast_tac (claset() addIs [Suc_mono, less_SucI] addEs [lessE]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   336
qed "less_linear";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   337
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   338
Goal "!!m::nat. (m ~= n) = (m<n | n<m)";
4737
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   339
by (cut_facts_tac [less_linear] 1);
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   340
by (blast_tac (claset() addSEs [less_irrefl]) 1);
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   341
qed "nat_neq_iff";
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   342
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   343
qed_goal "nat_less_cases" thy 
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   344
   "[| (m::nat)<n ==> P n m; m=n ==> P n m; n<m ==> P n m |] ==> P n m"
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2922
diff changeset
   345
( fn [major,eqCase,lessCase] =>
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   346
        [
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2922
diff changeset
   347
        (rtac (less_linear RS disjE) 1),
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   348
        (etac disjE 2),
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2922
diff changeset
   349
        (etac lessCase 1),
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2922
diff changeset
   350
        (etac (sym RS eqCase) 1),
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2922
diff changeset
   351
        (etac major 1)
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   352
        ]);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   353
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   354
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   355
(** Inductive (?) properties **)
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   356
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   357
Goal "[| m<n; Suc m ~= n |] ==> Suc(m) < n";
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   358
by (full_simp_tac (simpset() addsimps [nat_neq_iff]) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   359
by (blast_tac (claset() addSEs [less_irrefl, less_SucE] addEs [less_asym]) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   360
qed "Suc_lessI";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   361
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   362
val [prem] = goal thy "Suc(m) < n ==> m<n";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   363
by (rtac (prem RS rev_mp) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   364
by (nat_ind_tac "n" 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   365
by (ALLGOALS (fast_tac (claset() addSIs [lessI RS less_SucI]
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   366
                                 addEs  [less_trans, lessE])));
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   367
qed "Suc_lessD";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   368
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   369
val [major,minor] = goal thy 
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   370
    "[| Suc(i)<k;  !!j. [| i<j;  k=Suc(j) |] ==> P \
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   371
\    |] ==> P";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   372
by (rtac (major RS lessE) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   373
by (etac (lessI RS minor) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   374
by (etac (Suc_lessD RS minor) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   375
by (assume_tac 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   376
qed "Suc_lessE";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   377
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   378
Goal "Suc(m) < Suc(n) ==> m<n";
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   379
by (blast_tac (claset() addEs [lessE, make_elim Suc_lessD]) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   380
qed "Suc_less_SucD";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   381
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   382
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   383
Goal "(Suc(m) < Suc(n)) = (m<n)";
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   384
by (EVERY1 [rtac iffI, etac Suc_less_SucD, etac Suc_mono]);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   385
qed "Suc_less_eq";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   386
Addsimps [Suc_less_eq];
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   387
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   388
Goal "~(Suc(n) < n)";
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   389
by (blast_tac (claset() addEs [Suc_lessD RS less_irrefl]) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   390
qed "not_Suc_n_less_n";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   391
Addsimps [not_Suc_n_less_n];
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   392
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   393
Goal "i<j ==> j<k --> Suc i < k";
4745
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   394
by (nat_ind_tac "k" 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   395
by (ALLGOALS (asm_simp_tac (simpset())));
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   396
by (asm_simp_tac (simpset() addsimps [less_Suc_eq]) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   397
by (blast_tac (claset() addDs [Suc_lessD]) 1);
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   398
qed_spec_mp "less_trans_Suc";
b855a7094195 re-ordered proofs
paulson
parents: 4737
diff changeset
   399
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   400
(*Can be used with less_Suc_eq to get n=m | n<m *)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   401
Goal "(~ m < n) = (n < Suc(m))";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   402
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   403
by (ALLGOALS Asm_simp_tac);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   404
qed "not_less_eq";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   405
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   406
(*Complete induction, aka course-of-values induction*)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   407
val prems = goalw thy [less_def]
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   408
    "[| !!n. [| ! m::nat. m<n --> P(m) |] ==> P(n) |]  ==>  P(n)";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   409
by (wf_ind_tac "n" [wf_pred_nat RS wf_trancl] 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   410
by (eresolve_tac prems 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   411
qed "less_induct";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   412
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   413
qed_goal "nat_induct2" thy 
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   414
"[| P 0; P 1; !!k. P k ==> P (Suc (Suc k)) |] ==> P n" (fn prems => [
3023
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   415
        cut_facts_tac prems 1,
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   416
        rtac less_induct 1,
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   417
        res_inst_tac [("n","n")] natE 1,
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   418
         hyp_subst_tac 1,
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   419
         atac 1,
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   420
        hyp_subst_tac 1,
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   421
        res_inst_tac [("n","x")] natE 1,
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   422
         hyp_subst_tac 1,
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   423
         atac 1,
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   424
        hyp_subst_tac 1,
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   425
        resolve_tac prems 1,
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   426
        dtac spec 1,
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   427
        etac mp 1,
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   428
        rtac (lessI RS less_trans) 1,
01364e2f30ad Ran expandshort
paulson
parents: 2935
diff changeset
   429
        rtac (lessI RS Suc_mono) 1]);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   430
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   431
(*** Properties of <= ***)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   432
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   433
Goalw [le_def] "(m <= n) = (m < Suc n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   434
by (rtac not_less_eq 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   435
qed "le_eq_less_Suc";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   436
3343
45986997f1fe Renamed lessD to Suc_leI
paulson
parents: 3308
diff changeset
   437
(*  m<=n ==> m < Suc n  *)
45986997f1fe Renamed lessD to Suc_leI
paulson
parents: 3308
diff changeset
   438
bind_thm ("le_imp_less_Suc", le_eq_less_Suc RS iffD1);
45986997f1fe Renamed lessD to Suc_leI
paulson
parents: 3308
diff changeset
   439
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   440
Goalw [le_def] "0 <= n";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   441
by (rtac not_less0 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   442
qed "le0";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   443
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   444
Goalw [le_def] "~ Suc n <= n";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   445
by (Simp_tac 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   446
qed "Suc_n_not_le_n";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   447
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   448
Goalw [le_def] "(i <= 0) = (i = 0)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   449
by (nat_ind_tac "i" 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   450
by (ALLGOALS Asm_simp_tac);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   451
qed "le_0_eq";
4614
122015efd4e1 New AddIffs le_0_eq and neq0_conv
paulson
parents: 4599
diff changeset
   452
AddIffs [le_0_eq];
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   453
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   454
Addsimps [(*less_Suc_eq, makes simpset non-confluent*) le0, le_0_eq,
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   455
          Suc_n_not_le_n,
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   456
          n_not_Suc_n, Suc_n_not_n,
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   457
          nat_case_0, nat_case_Suc, nat_rec_0, nat_rec_Suc];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   458
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   459
Goal "(m <= Suc(n)) = (m<=n | m = Suc n)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   460
by (simp_tac (simpset() addsimps [le_eq_less_Suc]) 1);
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   461
by (blast_tac (claset() addSEs [less_SucE] addIs [less_SucI]) 1);
3355
0d955bcf8e0a New theorem le_Suc_eq
paulson
parents: 3343
diff changeset
   462
qed "le_Suc_eq";
0d955bcf8e0a New theorem le_Suc_eq
paulson
parents: 3343
diff changeset
   463
4614
122015efd4e1 New AddIffs le_0_eq and neq0_conv
paulson
parents: 4599
diff changeset
   464
(* [| 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
   465
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
   466
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   467
(*
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   468
Goal "(Suc m < n | Suc m = n) = (m < n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   469
by (stac (less_Suc_eq RS sym) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   470
by (rtac Suc_less_eq 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   471
qed "Suc_le_eq";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   472
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   473
this could make the simpset (with less_Suc_eq added again) more confluent,
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   474
but less_Suc_eq makes additional problems with terms of the form 0 < Suc (...)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   475
*)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   476
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   477
(*Prevents simplification of f and g: much faster*)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   478
qed_goal "nat_case_weak_cong" thy
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   479
  "m=n ==> nat_case a f m = nat_case a f n"
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   480
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   481
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   482
qed_goal "nat_rec_weak_cong" thy
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   483
  "m=n ==> nat_rec a f m = nat_rec a f n"
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   484
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   485
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4821
diff changeset
   486
qed_goal "split_nat_case" thy
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   487
  "P(nat_case z s n) = ((n=0 --> P z) & (!m. n = Suc m --> P(s m)))"
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   488
  (fn _ => [nat_ind_tac "n" 1, ALLGOALS Asm_simp_tac]);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   489
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   490
val prems = goalw thy [le_def] "~n<m ==> m<=(n::nat)";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   491
by (resolve_tac prems 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   492
qed "leI";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   493
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   494
val prems = goalw thy [le_def] "m<=n ==> ~ n < (m::nat)";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   495
by (resolve_tac prems 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   496
qed "leD";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   497
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   498
val leE = make_elim leD;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   499
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   500
Goal "(~n<m) = (m<=(n::nat))";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   501
by (blast_tac (claset() addIs [leI] addEs [leE]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   502
qed "not_less_iff_le";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   503
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   504
Goalw [le_def] "~ m <= n ==> n<(m::nat)";
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   505
by (Blast_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   506
qed "not_leE";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   507
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   508
Goalw [le_def] "(~n<=m) = (m<(n::nat))";
4599
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   509
by (Simp_tac 1);
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   510
qed "not_le_iff_less";
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   511
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   512
Goalw [le_def] "m < n ==> Suc(m) <= n";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   513
by (simp_tac (simpset() addsimps [less_Suc_eq]) 1);
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   514
by (blast_tac (claset() addSEs [less_irrefl,less_asym]) 1);
3343
45986997f1fe Renamed lessD to Suc_leI
paulson
parents: 3308
diff changeset
   515
qed "Suc_leI";  (*formerly called lessD*)
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   516
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   517
Goalw [le_def] "Suc(m) <= n ==> m <= n";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   518
by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   519
qed "Suc_leD";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   520
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   521
(* stronger version of Suc_leD *)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   522
Goalw [le_def] 
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   523
        "!!m. Suc m <= n ==> m < n";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   524
by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   525
by (cut_facts_tac [less_linear] 1);
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   526
by (Blast_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   527
qed "Suc_le_lessD";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   528
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   529
Goal "(Suc m <= n) = (m < n)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   530
by (blast_tac (claset() addIs [Suc_leI, Suc_le_lessD]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   531
qed "Suc_le_eq";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   532
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   533
Goalw [le_def] "m <= n ==> m <= Suc n";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   534
by (blast_tac (claset() addDs [Suc_lessD]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   535
qed "le_SucI";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   536
Addsimps[le_SucI];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   537
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   538
bind_thm ("le_Suc", not_Suc_n_less_n RS leI);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   539
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   540
Goalw [le_def] "m < n ==> m <= (n::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   541
by (blast_tac (claset() addEs [less_asym]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   542
qed "less_imp_le";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   543
3343
45986997f1fe Renamed lessD to Suc_leI
paulson
parents: 3308
diff changeset
   544
(** Equivalence of m<=n and  m<n | m=n **)
45986997f1fe Renamed lessD to Suc_leI
paulson
parents: 3308
diff changeset
   545
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   546
Goalw [le_def] "m <= n ==> m < n | m=(n::nat)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   547
by (cut_facts_tac [less_linear] 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   548
by (blast_tac (claset() addEs [less_irrefl,less_asym]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   549
qed "le_imp_less_or_eq";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   550
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   551
Goalw [le_def] "m<n | m=n ==> m <=(n::nat)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   552
by (cut_facts_tac [less_linear] 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   553
by (blast_tac (claset() addSEs [less_irrefl] addEs [less_asym]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   554
qed "less_or_eq_imp_le";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   555
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   556
Goal "(m <= (n::nat)) = (m < n | m=n)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   557
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
   558
qed "le_eq_less_or_eq";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   559
4635
c448e09d0fca New theorem eq_imp_le
paulson
parents: 4614
diff changeset
   560
(*Useful with Blast_tac.   m=n ==> m<=n *)
c448e09d0fca New theorem eq_imp_le
paulson
parents: 4614
diff changeset
   561
bind_thm ("eq_imp_le", disjI2 RS less_or_eq_imp_le);
c448e09d0fca New theorem eq_imp_le
paulson
parents: 4614
diff changeset
   562
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   563
Goal "n <= (n::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   564
by (simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   565
qed "le_refl";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   566
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   567
Goal "[| i <= j; j < k |] ==> i < (k::nat)";
4468
paulson
parents: 4423
diff changeset
   568
by (blast_tac (claset() addSDs [le_imp_less_or_eq]
paulson
parents: 4423
diff changeset
   569
	                addIs [less_trans]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   570
qed "le_less_trans";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   571
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   572
Goal "[| i < j; j <= k |] ==> i < (k::nat)";
4468
paulson
parents: 4423
diff changeset
   573
by (blast_tac (claset() addSDs [le_imp_less_or_eq]
paulson
parents: 4423
diff changeset
   574
	                addIs [less_trans]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   575
qed "less_le_trans";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   576
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   577
Goal "[| i <= j; j <= k |] ==> i <= (k::nat)";
4468
paulson
parents: 4423
diff changeset
   578
by (blast_tac (claset() addSDs [le_imp_less_or_eq]
paulson
parents: 4423
diff changeset
   579
	                addIs [less_or_eq_imp_le, less_trans]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   580
qed "le_trans";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   581
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5132
diff changeset
   582
Goal "[| m <= n; n <= m |] ==> m = (n::nat)";
4468
paulson
parents: 4423
diff changeset
   583
(*order_less_irrefl could make this proof fail*)
paulson
parents: 4423
diff changeset
   584
by (blast_tac (claset() addSDs [le_imp_less_or_eq]
paulson
parents: 4423
diff changeset
   585
	                addSEs [less_irrefl] addEs [less_asym]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   586
qed "le_anti_sym";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   587
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   588
Goal "(Suc(n) <= Suc(m)) = (n <= m)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   589
by (simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   590
qed "Suc_le_mono";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   591
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   592
AddIffs [Suc_le_mono];
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   593
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   594
(* Axiom 'order_le_less' of class 'order': *)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   595
Goal "(m::nat) < n = (m <= n & m ~= n)";
4737
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   596
by (simp_tac (simpset() addsimps [le_def, nat_neq_iff]) 1);
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   597
by (blast_tac (claset() addSEs [less_asym]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   598
qed "nat_less_le";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   599
4640
ac6cf9f18653 Congruence rules use == in premises now.
nipkow
parents: 4635
diff changeset
   600
(* Axiom 'linorder_linear' of class 'linorder': *)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   601
Goal "(m::nat) <= n | n <= m";
4640
ac6cf9f18653 Congruence rules use == in premises now.
nipkow
parents: 4635
diff changeset
   602
by (simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1);
ac6cf9f18653 Congruence rules use == in premises now.
nipkow
parents: 4635
diff changeset
   603
by (cut_facts_tac [less_linear] 1);
5132
24f992a25adc isatool expandshort;
wenzelm
parents: 5069
diff changeset
   604
by (Blast_tac 1);
4640
ac6cf9f18653 Congruence rules use == in premises now.
nipkow
parents: 4635
diff changeset
   605
qed "nat_le_linear";
ac6cf9f18653 Congruence rules use == in premises now.
nipkow
parents: 4635
diff changeset
   606
ac6cf9f18653 Congruence rules use == in premises now.
nipkow
parents: 4635
diff changeset
   607
ac6cf9f18653 Congruence rules use == in premises now.
nipkow
parents: 4635
diff changeset
   608
(** max
4599
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   609
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   610
Goalw [max_def] "!!z::nat. (z <= max x y) = (z <= x | z <= y)";
4686
74a12e86b20b Removed `addsplits [expand_if]'
nipkow
parents: 4640
diff changeset
   611
by (simp_tac (simpset() addsimps [not_le_iff_less]) 1);
4599
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   612
by (blast_tac (claset() addIs [less_imp_le, le_trans]) 1);
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   613
qed "le_max_iff_disj";
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   614
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   615
Goalw [max_def] "!!z::nat. (max x y <= z) = (x <= z & y <= z)";
4686
74a12e86b20b Removed `addsplits [expand_if]'
nipkow
parents: 4640
diff changeset
   616
by (simp_tac (simpset() addsimps [not_le_iff_less]) 1);
4599
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   617
by (blast_tac (claset() addIs [less_imp_le, le_trans]) 1);
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   618
qed "max_le_iff_conj";
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   619
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   620
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   621
(** min **)
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   622
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   623
Goalw [min_def] "!!z::nat. (z <= min x y) = (z <= x & z <= y)";
4686
74a12e86b20b Removed `addsplits [expand_if]'
nipkow
parents: 4640
diff changeset
   624
by (simp_tac (simpset() addsimps [not_le_iff_less]) 1);
4599
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   625
by (blast_tac (claset() addIs [less_imp_le, le_trans]) 1);
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   626
qed "le_min_iff_conj";
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   627
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   628
Goalw [min_def] "!!z::nat. (min x y <= z) = (x <= z | y <= z)";
4686
74a12e86b20b Removed `addsplits [expand_if]'
nipkow
parents: 4640
diff changeset
   629
by (simp_tac (simpset() addsimps [not_le_iff_less] addsplits) 1);
4599
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   630
by (blast_tac (claset() addIs [less_imp_le, le_trans]) 1);
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   631
qed "min_le_iff_disj";
4640
ac6cf9f18653 Congruence rules use == in premises now.
nipkow
parents: 4635
diff changeset
   632
 **)
4599
3a4348a3d6ff New max, min theorems
paulson
parents: 4535
diff changeset
   633
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   634
(** LEAST -- the least number operator **)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   635
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   636
Goal "(! m::nat. P m --> n <= m) = (! m. m < n --> ~ P m)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   637
by (blast_tac (claset() addIs [leI] addEs [leE]) 1);
3143
d60e49b86c6a Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents: 3085
diff changeset
   638
val lemma = result();
d60e49b86c6a Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents: 3085
diff changeset
   639
d60e49b86c6a Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents: 3085
diff changeset
   640
(* This is an old def of Least for nat, which is derived for compatibility *)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   641
Goalw [Least_def]
3143
d60e49b86c6a Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents: 3085
diff changeset
   642
  "(LEAST n::nat. P n) == (@n. P(n) & (ALL m. m < n --> ~P(m)))";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   643
by (simp_tac (simpset() addsimps [lemma]) 1);
3143
d60e49b86c6a Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents: 3085
diff changeset
   644
qed "Least_nat_def";
d60e49b86c6a Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents: 3085
diff changeset
   645
d60e49b86c6a Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents: 3085
diff changeset
   646
val [prem1,prem2] = goalw thy [Least_nat_def]
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3768
diff changeset
   647
    "[| P(k::nat);  !!x. x<k ==> ~P(x) |] ==> (LEAST x. P(x)) = k";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   648
by (rtac select_equality 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   649
by (blast_tac (claset() addSIs [prem1,prem2]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   650
by (cut_facts_tac [less_linear] 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   651
by (blast_tac (claset() addSIs [prem1] addSDs [prem2]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   652
qed "Least_equality";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   653
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3768
diff changeset
   654
val [prem] = goal thy "P(k::nat) ==> P(LEAST x. P(x))";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   655
by (rtac (prem RS rev_mp) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   656
by (res_inst_tac [("n","k")] less_induct 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   657
by (rtac impI 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   658
by (rtac classical 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   659
by (res_inst_tac [("s","n")] (Least_equality RS ssubst) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   660
by (assume_tac 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   661
by (assume_tac 2);
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   662
by (Blast_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   663
qed "LeastI";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   664
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   665
(*Proof is almost identical to the one above!*)
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3768
diff changeset
   666
val [prem] = goal thy "P(k::nat) ==> (LEAST x. P(x)) <= k";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   667
by (rtac (prem RS rev_mp) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   668
by (res_inst_tac [("n","k")] less_induct 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   669
by (rtac impI 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   670
by (rtac classical 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   671
by (res_inst_tac [("s","n")] (Least_equality RS ssubst) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   672
by (assume_tac 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   673
by (rtac le_refl 2);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   674
by (blast_tac (claset() addIs [less_imp_le,le_trans]) 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   675
qed "Least_le";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   676
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3768
diff changeset
   677
val [prem] = goal thy "k < (LEAST x. P(x)) ==> ~P(k::nat)";
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   678
by (rtac notI 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   679
by (etac (rewrite_rule [le_def] Least_le RS notE) 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   680
by (rtac prem 1);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   681
qed "not_less_Least";
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   682
3143
d60e49b86c6a Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents: 3085
diff changeset
   683
qed_goalw "Least_Suc" thy [Least_nat_def]
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   684
 "!!P. [| ? n. P(Suc n); ~ P 0 |] ==> (LEAST n. P n) = Suc (LEAST m. P(Suc m))"
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   685
 (fn _ => [
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   686
        rtac select_equality 1,
3143
d60e49b86c6a Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents: 3085
diff changeset
   687
        fold_goals_tac [Least_nat_def],
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   688
        safe_tac (claset() addSEs [LeastI]),
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   689
        rename_tac "j" 1,
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   690
        res_inst_tac [("n","j")] natE 1,
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   691
        Blast_tac 1,
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   692
        blast_tac (claset() addDs [Suc_less_SucD, not_less_Least]) 1,
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   693
        rename_tac "k n" 1,
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   694
        res_inst_tac [("n","k")] natE 1,
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   695
        Blast_tac 1,
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   696
        hyp_subst_tac 1,
3143
d60e49b86c6a Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents: 3085
diff changeset
   697
        rewtac Least_nat_def,
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   698
        rtac (select_equality RS arg_cong RS sym) 1,
4153
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4104
diff changeset
   699
        Safe_tac,
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   700
        dtac Suc_mono 1,
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   701
        Blast_tac 1,
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   702
        cut_facts_tac [less_linear] 1,
4153
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4104
diff changeset
   703
        Safe_tac,
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   704
        atac 2,
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   705
        Blast_tac 2,
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   706
        dtac Suc_mono 1,
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   707
        Blast_tac 1]);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   708
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   709
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   710
(*** Instantiation of transitivity prover ***)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   711
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   712
structure Less_Arith =
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   713
struct
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   714
val nat_leI = leI;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   715
val nat_leD = leD;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   716
val lessI = lessI;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   717
val zero_less_Suc = zero_less_Suc;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   718
val less_reflE = less_irrefl;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   719
val less_zeroE = less_zeroE;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   720
val less_incr = Suc_mono;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   721
val less_decr = Suc_less_SucD;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   722
val less_incr_rhs = Suc_mono RS Suc_lessD;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   723
val less_decr_lhs = Suc_lessD;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   724
val less_trans_Suc = less_trans_Suc;
3343
45986997f1fe Renamed lessD to Suc_leI
paulson
parents: 3308
diff changeset
   725
val leI = Suc_leI RS (Suc_le_mono RS iffD1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   726
val not_lessI = leI RS leD
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   727
val not_leI = prove_goal thy "!!m::nat. n < m ==> ~ m <= n"
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   728
  (fn _ => [etac swap2 1, etac leD 1]);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   729
val eqI = prove_goal thy "!!m. [| m < Suc n; n < Suc m |] ==> m=n"
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   730
  (fn _ => [etac less_SucE 1,
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4032
diff changeset
   731
            blast_tac (claset() addSDs [Suc_less_SucD] addSEs [less_irrefl]
2891
d8f254ad1ab9 Calls Blast_tac
paulson
parents: 2718
diff changeset
   732
                              addDs [less_trans_Suc]) 1,
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2922
diff changeset
   733
            assume_tac 1]);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   734
val leD = le_eq_less_Suc RS iffD1;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   735
val not_lessD = nat_leI RS leD;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   736
val not_leD = not_leE
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   737
val eqD1 = prove_goal thy  "!!n. m = n ==> m < Suc n"
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   738
 (fn _ => [etac subst 1, rtac lessI 1]);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   739
val eqD2 = sym RS eqD1;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   740
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   741
fun is_zero(t) =  t = Const("0",Type("nat",[]));
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   742
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   743
fun nnb T = T = Type("fun",[Type("nat",[]),
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   744
                            Type("fun",[Type("nat",[]),
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   745
                                        Type("bool",[])])])
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   746
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   747
fun decomp_Suc(Const("Suc",_)$t) = let val (a,i) = decomp_Suc t in (a,i+1) end
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   748
  | decomp_Suc t = (t,0);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   749
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   750
fun decomp2(rel,T,lhs,rhs) =
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   751
  if not(nnb T) then None else
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   752
  let val (x,i) = decomp_Suc lhs
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   753
      val (y,j) = decomp_Suc rhs
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   754
  in case rel of
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   755
       "op <"  => Some(x,i,"<",y,j)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   756
     | "op <=" => Some(x,i,"<=",y,j)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   757
     | "op ="  => Some(x,i,"=",y,j)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   758
     | _       => None
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   759
  end;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   760
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   761
fun negate(Some(x,i,rel,y,j)) = Some(x,i,"~"^rel,y,j)
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   762
  | negate None = None;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   763
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   764
fun decomp(_$(Const(rel,T)$lhs$rhs)) = decomp2(rel,T,lhs,rhs)
2718
460fd0f8d478 Renamed constant "not" to "Not"
paulson
parents: 2680
diff changeset
   765
  | decomp(_$(Const("Not",_)$(Const(rel,T)$lhs$rhs))) =
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   766
      negate(decomp2(rel,T,lhs,rhs))
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   767
  | decomp _ = None
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   768
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   769
end;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   770
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   771
structure Trans_Tac = Trans_Tac_Fun(Less_Arith);
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   772
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   773
open Trans_Tac;
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   774
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents:
diff changeset
   775
(*** eliminates ~= in premises, which trans_tac cannot deal with ***)
4737
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   776
bind_thm("nat_neqE", nat_neq_iff RS iffD1 RS disjE);
2680
20fa49e610ca function nat_add_primrec added to allow primrec definitions over nat
pusch
parents: 2608
diff changeset
   777
20fa49e610ca function nat_add_primrec added to allow primrec definitions over nat
pusch
parents: 2608
diff changeset
   778
20fa49e610ca function nat_add_primrec added to allow primrec definitions over nat
pusch
parents: 2608
diff changeset
   779
(* add function nat_add_primrec *) 
4737
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   780
val (_, nat_add_primrec, _, _) = 
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   781
    Datatype.add_datatype ([], "nat", 
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   782
			   [("0", [], Mixfix ("0", [], max_pri)), 
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   783
			    ("Suc", [dtTyp ([], "nat")], NoSyn)])
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   784
    (Theory.add_name "Arith" HOL.thy);
4544290d5a6b The theorem nat_neqE, and some tidying
paulson
parents: 4686
diff changeset
   785
3768
67f4ac759100 fully qualified names: Theory.add_XXX;
wenzelm
parents: 3718
diff changeset
   786
(*pretend Arith is part of the basic theory to fool package*)