SSL CCL.thy
Interaktion und Portierbarkeitunbekannt
(* Title: CCL/CCL.thy Author: Martin Coen Copyright 1993 University of Cambridge
*)
section \<open>Classical Computational Logic for Untyped Lambda Calculus with reduction to weak head-normal form\<close>
theory CCL imports Gfp begin
text\<open>
Based on FOL extended with set collection, a primitive higher-order
logic. HOL is too strong - descriptions prevent a type of programs
being defined which contains only executable terms. \<close>
(** This is the evaluation semantics from which the axioms below were derived. **) (** It is included here just as an evaluator for FUN and has no influence on **) (** inference in the theory CCL. **)
axiomatizationwhere
trueV: "true \ true" and
falseV: "false \ false" and
pairV: " \" and
lamV: "\b. lam x. b(x) \ lam x. b(x)" and
caseVtrue: "\t \ true; d \ c\ \ case(t,d,e,f,g) \ c" and
caseVfalse: "\t \ false; e \ c\ \ case(t,d,e,f,g) \ c" and
caseVpair: "\t \; f(a,b) \ c\ \ case(t,d,e,f,g) \ c" and
caseVlam: "\b. \t \ lam x. b(x); g(b) \ c\ \ case(t,d,e,f,g) \ c"
(*** Properties of evaluation: note that "t \<longlongrightarrow> c" impies that c is canonical ***)
(* The pre-order ([=) is defined as a simulation, and behavioural equivalence (=) *) (* as a bisimulation. They can both be expressed as (bi)simulations up to *) (* behavioural equivalence (ie the relations PO and EQ defined below). *)
(** The theory is non-trivial **) axiomatizationwhere
distinctness: "\ lam x. b(x) = bot"
(*** Definitions of Termination and Divergence ***)
definition Dvg :: "i \ o" where"Dvg(t) == t = bot"
definition Trm :: "i \ o" where"Trm(t) == \ Dvg(t)"
text\<open>
Would be interesting to build a similar theoryfor a typed programming language:
ie. true :: bool, fix :: ('a\'a)\'a etc......
This is starting to look like LCF.
What are the advantages of this approach?
- less axiomatic
- wfd induction / coinduction and fixed point induction available \<close>
lemmas ccl_data_defs = apply_def fix_def
declare po_refl [simp]
subsection \<open>Congruence Rules\<close>
(*similar to AP_THM in Gordon's HOL*) lemma fun_cong: "(f::'a\'b) = g \ f(x)=g(x)" by simp
(*similar to AP_TERM in Gordon's HOL and FOL's subst_context*) lemma arg_cong: "x=y \ f(x)=f(y)" by simp
subsection \<open>Constructors are distinct\<close>
lemma lem: "t=t' \ case(t,b,c,d,e) = case(t',b,c,d,e)" by simp
ML \<open> local fun pairs_of _ _ [] = []
| pairs_of f x (y::ys) = (f x y) :: (f y x) :: (pairs_of f x ys)
fun mk_combs _ [] = []
| mk_combs ff (x::xs) = (pairs_of ff x xs) @ mk_combs ff xs
(* Doesn't handle binder types correctly *) fun saturate thy sy name = letfun arg_str 0 _ s = s
| arg_str 1 a s = "(" ^ a ^ "a" ^ s ^ ")"
| arg_str n a s = arg_str (n-1) a ("," ^ a ^ (chr((ord "a")+n-1)) ^ s)
val T = Sign.the_const_type thy (Sign.intern_const thy sy);
val arity = length (binder_types T) in sy ^ (arg_str arity name "") end
fun mk_thm_str thy a b = "\ " ^ (saturate thy a "a") ^ " = " ^ (saturate thy b "b")
val lemma = @{thm lem};
val eq_lemma = @{thm eq_lemma};
val distinctness = @{thm distinctness}; fun mk_lemma (ra,rb) =
[lemma] RL [ra RS (rb RS eq_lemma)] RL
[distinctness RS @{thmnotE}, @{thm sym} RS (distinctness RS @{thmnotE})] in fun mk_lemmas rls = maps mk_lemma (mk_combs pair rls) fun mk_dstnct_rls thy xs = mk_combs (mk_thm_str thy) xs end \<close>
ML \<open>
val caseB_lemmas = mk_lemmas @{thms caseBs}
val ccl_dstncts = let fun mk_raw_dstnct_thm rls s =
Goal.prove_global \<^theory> [] [] (Syntax.read_prop_global \<^theory> s)
(fn {context = ctxt, ...} => resolve_tac ctxt @{thms notI} 1 THEN eresolve_tac ctxt rls 1) in map (mk_raw_dstnct_thm caseB_lemmas)
(mk_dstnct_rls \<^theory> ["bot","true","false","pair","lambda"]) end
fun mk_dstnct_thms ctxt defs inj_rls xs = let
val thy = Proof_Context.theory_of ctxt; fun mk_dstnct_thm rls s =
Goal.prove_global thy [] [] (Syntax.read_prop ctxt s)
(fn _ =>
rewrite_goals_tac ctxt defsTHEN
simp_tac (ctxt |> Simplifier.add_simps (rls @ inj_rls)) 1) in map (mk_dstnct_thm ccl_dstncts) (mk_dstnct_rls thy xs) end
lemma case_pocong: assumes 1: "t [= t'" and 2: "a [= a'" and 3: "b [= b'" and 4: "\x y. c(x,y) [= c'(x,y)" and 5: "\u. d(u) [= d'(u)" shows"case(t,a,b,c,d) [= case(t',a',b',c',d')" apply (rule 1 [THEN po_cong, THEN po_trans]) apply (rule 2 [THEN po_cong, THEN po_trans]) apply (rule 3 [THEN po_cong, THEN po_trans]) apply (rule 4 [THEN po_abstractn, THEN po_abstractn, THEN po_cong, THEN po_trans]) apply (rule_tac f1 = "\d. case (t',a',b',c',d)" in
5 [THEN po_abstractn, THEN po_cong, THEN po_trans]) apply (rule po_refl) done
lemma apply_pocong: "\f [= f'; a [= a'\ \ f ` a [= f' ` a'" unfolding ccl_data_defs apply (rule case_pocong, (rule po_refl | assumption)+) apply (erule po_cong) done