385 val exhausts = map #exhaust dtinfos; |
385 val exhausts = map #exhaust dtinfos; |
386 val _ = tracing "Defining permutations, fv and alpha"; |
386 val _ = tracing "Defining permutations, fv and alpha"; |
387 val ((raw_perm_def, raw_perm_simps, perms), lthy3) = |
387 val ((raw_perm_def, raw_perm_simps, perms), lthy3) = |
388 Local_Theory.theory_result (define_raw_perms dtinfo (length dts)) lthy2; |
388 Local_Theory.theory_result (define_raw_perms dtinfo (length dts)) lthy2; |
389 val raw_binds_flat = map (map flat) raw_binds; |
389 val raw_binds_flat = map (map flat) raw_binds; |
390 val ((((fv_ts, ordered_fv_ts), fv_def), ((alpha_ts, alpha_intros), (alpha_cases, alpha_induct))), lthy4) = |
390 val ((((_, fv_ts), fv_def), ((alpha_ts, alpha_intros), (alpha_cases, alpha_induct))), lthy4) = |
391 define_fv_alpha_export dtinfo raw_binds_flat bn_funs_decls lthy3; |
391 define_fv_alpha_export dtinfo raw_binds_flat bn_funs_decls lthy3; |
|
392 val (fv, fvbn) = chop (length perms) fv_ts; |
|
393 |
392 val (alpha_ts_nobn, alpha_ts_bn) = chop (length perms) alpha_ts |
394 val (alpha_ts_nobn, alpha_ts_bn) = chop (length perms) alpha_ts |
393 val alpha_inducts = Project_Rule.projects lthy4 (1 upto (length dts)) alpha_induct; |
395 val alpha_inducts = Project_Rule.projects lthy4 (1 upto (length dts)) alpha_induct; |
394 val dts_names = map (fn (i, (s, _, _)) => (s, i)) (#descr dtinfo); |
396 val dts_names = map (fn (i, (s, _, _)) => (s, i)) (#descr dtinfo); |
395 val bn_tys = map (domain_type o fastype_of) raw_bn_funs; |
397 val bn_tys = map (domain_type o fastype_of) raw_bn_funs; |
396 val bn_nos = map (dtyp_no_of_typ dts_names) bn_tys; |
398 val bn_nos = map (dtyp_no_of_typ dts_names) bn_tys; |
400 val rel_dists_bn = flat (map (distinct_rel lthy4 alpha_cases) |
402 val rel_dists_bn = flat (map (distinct_rel lthy4 alpha_cases) |
401 ((map (fn i => nth rel_distinct i) bn_nos) ~~ alpha_ts_bn)) |
403 ((map (fn i => nth rel_distinct i) bn_nos) ~~ alpha_ts_bn)) |
402 val alpha_eq_iff = build_rel_inj alpha_intros (inject @ distincts) alpha_cases lthy4 |
404 val alpha_eq_iff = build_rel_inj alpha_intros (inject @ distincts) alpha_cases lthy4 |
403 val _ = tracing "Proving equivariance"; |
405 val _ = tracing "Proving equivariance"; |
404 val (bv_eqvt, lthy5) = prove_eqvt raw_tys induct (raw_bn_eqs @ raw_perm_def) (map fst bns) lthy4 |
406 val (bv_eqvt, lthy5) = prove_eqvt raw_tys induct (raw_bn_eqs @ raw_perm_def) (map fst bns) lthy4 |
405 val (fv_eqvt, lthy6) = prove_eqvt raw_tys induct (fv_def @ raw_perm_def) ordered_fv_ts lthy5 |
407 val (fv_eqvt, lthy6) = prove_eqvt raw_tys induct (fv_def @ raw_perm_def) (fv @ fvbn) lthy5 |
406 fun alpha_eqvt_tac' _ = |
408 fun alpha_eqvt_tac' _ = |
407 if !cheat_alpha_eqvt then Skip_Proof.cheat_tac thy |
409 if !cheat_alpha_eqvt then Skip_Proof.cheat_tac thy |
408 else alpha_eqvt_tac alpha_induct (raw_perm_def @ alpha_eq_iff) lthy6 1 |
410 else alpha_eqvt_tac alpha_induct (raw_perm_def @ alpha_eq_iff) lthy6 1 |
409 val alpha_eqvt = build_alpha_eqvts alpha_ts alpha_eqvt_tac' lthy6; |
411 val alpha_eqvt = build_alpha_eqvts alpha_ts alpha_eqvt_tac' lthy6; |
410 val _ = tracing "Proving equivalence"; |
412 val _ = tracing "Proving equivalence"; |
411 val (rfv_ts_nobn, rfv_ts_bn) = chop (length perms) ordered_fv_ts; |
413 val fv_alpha_all = combine_fv_alpha_bns (fv, fvbn) (alpha_ts_nobn, alpha_ts_bn) bn_nos; |
412 val fv_alpha_all = combine_fv_alpha_bns (rfv_ts_nobn, rfv_ts_bn) (alpha_ts_nobn, alpha_ts_bn) bn_nos; |
|
413 val reflps = build_alpha_refl fv_alpha_all alpha_ts induct alpha_eq_iff lthy6; |
414 val reflps = build_alpha_refl fv_alpha_all alpha_ts induct alpha_eq_iff lthy6; |
414 val alpha_equivp = |
415 val alpha_equivp = |
415 if !cheat_equivp then map (equivp_hack lthy6) alpha_ts_nobn |
416 if !cheat_equivp then map (equivp_hack lthy6) alpha_ts_nobn |
416 else build_equivps alpha_ts reflps alpha_induct |
417 else build_equivps alpha_ts reflps alpha_induct |
417 inject alpha_eq_iff distincts alpha_cases alpha_eqvt lthy6; |
418 inject alpha_eq_iff distincts alpha_cases alpha_eqvt lthy6; |
428 val (consts, const_defs, lthy8) = quotient_lift_consts_export qtys (const_names ~~ raw_consts) lthy7; |
429 val (consts, const_defs, lthy8) = quotient_lift_consts_export qtys (const_names ~~ raw_consts) lthy7; |
429 val _ = tracing "Proving respects"; |
430 val _ = tracing "Proving respects"; |
430 val bns_rsp_pre' = build_fvbv_rsps alpha_ts alpha_induct raw_bn_eqs (map fst bns) lthy8; |
431 val bns_rsp_pre' = build_fvbv_rsps alpha_ts alpha_induct raw_bn_eqs (map fst bns) lthy8; |
431 val _ = map tracing (map PolyML.makestring bns_rsp_pre') |
432 val _ = map tracing (map PolyML.makestring bns_rsp_pre') |
432 val (bns_rsp_pre, lthy9) = fold_map ( |
433 val (bns_rsp_pre, lthy9) = fold_map ( |
433 fn (bn_t, i) => prove_const_rsp qtys Binding.empty [bn_t] (fn _ => |
434 fn (bn_t, _) => prove_const_rsp qtys Binding.empty [bn_t] (fn _ => |
434 resolve_tac bns_rsp_pre' 1)) bns lthy8; |
435 resolve_tac bns_rsp_pre' 1)) bns lthy8; |
435 val bns_rsp = flat (map snd bns_rsp_pre); |
436 val bns_rsp = flat (map snd bns_rsp_pre); |
436 fun fv_rsp_tac _ = if !cheat_fv_rsp then Skip_Proof.cheat_tac thy |
437 fun fv_rsp_tac _ = if !cheat_fv_rsp then Skip_Proof.cheat_tac thy |
437 else fvbv_rsp_tac alpha_induct fv_def lthy8 1; |
438 else fvbv_rsp_tac alpha_induct fv_def lthy8 1; |
438 val fv_rsps = prove_fv_rsp fv_alpha_all alpha_ts fv_rsp_tac lthy9; |
439 val fv_rsps = prove_fv_rsp fv_alpha_all alpha_ts fv_rsp_tac lthy9; |
439 val (fv_rsp_pre, lthy10) = fold_map |
440 val (fv_rsp_pre, lthy10) = fold_map |
440 (fn fv => fn ctxt => prove_const_rsp qtys Binding.empty [fv] |
441 (fn fv => fn ctxt => prove_const_rsp qtys Binding.empty [fv] |
441 (fn _ => asm_simp_tac (HOL_ss addsimps fv_rsps) 1) ctxt) ordered_fv_ts lthy9; |
442 (fn _ => asm_simp_tac (HOL_ss addsimps fv_rsps) 1) ctxt) (fv @ fvbn) lthy9; |
442 val fv_rsp = flat (map snd fv_rsp_pre); |
443 val fv_rsp = flat (map snd fv_rsp_pre); |
443 val (perms_rsp, lthy11) = prove_const_rsp qtys Binding.empty perms |
444 val (perms_rsp, lthy11) = prove_const_rsp qtys Binding.empty perms |
444 (fn _ => asm_simp_tac (HOL_ss addsimps alpha_eqvt) 1) lthy10; |
445 (fn _ => asm_simp_tac (HOL_ss addsimps alpha_eqvt) 1) lthy10; |
445 val alpha_bn_rsp_pre = prove_alpha_bn_rsp alpha_ts alpha_induct (alpha_eq_iff @ rel_dists @ rel_dists_bn) alpha_equivp exhausts alpha_ts_bn lthy11; |
446 val alpha_bn_rsp_pre = prove_alpha_bn_rsp alpha_ts alpha_induct (alpha_eq_iff @ rel_dists @ rel_dists_bn) alpha_equivp exhausts alpha_ts_bn lthy11; |
446 val (alpha_bn_rsps, lthy11a) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst] |
447 val (alpha_bn_rsps, lthy11a) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst] |
450 if !cheat_const_rsp then Skip_Proof.cheat_tac thy |
451 if !cheat_const_rsp then Skip_Proof.cheat_tac thy |
451 else let val alpha_alphabn = prove_alpha_alphabn alpha_ts alpha_induct alpha_eq_iff alpha_ts_bn lthy11a |
452 else let val alpha_alphabn = prove_alpha_alphabn alpha_ts alpha_induct alpha_eq_iff alpha_ts_bn lthy11a |
452 in constr_rsp_tac alpha_eq_iff (fv_rsp @ bns_rsp @ reflps @ alpha_alphabn) 1 end |
453 in constr_rsp_tac alpha_eq_iff (fv_rsp @ bns_rsp @ reflps @ alpha_alphabn) 1 end |
453 val (const_rsps, lthy12) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst] |
454 val (const_rsps, lthy12) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst] |
454 const_rsp_tac) raw_consts lthy11a |
455 const_rsp_tac) raw_consts lthy11a |
455 val qfv_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) ordered_fv_ts |
456 val qfv_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) (fv @ fvbn) |
456 val (qfv_ts, qfv_defs, lthy12a) = quotient_lift_consts_export qtys (qfv_names ~~ ordered_fv_ts) lthy12; |
457 val (qfv_ts, qfv_defs, lthy12a) = quotient_lift_consts_export qtys (qfv_names ~~ (fv @ fvbn)) lthy12; |
457 val (qfv_ts_nobn, qfv_ts_bn) = chop (length perms) qfv_ts; |
458 val (qfv_ts_nobn, qfv_ts_bn) = chop (length perms) qfv_ts; |
458 val qbn_names = map (fn (b, _ , _) => Name.of_binding b) bn_funs |
459 val qbn_names = map (fn (b, _ , _) => Name.of_binding b) bn_funs |
459 val (qbn_ts, qbn_defs, lthy12b) = quotient_lift_consts_export qtys (qbn_names ~~ raw_bn_funs) lthy12a; |
460 val (qbn_ts, qbn_defs, lthy12b) = quotient_lift_consts_export qtys (qbn_names ~~ raw_bn_funs) lthy12a; |
460 val qalpha_bn_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) alpha_ts_bn |
461 val qalpha_bn_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) alpha_ts_bn |
461 val (qalpha_ts_bn, qalphabn_defs, lthy12c) = quotient_lift_consts_export qtys (qalpha_bn_names ~~ alpha_ts_bn) lthy12b; |
462 val (qalpha_ts_bn, qalphabn_defs, lthy12c) = quotient_lift_consts_export qtys (qalpha_bn_names ~~ alpha_ts_bn) lthy12b; |