Nominal/Ex/LamTest.thy
changeset 2651 4aa72a88b2c1
parent 2650 e5fa8de0e4bd
child 2652 e9a2770660ef
equal deleted inserted replaced
2650:e5fa8de0e4bd 2651:4aa72a88b2c1
    14 
    14 
    15 lemma eqvtI:
    15 lemma eqvtI:
    16   "(\<And>p. p \<bullet> x \<equiv> x) \<Longrightarrow> eqvt x"
    16   "(\<And>p. p \<bullet> x \<equiv> x) \<Longrightarrow> eqvt x"
    17 apply(auto simp add: eqvt_def)
    17 apply(auto simp add: eqvt_def)
    18 done
    18 done
       
    19 
       
    20 
       
    21 lemma the_default_eqvt:
       
    22   assumes unique: "\<exists>!x. P x"
       
    23   shows "(p \<bullet> (THE_default d P)) = (THE_default (p \<bullet> d) (p \<bullet> P))"
       
    24   apply(rule THE_default1_equality [symmetric])
       
    25   apply(rule_tac p="-p" in permute_boolE)
       
    26   apply(perm_simp add: permute_minus_cancel)
       
    27   apply(rule unique)
       
    28   apply(rule_tac p="-p" in permute_boolE)
       
    29   apply(perm_simp add: permute_minus_cancel)
       
    30   apply(rule THE_defaultI'[OF unique])
       
    31   done
       
    32 
    19 
    33 
    20 ML {*
    34 ML {*
    21 
    35 
    22 
    36 
    23 val trace = Unsynchronized.ref false
    37 val trace = Unsynchronized.ref false
    71   qglr : ((string * typ) list * term list * term * term),
    85   qglr : ((string * typ) list * term list * term * term),
    72   cdata : clause_context,
    86   cdata : clause_context,
    73   tree: Function_Ctx_Tree.ctx_tree,
    87   tree: Function_Ctx_Tree.ctx_tree,
    74   lGI: thm,
    88   lGI: thm,
    75   RCs: rec_call_info list}
    89   RCs: rec_call_info list}
    76 
    90 *}
    77 
    91 
       
    92 thm accp_induct_rule
       
    93 
       
    94 ML {*
    78 (* Theory dependencies. *)
    95 (* Theory dependencies. *)
    79 val acc_induct_rule = @{thm accp_induct_rule}
    96 val acc_induct_rule = @{thm accp_induct_rule}
    80 
    97 
    81 val ex1_implies_ex = @{thm FunDef.fundef_ex1_existence}
    98 val ex1_implies_ex = @{thm FunDef.fundef_ex1_existence}
    82 val ex1_implies_un = @{thm FunDef.fundef_ex1_uniqueness}
    99 val ex1_implies_un = @{thm FunDef.fundef_ex1_uniqueness}
   126       in
   143       in
   127         Logic.mk_implies
   144         Logic.mk_implies
   128           (HOLogic.mk_Trueprop (HOLogic.eq_const domT $ shift lhs $ lhs'),
   145           (HOLogic.mk_Trueprop (HOLogic.eq_const domT $ shift lhs $ lhs'),
   129             HOLogic.mk_Trueprop (HOLogic.eq_const ranT $ shift rhs $ rhs'))
   146             HOLogic.mk_Trueprop (HOLogic.eq_const ranT $ shift rhs $ rhs'))
   130         |> fold_rev (curry Logic.mk_implies) (map shift gs @ gs')
   147         |> fold_rev (curry Logic.mk_implies) (map shift gs @ gs')
   131         (* HERE |> (curry Logic.mk_implies) (mk_eqvt fvar) *)
   148         (*|> (curry Logic.mk_implies) (mk_eqvt fvar) *)
   132         |> (curry Logic.mk_implies) @{term "Trueprop True"}
   149         |> (curry Logic.mk_implies) @{term "Trueprop True"}  (* HERE *)
   133         |> fold_rev (fn (n,T) => fn b => Term.all T $ Abs(n,T,b)) (qs @ qs')
   150         |> fold_rev (fn (n,T) => fn b => Term.all T $ Abs(n,T,b)) (qs @ qs')
   134         |> curry abstract_over fvar
   151         |> curry abstract_over fvar
   135         |> curry subst_bound f
   152         |> curry subst_bound f
   136       end
   153       end
   137   in
   154   in
   260     let
   277     let
   261       val compat = lookup_compat_thm j i cts
   278       val compat = lookup_compat_thm j i cts
   262     in
   279     in
   263       compat         (* "!!qj qi. Gsj => Gsi => lhsj = lhsi ==> rhsj = rhsi" *)
   280       compat         (* "!!qj qi. Gsj => Gsi => lhsj = lhsi ==> rhsj = rhsi" *)
   264       |> fold Thm.forall_elim (cqsj @ cqsi) (* "Gsj => Gsi => lhsj = lhsi ==> rhsj = rhsi" *)
   281       |> fold Thm.forall_elim (cqsj @ cqsi) (* "Gsj => Gsi => lhsj = lhsi ==> rhsj = rhsi" *)
       
   282       (*|> tap (fn th => tracing ("NEED TO PROVE" ^ @{make_string} th)) *)
   265       |> Thm.elim_implies @{thm TrueI}
   283       |> Thm.elim_implies @{thm TrueI}
   266       |> fold Thm.elim_implies agsj
   284       |> fold Thm.elim_implies agsj
   267       |> fold Thm.elim_implies agsi
   285       |> fold Thm.elim_implies agsi
   268       |> Thm.elim_implies ((Thm.assume lhsi_eq_lhsj) RS sym) (* "Gsj, Gsi, lhsi = lhsj |-- rhsj = rhsi" *)
   286       |> Thm.elim_implies ((Thm.assume lhsi_eq_lhsj) RS sym) (* "Gsj, Gsi, lhsi = lhsj |-- rhsj = rhsi" *)
   269     end
   287     end
   271     let
   289     let
   272       val compat = lookup_compat_thm i j cts
   290       val compat = lookup_compat_thm i j cts
   273     in
   291     in
   274       compat        (* "!!qi qj. Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *)
   292       compat        (* "!!qi qj. Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *)
   275       |> fold Thm.forall_elim (cqsi @ cqsj) (* "Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *)
   293       |> fold Thm.forall_elim (cqsi @ cqsj) (* "Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *)
       
   294       (* |> tap (fn th => tracing ("NEED TO PROVE" ^ @{make_string} th)) *)
   276       |> Thm.elim_implies @{thm TrueI}
   295       |> Thm.elim_implies @{thm TrueI}
   277       |> fold Thm.elim_implies agsi
   296       |> fold Thm.elim_implies agsi
   278       |> fold Thm.elim_implies agsj
   297       |> fold Thm.elim_implies agsj
   279       |> Thm.elim_implies (Thm.assume lhsi_eq_lhsj)
   298       |> Thm.elim_implies (Thm.assume lhsi_eq_lhsj)
   280       |> (fn thm => thm RS sym) (* "Gsi, Gsj, lhsi = lhsj |-- rhsj = rhsi" *)
   299       |> (fn thm => thm RS sym) (* "Gsi, Gsj, lhsi = lhsj |-- rhsj = rhsi" *)
   376     val P = cterm_of thy (mk_eq (y, rhsC))
   395     val P = cterm_of thy (mk_eq (y, rhsC))
   377     val G_lhs_y = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (G $ lhs $ y)))
   396     val G_lhs_y = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (G $ lhs $ y)))
   378 
   397 
   379     val unique_clauses =
   398     val unique_clauses =
   380       map2 (mk_uniqueness_clause thy globals compat_store clausei) clauses rep_lemmas
   399       map2 (mk_uniqueness_clause thy globals compat_store clausei) clauses rep_lemmas
   381   
   400      
       
   401     val _ = tracing ("unique_clauses\n" ^ cat_lines (map @{make_string} unique_clauses))
       
   402 
   382     fun elim_implies_eta A AB =
   403     fun elim_implies_eta A AB =
   383       Thm.compose_no_flatten true (A, 0) 1 AB |> Seq.list_of |> the_single
   404       Thm.compose_no_flatten true (A, 0) 1 AB |> Seq.list_of |> the_single
   384 
   405 
   385     val uniqueness = G_cases
   406     val uniqueness = G_cases
   386       |> Thm.forall_elim (cterm_of thy lhs)
   407       |> Thm.forall_elim (cterm_of thy lhs)
   412   in
   433   in
   413     (exactly_one, function_value)
   434     (exactly_one, function_value)
   414   end
   435   end
   415 *}
   436 *}
   416 
   437 
       
   438 (* AAA *)
       
   439 
   417 ML {*
   440 ML {*
   418 fun prove_stuff ctxt globals G f R clauses complete compat compat_store G_elim f_def =
   441 fun prove_stuff ctxt globals G f R clauses complete compat compat_store G_elim f_def =
   419   let
   442   let
   420     val Globals {h, domT, ranT, x, ...} = globals
   443     val Globals {h, domT, ranT, x, ...} = globals
   421     val thy = ProofContext.theory_of ctxt
   444     val thy = ProofContext.theory_of ctxt
   430     val ihyp_thm = Thm.assume ihyp |> Thm.forall_elim_vars 0
   453     val ihyp_thm = Thm.assume ihyp |> Thm.forall_elim_vars 0
   431     val ih_intro = ihyp_thm RS (f_def RS ex1_implies_ex)
   454     val ih_intro = ihyp_thm RS (f_def RS ex1_implies_ex)
   432     val ih_elim = ihyp_thm RS (f_def RS ex1_implies_un)
   455     val ih_elim = ihyp_thm RS (f_def RS ex1_implies_un)
   433       |> instantiate' [] [NONE, SOME (cterm_of thy h)]
   456       |> instantiate' [] [NONE, SOME (cterm_of thy h)]
   434 
   457 
       
   458     val _ = tracing ("ihyp\n" ^ @{make_string} ihyp)
       
   459     val _ = tracing ("ihyp_thm\n" ^ @{make_string} ihyp_thm)
       
   460     val _ = tracing ("ih_intro\n" ^ @{make_string} ih_intro)
       
   461     val _ = tracing ("ih_elim\n" ^ @{make_string} ih_elim)
       
   462 
   435     val _ = trace_msg (K "Proving Replacement lemmas...")
   463     val _ = trace_msg (K "Proving Replacement lemmas...")
   436     val repLemmas = map (mk_replacement_lemma thy h ih_elim) clauses
   464     val repLemmas = map (mk_replacement_lemma thy h ih_elim) clauses
       
   465 
       
   466     val _ = tracing (cat_lines (map @{make_string} repLemmas))
   437 
   467 
   438     val _ = trace_msg (K "Proving cases for unique existence...")
   468     val _ = trace_msg (K "Proving cases for unique existence...")
   439     val (ex1s, values) =
   469     val (ex1s, values) =
   440       split_list (map (mk_uniqueness_case thy globals G f 
   470       split_list (map (mk_uniqueness_case thy globals G f 
   441         ihyp ih_intro G_elim compat_store clauses repLemmas) clauses)
   471         ihyp ih_intro G_elim compat_store clauses repLemmas) clauses)
       
   472     
       
   473     val _ = tracing ("ex1s\n" ^ cat_lines (map @{make_string} ex1s))
       
   474     val _ = tracing ("values\n" ^ cat_lines (map @{make_string} values)) 
   442 
   475 
   443     val _ = trace_msg (K "Proving: Graph is a function")
   476     val _ = trace_msg (K "Proving: Graph is a function")
   444     val graph_is_function = complete
   477     val graph_is_function = complete
   445       |> Thm.forall_elim_vars 0
   478       |> Thm.forall_elim_vars 0
   446       |> fold (curry op COMP) ex1s
   479       |> fold (curry op COMP) ex1s
   458   in
   491   in
   459     (goalstate, values)
   492     (goalstate, values)
   460   end
   493   end
   461 *}
   494 *}
   462 
   495 
   463 ML {* 
   496 
   464 Inductive.add_inductive_i;
       
   465 Local_Theory.conceal
       
   466 *}
       
   467 
   497 
   468 ML {*
   498 ML {*
   469 (* wrapper -- restores quantifiers in rule specifications *)
   499 (* wrapper -- restores quantifiers in rule specifications *)
   470 fun inductive_def (binding as ((R, T), _)) intrs lthy =
   500 fun inductive_def (binding as ((R, T), _)) intrs lthy =
   471   let
   501   let
   946     val ((G, GIntro_thms, G_elim, G_induct, G_eqvt), lthy) =
   976     val ((G, GIntro_thms, G_elim, G_induct, G_eqvt), lthy) =
   947       PROFILE "def_graph" (define_graph (graph_name defname) fvar domT ranT clauses RCss) lthy
   977       PROFILE "def_graph" (define_graph (graph_name defname) fvar domT ranT clauses RCss) lthy
   948 
   978 
   949     val _ = tracing ("Graph - name: " ^ @{make_string} G)
   979     val _ = tracing ("Graph - name: " ^ @{make_string} G)
   950     val _ = tracing ("Graph intros:\n" ^ cat_lines (map @{make_string} GIntro_thms))
   980     val _ = tracing ("Graph intros:\n" ^ cat_lines (map @{make_string} GIntro_thms))
   951     val _ = tracing ("Graph Equivariance" ^ @{make_string} G_eqvt)
   981     val _ = tracing ("Graph Equivariance " ^ @{make_string} G_eqvt)
   952     
   982     
   953 
   983 
   954     val ((f, (_, f_defthm)), lthy) =
   984     val ((f, (_, f_defthm)), lthy) =
   955       PROFILE "def_fun" (define_function (defname ^ "_sumC_def") (fname, mixfix) domT ranT G default) lthy
   985       PROFILE "def_fun" (define_function (defname ^ "_sumC_def") (fname, mixfix) domT ranT G default) lthy
   956 
   986 
   963     val ((R, RIntro_thmss, R_elim, R_eqvt), lthy) =
   993     val ((R, RIntro_thmss, R_elim, R_eqvt), lthy) =
   964       PROFILE "def_rel" (define_recursion_relation (rel_name defname) domT abstract_qglrs clauses RCss) lthy
   994       PROFILE "def_rel" (define_recursion_relation (rel_name defname) domT abstract_qglrs clauses RCss) lthy
   965 
   995 
   966     val _ = tracing ("Relation - name: " ^ @{make_string} R) 
   996     val _ = tracing ("Relation - name: " ^ @{make_string} R) 
   967     val _ = tracing ("Relation intros:\n" ^ cat_lines (map @{make_string} RIntro_thmss))
   997     val _ = tracing ("Relation intros:\n" ^ cat_lines (map @{make_string} RIntro_thmss))
   968     val _ = tracing ("Relation Equivariance" ^ @{make_string} R_eqvt)
   998     val _ = tracing ("Relation Equivariance " ^ @{make_string} R_eqvt)
   969 
   999 
   970     val (_, lthy) =
  1000     val (_, lthy) =
   971       Local_Theory.abbrev Syntax.mode_default ((Binding.name (dom_name defname), NoSyn), mk_acc domT R) lthy
  1001       Local_Theory.abbrev Syntax.mode_default ((Binding.name (dom_name defname), NoSyn), mk_acc domT R) lthy
   972 
  1002 
   973     val newthy = ProofContext.theory_of lthy
  1003     val newthy = ProofContext.theory_of lthy
  1498 apply(simp_all)[3]
  1528 apply(simp_all)[3]
  1499 apply(simp_all only: lam.distinct)
  1529 apply(simp_all only: lam.distinct)
  1500 apply(simp add: lam.eq_iff)
  1530 apply(simp add: lam.eq_iff)
  1501 apply(simp add: lam.eq_iff)
  1531 apply(simp add: lam.eq_iff)
  1502 sorry
  1532 sorry
       
  1533 
       
  1534 thm depth.psimps
  1503 
  1535 
  1504 nominal_primrec 
  1536 nominal_primrec 
  1505   frees :: "lam \<Rightarrow> name set"
  1537   frees :: "lam \<Rightarrow> name set"
  1506 where
  1538 where
  1507   "frees (Var x) = {x}"
  1539   "frees (Var x) = {x}"