653 let |
670 let |
654 (* Term.term -> Term.term *) |
671 (* Term.term -> Term.term *) |
655 fun unfold_loop t = |
672 fun unfold_loop t = |
656 case t of |
673 case t of |
657 (* Pure *) |
674 (* Pure *) |
658 Const ("all", _) => t |
675 Const (@{const_name all}, _) => t |
659 | Const ("==", _) => t |
676 | Const (@{const_name "=="}, _) => t |
660 | Const ("==>", _) => t |
677 | Const (@{const_name "==>"}, _) => t |
661 | Const ("TYPE", _) => t (* axiomatic type classes *) |
678 | Const (@{const_name TYPE}, _) => t (* axiomatic type classes *) |
662 (* HOL *) |
679 (* HOL *) |
663 | Const ("Trueprop", _) => t |
680 | Const (@{const_name Trueprop}, _) => t |
664 | Const ("Not", _) => t |
681 | Const (@{const_name Not}, _) => t |
665 | (* redundant, since 'True' is also an IDT constructor *) |
682 | (* redundant, since 'True' is also an IDT constructor *) |
666 Const ("True", _) => t |
683 Const (@{const_name True}, _) => t |
667 | (* redundant, since 'False' is also an IDT constructor *) |
684 | (* redundant, since 'False' is also an IDT constructor *) |
668 Const ("False", _) => t |
685 Const (@{const_name False}, _) => t |
669 | Const (@{const_name undefined}, _) => t |
686 | Const (@{const_name undefined}, _) => t |
670 | Const ("The", _) => t |
687 | Const (@{const_name The}, _) => t |
671 | Const ("Hilbert_Choice.Eps", _) => t |
688 | Const ("Hilbert_Choice.Eps", _) => t |
672 | Const ("All", _) => t |
689 | Const (@{const_name All}, _) => t |
673 | Const ("Ex", _) => t |
690 | Const (@{const_name Ex}, _) => t |
674 | Const ("op =", _) => t |
691 | Const (@{const_name "op ="}, _) => t |
675 | Const ("op &", _) => t |
692 | Const (@{const_name "op &"}, _) => t |
676 | Const ("op |", _) => t |
693 | Const (@{const_name "op |"}, _) => t |
677 | Const ("op -->", _) => t |
694 | Const (@{const_name "op -->"}, _) => t |
678 (* sets *) |
695 (* sets *) |
679 | Const ("Collect", _) => t |
696 | Const (@{const_name Collect}, _) => t |
680 | Const ("op :", _) => t |
697 | Const (@{const_name "op :"}, _) => t |
681 (* other optimizations *) |
698 (* other optimizations *) |
682 | Const ("Finite_Set.card", _) => t |
699 | Const ("Finite_Set.card", _) => t |
683 | Const ("Finite_Set.Finites", _) => t |
700 | Const ("Finite_Set.finite", _) => t |
684 | Const ("Finite_Set.finite", _) => t |
|
685 | Const (@{const_name HOL.less}, Type ("fun", [Type ("nat", []), |
701 | Const (@{const_name HOL.less}, Type ("fun", [Type ("nat", []), |
686 Type ("fun", [Type ("nat", []), Type ("bool", [])])])) => t |
702 Type ("fun", [Type ("nat", []), Type ("bool", [])])])) => t |
687 | Const (@{const_name HOL.plus}, Type ("fun", [Type ("nat", []), |
703 | Const (@{const_name HOL.plus}, Type ("fun", [Type ("nat", []), |
688 Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => t |
704 Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => t |
689 | Const (@{const_name HOL.minus}, Type ("fun", [Type ("nat", []), |
705 | Const (@{const_name HOL.minus}, Type ("fun", [Type ("nat", []), |
690 Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => t |
706 Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => t |
691 | Const (@{const_name HOL.times}, Type ("fun", [Type ("nat", []), |
707 | Const (@{const_name HOL.times}, Type ("fun", [Type ("nat", []), |
692 Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => t |
708 Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => t |
693 | Const ("List.append", _) => t |
709 | Const ("List.append", _) => t |
694 | Const ("Lfp.lfp", _) => t |
710 | Const (@{const_name lfp}, _) => t |
695 | Const ("Gfp.gfp", _) => t |
711 | Const (@{const_name gfp}, _) => t |
696 | Const ("fst", _) => t |
712 | Const ("Product_Type.fst", _) => t |
697 | Const ("snd", _) => t |
713 | Const ("Product_Type.snd", _) => t |
698 (* simply-typed lambda calculus *) |
714 (* simply-typed lambda calculus *) |
699 | Const (s, T) => |
715 | Const (s, T) => |
700 (if is_IDT_constructor thy (s, T) |
716 (if is_IDT_constructor thy (s, T) |
701 orelse is_IDT_recursor thy (s, T) then |
717 orelse is_IDT_recursor thy (s, T) then |
702 t (* do not unfold IDT constructors/recursors *) |
718 t (* do not unfold IDT constructors/recursors *) |
827 | TVar _ => collect_sort_axioms (axs, T) |
842 | TVar _ => collect_sort_axioms (axs, T) |
828 (* Term.term list * Term.term -> Term.term list *) |
843 (* Term.term list * Term.term -> Term.term list *) |
829 and collect_term_axioms (axs, t) = |
844 and collect_term_axioms (axs, t) = |
830 case t of |
845 case t of |
831 (* Pure *) |
846 (* Pure *) |
832 Const ("all", _) => axs |
847 Const (@{const_name all}, _) => axs |
833 | Const ("==", _) => axs |
848 | Const (@{const_name "=="}, _) => axs |
834 | Const ("==>", _) => axs |
849 | Const (@{const_name "==>"}, _) => axs |
835 (* axiomatic type classes *) |
850 (* axiomatic type classes *) |
836 | Const ("TYPE", T) => collect_type_axioms (axs, T) |
851 | Const (@{const_name TYPE}, T) => collect_type_axioms (axs, T) |
837 (* HOL *) |
852 (* HOL *) |
838 | Const ("Trueprop", _) => axs |
853 | Const (@{const_name Trueprop}, _) => axs |
839 | Const ("Not", _) => axs |
854 | Const (@{const_name Not}, _) => axs |
840 (* redundant, since 'True' is also an IDT constructor *) |
855 (* redundant, since 'True' is also an IDT constructor *) |
841 | Const ("True", _) => axs |
856 | Const (@{const_name True}, _) => axs |
842 (* redundant, since 'False' is also an IDT constructor *) |
857 (* redundant, since 'False' is also an IDT constructor *) |
843 | Const ("False", _) => axs |
858 | Const (@{const_name False}, _) => axs |
844 | Const (@{const_name undefined}, T) => collect_type_axioms (axs, T) |
859 | Const (@{const_name undefined}, T) => collect_type_axioms (axs, T) |
845 | Const ("The", T) => |
860 | Const (@{const_name The}, T) => |
846 let |
861 let |
847 val ax = specialize_type thy ("The", T) |
862 val ax = specialize_type thy (@{const_name The}, T) |
848 (the (AList.lookup (op =) axioms "HOL.the_eq_trivial")) |
863 (the (AList.lookup (op =) axioms "HOL.the_eq_trivial")) |
849 in |
864 in |
850 collect_this_axiom ("HOL.the_eq_trivial", ax) axs |
865 collect_this_axiom ("HOL.the_eq_trivial", ax) axs |
851 end |
866 end |
852 | Const ("Hilbert_Choice.Eps", T) => |
867 | Const ("Hilbert_Choice.Eps", T) => |
854 val ax = specialize_type thy ("Hilbert_Choice.Eps", T) |
869 val ax = specialize_type thy ("Hilbert_Choice.Eps", T) |
855 (the (AList.lookup (op =) axioms "Hilbert_Choice.someI")) |
870 (the (AList.lookup (op =) axioms "Hilbert_Choice.someI")) |
856 in |
871 in |
857 collect_this_axiom ("Hilbert_Choice.someI", ax) axs |
872 collect_this_axiom ("Hilbert_Choice.someI", ax) axs |
858 end |
873 end |
859 | Const ("All", T) => collect_type_axioms (axs, T) |
874 | Const (@{const_name All}, T) => collect_type_axioms (axs, T) |
860 | Const ("Ex", T) => collect_type_axioms (axs, T) |
875 | Const (@{const_name Ex}, T) => collect_type_axioms (axs, T) |
861 | Const ("op =", T) => collect_type_axioms (axs, T) |
876 | Const (@{const_name "op ="}, T) => collect_type_axioms (axs, T) |
862 | Const ("op &", _) => axs |
877 | Const (@{const_name "op &"}, _) => axs |
863 | Const ("op |", _) => axs |
878 | Const (@{const_name "op |"}, _) => axs |
864 | Const ("op -->", _) => axs |
879 | Const (@{const_name "op -->"}, _) => axs |
865 (* sets *) |
880 (* sets *) |
866 | Const ("Collect", T) => collect_type_axioms (axs, T) |
881 | Const (@{const_name Collect}, T) => collect_type_axioms (axs, T) |
867 | Const ("op :", T) => collect_type_axioms (axs, T) |
882 | Const (@{const_name "op :"}, T) => collect_type_axioms (axs, T) |
868 (* other optimizations *) |
883 (* other optimizations *) |
869 | Const ("Finite_Set.card", T) => collect_type_axioms (axs, T) |
884 | Const ("Finite_Set.card", T) => collect_type_axioms (axs, T) |
870 | Const ("Finite_Set.Finites", T) => collect_type_axioms (axs, T) |
885 | Const ("Finite_Set.finite", T) => collect_type_axioms (axs, T) |
871 | Const ("Finite_Set.finite", T) => collect_type_axioms (axs, T) |
|
872 | Const (@{const_name HOL.less}, T as Type ("fun", [Type ("nat", []), |
886 | Const (@{const_name HOL.less}, T as Type ("fun", [Type ("nat", []), |
873 Type ("fun", [Type ("nat", []), Type ("bool", [])])])) => |
887 Type ("fun", [Type ("nat", []), Type ("bool", [])])])) => |
874 collect_type_axioms (axs, T) |
888 collect_type_axioms (axs, T) |
875 | Const (@{const_name HOL.plus}, T as Type ("fun", [Type ("nat", []), |
889 | Const (@{const_name HOL.plus}, T as Type ("fun", [Type ("nat", []), |
876 Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => |
890 Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => |
879 Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => |
893 Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => |
880 collect_type_axioms (axs, T) |
894 collect_type_axioms (axs, T) |
881 | Const (@{const_name HOL.times}, T as Type ("fun", [Type ("nat", []), |
895 | Const (@{const_name HOL.times}, T as Type ("fun", [Type ("nat", []), |
882 Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => |
896 Type ("fun", [Type ("nat", []), Type ("nat", [])])])) => |
883 collect_type_axioms (axs, T) |
897 collect_type_axioms (axs, T) |
884 | Const ("List.append", T) => collect_type_axioms (axs, T) |
898 | Const ("List.append", T) => collect_type_axioms (axs, T) |
885 | Const ("Lfp.lfp", T) => collect_type_axioms (axs, T) |
899 | Const (@{const_name lfp}, T) => collect_type_axioms (axs, T) |
886 | Const ("Gfp.gfp", T) => collect_type_axioms (axs, T) |
900 | Const (@{const_name gfp}, T) => collect_type_axioms (axs, T) |
887 | Const ("fst", T) => collect_type_axioms (axs, T) |
901 | Const ("Product_Type.fst", T) => collect_type_axioms (axs, T) |
888 | Const ("snd", T) => collect_type_axioms (axs, T) |
902 | Const ("Product_Type.snd", T) => collect_type_axioms (axs, T) |
889 (* simply-typed lambda calculus *) |
903 (* simply-typed lambda calculus *) |
890 | Const (s, T) => |
904 | Const (s, T) => |
891 if is_const_of_class thy (s, T) then |
905 if is_const_of_class thy (s, T) then |
892 (* axiomatic type classes: add "OFCLASS(?'a::c, c_class)" *) |
906 (* axiomatic type classes: add "OFCLASS(?'a::c, c_class)" *) |
893 (* and the class definition *) |
907 (* and the class definition *) |
894 let |
908 let |
895 val class = Logic.class_of_const s |
909 val class = Logic.class_of_const s |
1301 (* while the SAT solver searches for an interpretation for Free's. *) |
1314 (* while the SAT solver searches for an interpretation for Free's. *) |
1302 (* Also we get more information back that way, namely an *) |
1315 (* Also we get more information back that way, namely an *) |
1303 (* interpretation which includes values for the (formerly) *) |
1316 (* interpretation which includes values for the (formerly) *) |
1304 (* quantified variables. *) |
1317 (* quantified variables. *) |
1305 (* maps !!x1...xn. !xk...xm. t to t *) |
1318 (* maps !!x1...xn. !xk...xm. t to t *) |
1306 fun strip_all_body (Const ("all", _) $ Abs (_, _, t)) = strip_all_body t |
1319 fun strip_all_body (Const (@{const_name all}, _) $ Abs (_, _, t)) = strip_all_body t |
1307 | strip_all_body (Const ("Trueprop", _) $ t) = strip_all_body t |
1320 | strip_all_body (Const (@{const_name Trueprop}, _) $ t) = strip_all_body t |
1308 | strip_all_body (Const ("All", _) $ Abs (_, _, t)) = strip_all_body t |
1321 | strip_all_body (Const (@{const_name All}, _) $ Abs (_, _, t)) = strip_all_body t |
1309 | strip_all_body t = t |
1322 | strip_all_body t = t |
1310 (* maps !!x1...xn. !xk...xm. t to [x1, ..., xn, xk, ..., xm] *) |
1323 (* maps !!x1...xn. !xk...xm. t to [x1, ..., xn, xk, ..., xm] *) |
1311 fun strip_all_vars (Const ("all", _) $ Abs (a, T, t)) = |
1324 fun strip_all_vars (Const (@{const_name all}, _) $ Abs (a, T, t)) = |
1312 (a, T) :: strip_all_vars t |
1325 (a, T) :: strip_all_vars t |
1313 | strip_all_vars (Const ("Trueprop", _) $ t) = |
1326 | strip_all_vars (Const (@{const_name Trueprop}, _) $ t) = |
1314 strip_all_vars t |
1327 strip_all_vars t |
1315 | strip_all_vars (Const ("All", _) $ Abs (a, T, t)) = |
1328 | strip_all_vars (Const (@{const_name All}, _) $ Abs (a, T, t)) = |
1316 (a, T) :: strip_all_vars t |
1329 (a, T) :: strip_all_vars t |
1317 | strip_all_vars t = |
1330 | strip_all_vars t = |
1318 [] : (string * typ) list |
1331 [] : (string * typ) list |
1319 val strip_t = strip_all_body ex_closure |
1332 val strip_t = strip_all_body ex_closure |
1320 val frees = Term.rename_wrt_term strip_t (strip_all_vars ex_closure) |
1333 val frees = Term.rename_wrt_term strip_t (strip_all_vars ex_closure) |
1321 val subst_t = Term.subst_bounds (map Free frees, strip_t) |
1334 val subst_t = Term.subst_bounds (map Free frees, strip_t) |
1322 in |
1335 in |
1779 end |
1792 end |
1780 | _ => |
1793 | _ => |
1781 raise REFUTE ("Pure_interpreter", |
1794 raise REFUTE ("Pure_interpreter", |
1782 "\"all\" is followed by a non-function") |
1795 "\"all\" is followed by a non-function") |
1783 end |
1796 end |
1784 | Const ("all", _) => |
1797 | Const (@{const_name all}, _) => |
1785 SOME (interpret thy model args (eta_expand t 1)) |
1798 SOME (interpret thy model args (eta_expand t 1)) |
1786 | Const ("==", _) $ t1 $ t2 => |
1799 | Const (@{const_name "=="}, _) $ t1 $ t2 => |
1787 let |
1800 let |
1788 val (i1, m1, a1) = interpret thy model args t1 |
1801 val (i1, m1, a1) = interpret thy model args t1 |
1789 val (i2, m2, a2) = interpret thy m1 a1 t2 |
1802 val (i2, m2, a2) = interpret thy m1 a1 t2 |
1790 in |
1803 in |
1791 (* we use either 'make_def_equality' or 'make_equality' *) |
1804 (* we use either 'make_def_equality' or 'make_equality' *) |
1792 SOME ((if #def_eq args then make_def_equality else make_equality) |
1805 SOME ((if #def_eq args then make_def_equality else make_equality) |
1793 (i1, i2), m2, a2) |
1806 (i1, i2), m2, a2) |
1794 end |
1807 end |
1795 | Const ("==", _) $ t1 => |
1808 | Const (@{const_name "=="}, _) $ t1 => |
1796 SOME (interpret thy model args (eta_expand t 1)) |
1809 SOME (interpret thy model args (eta_expand t 1)) |
1797 | Const ("==", _) => |
1810 | Const (@{const_name "=="}, _) => |
1798 SOME (interpret thy model args (eta_expand t 2)) |
1811 SOME (interpret thy model args (eta_expand t 2)) |
1799 | Const ("==>", _) $ t1 $ t2 => |
1812 | Const (@{const_name "==>"}, _) $ t1 $ t2 => |
1800 (* 3-valued logic *) |
1813 (* 3-valued logic *) |
1801 let |
1814 let |
1802 val (i1, m1, a1) = interpret thy model args t1 |
1815 val (i1, m1, a1) = interpret thy model args t1 |
1803 val (i2, m2, a2) = interpret thy m1 a1 t2 |
1816 val (i2, m2, a2) = interpret thy m1 a1 t2 |
1804 val fmTrue = PropLogic.SOr (toFalse i1, toTrue i2) |
1817 val fmTrue = PropLogic.SOr (toFalse i1, toTrue i2) |
1805 val fmFalse = PropLogic.SAnd (toTrue i1, toFalse i2) |
1818 val fmFalse = PropLogic.SAnd (toTrue i1, toFalse i2) |
1806 in |
1819 in |
1807 SOME (Leaf [fmTrue, fmFalse], m2, a2) |
1820 SOME (Leaf [fmTrue, fmFalse], m2, a2) |
1808 end |
1821 end |
1809 | Const ("==>", _) $ t1 => |
1822 | Const (@{const_name "==>"}, _) $ t1 => |
1810 SOME (interpret thy model args (eta_expand t 1)) |
1823 SOME (interpret thy model args (eta_expand t 1)) |
1811 | Const ("==>", _) => |
1824 | Const (@{const_name "==>"}, _) => |
1812 SOME (interpret thy model args (eta_expand t 2)) |
1825 SOME (interpret thy model args (eta_expand t 2)) |
1813 | _ => NONE; |
1826 | _ => NONE; |
1814 |
1827 |
1815 (* theory -> model -> arguments -> Term.term -> |
1828 (* theory -> model -> arguments -> Term.term -> |
1816 (interpretation * model * arguments) option *) |
1829 (interpretation * model * arguments) option *) |
1818 fun HOLogic_interpreter thy model args t = |
1831 fun HOLogic_interpreter thy model args t = |
1819 (* Providing interpretations directly is more efficient than unfolding the *) |
1832 (* Providing interpretations directly is more efficient than unfolding the *) |
1820 (* logical constants. In HOL however, logical constants can themselves be *) |
1833 (* logical constants. In HOL however, logical constants can themselves be *) |
1821 (* arguments. They are then translated using eta-expansion. *) |
1834 (* arguments. They are then translated using eta-expansion. *) |
1822 case t of |
1835 case t of |
1823 Const ("Trueprop", _) => |
1836 Const (@{const_name Trueprop}, _) => |
1824 SOME (Node [TT, FF], model, args) |
1837 SOME (Node [TT, FF], model, args) |
1825 | Const ("Not", _) => |
1838 | Const (@{const_name Not}, _) => |
1826 SOME (Node [FF, TT], model, args) |
1839 SOME (Node [FF, TT], model, args) |
1827 (* redundant, since 'True' is also an IDT constructor *) |
1840 (* redundant, since 'True' is also an IDT constructor *) |
1828 | Const ("True", _) => |
1841 | Const (@{const_name True}, _) => |
1829 SOME (TT, model, args) |
1842 SOME (TT, model, args) |
1830 (* redundant, since 'False' is also an IDT constructor *) |
1843 (* redundant, since 'False' is also an IDT constructor *) |
1831 | Const ("False", _) => |
1844 | Const (@{const_name False}, _) => |
1832 SOME (FF, model, args) |
1845 SOME (FF, model, args) |
1833 | Const ("All", _) $ t1 => (* similar to "all" (Pure) *) |
1846 | Const (@{const_name All}, _) $ t1 => (* similar to "all" (Pure) *) |
1834 let |
1847 let |
1835 val (i, m, a) = interpret thy model args t1 |
1848 val (i, m, a) = interpret thy model args t1 |
1836 in |
1849 in |
1837 case i of |
1850 case i of |
1838 Node xs => |
1851 Node xs => |
1864 end |
1877 end |
1865 | _ => |
1878 | _ => |
1866 raise REFUTE ("HOLogic_interpreter", |
1879 raise REFUTE ("HOLogic_interpreter", |
1867 "\"Ex\" is followed by a non-function") |
1880 "\"Ex\" is followed by a non-function") |
1868 end |
1881 end |
1869 | Const ("Ex", _) => |
1882 | Const (@{const_name Ex}, _) => |
1870 SOME (interpret thy model args (eta_expand t 1)) |
1883 SOME (interpret thy model args (eta_expand t 1)) |
1871 | Const ("op =", _) $ t1 $ t2 => (* similar to "==" (Pure) *) |
1884 | Const (@{const_name "op ="}, _) $ t1 $ t2 => (* similar to "==" (Pure) *) |
1872 let |
1885 let |
1873 val (i1, m1, a1) = interpret thy model args t1 |
1886 val (i1, m1, a1) = interpret thy model args t1 |
1874 val (i2, m2, a2) = interpret thy m1 a1 t2 |
1887 val (i2, m2, a2) = interpret thy m1 a1 t2 |
1875 in |
1888 in |
1876 SOME (make_equality (i1, i2), m2, a2) |
1889 SOME (make_equality (i1, i2), m2, a2) |
1877 end |
1890 end |
1878 | Const ("op =", _) $ t1 => |
1891 | Const (@{const_name "op ="}, _) $ t1 => |
1879 SOME (interpret thy model args (eta_expand t 1)) |
1892 SOME (interpret thy model args (eta_expand t 1)) |
1880 | Const ("op =", _) => |
1893 | Const (@{const_name "op ="}, _) => |
1881 SOME (interpret thy model args (eta_expand t 2)) |
1894 SOME (interpret thy model args (eta_expand t 2)) |
1882 | Const ("op &", _) $ t1 $ t2 => |
1895 | Const (@{const_name "op &"}, _) $ t1 $ t2 => |
1883 (* 3-valued logic *) |
1896 (* 3-valued logic *) |
1884 let |
1897 let |
1885 val (i1, m1, a1) = interpret thy model args t1 |
1898 val (i1, m1, a1) = interpret thy model args t1 |
1886 val (i2, m2, a2) = interpret thy m1 a1 t2 |
1899 val (i2, m2, a2) = interpret thy m1 a1 t2 |
1887 val fmTrue = PropLogic.SAnd (toTrue i1, toTrue i2) |
1900 val fmTrue = PropLogic.SAnd (toTrue i1, toTrue i2) |
1888 val fmFalse = PropLogic.SOr (toFalse i1, toFalse i2) |
1901 val fmFalse = PropLogic.SOr (toFalse i1, toFalse i2) |
1889 in |
1902 in |
1890 SOME (Leaf [fmTrue, fmFalse], m2, a2) |
1903 SOME (Leaf [fmTrue, fmFalse], m2, a2) |
1891 end |
1904 end |
1892 | Const ("op &", _) $ t1 => |
1905 | Const (@{const_name "op &"}, _) $ t1 => |
1893 SOME (interpret thy model args (eta_expand t 1)) |
1906 SOME (interpret thy model args (eta_expand t 1)) |
1894 | Const ("op &", _) => |
1907 | Const (@{const_name "op &"}, _) => |
1895 SOME (interpret thy model args (eta_expand t 2)) |
1908 SOME (interpret thy model args (eta_expand t 2)) |
1896 (* this would make "undef" propagate, even for formulae like *) |
1909 (* this would make "undef" propagate, even for formulae like *) |
1897 (* "False & undef": *) |
1910 (* "False & undef": *) |
1898 (* SOME (Node [Node [TT, FF], Node [FF, FF]], model, args) *) |
1911 (* SOME (Node [Node [TT, FF], Node [FF, FF]], model, args) *) |
1899 | Const ("op |", _) $ t1 $ t2 => |
1912 | Const (@{const_name "op |"}, _) $ t1 $ t2 => |
1900 (* 3-valued logic *) |
1913 (* 3-valued logic *) |
1901 let |
1914 let |
1902 val (i1, m1, a1) = interpret thy model args t1 |
1915 val (i1, m1, a1) = interpret thy model args t1 |
1903 val (i2, m2, a2) = interpret thy m1 a1 t2 |
1916 val (i2, m2, a2) = interpret thy m1 a1 t2 |
1904 val fmTrue = PropLogic.SOr (toTrue i1, toTrue i2) |
1917 val fmTrue = PropLogic.SOr (toTrue i1, toTrue i2) |
1905 val fmFalse = PropLogic.SAnd (toFalse i1, toFalse i2) |
1918 val fmFalse = PropLogic.SAnd (toFalse i1, toFalse i2) |
1906 in |
1919 in |
1907 SOME (Leaf [fmTrue, fmFalse], m2, a2) |
1920 SOME (Leaf [fmTrue, fmFalse], m2, a2) |
1908 end |
1921 end |
1909 | Const ("op |", _) $ t1 => |
1922 | Const (@{const_name "op |"}, _) $ t1 => |
1910 SOME (interpret thy model args (eta_expand t 1)) |
1923 SOME (interpret thy model args (eta_expand t 1)) |
1911 | Const ("op |", _) => |
1924 | Const (@{const_name "op |"}, _) => |
1912 SOME (interpret thy model args (eta_expand t 2)) |
1925 SOME (interpret thy model args (eta_expand t 2)) |
1913 (* this would make "undef" propagate, even for formulae like *) |
1926 (* this would make "undef" propagate, even for formulae like *) |
1914 (* "True | undef": *) |
1927 (* "True | undef": *) |
1915 (* SOME (Node [Node [TT, TT], Node [TT, FF]], model, args) *) |
1928 (* SOME (Node [Node [TT, TT], Node [TT, FF]], model, args) *) |
1916 | Const ("op -->", _) $ t1 $ t2 => (* similar to "==>" (Pure) *) |
1929 | Const (@{const_name "op -->"}, _) $ t1 $ t2 => (* similar to "==>" (Pure) *) |
1917 (* 3-valued logic *) |
1930 (* 3-valued logic *) |
1918 let |
1931 let |
1919 val (i1, m1, a1) = interpret thy model args t1 |
1932 val (i1, m1, a1) = interpret thy model args t1 |
1920 val (i2, m2, a2) = interpret thy m1 a1 t2 |
1933 val (i2, m2, a2) = interpret thy m1 a1 t2 |
1921 val fmTrue = PropLogic.SOr (toFalse i1, toTrue i2) |
1934 val fmTrue = PropLogic.SOr (toFalse i1, toTrue i2) |
1922 val fmFalse = PropLogic.SAnd (toTrue i1, toFalse i2) |
1935 val fmFalse = PropLogic.SAnd (toTrue i1, toFalse i2) |
1923 in |
1936 in |
1924 SOME (Leaf [fmTrue, fmFalse], m2, a2) |
1937 SOME (Leaf [fmTrue, fmFalse], m2, a2) |
1925 end |
1938 end |
1926 | Const ("op -->", _) $ t1 => |
1939 | Const (@{const_name "op -->"}, _) $ t1 => |
1927 SOME (interpret thy model args (eta_expand t 1)) |
1940 SOME (interpret thy model args (eta_expand t 1)) |
1928 | Const ("op -->", _) => |
1941 | Const (@{const_name "op -->"}, _) => |
1929 SOME (interpret thy model args (eta_expand t 2)) |
1942 SOME (interpret thy model args (eta_expand t 2)) |
1930 (* this would make "undef" propagate, even for formulae like *) |
1943 (* this would make "undef" propagate, even for formulae like *) |
1931 (* "False --> undef": *) |
1944 (* "False --> undef": *) |
1932 (* SOME (Node [Node [TT, FF], Node [TT, TT]], model, args) *) |
1945 (* SOME (Node [Node [TT, FF], Node [TT, TT]], model, args) *) |
1933 | _ => NONE; |
1946 | _ => NONE; |
1934 |
|
1935 (* theory -> model -> arguments -> Term.term -> |
|
1936 (interpretation * model * arguments) option *) |
|
1937 |
|
1938 fun set_interpreter thy model args t = |
|
1939 (* "T set" is isomorphic to "T --> bool" *) |
|
1940 let |
|
1941 val (typs, terms) = model |
|
1942 in |
|
1943 case AList.lookup (op =) terms t of |
|
1944 SOME intr => |
|
1945 (* return an existing interpretation *) |
|
1946 SOME (intr, model, args) |
|
1947 | NONE => |
|
1948 (case t of |
|
1949 Free (x, Type ("set", [T])) => |
|
1950 let |
|
1951 val (intr, _, args') = |
|
1952 interpret thy (typs, []) args (Free (x, T --> HOLogic.boolT)) |
|
1953 in |
|
1954 SOME (intr, (typs, (t, intr)::terms), args') |
|
1955 end |
|
1956 | Var ((x, i), Type ("set", [T])) => |
|
1957 let |
|
1958 val (intr, _, args') = |
|
1959 interpret thy (typs, []) args (Var ((x,i), T --> HOLogic.boolT)) |
|
1960 in |
|
1961 SOME (intr, (typs, (t, intr)::terms), args') |
|
1962 end |
|
1963 | Const (s, Type ("set", [T])) => |
|
1964 let |
|
1965 val (intr, _, args') = |
|
1966 interpret thy (typs, []) args (Const (s, T --> HOLogic.boolT)) |
|
1967 in |
|
1968 SOME (intr, (typs, (t, intr)::terms), args') |
|
1969 end |
|
1970 (* 'Collect' == identity *) |
|
1971 | Const ("Collect", _) $ t1 => |
|
1972 SOME (interpret thy model args t1) |
|
1973 | Const ("Collect", _) => |
|
1974 SOME (interpret thy model args (eta_expand t 1)) |
|
1975 (* 'op :' == application *) |
|
1976 | Const ("op :", _) $ t1 $ t2 => |
|
1977 SOME (interpret thy model args (t2 $ t1)) |
|
1978 | Const ("op :", _) $ t1 => |
|
1979 SOME (interpret thy model args (eta_expand t 1)) |
|
1980 | Const ("op :", _) => |
|
1981 SOME (interpret thy model args (eta_expand t 2)) |
|
1982 | _ => NONE) |
|
1983 end; |
|
1984 |
1947 |
1985 (* theory -> model -> arguments -> Term.term -> |
1948 (* theory -> model -> arguments -> Term.term -> |
1986 (interpretation * model * arguments) option *) |
1949 (interpretation * model * arguments) option *) |
1987 |
1950 |
1988 (* interprets variables and constants whose type is an IDT (this is *) |
1951 (* interprets variables and constants whose type is an IDT (this is *) |
3012 (* interpretation * interpretation -> bool *) |
2957 (* interpretation * interpretation -> bool *) |
3013 fun is_subset (Node subs, Node sups) = |
2958 fun is_subset (Node subs, Node sups) = |
3014 List.all (fn (sub, sup) => (sub = FF) orelse (sup = TT)) |
2959 List.all (fn (sub, sup) => (sub = FF) orelse (sup = TT)) |
3015 (subs ~~ sups) |
2960 (subs ~~ sups) |
3016 | is_subset (_, _) = |
2961 | is_subset (_, _) = |
3017 raise REFUTE ("Lfp_lfp_interpreter", |
2962 raise REFUTE ("lfp_interpreter", |
3018 "is_subset: interpretation for set is not a node") |
2963 "is_subset: interpretation for set is not a node") |
3019 (* interpretation * interpretation -> interpretation *) |
2964 (* interpretation * interpretation -> interpretation *) |
3020 fun intersection (Node xs, Node ys) = |
2965 fun intersection (Node xs, Node ys) = |
3021 Node (map (fn (x, y) => if x=TT andalso y=TT then TT else FF) |
2966 Node (map (fn (x, y) => if x=TT andalso y=TT then TT else FF) |
3022 (xs ~~ ys)) |
2967 (xs ~~ ys)) |
3023 | intersection (_, _) = |
2968 | intersection (_, _) = |
3024 raise REFUTE ("Lfp_lfp_interpreter", |
2969 raise REFUTE ("lfp_interpreter", |
3025 "intersection: interpretation for set is not a node") |
2970 "intersection: interpretation for set is not a node") |
3026 (* interpretation -> interpretaion *) |
2971 (* interpretation -> interpretaion *) |
3027 fun lfp (Node resultsets) = |
2972 fun lfp (Node resultsets) = |
3028 foldl (fn ((set, resultset), acc) => |
2973 foldl (fn ((set, resultset), acc) => |
3029 if is_subset (resultset, set) then |
2974 if is_subset (resultset, set) then |
3030 intersection (acc, set) |
2975 intersection (acc, set) |
3031 else |
2976 else |
3032 acc) i_univ (i_sets ~~ resultsets) |
2977 acc) i_univ (i_sets ~~ resultsets) |
3033 | lfp _ = |
2978 | lfp _ = |
3034 raise REFUTE ("Lfp_lfp_interpreter", |
2979 raise REFUTE ("lfp_interpreter", |
3035 "lfp: interpretation for function is not a node") |
2980 "lfp: interpretation for function is not a node") |
3036 in |
2981 in |
3037 SOME (Node (map lfp i_funs), model, args) |
2982 SOME (Node (map lfp i_funs), model, args) |
3038 end |
2983 end |
3039 | _ => |
2984 | _ => |
3063 (* interpretation * interpretation -> bool *) |
3008 (* interpretation * interpretation -> bool *) |
3064 fun is_subset (Node subs, Node sups) = |
3009 fun is_subset (Node subs, Node sups) = |
3065 List.all (fn (sub, sup) => (sub = FF) orelse (sup = TT)) |
3010 List.all (fn (sub, sup) => (sub = FF) orelse (sup = TT)) |
3066 (subs ~~ sups) |
3011 (subs ~~ sups) |
3067 | is_subset (_, _) = |
3012 | is_subset (_, _) = |
3068 raise REFUTE ("Gfp_gfp_interpreter", |
3013 raise REFUTE ("gfp_interpreter", |
3069 "is_subset: interpretation for set is not a node") |
3014 "is_subset: interpretation for set is not a node") |
3070 (* interpretation * interpretation -> interpretation *) |
3015 (* interpretation * interpretation -> interpretation *) |
3071 fun union (Node xs, Node ys) = |
3016 fun union (Node xs, Node ys) = |
3072 Node (map (fn (x,y) => if x=TT orelse y=TT then TT else FF) |
3017 Node (map (fn (x,y) => if x=TT orelse y=TT then TT else FF) |
3073 (xs ~~ ys)) |
3018 (xs ~~ ys)) |
3074 | union (_, _) = |
3019 | union (_, _) = |
3075 raise REFUTE ("Gfp_gfp_interpreter", |
3020 raise REFUTE ("gfp_interpreter", |
3076 "union: interpretation for set is not a node") |
3021 "union: interpretation for set is not a node") |
3077 (* interpretation -> interpretaion *) |
3022 (* interpretation -> interpretaion *) |
3078 fun gfp (Node resultsets) = |
3023 fun gfp (Node resultsets) = |
3079 foldl (fn ((set, resultset), acc) => |
3024 foldl (fn ((set, resultset), acc) => |
3080 if is_subset (set, resultset) then |
3025 if is_subset (set, resultset) then |
3081 union (acc, set) |
3026 union (acc, set) |
3082 else |
3027 else |
3083 acc) i_univ (i_sets ~~ resultsets) |
3028 acc) i_univ (i_sets ~~ resultsets) |
3084 | gfp _ = |
3029 | gfp _ = |
3085 raise REFUTE ("Gfp_gfp_interpreter", |
3030 raise REFUTE ("gfp_interpreter", |
3086 "gfp: interpretation for function is not a node") |
3031 "gfp: interpretation for function is not a node") |
3087 in |
3032 in |
3088 SOME (Node (map gfp i_funs), model, args) |
3033 SOME (Node (map gfp i_funs), model, args) |
3089 end |
3034 end |
3090 | _ => |
3035 | _ => |
3357 |
3263 |
3358 val setup = |
3264 val setup = |
3359 add_interpreter "stlc" stlc_interpreter #> |
3265 add_interpreter "stlc" stlc_interpreter #> |
3360 add_interpreter "Pure" Pure_interpreter #> |
3266 add_interpreter "Pure" Pure_interpreter #> |
3361 add_interpreter "HOLogic" HOLogic_interpreter #> |
3267 add_interpreter "HOLogic" HOLogic_interpreter #> |
3362 add_interpreter "set" set_interpreter #> |
|
3363 add_interpreter "IDT" IDT_interpreter #> |
3268 add_interpreter "IDT" IDT_interpreter #> |
3364 add_interpreter "IDT_constructor" IDT_constructor_interpreter #> |
3269 add_interpreter "IDT_constructor" IDT_constructor_interpreter #> |
3365 add_interpreter "IDT_recursion" IDT_recursion_interpreter #> |
3270 add_interpreter "IDT_recursion" IDT_recursion_interpreter #> |
3366 add_interpreter "Finite_Set.card" Finite_Set_card_interpreter #> |
3271 add_interpreter "Finite_Set.card" Finite_Set_card_interpreter #> |
3367 add_interpreter "Finite_Set.Finites" Finite_Set_Finites_interpreter #> |
|
3368 add_interpreter "Finite_Set.finite" Finite_Set_finite_interpreter #> |
3272 add_interpreter "Finite_Set.finite" Finite_Set_finite_interpreter #> |
3369 add_interpreter "Nat_Orderings.less" Nat_less_interpreter #> |
3273 add_interpreter "Nat_Orderings.less" Nat_less_interpreter #> |
3370 add_interpreter "Nat_HOL.plus" Nat_plus_interpreter #> |
3274 add_interpreter "Nat_HOL.plus" Nat_plus_interpreter #> |
3371 add_interpreter "Nat_HOL.minus" Nat_minus_interpreter #> |
3275 add_interpreter "Nat_HOL.minus" Nat_minus_interpreter #> |
3372 add_interpreter "Nat_HOL.times" Nat_times_interpreter #> |
3276 add_interpreter "Nat_HOL.times" Nat_times_interpreter #> |
3373 add_interpreter "List.append" List_append_interpreter #> |
3277 add_interpreter "List.append" List_append_interpreter #> |
3374 add_interpreter "Lfp.lfp" Lfp_lfp_interpreter #> |
3278 add_interpreter "lfp" lfp_interpreter #> |
3375 add_interpreter "Gfp.gfp" Gfp_gfp_interpreter #> |
3279 add_interpreter "gfp" gfp_interpreter #> |
3376 add_interpreter "fst" Product_Type_fst_interpreter #> |
3280 add_interpreter "fst" Product_Type_fst_interpreter #> |
3377 add_interpreter "snd" Product_Type_snd_interpreter #> |
3281 add_interpreter "snd" Product_Type_snd_interpreter #> |
3378 add_printer "stlc" stlc_printer #> |
3282 add_printer "stlc" stlc_printer #> |
3379 add_printer "set" set_printer #> |
|
3380 add_printer "IDT" IDT_printer; |
3283 add_printer "IDT" IDT_printer; |
3381 |
3284 |
3382 end (* structure Refute *) |
3285 end (* structure Refute *) |