src/HOL/ex/Recdefs.ML
author wenzelm
Mon, 29 Nov 1999 15:52:49 +0100
changeset 8039 a901bafe4578
parent 6451 bc943acc5fda
child 8415 852c63072334
permissions -rw-r--r--
Goal: tuned pris;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5124
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/ex/Recdefs.ML
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
     3
    Author:     Konrad Lawrence C Paulson
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
     4
    Copyright   1997  University of Cambridge
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
     5
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
     6
A few proofs to demonstrate the functions defined in Recdefs.thy
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
     7
Lemma statements from Konrad Slind's Web site
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
     8
*)
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
     9
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    10
Addsimps qsort.rules;
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    11
5518
654ead0ba4f7 re-added mem and list_all
oheimb
parents: 5124
diff changeset
    12
Goal "(x: set (qsort (ord,l))) = (x: set l)";
5124
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    13
by (res_inst_tac [("u","ord"),("v","l")] qsort.induct 1);
6451
paulson
parents: 5655
diff changeset
    14
by Auto_tac;
5124
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    15
qed "qsort_mem_stable";
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    16
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    17
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    18
(** The silly g function: example of nested recursion **)
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    19
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    20
Addsimps g.rules;
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    21
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    22
Goal "g x < Suc x";
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    23
by (res_inst_tac [("u","x")] g.induct 1);
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    24
by Auto_tac;
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    25
qed "g_terminates";
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    26
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    27
Goal "g x = 0";
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    28
by (res_inst_tac [("u","x")] g.induct 1);
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    29
by (ALLGOALS (asm_simp_tac (simpset() addsimps [g_terminates])));
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    30
qed "g_zero";
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    31
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    32
(*** the contrived `mapf' ***)
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    33
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    34
(* proving the termination condition: *)
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    35
val [tc] = mapf.tcs;
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    36
goalw_cterm [] (cterm_of (sign_of thy) (HOLogic.mk_Trueprop tc));
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    37
by (rtac allI 1);
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    38
by (case_tac "n=0" 1);
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    39
by (ALLGOALS Asm_simp_tac);
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    40
val lemma = result();
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    41
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    42
(* removing the termination condition from the generated thms: *)
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    43
val [mapf_0,mapf_Suc] = mapf.rules;
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    44
val mapf_Suc = lemma RS mapf_Suc;
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    45
1ce3cccfacdb stepping stones: Recdef, Main;
wenzelm
parents:
diff changeset
    46
val mapf_induct = lemma RS mapf.induct;