Nominal/Ex/LamTest.thy
changeset 2661 16896fd8eff5
parent 2660 3342a2d13d95
child 2662 7c5bca978886
equal deleted inserted replaced
2660:3342a2d13d95 2661:16896fd8eff5
   343   end
   343   end
   344 *}
   344 *}
   345 
   345 
   346 
   346 
   347 ML {*
   347 ML {*
   348 (*
       
   349 fun eqvt_at_elim thy (eqvts:thm list) thm =
   348 fun eqvt_at_elim thy (eqvts:thm list) thm =
   350   case (prop_of thm) of
   349   case (prop_of thm) of
   351     Const ("==>", _) $ (t as (@{term Trueprop} $ (Const (@{const_name eqvt_at}, _) $ _ $ _))) $ _ => 
   350     Const ("==>", _) $ (t as (@{term Trueprop} $ (Const (@{const_name eqvt_at}, _) $ _ $ _))) $ _ => 
   352       let
   351       let
   353         val el_thm = Skip_Proof.make_thm thy t
   352         val el_thm = Skip_Proof.make_thm thy t
   356       in
   355       in
   357         Thm.elim_implies el_thm thm 
   356         Thm.elim_implies el_thm thm 
   358         |> eqvt_at_elim thy eqvts 
   357         |> eqvt_at_elim thy eqvts 
   359       end
   358       end
   360   | _ => thm
   359   | _ => thm
   361 *)
       
   362 *}
   360 *}
   363 
   361 
   364 ML {*
   362 ML {*
   365 (* expects i <= j *)
   363 (* expects i <= j *)
   366 fun lookup_compat_thm i j cts =
   364 fun lookup_compat_thm i j cts =
   392       val compat = lookup_compat_thm i j cts
   390       val compat = lookup_compat_thm i j cts
   393       (* val _ = tracing ("XXXX compat clause else:\n" ^ @{make_string} compat) *)
   391       (* val _ = tracing ("XXXX compat clause else:\n" ^ @{make_string} compat) *)
   394     in
   392     in
   395       compat        (* "!!qi qj. Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *)
   393       compat        (* "!!qi qj. Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *)
   396       |> fold Thm.forall_elim (cqsi @ cqsj) (* "Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *)
   394       |> fold Thm.forall_elim (cqsi @ cqsj) (* "Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *)
   397       |> fold Thm.elim_implies (rev eqvtsi) (* HERE *)
   395       |> fold Thm.elim_implies (rev eqvtsi)  (* HERE *)
   398       (* |> eqvt_at_elim thy eqvts *) 
   396       (* |> eqvt_at_elim thy eqvtsi *)
   399       |> fold Thm.elim_implies agsi
   397       |> fold Thm.elim_implies agsi
   400       |> fold Thm.elim_implies agsj
   398       |> fold Thm.elim_implies agsj
   401       |> Thm.elim_implies (Thm.assume lhsi_eq_lhsj)
   399       |> Thm.elim_implies (Thm.assume lhsi_eq_lhsj)
   402       |> (fn thm => thm RS sym) (* "Gsi, Gsj, lhsi = lhsj |-- rhsj = rhsi" *)
   400       |> (fn thm => thm RS sym) (* "Gsi, Gsj, lhsi = lhsj |-- rhsj = rhsi" *)
   403     end
   401     end
   437 *}
   435 *}
   438 
   436 
   439 ML {*
   437 ML {*
   440 fun mk_eqvt_lemma thy ih_eqvt clause =
   438 fun mk_eqvt_lemma thy ih_eqvt clause =
   441   let
   439   let
   442     val ClauseInfo {cdata=ClauseContext {cqs, case_hyp, ...}, RCs, ...} = clause
   440     val ClauseInfo {cdata=ClauseContext {cqs, ags, case_hyp, ...}, RCs, ...} = clause
   443 
   441 
   444     local open Conv in
   442     local open Conv in
   445       val ih_conv = arg1_conv o arg_conv o arg_conv
   443       val ih_conv = arg1_conv o arg_conv o arg_conv
   446     end
   444     end
   447 
   445 
   452         (llRI RS ih_eqvt_case)
   450         (llRI RS ih_eqvt_case)
   453         |> fold_rev (Thm.implies_intr o cprop_of) CCas
   451         |> fold_rev (Thm.implies_intr o cprop_of) CCas
   454         |> fold_rev (Thm.forall_intr o cterm_of thy o Free) RIvs
   452         |> fold_rev (Thm.forall_intr o cterm_of thy o Free) RIvs
   455   in
   453   in
   456     map prep_eqvt RCs
   454     map prep_eqvt RCs
       
   455     |> map (fold_rev (Thm.implies_intr o cprop_of) ags)
   457     |> map (Thm.implies_intr (cprop_of case_hyp))
   456     |> map (Thm.implies_intr (cprop_of case_hyp))
   458     |> map (fold_rev Thm.forall_intr cqs)
   457     |> map (fold_rev Thm.forall_intr cqs)
   459     |> map (Thm.close_derivation) 
   458     |> map (Thm.close_derivation) 
   460   end
   459   end
   461 *}
   460 *}
   462 
   461 
   463 ML {*
   462 ML {*
   464 fun mk_uniqueness_clause thy globals compat_store eqvts clausei clausej RLj =
   463 fun mk_uniqueness_clause thy globals compat_store eqvts clausei clausej RLj =
   465   let
   464   let
       
   465     val _ = tracing "START"
       
   466 
   466     val Globals {h, y, x, fvar, ...} = globals
   467     val Globals {h, y, x, fvar, ...} = globals
   467     val ClauseInfo {no=i, cdata=cctxi as ClauseContext {ctxt=ctxti, lhs=lhsi, case_hyp, cqs = cqsi, ...}, ...} = clausei
   468     val ClauseInfo {no=i, cdata=cctxi as ClauseContext {ctxt=ctxti, lhs=lhsi, case_hyp, cqs = cqsi, ags = agsi, ...}, ...} = clausei
   468     val ClauseInfo {no=j, qglr=cdescj, RCs=RCsj, ...} = clausej
   469     val ClauseInfo {no=j, qglr=cdescj, RCs=RCsj, ...} = clausej
   469 
   470 
   470     val cctxj as ClauseContext {ags = agsj', lhs = lhsj', rhs = rhsj', qs = qsj', cqs = cqsj', ...} =
   471     val cctxj as ClauseContext {ags = agsj', lhs = lhsj', rhs = rhsj', qs = qsj', cqs = cqsj', ...} =
   471       mk_clause_context x ctxti cdescj 
   472       mk_clause_context x ctxti cdescj 
   472 
   473 
   476       (fn RCInfo {h_assum, ...} => Thm.assume (cterm_of thy (subst_bounds (rev qsj', h_assum)))) RCsj
   477       (fn RCInfo {h_assum, ...} => Thm.assume (cterm_of thy (subst_bounds (rev qsj', h_assum)))) RCsj
   477 
   478 
   478     val y_eq_rhsj'h = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (mk_eq (y, rhsj'h))))
   479     val y_eq_rhsj'h = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (mk_eq (y, rhsj'h))))
   479     val lhsi_eq_lhsj' = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (mk_eq (lhsi, lhsj'))))
   480     val lhsi_eq_lhsj' = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (mk_eq (lhsi, lhsj'))))
   480        (* lhs_i = lhs_j' |-- lhs_i = lhs_j' *) 
   481        (* lhs_i = lhs_j' |-- lhs_i = lhs_j' *) 
       
   482 
       
   483     val _ = tracing "POINT B"
   481 
   484 
   482     val case_hypj' = trans OF [case_hyp, lhsi_eq_lhsj']
   485     val case_hypj' = trans OF [case_hyp, lhsi_eq_lhsj']
   483 
   486 
   484     val RLj_import = RLj
   487     val RLj_import = RLj
   485       |> fold Thm.forall_elim cqsj'
   488       |> fold Thm.forall_elim cqsj'
   486       |> fold Thm.elim_implies agsj'
   489       |> fold Thm.elim_implies agsj'
   487       |> fold Thm.elim_implies Ghsj'
   490       |> fold Thm.elim_implies Ghsj'
   488 
   491 
       
   492     val _ = tracing "POINT C"
       
   493  
   489     val eqvtsi = nth eqvts (i - 1)
   494     val eqvtsi = nth eqvts (i - 1)
   490       |> map (fold Thm.forall_elim cqsi)
   495       |> map (fold Thm.forall_elim cqsi)
   491       |> map (fold Thm.elim_implies [case_hyp])
   496       |> map (fold Thm.elim_implies [case_hyp])
       
   497       |> map (fold Thm.elim_implies agsi)
       
   498 
       
   499     val _ = tracing "POINT D"
   492 
   500 
   493     val eqvtsj = nth eqvts (j - 1)
   501     val eqvtsj = nth eqvts (j - 1)
       
   502       |> tap (fn thms => tracing ("O1:\n" ^ cat_lines (map @{make_string} thms)))
   494       |> map (fold Thm.forall_elim cqsj')
   503       |> map (fold Thm.forall_elim cqsj')
       
   504       |> tap (fn thms => tracing ("O2:\n" ^ cat_lines (map @{make_string} thms)))
   495       |> map (fold Thm.elim_implies [case_hypj'])
   505       |> map (fold Thm.elim_implies [case_hypj'])
       
   506       |> tap (fn thms => tracing ("O3:\n" ^ cat_lines (map @{make_string} thms)))
       
   507       |> map (fold Thm.elim_implies agsj')
   496 
   508 
   497     val _ = tracing ("eqvtsi:\n" ^ cat_lines (map @{make_string} eqvtsi))
   509     val _ = tracing ("eqvtsi:\n" ^ cat_lines (map @{make_string} eqvtsi))
   498     val _ = tracing ("eqvtsj:\n" ^ cat_lines (map @{make_string} eqvtsj))
   510     val _ = tracing ("eqvtsj:\n" ^ cat_lines (map @{make_string} eqvtsj))
   499     val _ = tracing ("case_hypi:\n" ^ @{make_string} case_hyp)
   511     val _ = tracing ("case_hypi:\n" ^ @{make_string} case_hyp)
   500     val _ = tracing ("case_hypj:\n" ^ @{make_string} case_hypj')
   512     val _ = tracing ("case_hypj:\n" ^ @{make_string} case_hypj')
   501 
   513 
   502     val compat = get_compat_thm thy compat_store eqvtsi eqvtsj i j cctxi cctxj
   514     val compat = get_compat_thm thy compat_store eqvtsi eqvtsj i j cctxi cctxj
   503     
   515     
   504     (* val _ = tracing ("compats:\n" ^ pp_thm compat)  *)
   516     val _ = tracing ("compats:\n" ^ pp_thm compat) 
   505     
   517     
   506 
   518 
   507     fun pppp str = tap (fn thm => tracing (str ^ ": " ^ pp_thm thm))
   519     fun pppp str = tap (fn thm => tracing (str ^ ": " ^ pp_thm thm))
   508     fun ppp str = I
   520     fun ppp str = I
   509   in
   521   in
   510     (trans OF [case_hyp, lhsi_eq_lhsj']) (* lhs_i = lhs_j' |-- x = lhs_j' *)
   522     (trans OF [case_hyp, lhsi_eq_lhsj']) (* lhs_i = lhs_j' |-- x = lhs_j' *)
   511     |> ppp "A"
   523     |> pppp "A"
   512     |> Thm.implies_elim RLj_import
   524     |> Thm.implies_elim RLj_import
   513       (* Rj1' ... Rjk', lhs_i = lhs_j' |-- rhs_j'_h = rhs_j'_f *)
   525       (* Rj1' ... Rjk', lhs_i = lhs_j' |-- rhs_j'_h = rhs_j'_f *)
   514     |> ppp "B"
   526     |> pppp "B"
   515     |> (fn it => trans OF [it, compat])
   527     |> (fn it => trans OF [it, compat])
   516       (* lhs_i = lhs_j', Gj', Rj1' ... Rjk' |-- rhs_j'_h = rhs_i_f *)
   528       (* lhs_i = lhs_j', Gj', Rj1' ... Rjk' |-- rhs_j'_h = rhs_i_f *)
   517     |> ppp "C"
   529     |> pppp "C"
   518     |> (fn it => trans OF [y_eq_rhsj'h, it])
   530     |> (fn it => trans OF [y_eq_rhsj'h, it])
   519       (* lhs_i = lhs_j', Gj', Rj1' ... Rjk', y = rhs_j_h' |-- y = rhs_i_f *)
   531       (* lhs_i = lhs_j', Gj', Rj1' ... Rjk', y = rhs_j_h' |-- y = rhs_i_f *)
   520     |> ppp "D"
   532     |> pppp "D"
   521     |> fold_rev (Thm.implies_intr o cprop_of) Ghsj'
   533     |> fold_rev (Thm.implies_intr o cprop_of) Ghsj'
   522     |> ppp "E"
   534     |> pppp "E"
   523     |> fold_rev (Thm.implies_intr o cprop_of) agsj'
   535     |> fold_rev (Thm.implies_intr o cprop_of) agsj'
   524       (* lhs_i = lhs_j' , y = rhs_j_h' |-- Gj', Rj1'...Rjk' ==> y = rhs_i_f *)
   536       (* lhs_i = lhs_j' , y = rhs_j_h' |-- Gj', Rj1'...Rjk' ==> y = rhs_i_f *)
   525     |> ppp "F"
   537     |> pppp "F"
   526     |> Thm.implies_intr (cprop_of y_eq_rhsj'h)
   538     |> Thm.implies_intr (cprop_of y_eq_rhsj'h)
   527     |> ppp "G"
   539     |> pppp "G"
   528     |> Thm.implies_intr (cprop_of lhsi_eq_lhsj')
   540     |> Thm.implies_intr (cprop_of lhsi_eq_lhsj')
   529     |> ppp "H"
   541     |> pppp "H"
   530     |> fold_rev Thm.forall_intr (cterm_of thy h :: cqsj')
   542     |> fold_rev Thm.forall_intr (cterm_of thy h :: cqsj')
   531     |> ppp "I"
   543     |> pppp "I"
   532   end
   544   end
   533 *}
   545 *}
   534 
   546 
   535 
   547 
   536 ML {*
   548 ML {*
   552     val P = cterm_of thy (mk_eq (y, rhsC))
   564     val P = cterm_of thy (mk_eq (y, rhsC))
   553     val G_lhs_y = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (G $ lhs $ y)))
   565     val G_lhs_y = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (G $ lhs $ y)))
   554 
   566 
   555     val unique_clauses =
   567     val unique_clauses =
   556       map2 (mk_uniqueness_clause thy globals compat_store eqvt_lemmas clausei) clauses rep_lemmas
   568       map2 (mk_uniqueness_clause thy globals compat_store eqvt_lemmas clausei) clauses rep_lemmas
       
   569 
       
   570     val _ = tracing ("DONE unique clauses") 
   557 
   571 
   558     fun elim_implies_eta A AB =
   572     fun elim_implies_eta A AB =
   559       Thm.compose_no_flatten true (A, 0) 1 AB |> Seq.list_of |> the_single
   573       Thm.compose_no_flatten true (A, 0) 1 AB |> Seq.list_of |> the_single
   560 
   574 
   561     val uniqueness = G_cases
   575     val uniqueness = G_cases
  1778 apply(simp_all add: lam.distinct)[5]
  1792 apply(simp_all add: lam.distinct)[5]
  1779 apply(simp add: lam.eq_iff)
  1793 apply(simp add: lam.eq_iff)
  1780 apply(simp add: lam.eq_iff)
  1794 apply(simp add: lam.eq_iff)
  1781 apply(simp add: lam.eq_iff)
  1795 apply(simp add: lam.eq_iff)
  1782 apply(erule conjE)+
  1796 apply(erule conjE)+
  1783 apply(subst (asm) Abs_eq_iff3) 
  1797 oops
  1784 apply(erule exE)
       
  1785 
  1798 
  1786 
  1799 
  1787 
  1800 
  1788 nominal_primrec
  1801 nominal_primrec
  1789   depth :: "lam \<Rightarrow> nat"
  1802   depth :: "lam \<Rightarrow> nat"