Nominal/Nominal2.thy
changeset 2959 9bd97ed202f7
parent 2957 01ff621599bc
child 2962 7a24d827cba9
equal deleted inserted replaced
2958:d0f83a35950e 2959:9bd97ed202f7
   212      raw_size_thms = raw_size_thms}
   212      raw_size_thms = raw_size_thms}
   213 in
   213 in
   214   (raw_bclauses, raw_bn_funs, raw_bn_eqs, raw_result, lthy1)
   214   (raw_bclauses, raw_bn_funs, raw_bn_eqs, raw_result, lthy1)
   215 end
   215 end
   216 *}
   216 *}
       
   217 
       
   218 ML {*
       
   219 infix 1 ||>>> |>>>
       
   220 
       
   221 fun (x |>>> f) = 
       
   222   let 
       
   223     val (x', y') = f x 
       
   224   in
       
   225     ([x'], y')
       
   226   end
       
   227 
       
   228 fun (([], y) ||>>> f) = ([], y)  
       
   229   | ((xs, y) ||>>> f) =
       
   230        let
       
   231          val (x', y') = f y
       
   232        in
       
   233          (xs @ [x'], y')
       
   234        end;
       
   235 (op ||>>)
       
   236 *}
       
   237 
   217 
   238 
   218 
   239 
   219 ML {*
   240 ML {*
   220 fun nominal_datatype2 opt_thms_name dts bn_funs bn_eqs bclauses lthy =
   241 fun nominal_datatype2 opt_thms_name dts bn_funs bn_eqs bclauses lthy =
   221 let
   242 let
   241   
   262   
   242   val _ = trace_msg (K "Defining raw permutations...")
   263   val _ = trace_msg (K "Defining raw permutations...")
   243   val ((raw_perm_funs, raw_perm_simps, raw_perm_laws), lthy2a) = define_raw_perms raw_dt_info lthy0
   264   val ((raw_perm_funs, raw_perm_simps, raw_perm_laws), lthy2a) = define_raw_perms raw_dt_info lthy0
   244  
   265  
   245   (* noting the raw permutations as eqvt theorems *)
   266   (* noting the raw permutations as eqvt theorems *)
   246   val (_, lthy3) = Local_Theory.note ((Binding.empty, [eqvt_attr]), raw_perm_simps) lthy2a
   267   val lthy3 = snd (Local_Theory.note ((Binding.empty, [eqvt_attr]), raw_perm_simps) lthy2a)
   247 
   268 
   248   val _ = trace_msg (K "Defining raw fv- and bn-functions...")
   269   val _ = trace_msg (K "Defining raw fv- and bn-functions...")
   249   val (raw_bns, raw_bn_defs, raw_bn_info, raw_bn_inducts, lthy3a) =
   270   val (raw_bns, raw_bn_defs, raw_bn_info, raw_bn_inducts, lthy3a) =
   250     define_raw_bns raw_dt_info raw_bn_funs raw_bn_eqs lthy3
   271     define_raw_bns raw_dt_info raw_bn_funs raw_bn_eqs lthy3
   251     
   272     
   404 
   425 
   405   val _ = trace_msg (K "Lifting of theorems...")  
   426   val _ = trace_msg (K "Lifting of theorems...")  
   406   val eq_iff_simps = @{thms alphas permute_prod.simps prod_fv.simps prod_alpha_def prod_rel_def
   427   val eq_iff_simps = @{thms alphas permute_prod.simps prod_fv.simps prod_alpha_def prod_rel_def
   407     prod.cases} 
   428     prod.cases} 
   408 
   429 
   409   val (((((((qdistincts, qeq_iffs), qfv_defs), qbn_defs), qperm_simps), qfv_qbn_eqvts), qbn_inducts), 
   430   val ([ qdistincts, qeq_iffs, qfv_defs, qbn_defs, qperm_simps, qfv_qbn_eqvts, 
   410     lthyA) = 
   431          qbn_inducts, qsize_eqvt, [qinduct], qexhausts, qsize_simps, qperm_bn_simps, 
       
   432          qalpha_refl_thms ], lthyB) = 
   411     lthy9a    
   433     lthy9a    
   412     |> lift_thms qtys [] alpha_distincts  
   434     |>>> lift_thms qtys [] alpha_distincts  
   413     ||>> lift_thms qtys eq_iff_simps alpha_eq_iff       
   435     ||>>> lift_thms qtys eq_iff_simps alpha_eq_iff       
   414     ||>> lift_thms qtys [] raw_fv_defs
   436     ||>>> lift_thms qtys [] raw_fv_defs
   415     ||>> lift_thms qtys [] raw_bn_defs
   437     ||>>> lift_thms qtys [] raw_bn_defs
   416     ||>> lift_thms qtys [] raw_perm_simps
   438     ||>>> lift_thms qtys [] raw_perm_simps
   417     ||>> lift_thms qtys [] (raw_fv_eqvt @ raw_bn_eqvt)
   439     ||>>> lift_thms qtys [] (raw_fv_eqvt @ raw_bn_eqvt)
   418     ||>> lift_thms qtys [] raw_bn_inducts
   440     ||>>> lift_thms qtys [] raw_bn_inducts
   419 
   441     ||>>> lift_thms qtys [] raw_size_eqvt
   420   val ((((((qsize_eqvt, [qinduct]), qexhausts), qsize_simps), qperm_bn_simps), qalpha_refl_thms), lthyB) = 
   442     ||>>> lift_thms qtys [] [raw_induct_thm]
   421     lthyA 
   443     ||>>> lift_thms qtys [] raw_exhaust_thms
   422     |> lift_thms qtys [] raw_size_eqvt
   444     ||>>> lift_thms qtys [] raw_size_thms
   423     ||>> lift_thms qtys [] [raw_induct_thm]
   445     ||>>> lift_thms qtys [] raw_perm_bn_simps
   424     ||>> lift_thms qtys [] raw_exhaust_thms
   446     ||>>> lift_thms qtys [] alpha_refl_thms
   425     ||>> lift_thms qtys [] raw_size_thms
       
   426     ||>> lift_thms qtys [] raw_perm_bn_simps
       
   427     ||>> lift_thms qtys [] alpha_refl_thms
       
   428 
   447 
   429   val qinducts = Project_Rule.projections lthyB qinduct
   448   val qinducts = Project_Rule.projections lthyB qinduct
   430 
   449 
   431   val _ = trace_msg (K "Proving supp lemmas and fs-instances...")
   450   val _ = trace_msg (K "Proving supp lemmas and fs-instances...")
   432   val qsupports_thms =
   451   val qsupports_thms = prove_supports lthyB qperm_simps (flat qtrms)
   433     prove_supports lthyB qperm_simps (flat qtrms)
       
   434 
   452 
   435   (* finite supp lemmas *)
   453   (* finite supp lemmas *)
   436   val qfsupp_thms = prove_fsupp lthyB qtys qinduct qsupports_thms
   454   val qfsupp_thms = prove_fsupp lthyB qtys qinduct qsupports_thms
   437 
   455 
   438   (* fs instances *)
   456   (* fs instances *)
   549     (constrs @ [(cname, cargs', mx)], sorts') 
   567     (constrs @ [(cname, cargs', mx)], sorts') 
   550   end
   568   end
   551   
   569   
   552   fun prep_dts (tvs, tname, mx, constrs) (constr_trms, dts, sorts) =
   570   fun prep_dts (tvs, tname, mx, constrs) (constr_trms, dts, sorts) =
   553   let 
   571   let 
       
   572 
   554     val (constrs', sorts') = 
   573     val (constrs', sorts') = 
   555       fold prep_constr constrs ([], sorts)
   574       fold prep_constr constrs ([], sorts)
   556 
   575 
   557     val constr_trms' = 
   576     val constr_trms' = 
   558       map (mk_type tname (rev sorts')) constrs'
   577       map (mk_type tname (rev sorts')) constrs'