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