# HG changeset patch # User haftmann # Date 1286196409 -7200 # Node ID 9f6503aaa77d6a2d3c56aead4f6b9f48629eabaf # Parent 7a1d8b9d17e7ebcb25edd8b782cce4c289697fae adjusted to inductive characterization of sorted diff -r 7a1d8b9d17e7 -r 9f6503aaa77d src/HOL/Predicate_Compile_Examples/Specialisation_Examples.thy --- a/src/HOL/Predicate_Compile_Examples/Specialisation_Examples.thy Mon Oct 04 14:46:49 2010 +0200 +++ b/src/HOL/Predicate_Compile_Examples/Specialisation_Examples.thy Mon Oct 04 14:46:49 2010 +0200 @@ -4,7 +4,7 @@ section {* Specialisation Examples *} -fun nth_el' +primrec nth_el' where "nth_el' [] i = None" | "nth_el' (x # xs) i = (case i of 0 => Some x | Suc j => nth_el' xs j)" @@ -48,7 +48,27 @@ subsection {* Sorts *} -code_pred [inductify] sorted . +declare sorted.Nil [code_pred_intro] + sorted_single [code_pred_intro] + sorted_many [code_pred_intro] + +code_pred sorted proof - + assume "sorted xa" + assume 1: "xa = [] \ thesis" + assume 2: "\x. xa = [x] \ thesis" + assume 3: "\x y zs. xa = x # y # zs \ x \ y \ sorted (y # zs) \ thesis" + show thesis proof (cases xa) + case Nil with 1 show ?thesis . + next + case (Cons x xs) show ?thesis proof (cases xs) + case Nil with Cons 2 show ?thesis by simp + next + case (Cons y zs) with `xa = x # xs` have "xa = x # y # zs" by simp + moreover with `sorted xa` have "x \ y" and "sorted (y # zs)" by simp_all + ultimately show ?thesis by (rule 3) + qed + qed +qed thm sorted.equation section {* Specialisation in POPLmark theory *} @@ -212,10 +232,10 @@ where T_Var: "\ \\<^bsub>wf\<^esub> \ \\i\ = \VarB U\ \ T = \\<^isub>\ (Suc i) 0 U \ \ \ Var i : T" | T_Abs: "VarB T\<^isub>1 \ \ \ t\<^isub>2 : T\<^isub>2 \ \ \ (\:T\<^isub>1. t\<^isub>2) : T\<^isub>1 \ \\<^isub>\ 1 0 T\<^isub>2" -| T_App: "\ \ t\<^isub>1 : T\<^isub>1\<^isub>1 \ T\<^isub>1\<^isub>2 \ \ \ t\<^isub>2 : T\<^isub>1\<^isub>1 \ \ \ t\<^isub>1 \ t\<^isub>2 : T\<^isub>1\<^isub>2" +| T_App: "\ \ t\<^isub>1 : T\<^isub>11 \ T\<^isub>12 \ \ \ t\<^isub>2 : T\<^isub>11 \ \ \ t\<^isub>1 \ t\<^isub>2 : T\<^isub>12" | T_TAbs: "TVarB T\<^isub>1 \ \ \ t\<^isub>2 : T\<^isub>2 \ \ \ (\<:T\<^isub>1. t\<^isub>2) : (\<:T\<^isub>1. T\<^isub>2)" -| T_TApp: "\ \ t\<^isub>1 : (\<:T\<^isub>1\<^isub>1. T\<^isub>1\<^isub>2) \ \ \ T\<^isub>2 <: T\<^isub>1\<^isub>1 \ - \ \ t\<^isub>1 \\<^isub>\ T\<^isub>2 : T\<^isub>1\<^isub>2[0 \\<^isub>\ T\<^isub>2]\<^isub>\" +| T_TApp: "\ \ t\<^isub>1 : (\<:T\<^isub>11. T\<^isub>12) \ \ \ T\<^isub>2 <: T\<^isub>11 \ + \ \ t\<^isub>1 \\<^isub>\ T\<^isub>2 : T\<^isub>12[0 \\<^isub>\ T\<^isub>2]\<^isub>\" | T_Sub: "\ \ t : S \ \ \ S <: T \ \ \ t : T" code_pred [inductify, skip_proof, specialise] typing .