Nominal/Ex/LamTest.thy
changeset 2653 d0f774d06e6e
parent 2652 e9a2770660ef
child 2654 0f0335d91456
equal deleted inserted replaced
2652:e9a2770660ef 2653:d0f774d06e6e
     8   Var "name"
     8   Var "name"
     9 | App "lam" "lam"
     9 | App "lam" "lam"
    10 | Lam x::"name" l::"lam"  bind x in l
    10 | Lam x::"name" l::"lam"  bind x in l
    11 
    11 
    12 definition
    12 definition
    13  "eqvt x \<equiv> \<forall>p. p \<bullet> x = x"
    13  "eqvt_at f x \<equiv> \<forall>p. p \<bullet> (f x) = f (p \<bullet> x)"
       
    14 
       
    15 definition
       
    16  "eqvt f \<equiv> \<forall>p. p \<bullet> f = f"
    14 
    17 
    15 lemma eqvtI:
    18 lemma eqvtI:
    16   "(\<And>p. p \<bullet> x \<equiv> x) \<Longrightarrow> eqvt x"
    19   "(\<And>p. p \<bullet> f \<equiv> f) \<Longrightarrow> eqvt f"
    17 apply(auto simp add: eqvt_def)
    20 apply(auto simp add: eqvt_def)
    18 done
    21 done
    19 
       
    20 term THE_default
       
    21 
    22 
    22 lemma the_default_eqvt:
    23 lemma the_default_eqvt:
    23   assumes unique: "\<exists>!x. P x"
    24   assumes unique: "\<exists>!x. P x"
    24   shows "(p \<bullet> (THE_default d P)) = (THE_default d (p \<bullet> P))"
    25   shows "(p \<bullet> (THE_default d P)) = (THE_default d (p \<bullet> P))"
    25   apply(rule THE_default1_equality [symmetric])
    26   apply(rule THE_default1_equality [symmetric])
    47 
    48 
    48 
    49 
    49 
    50 
    50 ML {*
    51 ML {*
    51 
    52 
    52 
       
    53 val trace = Unsynchronized.ref false
    53 val trace = Unsynchronized.ref false
    54 fun trace_msg msg = if ! trace then tracing (msg ()) else ()
    54 fun trace_msg msg = if ! trace then tracing (msg ()) else ()
    55 
    55 
    56 val boolT = HOLogic.boolT
    56 val boolT = HOLogic.boolT
    57 val mk_eq = HOLogic.mk_eq
    57 val mk_eq = HOLogic.mk_eq
   132     rev (Function_Ctx_Tree.traverse_tree add_Ri tree [])
   132     rev (Function_Ctx_Tree.traverse_tree add_Ri tree [])
   133   end
   133   end
   134 *}
   134 *}
   135 
   135 
   136 ML {*
   136 ML {*
   137 fun mk_eqvt trm =
   137 fun mk_eqvt_at (f_trm, arg_trm) =
   138   let
   138   let
   139     val ty = fastype_of trm
   139     val f_ty = fastype_of f_trm
   140   in
   140     val arg_ty = domain_type f_ty
   141     Const (@{const_name eqvt}, ty --> @{typ bool}) $ trm
   141   in
       
   142     Const (@{const_name eqvt_at}, [f_ty, arg_ty] ---> @{typ bool}) $ f_trm $ arg_trm
   142     |> HOLogic.mk_Trueprop
   143     |> HOLogic.mk_Trueprop
   143   end
   144   end
       
   145 *}
       
   146 
       
   147 ML {*
       
   148 fun find_calls2 f t = 
       
   149   let
       
   150     fun aux (g $ arg) = aux g #> aux arg #> (if f = g then cons ((g, arg)) else I)
       
   151       | aux (Abs (_, _, t)) = aux t 
       
   152       | aux _ = I
       
   153   in
       
   154     aux t []
       
   155   end 
   144 *}
   156 *}
   145 
   157 
   146 
   158 
   147 ML {*
   159 ML {*
   148 (** building proof obligations *)
   160 (** building proof obligations *)
   151   let
   163   let
   152     val _ = tracing ("domT: " ^ @{make_string} domT)
   164     val _ = tracing ("domT: " ^ @{make_string} domT)
   153     val _ = tracing ("ranT: " ^ @{make_string} ranT)
   165     val _ = tracing ("ranT: " ^ @{make_string} ranT)
   154     val _ = tracing ("fvar: " ^ @{make_string} fvar)
   166     val _ = tracing ("fvar: " ^ @{make_string} fvar)
   155     val _ = tracing ("f: " ^ @{make_string} f)
   167     val _ = tracing ("f: " ^ @{make_string} f)
   156     fun mk_impl ((qs, gs, lhs, rhs),(qs', gs', lhs', rhs')) =
   168 
       
   169     fun mk_impl ((qs, gs, lhs, rhs), (qs', gs', lhs', rhs')) =
   157       let
   170       let
   158         val shift = incr_boundvars (length qs')
   171         val shift = incr_boundvars (length qs')
       
   172 
       
   173         val RCs_rhs  = find_calls2 fvar rhs
       
   174         val RCs_rhs' = find_calls2 fvar rhs'
   159       in
   175       in
   160         Logic.mk_implies
   176         Logic.mk_implies
   161           (HOLogic.mk_Trueprop (HOLogic.eq_const domT $ shift lhs $ lhs'),
   177           (HOLogic.mk_Trueprop (HOLogic.eq_const domT $ shift lhs $ lhs'),
   162             HOLogic.mk_Trueprop (HOLogic.eq_const ranT $ shift rhs $ rhs'))
   178             HOLogic.mk_Trueprop (HOLogic.eq_const ranT $ shift rhs $ rhs'))
   163         |> fold_rev (curry Logic.mk_implies) (map shift gs @ gs')
   179         |> fold_rev (curry Logic.mk_implies) (map shift gs @ gs')
   164         (*|> (curry Logic.mk_implies) (mk_eqvt fvar) *)
   180         |> fold_rev (curry Logic.mk_implies) (map (shift o mk_eqvt_at) RCs_rhs) 
   165         |> (curry Logic.mk_implies) @{term "Trueprop True"}  (* HERE *)
   181         |> fold_rev (curry Logic.mk_implies) (map mk_eqvt_at RCs_rhs')
       
   182         (*|> (curry Logic.mk_implies) @{term "Trueprop True"}*)  (* HERE *)
   166         |> fold_rev (fn (n,T) => fn b => Term.all T $ Abs(n,T,b)) (qs @ qs')
   183         |> fold_rev (fn (n,T) => fn b => Term.all T $ Abs(n,T,b)) (qs @ qs')
   167         |> curry abstract_over fvar
   184         |> curry abstract_over fvar
   168         |> curry subst_bound f
   185         |> curry subst_bound f
   169       end
   186       end
   170   in
   187   in
   274   in
   291   in
   275     (thms1 :: store_compat_thms (n - 1) thms2)
   292     (thms1 :: store_compat_thms (n - 1) thms2)
   276   end
   293   end
   277 *}
   294 *}
   278 
   295 
       
   296 
       
   297 ML {*
       
   298 fun eqvt_at_elim thm =
       
   299   let
       
   300     val _ = tracing ("term\n" ^ @{make_string} (prop_of thm))
       
   301   in
       
   302   case (prop_of thm) of
       
   303     Const ("==>", _) $ (t as (@{term Trueprop} $ (Const (@{const_name eqvt_at}, _) $ _ $ _))) $ _ => 
       
   304       let
       
   305         val el_thm = Skip_Proof.make_thm @{theory} t
       
   306       in
       
   307         Thm.elim_implies el_thm thm 
       
   308         |> eqvt_at_elim
       
   309       end
       
   310   | _ => thm
       
   311   end
       
   312 *}
       
   313 
   279 ML {*
   314 ML {*
   280 (* expects i <= j *)
   315 (* expects i <= j *)
   281 fun lookup_compat_thm i j cts =
   316 fun lookup_compat_thm i j cts =
   282   nth (nth cts (i - 1)) (j - i)
   317   nth (nth cts (i - 1)) (j - i)
   283 
   318 
   293     let
   328     let
   294       val compat = lookup_compat_thm j i cts
   329       val compat = lookup_compat_thm j i cts
   295     in
   330     in
   296       compat         (* "!!qj qi. Gsj => Gsi => lhsj = lhsi ==> rhsj = rhsi" *)
   331       compat         (* "!!qj qi. Gsj => Gsi => lhsj = lhsi ==> rhsj = rhsi" *)
   297       |> fold Thm.forall_elim (cqsj @ cqsi) (* "Gsj => Gsi => lhsj = lhsi ==> rhsj = rhsi" *)
   332       |> fold Thm.forall_elim (cqsj @ cqsi) (* "Gsj => Gsi => lhsj = lhsi ==> rhsj = rhsi" *)
   298       (*|> tap (fn th => tracing ("NEED TO PROVE" ^ @{make_string} th)) *)
   333       |> tap (fn th => tracing ("NEED TO PROVE " ^ @{make_string} th))
   299       |> Thm.elim_implies @{thm TrueI}
   334       (*|> Thm.elim_implies @{thm TrueI}*) (* THERE *)
       
   335       |> eqvt_at_elim 
       
   336       |> tap (fn th => tracing ("AFTER " ^ @{make_string} th))
   300       |> fold Thm.elim_implies agsj
   337       |> fold Thm.elim_implies agsj
   301       |> fold Thm.elim_implies agsi
   338       |> fold Thm.elim_implies agsi
   302       |> Thm.elim_implies ((Thm.assume lhsi_eq_lhsj) RS sym) (* "Gsj, Gsi, lhsi = lhsj |-- rhsj = rhsi" *)
   339       |> Thm.elim_implies ((Thm.assume lhsi_eq_lhsj) RS sym) (* "Gsj, Gsi, lhsi = lhsj |-- rhsj = rhsi" *)
   303     end
   340     end
   304     else
   341     else
   305     let
   342     let
   306       val compat = lookup_compat_thm i j cts
   343       val compat = lookup_compat_thm i j cts
   307     in
   344     in
   308       compat        (* "!!qi qj. Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *)
   345       compat        (* "!!qi qj. Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *)
   309       |> fold Thm.forall_elim (cqsi @ cqsj) (* "Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *)
   346       |> fold Thm.forall_elim (cqsi @ cqsj) (* "Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *)
   310       (* |> tap (fn th => tracing ("NEED TO PROVE" ^ @{make_string} th)) *)
   347       |> tap (fn th => tracing ("NEED TO PROVE " ^ @{make_string} th)) 
   311       |> Thm.elim_implies @{thm TrueI}
   348       (*|> Thm.elim_implies @{thm TrueI}*)
       
   349       |> eqvt_at_elim 
       
   350       |> tap (fn th => tracing ("AFTER " ^ @{make_string} th))
   312       |> fold Thm.elim_implies agsi
   351       |> fold Thm.elim_implies agsi
   313       |> fold Thm.elim_implies agsj
   352       |> fold Thm.elim_implies agsj
   314       |> Thm.elim_implies (Thm.assume lhsi_eq_lhsj)
   353       |> Thm.elim_implies (Thm.assume lhsi_eq_lhsj)
   315       |> (fn thm => thm RS sym) (* "Gsi, Gsj, lhsi = lhsj |-- rhsj = rhsi" *)
   354       |> (fn thm => thm RS sym) (* "Gsi, Gsj, lhsi = lhsj |-- rhsj = rhsi" *)
   316     end
   355     end
   317   end
   356   end
   318 *}
   357 *}
   319 
   358 
   320 (* WASS *)
       
   321 
   359 
   322 ML {*
   360 ML {*
   323 (* Generates the replacement lemma in fully quantified form. *)
   361 (* Generates the replacement lemma in fully quantified form. *)
   324 fun mk_replacement_lemma thy h ih_elim clause =
   362 fun mk_replacement_lemma thy h ih_elim clause =
   325   let
   363   let
   412     val G_lhs_y = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (G $ lhs $ y)))
   450     val G_lhs_y = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (G $ lhs $ y)))
   413 
   451 
   414     val unique_clauses =
   452     val unique_clauses =
   415       map2 (mk_uniqueness_clause thy globals compat_store clausei) clauses rep_lemmas
   453       map2 (mk_uniqueness_clause thy globals compat_store clausei) clauses rep_lemmas
   416      
   454      
       
   455     (*
   417     val _ = tracing ("unique_clauses\n" ^ cat_lines (map @{make_string} unique_clauses))
   456     val _ = tracing ("unique_clauses\n" ^ cat_lines (map @{make_string} unique_clauses))
       
   457     *)
   418 
   458 
   419     fun elim_implies_eta A AB =
   459     fun elim_implies_eta A AB =
   420       Thm.compose_no_flatten true (A, 0) 1 AB |> Seq.list_of |> the_single
   460       Thm.compose_no_flatten true (A, 0) 1 AB |> Seq.list_of |> the_single
   421 
   461 
   422     val uniqueness = G_cases
   462     val uniqueness = G_cases
   469     val ihyp_thm = Thm.assume ihyp |> Thm.forall_elim_vars 0
   509     val ihyp_thm = Thm.assume ihyp |> Thm.forall_elim_vars 0
   470     val ih_intro = ihyp_thm RS (f_def RS ex1_implies_ex)
   510     val ih_intro = ihyp_thm RS (f_def RS ex1_implies_ex)
   471     val ih_elim = ihyp_thm RS (f_def RS ex1_implies_un)
   511     val ih_elim = ihyp_thm RS (f_def RS ex1_implies_un)
   472       |> instantiate' [] [NONE, SOME (cterm_of thy h)]
   512       |> instantiate' [] [NONE, SOME (cterm_of thy h)]
   473 
   513 
       
   514     (*
   474     val _ = tracing ("ihyp\n" ^ @{make_string} ihyp)
   515     val _ = tracing ("ihyp\n" ^ @{make_string} ihyp)
   475     val _ = tracing ("ihyp_thm\n" ^ @{make_string} ihyp_thm)
   516     val _ = tracing ("ihyp_thm\n" ^ @{make_string} ihyp_thm)
   476     val _ = tracing ("ih_intro\n" ^ @{make_string} ih_intro)
   517     val _ = tracing ("ih_intro\n" ^ @{make_string} ih_intro)
   477     val _ = tracing ("ih_elim\n" ^ @{make_string} ih_elim)
   518     val _ = tracing ("ih_elim\n" ^ @{make_string} ih_elim)
       
   519     *)
   478 
   520 
   479     val _ = trace_msg (K "Proving Replacement lemmas...")
   521     val _ = trace_msg (K "Proving Replacement lemmas...")
   480     val repLemmas = map (mk_replacement_lemma thy h ih_elim) clauses
   522     val repLemmas = map (mk_replacement_lemma thy h ih_elim) clauses
   481 
   523 
       
   524     (*
   482     val _ = tracing (cat_lines (map @{make_string} repLemmas))
   525     val _ = tracing (cat_lines (map @{make_string} repLemmas))
       
   526     *)
   483 
   527 
   484     val _ = trace_msg (K "Proving cases for unique existence...")
   528     val _ = trace_msg (K "Proving cases for unique existence...")
   485     val (ex1s, values) =
   529     val (ex1s, values) =
   486       split_list (map (mk_uniqueness_case thy globals G f 
   530       split_list (map (mk_uniqueness_case thy globals G f 
   487         ihyp ih_intro G_elim compat_store clauses repLemmas) clauses)
   531         ihyp ih_intro G_elim compat_store clauses repLemmas) clauses)
   488     
   532      
       
   533     (* 
   489     val _ = tracing ("ex1s\n" ^ cat_lines (map @{make_string} ex1s))
   534     val _ = tracing ("ex1s\n" ^ cat_lines (map @{make_string} ex1s))
   490     val _ = tracing ("values\n" ^ cat_lines (map @{make_string} values)) 
   535     val _ = tracing ("values\n" ^ cat_lines (map @{make_string} values)) 
       
   536     *)
   491 
   537 
   492     val _ = trace_msg (K "Proving: Graph is a function")
   538     val _ = trace_msg (K "Proving: Graph is a function")
   493     val graph_is_function = complete
   539     val graph_is_function = complete
   494       |> Thm.forall_elim_vars 0
   540       |> Thm.forall_elim_vars 0
   495       |> fold (curry op COMP) ex1s
   541       |> fold (curry op COMP) ex1s
   990     val RCss = map find_calls trees
  1036     val RCss = map find_calls trees
   991 
  1037 
   992     val ((G, GIntro_thms, G_elim, G_induct, G_eqvt), lthy) =
  1038     val ((G, GIntro_thms, G_elim, G_induct, G_eqvt), lthy) =
   993       PROFILE "def_graph" (define_graph (graph_name defname) fvar domT ranT clauses RCss) lthy
  1039       PROFILE "def_graph" (define_graph (graph_name defname) fvar domT ranT clauses RCss) lthy
   994 
  1040 
       
  1041     (* 
   995     val _ = tracing ("Graph - name: " ^ @{make_string} G)
  1042     val _ = tracing ("Graph - name: " ^ @{make_string} G)
   996     val _ = tracing ("Graph intros:\n" ^ cat_lines (map @{make_string} GIntro_thms))
  1043     val _ = tracing ("Graph intros:\n" ^ cat_lines (map @{make_string} GIntro_thms))
   997     val _ = tracing ("Graph Equivariance " ^ @{make_string} G_eqvt)
  1044     val _ = tracing ("Graph Equivariance " ^ @{make_string} G_eqvt)
   998     
  1045     *)
   999 
  1046 
  1000     val ((f, (_, f_defthm)), lthy) =
  1047     val ((f, (_, f_defthm)), lthy) =
  1001       PROFILE "def_fun" (define_function (defname ^ "_sumC_def") (fname, mixfix) domT ranT G default) lthy
  1048       PROFILE "def_fun" (define_function (defname ^ "_sumC_def") (fname, mixfix) domT ranT G default) lthy
  1002 
  1049 
       
  1050     (*
  1003     val _ = tracing ("f - name: " ^ @{make_string} f)
  1051     val _ = tracing ("f - name: " ^ @{make_string} f)
  1004     val _ = tracing ("f_defthm:\n" ^ @{make_string} f_defthm)
  1052     val _ = tracing ("f_defthm:\n" ^ @{make_string} f_defthm)
       
  1053     *)
  1005 
  1054 
  1006     val RCss = map (map (inst_RC (ProofContext.theory_of lthy) fvar f)) RCss
  1055     val RCss = map (map (inst_RC (ProofContext.theory_of lthy) fvar f)) RCss
  1007     val trees = map (Function_Ctx_Tree.inst_tree (ProofContext.theory_of lthy) fvar f) trees
  1056     val trees = map (Function_Ctx_Tree.inst_tree (ProofContext.theory_of lthy) fvar f) trees
  1008 
  1057 
       
  1058     val _ = tracing ("recursive calls:\n" ^ cat_lines (map @{make_string} RCss))
       
  1059 
  1009     val ((R, RIntro_thmss, R_elim, R_eqvt), lthy) =
  1060     val ((R, RIntro_thmss, R_elim, R_eqvt), lthy) =
  1010       PROFILE "def_rel" (define_recursion_relation (rel_name defname) domT abstract_qglrs clauses RCss) lthy
  1061       PROFILE "def_rel" (define_recursion_relation (rel_name defname) domT abstract_qglrs clauses RCss) lthy
  1011 
  1062 
       
  1063     (*
  1012     val _ = tracing ("Relation - name: " ^ @{make_string} R) 
  1064     val _ = tracing ("Relation - name: " ^ @{make_string} R) 
  1013     val _ = tracing ("Relation intros:\n" ^ cat_lines (map @{make_string} RIntro_thmss))
  1065     val _ = tracing ("Relation intros:\n" ^ cat_lines (map @{make_string} RIntro_thmss))
  1014     val _ = tracing ("Relation Equivariance " ^ @{make_string} R_eqvt)
  1066     val _ = tracing ("Relation Equivariance " ^ @{make_string} R_eqvt)
       
  1067     *)    
  1015 
  1068 
  1016     val (_, lthy) =
  1069     val (_, lthy) =
  1017       Local_Theory.abbrev Syntax.mode_default ((Binding.name (dom_name defname), NoSyn), mk_acc domT R) lthy
  1070       Local_Theory.abbrev Syntax.mode_default ((Binding.name (dom_name defname), NoSyn), mk_acc domT R) lthy
  1018 
  1071 
  1019     val newthy = ProofContext.theory_of lthy
  1072     val newthy = ProofContext.theory_of lthy
  1027 
  1080 
  1028     val complete =
  1081     val complete =
  1029       mk_completeness globals clauses abstract_qglrs |> cert |> Thm.assume
  1082       mk_completeness globals clauses abstract_qglrs |> cert |> Thm.assume
  1030 
  1083 
  1031     val compat =
  1084     val compat =
  1032       mk_compat_proof_obligations domT ranT fvar f abstract_qglrs
  1085       mk_compat_proof_obligations domT ranT fvar f abstract_qglrs 
  1033       |> map (cert #> Thm.assume)
  1086       |> map (cert #> Thm.assume)
  1034 
  1087 
  1035     val compat_store = store_compat_thms n compat
  1088     val compat_store = store_compat_thms n compat
  1036 
  1089 
  1037     (*
  1090     (*
  1165     fun define (fvar as (n, _)) caTs resultT i =
  1218     fun define (fvar as (n, _)) caTs resultT i =
  1166       let
  1219       let
  1167         val vars = map_index (fn (j,T) => Free ("x" ^ string_of_int j, T)) caTs (* FIXME: Bind xs properly *)
  1220         val vars = map_index (fn (j,T) => Free ("x" ^ string_of_int j, T)) caTs (* FIXME: Bind xs properly *)
  1168         val i' = find_index (fn Ta => Ta = resultT) dresultTs + 1
  1221         val i' = find_index (fn Ta => Ta = resultT) dresultTs + 1
  1169 
  1222 
  1170         val f_exp = SumTree.mk_proj RST n' i' (Free fsum_var $ SumTree.mk_inj ST num i (foldr1 HOLogic.mk_prod vars))
  1223         val f_exp = SumTree.mk_proj RST n' i' 
       
  1224           (Free fsum_var $ SumTree.mk_inj ST num i (foldr1 HOLogic.mk_prod vars))
       
  1225         
  1171         val def = Term.abstract_over (Free fsum_var, fold_rev lambda vars f_exp)
  1226         val def = Term.abstract_over (Free fsum_var, fold_rev lambda vars f_exp)
  1172 
  1227 
  1173         val rew = (n, fold_rev lambda vars f_exp)
  1228         val rew = (n, fold_rev lambda vars f_exp)
  1174       in
  1229       in
  1175         (MutualPart {i=i, i'=i', fvar=fvar,cargTs=caTs,f_def=def,f=NONE,f_defthm=NONE}, rew)
  1230         (MutualPart {i=i, i'=i', fvar=fvar,cargTs=caTs,f_def=def,f=NONE,f_defthm=NONE}, rew)
  1185          SumTree.mk_inj RST n' i' (replace_frees rews rhs)
  1240          SumTree.mk_inj RST n' i' (replace_frees rews rhs)
  1186          |> Envir.beta_norm)
  1241          |> Envir.beta_norm)
  1187       end
  1242       end
  1188 
  1243 
  1189     val qglrs = map convert_eqs fqgars
  1244     val qglrs = map convert_eqs fqgars
       
  1245    
       
  1246     fun pp_f (f, args, precond, lhs, rhs) =
       
  1247       (tracing ("lhs: " ^ commas 
       
  1248          (map (fn t => Syntax.string_of_term ctxt (subst_bounds (map Free (rev args), t))) lhs));
       
  1249        tracing ("rhs: " ^ Syntax.string_of_term ctxt (subst_bounds (map Free (rev args), rhs))))
       
  1250 
       
  1251     fun pp_q (args, precond, lhs, rhs) =
       
  1252       (tracing ("qlhs: " ^ Syntax.string_of_term ctxt (subst_bounds (map Free (rev args), lhs)));
       
  1253        tracing ("qrhs: " ^ Syntax.string_of_term ctxt (subst_bounds (map Free (rev args), rhs))))
       
  1254 
  1190   in
  1255   in
  1191     Mutual {n=num, n'=n', fsum_var=fsum_var, ST=ST, RST=RST,
  1256     Mutual {n=num, n'=n', fsum_var=fsum_var, ST=ST, RST=RST,
  1192       parts=parts, fqgars=fqgars, qglrs=qglrs, fsum=NONE}
  1257       parts=parts, fqgars=fqgars, qglrs=qglrs, fsum=NONE}
  1193   end
  1258   end
  1194 
  1259 *}
       
  1260 
       
  1261 ML {*
  1195 fun define_projections fixes mutual fsum lthy =
  1262 fun define_projections fixes mutual fsum lthy =
  1196   let
  1263   let
  1197     fun def ((MutualPart {i=i, i'=i', fvar=(fname, fT), cargTs, f_def, ...}), (_, mixfix)) lthy =
  1264     fun def ((MutualPart {i=i, i'=i', fvar=(fname, fT), cargTs, f_def, ...}), (_, mixfix)) lthy =
  1198       let
  1265       let
  1199         val ((f, (_, f_defthm)), lthy') =
  1266         val ((f, (_, f_defthm)), lthy') =
  1570 | "(App t\<^isub>1 t\<^isub>2)[y ::= s] = App (t\<^isub>1[y ::= s]) (t\<^isub>2[y ::= s])"
  1637 | "(App t\<^isub>1 t\<^isub>2)[y ::= s] = App (t\<^isub>1[y ::= s]) (t\<^isub>2[y ::= s])"
  1571 | "atom x \<sharp> (y, s) \<Longrightarrow> (Lam x t)[y ::= s] = Lam x (t[y ::= s])"
  1638 | "atom x \<sharp> (y, s) \<Longrightarrow> (Lam x t)[y ::= s] = Lam x (t[y ::= s])"
  1572 apply(case_tac x)
  1639 apply(case_tac x)
  1573 apply(simp)
  1640 apply(simp)
  1574 apply(rule_tac y="a" and c="(b, c)" in lam.strong_exhaust)
  1641 apply(rule_tac y="a" and c="(b, c)" in lam.strong_exhaust)
  1575 apply(simp_all add: lam.distinct)[3]
  1642 apply(simp add: lam.eq_iff lam.distinct)
  1576 apply(auto)[1]
  1643 apply(auto)[1]
       
  1644 apply(simp add: lam.eq_iff lam.distinct)
  1577 apply(auto)[1]
  1645 apply(auto)[1]
  1578 apply(simp add: fresh_star_def)
  1646 apply(simp add: fresh_star_def lam.eq_iff lam.distinct)
  1579 apply(simp_all add: lam.distinct)[5]
  1647 apply(simp_all add: lam.distinct)
  1580 apply(simp add: lam.eq_iff)
  1648 apply(simp add: lam.eq_iff)
  1581 apply(simp add: lam.eq_iff)
  1649 apply(simp add: lam.eq_iff)
  1582 apply(simp add: lam.eq_iff)
  1650 apply(simp add: lam.eq_iff)
  1583 sorry
  1651 sorry
  1584 
  1652 
  1585 
  1653 (* this should not work *)
       
  1654 nominal_primrec 
       
  1655   bnds :: "lam \<Rightarrow> name set"
       
  1656 where
       
  1657   "bnds (Var x) = {}"
       
  1658 | "bnds (App t1 t2) = (bnds t1) \<union> (bnds t2)"
       
  1659 | "bnds (Lam x t) = (bnds t) \<union> {x}"
       
  1660 apply(rule_tac y="x" in lam.exhaust)
       
  1661 apply(simp_all)[3]
       
  1662 apply(simp_all only: lam.distinct)
       
  1663 apply(simp add: lam.eq_iff)
       
  1664 apply(simp add: lam.eq_iff)
       
  1665 apply(simp add: lam.eq_iff)
       
  1666 sorry
  1586 
  1667 
  1587 end
  1668 end
  1588 
  1669 
  1589 
  1670 
  1590 
  1671