src/CCL/ex/nat.ML
changeset 0 a5a9c433f639
child 8 c3d2c6dcf3f0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/CCL/ex/nat.ML	Thu Sep 16 12:20:38 1993 +0200
     1.3 @@ -0,0 +1,75 @@
     1.4 +(*  Title: 	CCL/ex/nat
     1.5 +    ID:         $Id$
     1.6 +    Author: 	Martin Coen, Cambridge University Computer Laboratory
     1.7 +    Copyright   1993  University of Cambridge
     1.8 +
     1.9 +For nat.thy.
    1.10 +*)
    1.11 +
    1.12 +open Nat;
    1.13 +
    1.14 +val nat_defs = [not_def,add_def,mult_def,sub_def,le_def,lt_def,ack_def,napply_def];
    1.15 +
    1.16 +val natBs = map (fn s=>prove_goalw Nat.thy nat_defs s (fn _ => [SIMP_TAC term_ss 1]))
    1.17 +     ["not(true) = false",
    1.18 +      "not(false) = true",
    1.19 +      "zero #+ n = n",
    1.20 +      "succ(n) #+ m = succ(n #+ m)",
    1.21 +      "zero #* n = zero",
    1.22 +      "succ(n) #* m = m #+ (n #* m)",
    1.23 +      "f^zero`a = a",
    1.24 +      "f^succ(n)`a = f(f^n`a)"];
    1.25 +
    1.26 +val nat_congs  = ccl_mk_congs Nat.thy ["not","op #+","op #*","op #-","op ##",
    1.27 +                                     "op #<","op #<=","ackermann","napply"];
    1.28 +
    1.29 +val nat_ss = term_ss addrews natBs addcongs nat_congs;
    1.30 +
    1.31 +(*** Lemma for napply ***)
    1.32 +
    1.33 +val [prem] = goal Nat.thy "n:Nat ==> f^n`f(a) = f^succ(n)`a";
    1.34 +br (prem RS Nat_ind) 1;
    1.35 +by (ALLGOALS (ASM_SIMP_TAC (nat_ss addcongs [read_instantiate [("f","f")] arg_cong])));
    1.36 +val napply_f = result();
    1.37 +
    1.38 +(****)
    1.39 +
    1.40 +val prems = goalw Nat.thy [add_def] "[| a:Nat;  b:Nat |] ==> a #+ b : Nat";
    1.41 +by (typechk_tac prems 1);
    1.42 +val addT = result();
    1.43 +
    1.44 +val prems = goalw Nat.thy [mult_def] "[| a:Nat;  b:Nat |] ==> a #* b : Nat";
    1.45 +by (typechk_tac (addT::prems) 1);
    1.46 +val multT = result();
    1.47 +
    1.48 +(* Defined to return zero if a<b *)
    1.49 +val prems = goalw Nat.thy [sub_def] "[| a:Nat;  b:Nat |] ==> a #- b : Nat";
    1.50 +by (typechk_tac (prems) 1);
    1.51 +by clean_ccs_tac;
    1.52 +be (NatPRI RS wfstI RS (NatPR_wf RS wmap_wf RS wfI)) 1;
    1.53 +val subT = result();
    1.54 +
    1.55 +val prems = goalw Nat.thy [le_def] "[| a:Nat;  b:Nat |] ==> a #<= b : Bool";
    1.56 +by (typechk_tac (prems) 1);
    1.57 +by clean_ccs_tac;
    1.58 +be (NatPRI RS wfstI RS (NatPR_wf RS wmap_wf RS wfI)) 1;
    1.59 +val leT = result();
    1.60 +
    1.61 +val prems = goalw Nat.thy [not_def,lt_def] "[| a:Nat;  b:Nat |] ==> a #< b : Bool";
    1.62 +by (typechk_tac (prems@[leT]) 1);
    1.63 +val ltT = result();
    1.64 +
    1.65 +(* Correctness conditions for subtractive division **)
    1.66 +
    1.67 +val prems = goalw Nat.thy [div_def] 
    1.68 +    "[| a:Nat;  b:{x:Nat.~x=zero} |] ==> a ## b : {x:Nat. DIV(a,b,x)}";
    1.69 +by (gen_ccs_tac (prems@[ltT,subT]) 1);
    1.70 +
    1.71 +(* Termination Conditions for Ackermann's Function *)
    1.72 +
    1.73 +val prems = goalw Nat.thy [ack_def]
    1.74 +    "[| a:Nat;  b:Nat |] ==> ackermann(a,b) : Nat";
    1.75 +by (gen_ccs_tac prems 1);
    1.76 +val relI = NatPR_wf RS (NatPR_wf RS lex_wf RS wfI);
    1.77 +by (REPEAT (eresolve_tac [NatPRI RS (lexI1 RS relI),NatPRI RS (lexI2 RS relI)] 1));
    1.78 +result();