Theory Generic_Context

theory Generic_Context
  imports Context_Notation
begin

locale "context" =
  context_notation +
  assumes
    compose_context_iff [simp]: "(c :: 'c) c' (t :: 't). (c c c')t = cc't" and
    compose_hole [simp]: "c.  c c = c" "c. c c  = c" and
    apply_hole [simp]: "t. t = t" and
    apply_context_eq: "c t t'. ct = ct'  t = t'"

locale context_interpretation = "context" where apply_context = apply_context 
  for apply_context :: "'c  't  't" +
fixes 
  More :: "'f  'e  't list  'c  't list  'c" and
  fun_sym :: "'c  'f" and 
  extra :: "'c  'e" and
  subtermsl :: "'c  't list" and
  subcontext :: "'c  'c" and
  subtermsr :: "'c  't list"
assumes
  context_fun_sym [simp]: "f e ls c rs. fun_sym (More f e ls c rs) = f" and
  context_extra [simp]: "f e ls c rs. extra (More f e ls c rs) = e" and
  subtermsl [simp]: "f e ls c rs. subtermsl (More f e ls c rs) = ls" and
  subcontext [simp]: "f e ls c rs. subcontext (More f e ls c rs) = c" and
  subtermsr [simp]: "f e ls c rs. subtermsr (More f e ls c rs) = rs" and
  context_destruct: "c. c    (f e ls c' rs. c = More f e ls c' rs)" and
  context_inject [intro]: 
    "More f1 e1 ls1 c1' rs1 = More f2 e2 ls2 c2' rs2  
      f1 = f2  e1 = e2  ls1 = ls2  c1' = c2'  rs1 = rs2" and
  compose_context [simp]: "More f e ls c rs c c' = More f e ls (c c c') rs"
begin

lemma interpretation_not_hole [intro]: "More f e ls c' rs  "
  using context_destruct
  by fast

end

locale smaller_subcontext =
  fixes hole :: 'c and size :: "'c  nat" and subcontext :: "'c  'c"
  assumes subcontext_smaller: "c. c  hole  size (subcontext c) < size c"

end