648 done |
664 done |
649 |
665 |
650 ML {* |
666 ML {* |
651 fun mk_rep x = @{term REP_fset} $ x; |
667 fun mk_rep x = @{term REP_fset} $ x; |
652 fun mk_abs x = @{term ABS_fset} $ x; |
668 fun mk_abs x = @{term ABS_fset} $ x; |
653 val consts = [@{const_name "Nil"}, @{const_name "append"}, |
669 val consts = [@{const_name "Nil"}, @{const_name "Cons"}, |
654 @{const_name "Cons"}, @{const_name "membship"}, |
670 @{const_name "membship"}, @{const_name "card1"}, |
655 @{const_name "card1"}] |
671 @{const_name "append"}, @{const_name "fold1"}]; |
656 *} |
672 |
|
673 *} |
|
674 |
|
675 ML {* val tm = @{term "x :: 'a list"} *} |
|
676 ML {* val ty = exchange_ty @{typ "'a list"} @{typ "'a fset"} (fastype_of tm) *} |
|
677 ML {* (fst (get_fun repF @{typ "'a list"} @{typ "'a fset"} @{context} ty)) $ tm *} |
657 |
678 |
658 ML {* val qty = @{typ "'a fset"} *} |
679 ML {* val qty = @{typ "'a fset"} *} |
659 ML {* val tt = Type ("fun", [Type ("fun", [qty, @{typ "prop"}]), @{typ "prop"}]) *} |
680 ML {* val tt = Type ("fun", [Type ("fun", [qty, @{typ "prop"}]), @{typ "prop"}]) *} |
660 ML {* val fall = Const(@{const_name all}, dummyT) *} |
681 ML {* val fall = Const(@{const_name all}, dummyT) *} |
661 |
682 |
662 ML {* |
683 ML {* |
663 fun build_goal_term ctxt thm constructors rty qty mk_rep mk_abs = |
684 fun needs_lift (rty as Type (rty_s, _)) ty = |
|
685 case ty of |
|
686 Type (s, tys) => |
|
687 (s = rty_s) orelse (exists (needs_lift rty) tys) |
|
688 | _ => false |
|
689 |
|
690 *} |
|
691 |
|
692 ML {* |
|
693 fun build_goal_term lthy thm constructors rty qty = |
|
694 let |
|
695 fun mk_rep tm = |
|
696 let |
|
697 val ty = exchange_ty rty qty (fastype_of tm) |
|
698 in fst (get_fun repF rty qty lthy ty) $ tm end |
|
699 |
|
700 fun mk_abs tm = |
|
701 let |
|
702 val _ = tracing (Syntax.string_of_term @{context} tm) |
|
703 val _ = tracing (Syntax.string_of_typ @{context} (fastype_of tm)) |
|
704 val ty = exchange_ty rty qty (fastype_of tm) in |
|
705 fst (get_fun absF rty qty lthy ty) $ tm end |
|
706 |
|
707 fun is_constructor (Const (x, _)) = member (op =) constructors x |
|
708 | is_constructor _ = false; |
|
709 |
|
710 fun build_aux lthy tm = |
|
711 case tm of |
|
712 Abs (a as (_, vty, _)) => |
|
713 let |
|
714 val (vs, t) = Term.dest_abs a; |
|
715 val v = Free(vs, vty); |
|
716 val t' = lambda v (build_aux lthy t) |
|
717 in |
|
718 if (not (needs_lift rty (fastype_of tm))) then t' |
|
719 else mk_rep (mk_abs ( |
|
720 if not (needs_lift rty vty) then t' |
|
721 else |
|
722 let |
|
723 val v' = mk_rep (mk_abs v); |
|
724 val t1 = Envir.beta_norm (t' $ v') |
|
725 in |
|
726 lambda v t1 |
|
727 end |
|
728 )) |
|
729 end |
|
730 | x => |
|
731 let |
|
732 val _ = tracing (">>" ^ Syntax.string_of_term @{context} tm) |
|
733 val (opp, tms0) = Term.strip_comb tm |
|
734 val tms = map (build_aux lthy) tms0 |
|
735 val ty = fastype_of tm |
|
736 in |
|
737 if (((fst (Term.dest_Const opp)) = @{const_name Respects}) handle _ => false) |
|
738 then (list_comb (opp, (hd tms0) :: (tl tms))) |
|
739 else if (is_constructor opp andalso needs_lift rty ty) then |
|
740 mk_rep (mk_abs (list_comb (opp,tms))) |
|
741 else if ((Term.is_Free opp) andalso (length tms > 0) andalso (needs_lift rty ty)) then |
|
742 mk_rep(mk_abs(list_comb(opp,tms))) |
|
743 else if tms = [] then opp |
|
744 else list_comb(opp, tms) |
|
745 end |
|
746 in |
|
747 build_aux lthy (Thm.prop_of thm) |
|
748 end |
|
749 |
|
750 *} |
|
751 |
|
752 ML {* |
|
753 fun build_goal_term_old ctxt thm constructors rty qty mk_rep mk_abs = |
664 let |
754 let |
665 fun mk_rep_abs x = mk_rep (mk_abs x); |
755 fun mk_rep_abs x = mk_rep (mk_abs x); |
666 |
756 |
667 fun is_constructor (Const (x, _)) = member (op =) constructors x |
757 fun is_constructor (Const (x, _)) = member (op =) constructors x |
668 | is_constructor _ = false; |
758 | is_constructor _ = false; |
717 build_aux ctxt (Thm.prop_of thm) |
807 build_aux ctxt (Thm.prop_of thm) |
718 end |
808 end |
719 *} |
809 *} |
720 |
810 |
721 ML {* |
811 ML {* |
722 fun build_goal ctxt thm cons rty qty mk_rep mk_abs = |
812 fun build_goal ctxt thm cons rty qty = |
723 Logic.mk_equals ((build_goal_term ctxt thm cons rty qty mk_rep mk_abs), (Thm.prop_of thm)) |
813 Logic.mk_equals ((build_goal_term ctxt thm cons rty qty), (Thm.prop_of thm)) |
724 *} |
814 *} |
725 |
815 |
726 ML {* |
816 ML {* |
727 val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m1})) |
817 val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m2})) |
728 *} |
818 *} |
729 |
819 |
730 ML {* |
820 ML {* |
731 m1_novars |> prop_of |
821 cterm_of @{theory} (prop_of m1_novars); |
732 |> Syntax.string_of_term @{context} |
822 cterm_of @{theory} (build_goal_term @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"}); |
733 |> writeln; |
823 cterm_of @{theory} (build_goal_term_old @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"} mk_rep mk_abs) |
734 build_goal_term @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"} mk_rep mk_abs |
|
735 |> Syntax.string_of_term @{context} |
|
736 |> writeln |
|
737 *} |
824 *} |
738 |
825 |
739 |
826 |
740 text {* |
827 text {* |
741 Unabs_def converts a definition given as |
828 Unabs_def converts a definition given as |
827 done |
914 done |
828 |
915 |
829 thm length_append (* Not true but worth checking that the goal is correct *) |
916 thm length_append (* Not true but worth checking that the goal is correct *) |
830 ML {* |
917 ML {* |
831 val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm length_append})) |
918 val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm length_append})) |
832 val goal = build_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"} mk_rep mk_abs |
919 val goal = build_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"} |
833 val cgoal = cterm_of @{theory} goal |
920 val cgoal = cterm_of @{theory} goal |
834 val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal) |
921 val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal) |
835 *} |
922 *} |
836 prove {* Thm.term_of cgoal2 *} |
923 prove {* Thm.term_of cgoal2 *} |
837 apply (tactic {* transconv_fset_tac' @{context} *}) |
924 apply (tactic {* transconv_fset_tac' @{context} *}) |
838 sorry |
925 sorry |
839 |
926 |
840 thm m2 |
927 thm m2 |
841 ML {* |
928 ML {* |
842 val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m2})) |
929 val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m2})) |
843 val goal = build_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"} mk_rep mk_abs |
930 val goal = build_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"} |
844 val cgoal = cterm_of @{theory} goal |
931 val cgoal = cterm_of @{theory} goal |
845 val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal) |
932 val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal) |
846 *} |
933 *} |
847 prove {* Thm.term_of cgoal2 *} |
934 prove {* Thm.term_of cgoal2 *} |
848 apply (tactic {* transconv_fset_tac' @{context} *}) |
935 apply (tactic {* transconv_fset_tac' @{context} *}) |
849 done |
936 done |
850 |
937 |
851 thm list_eq.intros(4) |
938 thm list_eq.intros(4) |
852 ML {* |
939 ML {* |
853 val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm list_eq.intros(4)})) |
940 val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm list_eq.intros(4)})) |
854 val goal = build_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"} mk_rep mk_abs |
941 val goal = build_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"} |
855 val cgoal = cterm_of @{theory} goal |
942 val cgoal = cterm_of @{theory} goal |
856 val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal) |
943 val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal) |
857 val cgoal3 = Thm.rhs_of (MetaSimplifier.rewrite true @{thms QUOT_TYPE_I_fset.thm10} cgoal2) |
944 val cgoal3 = Thm.rhs_of (MetaSimplifier.rewrite true @{thms QUOT_TYPE_I_fset.thm10} cgoal2) |
858 *} |
945 *} |
859 |
946 |
860 (* It is the same, but we need a name for it. *) |
947 (* It is the same, but we need a name for it. *) |
861 prove zzz : {* Thm.term_of cgoal3 *} |
948 prove zzz : {* Thm.term_of cgoal3 *} |
862 apply (tactic {* transconv_fset_tac' @{context} *}) |
949 apply (tactic {* transconv_fset_tac' @{context} *}) |
863 done |
950 done |
864 |
951 |
865 lemma zzz' : |
952 (*lemma zzz' : |
866 "(REP_fset (INSERT a (INSERT a (ABS_fset xs))) \<approx> REP_fset (INSERT a (ABS_fset xs)))" |
953 "(REP_fset (INSERT a (INSERT a (ABS_fset xs))) \<approx> REP_fset (INSERT a (ABS_fset xs)))" |
867 using list_eq.intros(4) by (simp only: zzz) |
954 using list_eq.intros(4) by (simp only: zzz) |
868 |
955 |
869 thm QUOT_TYPE_I_fset.REPS_same |
956 thm QUOT_TYPE_I_fset.REPS_same |
870 ML {* val zzz'' = MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.REPS_same} @{thm zzz'} *} |
957 ML {* val zzz'' = MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.REPS_same} @{thm zzz'} *} |
|
958 *) |
871 |
959 |
872 thm list_eq.intros(5) |
960 thm list_eq.intros(5) |
873 ML {* |
961 ML {* |
874 val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm list_eq.intros(5)})) |
962 val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm list_eq.intros(5)})) |
875 val goal = build_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"} mk_rep mk_abs |
963 val goal = build_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"} |
876 val cgoal = cterm_of @{theory} goal |
964 val cgoal = cterm_of @{theory} goal |
877 val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true fset_defs_sym cgoal) |
965 val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true fset_defs_sym cgoal) |
878 *} |
966 *} |
879 prove {* Thm.term_of cgoal2 *} |
967 prove {* Thm.term_of cgoal2 *} |
880 apply (tactic {* transconv_fset_tac' @{context} *}) |
968 apply (tactic {* transconv_fset_tac' @{context} *}) |