src/CCL/ex/Nat.ML
author paulson
Mon Dec 07 18:26:25 1998 +0100 (1998-12-07)
changeset 6019 0e55c2fb2ebb
parent 1459 d12da312eff4
child 17456 bcf7544875b2
permissions -rw-r--r--
tidying
clasohm@1459
     1
(*  Title:      CCL/ex/nat
clasohm@0
     2
    ID:         $Id$
clasohm@1459
     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
lcp@8
    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
lcp@8
    23
val nat_ss = term_ss addsimps natBs;
clasohm@0
    24
clasohm@0
    25
(*** Lemma for napply ***)
clasohm@0
    26
clasohm@0
    27
val [prem] = goal Nat.thy "n:Nat ==> f^n`f(a) = f^succ(n)`a";
clasohm@1459
    28
by (rtac (prem RS Nat_ind) 1);
lcp@8
    29
by (ALLGOALS (asm_simp_tac nat_ss));
clasohm@757
    30
qed "napply_f";
clasohm@0
    31
clasohm@0
    32
(****)
clasohm@0
    33
clasohm@0
    34
val prems = goalw Nat.thy [add_def] "[| a:Nat;  b:Nat |] ==> a #+ b : Nat";
clasohm@0
    35
by (typechk_tac prems 1);
clasohm@757
    36
qed "addT";
clasohm@0
    37
clasohm@0
    38
val prems = goalw Nat.thy [mult_def] "[| a:Nat;  b:Nat |] ==> a #* b : Nat";
clasohm@0
    39
by (typechk_tac (addT::prems) 1);
clasohm@757
    40
qed "multT";
clasohm@0
    41
clasohm@0
    42
(* Defined to return zero if a<b *)
clasohm@0
    43
val prems = goalw Nat.thy [sub_def] "[| a:Nat;  b:Nat |] ==> a #- b : Nat";
clasohm@0
    44
by (typechk_tac (prems) 1);
clasohm@0
    45
by clean_ccs_tac;
clasohm@1459
    46
by (etac (NatPRI RS wfstI RS (NatPR_wf RS wmap_wf RS wfI)) 1);
clasohm@757
    47
qed "subT";
clasohm@0
    48
clasohm@0
    49
val prems = goalw Nat.thy [le_def] "[| a:Nat;  b:Nat |] ==> a #<= b : Bool";
clasohm@0
    50
by (typechk_tac (prems) 1);
clasohm@0
    51
by clean_ccs_tac;
clasohm@1459
    52
by (etac (NatPRI RS wfstI RS (NatPR_wf RS wmap_wf RS wfI)) 1);
clasohm@757
    53
qed "leT";
clasohm@0
    54
clasohm@0
    55
val prems = goalw Nat.thy [not_def,lt_def] "[| a:Nat;  b:Nat |] ==> a #< b : Bool";
clasohm@0
    56
by (typechk_tac (prems@[leT]) 1);
clasohm@757
    57
qed "ltT";
clasohm@0
    58
clasohm@0
    59
(* Correctness conditions for subtractive division **)
clasohm@0
    60
clasohm@0
    61
val prems = goalw Nat.thy [div_def] 
clasohm@0
    62
    "[| a:Nat;  b:{x:Nat.~x=zero} |] ==> a ## b : {x:Nat. DIV(a,b,x)}";
clasohm@0
    63
by (gen_ccs_tac (prems@[ltT,subT]) 1);
clasohm@0
    64
clasohm@0
    65
(* Termination Conditions for Ackermann's Function *)
clasohm@0
    66
clasohm@0
    67
val prems = goalw Nat.thy [ack_def]
clasohm@0
    68
    "[| a:Nat;  b:Nat |] ==> ackermann(a,b) : Nat";
clasohm@0
    69
by (gen_ccs_tac prems 1);
clasohm@0
    70
val relI = NatPR_wf RS (NatPR_wf RS lex_wf RS wfI);
clasohm@0
    71
by (REPEAT (eresolve_tac [NatPRI RS (lexI1 RS relI),NatPRI RS (lexI2 RS relI)] 1));
clasohm@0
    72
result();