Theory IsaFoR_Ground_Context

theory IsaFoR_Ground_Context
  imports
    Generic_Term_Context
    IsaFoR_Abstract_Context
    IsaFoR_Ground_Term
begin

type_synonym 'f gcontext = "('f, 'f gterm) actxt"

abbreviation apply_ground_context (‹__G [1000, 0] 1000) where
  "ctG  GFunc;t"

fun context_atG :: "'f gterm  pos  'f gcontext" where
  "context_atG t [] = " |
  "context_atG (GFun f ts) (i # ps) = More f (take i ts) (context_atG (ts!i) ps) (drop (Suc i) ts)"

interpretation gcontext: term_context_interpretation where
  subterms = gargs and fun_sym = groot_sym and extra = "λ_. ()" and is_var = is_var and
  Fun = "λf _. GFun f" and
  hole =  and apply_context = apply_ground_context and compose_context = "(∘c)" and
  More = "λf _. More f" and fun_symc = fun_symc and extrac = "λ_. ()" and subtermsl = subtermsl and
  subcontext = subcontext and subtermsr = subtermsr
proof unfold_locales
  fix c :: "'f gcontext" and t t' 
  assume "ctG = ct'G" 

  then show "t = t'"
    by (induction c) auto
next
  fix c :: "'f gcontext"

  show "c    (f e ls c' rs. c = More f ls c' rs)"
    by (metis actxt.distinct(1) actxt.exhaust)
qed (simp_all add: intp_actxt_compose)

interpretation gcontext: replace_at_subterm where  
  subterms = gargs and fun_sym = groot_sym and extra = "λ_. ()" and is_var = is_var and
  Fun = "λf _. GFun f" and size = size and
  hole =  and apply_context = apply_ground_context and compose_context = "(∘c)" and
  hole_position = hole_pos and context_at = context_atG
proof unfold_locales
  fix c :: "'f gcontext" and t

  show "gterm.subterm_at ctG (hole_pos c) = t"
    by (induction c) auto

  show "hole_pos c  gterm.positions ctG"
    by (induction c) auto

  show "context_atG ctG (hole_pos c) = c"
    by (induction c) auto
next
  fix p and t :: "'f gterm"
  assume "p  gterm.positions t"

  then show "(context_atG t p)gterm.subterm_at t pG = t"
    by (induction t p rule: context_atG.induct) (auto simp: Cons_nth_drop_Suc)
qed auto

end