756 |
756 |
757 (* technical transformations of code equations *) |
757 (* technical transformations of code equations *) |
758 |
758 |
759 fun meta_rewrite thy = Local_Defs.meta_rewrite_rule (Proof_Context.init_global thy); |
759 fun meta_rewrite thy = Local_Defs.meta_rewrite_rule (Proof_Context.init_global thy); |
760 |
760 |
761 fun expand_eta thy k thm = |
|
762 let |
|
763 val (lhs, rhs) = (Logic.dest_equals o Thm.plain_prop_of) thm; |
|
764 val (_, args) = strip_comb lhs; |
|
765 val l = if k = ~1 |
|
766 then (length o fst o strip_abs) rhs |
|
767 else Int.max (0, k - length args); |
|
768 val (raw_vars, _) = Term.strip_abs_eta l rhs; |
|
769 val vars = burrow_fst (Name.variant_list (map (fst o fst) (Term.add_vars lhs []))) |
|
770 raw_vars; |
|
771 fun expand (v, ty) thm = Drule.fun_cong_rule thm |
|
772 (Thm.global_cterm_of thy (Var ((v, 0), ty))); |
|
773 in |
|
774 thm |
|
775 |> fold expand vars |
|
776 |> Conv.fconv_rule Drule.beta_eta_conversion |
|
777 end; |
|
778 |
|
779 fun same_arity thy thms = |
761 fun same_arity thy thms = |
780 let |
762 let |
781 val num_args_of = length o snd o strip_comb o fst o Logic.dest_equals; |
763 val lhs_rhss = map (Logic.dest_equals o Thm.plain_prop_of) thms; |
782 val k = fold (Integer.max o num_args_of o Thm.prop_of) thms 0; |
764 val k = fold (Integer.max o length o snd o strip_comb o fst) lhs_rhss 0; |
783 in map (expand_eta thy k) thms end; |
765 fun expand_eta (lhs, rhs) thm = |
|
766 let |
|
767 val l = k - length (snd (strip_comb lhs)); |
|
768 val (raw_vars, _) = Term.strip_abs_eta l rhs; |
|
769 val vars = burrow_fst (Name.variant_list (map (fst o fst) (Term.add_vars lhs []))) |
|
770 raw_vars; |
|
771 fun expand (v, ty) thm = Drule.fun_cong_rule thm |
|
772 (Thm.global_cterm_of thy (Var ((v, 0), ty))); |
|
773 in |
|
774 thm |
|
775 |> fold expand vars |
|
776 |> Conv.fconv_rule Drule.beta_eta_conversion |
|
777 end; |
|
778 in map2 expand_eta lhs_rhss thms end; |
784 |
779 |
785 fun mk_desymbolization pre post mk vs = |
780 fun mk_desymbolization pre post mk vs = |
786 let |
781 let |
787 val names = map (pre o fst o fst) vs |
782 val names = map (pre o fst o fst) vs |
788 |> map (Name.desymbolize (SOME false)) |
783 |> map (Name.desymbolize (SOME false)) |