5 Simproc for rewriting set comprehensions to pointfree expressions. |
5 Simproc for rewriting set comprehensions to pointfree expressions. |
6 *) |
6 *) |
7 |
7 |
8 signature SET_COMPREHENSION_POINTFREE = |
8 signature SET_COMPREHENSION_POINTFREE = |
9 sig |
9 sig |
10 val base_simproc : Simplifier.proc |
10 val base_proc : Simplifier.proc |
11 val code_simproc : Simplifier.proc |
11 val code_proc : Simplifier.proc |
12 val simproc : Simplifier.proc |
12 val proc : Simplifier.proc |
13 end |
13 end |
14 |
14 |
15 structure Set_Comprehension_Pointfree : SET_COMPREHENSION_POINTFREE = |
15 structure Set_Comprehension_Pointfree : SET_COMPREHENSION_POINTFREE = |
16 struct |
16 struct |
17 |
17 |
482 val export = singleton (Variable.export ctxt' ctxt) |
482 val export = singleton (Variable.export ctxt' ctxt) |
483 in |
483 in |
484 Option.map (export o post o unfold o mk_thm) (rewrite_term t'') |
484 Option.map (export o post o unfold o mk_thm) (rewrite_term t'') |
485 end; |
485 end; |
486 |
486 |
487 fun base_simproc ctxt redex = |
487 fun base_proc ctxt redex = |
488 let |
488 let |
489 val set_compr = Thm.term_of redex |
489 val set_compr = Thm.term_of redex |
490 in |
490 in |
491 conv ctxt set_compr |
491 conv ctxt set_compr |
492 |> Option.map (fn thm => thm RS @{thm eq_reflection}) |
492 |> Option.map (fn thm => thm RS @{thm eq_reflection}) |
498 val (Var (f, _) $ _, _) = HOLogic.dest_eq (HOLogic.dest_Trueprop (Thm.concl_of arg_cong)) |
498 val (Var (f, _) $ _, _) = HOLogic.dest_eq (HOLogic.dest_Trueprop (Thm.concl_of arg_cong)) |
499 in |
499 in |
500 infer_instantiate ctxt [(f, Thm.cterm_of ctxt pred)] arg_cong |
500 infer_instantiate ctxt [(f, Thm.cterm_of ctxt pred)] arg_cong |
501 end; |
501 end; |
502 |
502 |
503 fun simproc ctxt redex = |
503 fun proc ctxt redex = |
504 let |
504 let |
505 val pred $ set_compr = Thm.term_of redex |
505 val pred $ set_compr = Thm.term_of redex |
506 val arg_cong' = instantiate_arg_cong ctxt pred |
506 val arg_cong' = instantiate_arg_cong ctxt pred |
507 in |
507 in |
508 conv ctxt set_compr |
508 conv ctxt set_compr |
509 |> Option.map (fn thm => thm RS arg_cong' RS @{thm eq_reflection}) |
509 |> Option.map (fn thm => thm RS arg_cong' RS @{thm eq_reflection}) |
510 end; |
510 end; |
511 |
511 |
512 fun code_simproc ctxt redex = |
512 fun code_proc ctxt redex = |
513 let |
513 let |
514 fun unfold_conv thms = |
514 fun unfold_conv thms = |
515 Raw_Simplifier.rewrite_cterm (false, false, false) (K (K NONE)) |
515 Raw_Simplifier.rewrite_cterm (false, false, false) (K (K NONE)) |
516 (empty_simpset ctxt addsimps thms) |
516 (empty_simpset ctxt addsimps thms) |
517 val prep_thm = unfold_conv @{thms eq_equal[symmetric]} redex |
517 val prep_thm = unfold_conv @{thms eq_equal[symmetric]} redex |
518 in |
518 in |
519 case base_simproc ctxt (Thm.rhs_of prep_thm) of |
519 case base_proc ctxt (Thm.rhs_of prep_thm) of |
520 SOME rewr_thm => SOME (transitive_thm OF [transitive_thm OF [prep_thm, rewr_thm], |
520 SOME rewr_thm => SOME (transitive_thm OF [transitive_thm OF [prep_thm, rewr_thm], |
521 unfold_conv @{thms eq_equal} (Thm.rhs_of rewr_thm)]) |
521 unfold_conv @{thms eq_equal} (Thm.rhs_of rewr_thm)]) |
522 | NONE => NONE |
522 | NONE => NONE |
523 end; |
523 end; |
524 |
524 |