src/FOLP/ex/Nat.ML
author paulson
Tue, 18 Nov 2003 11:03:56 +0100
changeset 14261 6c418d139f74
parent 5061 f947332d5465
child 17480 fd19f77dcf60
permissions -rw-r--r--
fixed a comment
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1459
d12da312eff4 expanded tabs
clasohm
parents: 0
diff changeset
     1
(*  Title:      FOLP/ex/nat.ML
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1459
d12da312eff4 expanded tabs
clasohm
parents: 0
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1992  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
Examples for the manual "Introduction to Isabelle"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
Proofs about the natural numbers
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     9
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
To generate similar output to manual, execute these commands:
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
    Pretty.setmargin 72; print_depth 0;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
open Nat;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
5061
f947332d5465 isatool fixgoal;
wenzelm
parents: 1459
diff changeset
    16
Goal "?p : ~ (Suc(k) = k)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
by (res_inst_tac [("n","k")] induct 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
by (rtac notI 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
by (etac Suc_neq_0 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
by (rtac notI 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
by (etac notE 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    22
by (etac Suc_inject 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
val Suc_n_not_n = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
5061
f947332d5465 isatool fixgoal;
wenzelm
parents: 1459
diff changeset
    26
Goal "?p : (k+m)+n = k+(m+n)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
prths ([induct] RL [topthm()]);  (*prints all 14 next states!*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
by (rtac induct 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
back();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    30
back();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
back();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
back();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
back();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
back();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    35
5061
f947332d5465 isatool fixgoal;
wenzelm
parents: 1459
diff changeset
    36
Goalw [add_def] "?p : 0+n = n";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
by (rtac rec_0 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
val add_0 = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
5061
f947332d5465 isatool fixgoal;
wenzelm
parents: 1459
diff changeset
    40
Goalw [add_def] "?p : Suc(m)+n = Suc(m+n)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    41
by (rtac rec_Suc 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    42
val add_Suc = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    44
(*
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
val nat_congs = mk_congs Nat.thy ["Suc", "op +"];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    46
prths nat_congs;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    47
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    48
val prems = goal Nat.thy "p: x=y ==> ?p : Suc(x) = Suc(y)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
by (resolve_tac (prems RL [subst]) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    50
by (rtac refl 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    51
val Suc_cong = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    52
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
val prems = goal Nat.thy "[| p : a=x;  q: b=y |] ==> ?p : a+b=x+y";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    54
by (resolve_tac (prems RL [subst]) 1 THEN resolve_tac (prems RL [subst]) 1 THEN 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    55
    rtac refl 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    56
val Plus_cong = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    58
val nat_congs = [Suc_cong,Plus_cong];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    59
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    60
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    61
val add_ss = FOLP_ss  addcongs nat_congs  
1459
d12da312eff4 expanded tabs
clasohm
parents: 0
diff changeset
    62
                     addrews  [add_0, add_Suc];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
5061
f947332d5465 isatool fixgoal;
wenzelm
parents: 1459
diff changeset
    64
Goal "?p : (k+m)+n = k+(m+n)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
by (res_inst_tac [("n","k")] induct 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
by (SIMP_TAC add_ss 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
by (ASM_SIMP_TAC add_ss 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
val add_assoc = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    69
5061
f947332d5465 isatool fixgoal;
wenzelm
parents: 1459
diff changeset
    70
Goal "?p : m+0 = m";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
by (res_inst_tac [("n","m")] induct 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    72
by (SIMP_TAC add_ss 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    73
by (ASM_SIMP_TAC add_ss 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
val add_0_right = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
5061
f947332d5465 isatool fixgoal;
wenzelm
parents: 1459
diff changeset
    76
Goal "?p : m+Suc(n) = Suc(m+n)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    77
by (res_inst_tac [("n","m")] induct 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    78
by (ALLGOALS (ASM_SIMP_TAC add_ss));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    79
val add_Suc_right = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    80
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    81
(*mk_typed_congs appears not to work with FOLP's version of subst*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82