src/CCL/ex/nat.ML
author clasohm
Thu Sep 16 12:20:38 1993 +0200 (1993-09-16)
changeset 0 a5a9c433f639
child 8 c3d2c6dcf3f0
permissions -rw-r--r--
Initial revision
clasohm@0
     1
(*  Title: 	CCL/ex/nat
clasohm@0
     2
    ID:         $Id$
clasohm@0
     3
    Author: 	Martin Coen, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1993  University of Cambridge
clasohm@0
     5
clasohm@0
     6
For nat.thy.
clasohm@0
     7
*)
clasohm@0
     8
clasohm@0
     9
open Nat;
clasohm@0
    10
clasohm@0
    11
val nat_defs = [not_def,add_def,mult_def,sub_def,le_def,lt_def,ack_def,napply_def];
clasohm@0
    12
clasohm@0
    13
val natBs = map (fn s=>prove_goalw Nat.thy nat_defs s (fn _ => [SIMP_TAC term_ss 1]))
clasohm@0
    14
     ["not(true) = false",
clasohm@0
    15
      "not(false) = true",
clasohm@0
    16
      "zero #+ n = n",
clasohm@0
    17
      "succ(n) #+ m = succ(n #+ m)",
clasohm@0
    18
      "zero #* n = zero",
clasohm@0
    19
      "succ(n) #* m = m #+ (n #* m)",
clasohm@0
    20
      "f^zero`a = a",
clasohm@0
    21
      "f^succ(n)`a = f(f^n`a)"];
clasohm@0
    22
clasohm@0
    23
val nat_congs  = ccl_mk_congs Nat.thy ["not","op #+","op #*","op #-","op ##",
clasohm@0
    24
                                     "op #<","op #<=","ackermann","napply"];
clasohm@0
    25
clasohm@0
    26
val nat_ss = term_ss addrews natBs addcongs nat_congs;
clasohm@0
    27
clasohm@0
    28
(*** Lemma for napply ***)
clasohm@0
    29
clasohm@0
    30
val [prem] = goal Nat.thy "n:Nat ==> f^n`f(a) = f^succ(n)`a";
clasohm@0
    31
br (prem RS Nat_ind) 1;
clasohm@0
    32
by (ALLGOALS (ASM_SIMP_TAC (nat_ss addcongs [read_instantiate [("f","f")] arg_cong])));
clasohm@0
    33
val napply_f = result();
clasohm@0
    34
clasohm@0
    35
(****)
clasohm@0
    36
clasohm@0
    37
val prems = goalw Nat.thy [add_def] "[| a:Nat;  b:Nat |] ==> a #+ b : Nat";
clasohm@0
    38
by (typechk_tac prems 1);
clasohm@0
    39
val addT = result();
clasohm@0
    40
clasohm@0
    41
val prems = goalw Nat.thy [mult_def] "[| a:Nat;  b:Nat |] ==> a #* b : Nat";
clasohm@0
    42
by (typechk_tac (addT::prems) 1);
clasohm@0
    43
val multT = result();
clasohm@0
    44
clasohm@0
    45
(* Defined to return zero if a<b *)
clasohm@0
    46
val prems = goalw Nat.thy [sub_def] "[| a:Nat;  b:Nat |] ==> a #- b : Nat";
clasohm@0
    47
by (typechk_tac (prems) 1);
clasohm@0
    48
by clean_ccs_tac;
clasohm@0
    49
be (NatPRI RS wfstI RS (NatPR_wf RS wmap_wf RS wfI)) 1;
clasohm@0
    50
val subT = result();
clasohm@0
    51
clasohm@0
    52
val prems = goalw Nat.thy [le_def] "[| a:Nat;  b:Nat |] ==> a #<= b : Bool";
clasohm@0
    53
by (typechk_tac (prems) 1);
clasohm@0
    54
by clean_ccs_tac;
clasohm@0
    55
be (NatPRI RS wfstI RS (NatPR_wf RS wmap_wf RS wfI)) 1;
clasohm@0
    56
val leT = result();
clasohm@0
    57
clasohm@0
    58
val prems = goalw Nat.thy [not_def,lt_def] "[| a:Nat;  b:Nat |] ==> a #< b : Bool";
clasohm@0
    59
by (typechk_tac (prems@[leT]) 1);
clasohm@0
    60
val ltT = result();
clasohm@0
    61
clasohm@0
    62
(* Correctness conditions for subtractive division **)
clasohm@0
    63
clasohm@0
    64
val prems = goalw Nat.thy [div_def] 
clasohm@0
    65
    "[| a:Nat;  b:{x:Nat.~x=zero} |] ==> a ## b : {x:Nat. DIV(a,b,x)}";
clasohm@0
    66
by (gen_ccs_tac (prems@[ltT,subT]) 1);
clasohm@0
    67
clasohm@0
    68
(* Termination Conditions for Ackermann's Function *)
clasohm@0
    69
clasohm@0
    70
val prems = goalw Nat.thy [ack_def]
clasohm@0
    71
    "[| a:Nat;  b:Nat |] ==> ackermann(a,b) : Nat";
clasohm@0
    72
by (gen_ccs_tac prems 1);
clasohm@0
    73
val relI = NatPR_wf RS (NatPR_wf RS lex_wf RS wfI);
clasohm@0
    74
by (REPEAT (eresolve_tac [NatPRI RS (lexI1 RS relI),NatPRI RS (lexI2 RS relI)] 1));
clasohm@0
    75
result();