src/FOL/ex/Nat2.ML
author wenzelm
Thu, 18 Jun 1998 18:28:45 +0200
changeset 5050 e925308df78b
parent 4423 a129b817b58a
child 17245 1c519a3cca59
permissions -rw-r--r--
isatool fixgoal;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1459
d12da312eff4 expanded tabs
clasohm
parents: 755
diff changeset
     1
(*  Title:      FOL/ex/nat2.ML
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1459
d12da312eff4 expanded tabs
clasohm
parents: 755
diff changeset
     3
    Author:     Tobias Nipkow
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1991  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
For ex/nat.thy.  
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
Examples of simplification and induction on the natural numbers
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     9
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
open Nat2;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    12
Addsimps [pred_0, pred_succ, plus_0, plus_succ, 
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    13
	  nat_distinct1, nat_distinct2, succ_inject,
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    14
	  leq_0, leq_succ_succ, leq_succ_0, 
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    15
	  lt_0_succ, lt_succ_succ, lt_0];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
val prems = goal Nat2.thy 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
    "[| P(0);  !!x. P(succ(x)) |] ==> All(P)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
by (rtac nat_ind 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
by (REPEAT (resolve_tac (prems@[allI,impI]) 1));
725
d9c629fbacc6 replaced 'val ... = result();' by 'qed "...";'
clasohm
parents: 0
diff changeset
    22
qed "nat_exh";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    24
Goal "~ n=succ(n)";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    25
by (IND_TAC nat_ind Simp_tac "n" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    28
Goal "~ succ(n)=n";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    29
by (IND_TAC nat_ind Simp_tac "n" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    30
result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    32
Goal "~ succ(succ(n))=n";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    33
by (IND_TAC nat_ind Simp_tac "n" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    35
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    36
Goal "~ n=succ(succ(n))";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    37
by (IND_TAC nat_ind Simp_tac "n" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    40
Goal "m+0 = m";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    41
by (IND_TAC nat_ind Simp_tac "m" 1);
725
d9c629fbacc6 replaced 'val ... = result();' by 'qed "...";'
clasohm
parents: 0
diff changeset
    42
qed "plus_0_right";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    44
Goal "m+succ(n) = succ(m+n)";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    45
by (IND_TAC nat_ind Simp_tac "m" 1);
725
d9c629fbacc6 replaced 'val ... = result();' by 'qed "...";'
clasohm
parents: 0
diff changeset
    46
qed "plus_succ_right";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    47
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    48
Addsimps [plus_0_right, plus_succ_right];
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    49
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    50
Goal "~n=0 --> m+pred(n) = pred(m+n)";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    51
by (IND_TAC nat_ind Simp_tac "n" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    52
result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    54
Goal "~n=0 --> succ(pred(n))=n";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    55
by (IND_TAC nat_ind Simp_tac "n" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    56
result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    58
Goal "m+n=0 <-> m=0 & n=0";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    59
by (IND_TAC nat_ind Simp_tac "m" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    60
result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    61
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    62
Goal "m <= n --> m <= succ(n)";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    63
by (IND_TAC nat_ind Simp_tac "m" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
by (rtac (impI RS allI) 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    65
by (ALL_IND_TAC nat_ind Simp_tac 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    66
by (Fast_tac 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    67
bind_thm("le_imp_le_succ", result() RS mp);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    69
Goal "n<succ(n)";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    70
by (IND_TAC nat_ind Simp_tac "n" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    72
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    73
Goal "~ n<n";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    74
by (IND_TAC nat_ind Simp_tac "n" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    77
Goal "m < n --> m < succ(n)";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    78
by (IND_TAC nat_ind Simp_tac "m" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    79
by (rtac (impI RS allI) 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    80
by (ALL_IND_TAC nat_ind Simp_tac 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    81
by (Fast_tac 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82
result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    83
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    84
Goal "m <= n --> m <= n+k";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    85
by (IND_TAC nat_ind (simp_tac (simpset() addsimps [le_imp_le_succ]))
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    86
     "k" 1);
755
dfb3894d78e4 replaced "val ... = result()" by "qed ..."
clasohm
parents: 725
diff changeset
    87
qed "le_plus";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    89
Goal "succ(m) <= n --> m <= n";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    90
by (res_inst_tac [("x","n")]spec 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    91
by (ALL_IND_TAC nat_exh (simp_tac (simpset() addsimps [le_imp_le_succ])) 1);
755
dfb3894d78e4 replaced "val ... = result()" by "qed ..."
clasohm
parents: 725
diff changeset
    92
qed "succ_le";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    93
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
    94
Goal "~m<n <-> n<=m";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    95
by (IND_TAC nat_ind Simp_tac "n" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    96
by (rtac (impI RS allI) 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
    97
by (ALL_IND_TAC nat_ind Asm_simp_tac 1);
725
d9c629fbacc6 replaced 'val ... = result();' by 'qed "...";'
clasohm
parents: 0
diff changeset
    98
qed "not_less";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    99
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
   100
Goal "n<=m --> ~m<n";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   101
by (simp_tac (simpset() addsimps [not_less]) 1);
755
dfb3894d78e4 replaced "val ... = result()" by "qed ..."
clasohm
parents: 725
diff changeset
   102
qed "le_imp_not_less";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   103
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
   104
Goal "m<n --> ~n<=m";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   105
by (cut_facts_tac [not_less] 1 THEN Fast_tac 1);
755
dfb3894d78e4 replaced "val ... = result()" by "qed ..."
clasohm
parents: 725
diff changeset
   106
qed "not_le";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   107
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
   108
Goal "m+k<=n --> m<=n";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   109
by (IND_TAC nat_ind (K all_tac) "k" 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   110
by (Simp_tac 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   111
by (rtac (impI RS allI) 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   112
by (Simp_tac 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   113
by (REPEAT (resolve_tac [allI,impI] 1));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   114
by (cut_facts_tac [succ_le] 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   115
by (Fast_tac 1);
755
dfb3894d78e4 replaced "val ... = result()" by "qed ..."
clasohm
parents: 725
diff changeset
   116
qed "plus_le";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   117
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   118
val prems = goal Nat2.thy "[| ~m=0;  m <= n |] ==> ~n=0";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   119
by (cut_facts_tac prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   120
by (REPEAT (etac rev_mp 1));
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   121
by (IND_TAC nat_exh Simp_tac "m" 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   122
by (ALL_IND_TAC nat_exh Simp_tac 1);
755
dfb3894d78e4 replaced "val ... = result()" by "qed ..."
clasohm
parents: 725
diff changeset
   123
qed "not0";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   124
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
   125
Goal "a<=a' & b<=b' --> a+b<=a'+b'";
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   126
by (IND_TAC nat_ind (simp_tac (simpset() addsimps [le_plus])) "b" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   127
by (resolve_tac [impI RS allI] 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   128
by (resolve_tac [allI RS allI] 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   129
by (ALL_IND_TAC nat_exh Asm_simp_tac 1);
755
dfb3894d78e4 replaced "val ... = result()" by "qed ..."
clasohm
parents: 725
diff changeset
   130
qed "plus_le_plus";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   131
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
   132
Goal "i<=j --> j<=k --> i<=k";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   133
by (IND_TAC nat_ind (K all_tac) "i" 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   134
by (Simp_tac 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   135
by (resolve_tac [impI RS allI] 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   136
by (ALL_IND_TAC nat_exh Simp_tac 1);
4423
a129b817b58a expandshort;
wenzelm
parents: 4091
diff changeset
   137
by (rtac impI 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   138
by (ALL_IND_TAC nat_exh Simp_tac 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   139
by (Fast_tac 1);
755
dfb3894d78e4 replaced "val ... = result()" by "qed ..."
clasohm
parents: 725
diff changeset
   140
qed "le_trans";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   141
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
   142
Goal "i < j --> j <=k --> i < k";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   143
by (IND_TAC nat_ind (K all_tac) "j" 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   144
by (Simp_tac 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   145
by (resolve_tac [impI RS allI] 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   146
by (ALL_IND_TAC nat_exh Simp_tac 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   147
by (ALL_IND_TAC nat_exh Simp_tac 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   148
by (ALL_IND_TAC nat_exh Simp_tac 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   149
by (Fast_tac 1);
755
dfb3894d78e4 replaced "val ... = result()" by "qed ..."
clasohm
parents: 725
diff changeset
   150
qed "less_le_trans";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   151
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
   152
Goal "succ(i) <= j <-> i < j";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   153
by (IND_TAC nat_ind Simp_tac "j" 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   154
by (resolve_tac [impI RS allI] 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   155
by (ALL_IND_TAC nat_exh Asm_simp_tac 1);
755
dfb3894d78e4 replaced "val ... = result()" by "qed ..."
clasohm
parents: 725
diff changeset
   156
qed "succ_le2";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   157
5050
e925308df78b isatool fixgoal;
wenzelm
parents: 4423
diff changeset
   158
Goal "i<succ(j) <-> i=j | i<j";
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   159
by (IND_TAC nat_ind Simp_tac "j" 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   160
by (ALL_IND_TAC nat_exh Simp_tac 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   161
by (resolve_tac [impI RS allI] 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   162
by (ALL_IND_TAC nat_exh Simp_tac 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1959
diff changeset
   163
by (Asm_simp_tac 1);
755
dfb3894d78e4 replaced "val ... = result()" by "qed ..."
clasohm
parents: 725
diff changeset
   164
qed "less_succ";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   165