src/HOL/HOL.thy
changeset 21547 9c9fdf4c2949
parent 21524 7843e2fd14a9
child 21671 f7d652ffef09
equal deleted inserted replaced
21546:268b6bed0cc8 21547:9c9fdf4c2949
   803   and [symmetric, defn] = atomize_all atomize_imp atomize_eq
   803   and [symmetric, defn] = atomize_all atomize_imp atomize_eq
   804 
   804 
   805 
   805 
   806 subsection {* Package setup *}
   806 subsection {* Package setup *}
   807 
   807 
   808 subsubsection {* Fundamental ML bindings *}
       
   809 
       
   810 ML {*
       
   811 structure HOL =
       
   812 struct
       
   813   (*FIXME reduce this to a minimum*)
       
   814   val eq_reflection = thm "eq_reflection";
       
   815   val def_imp_eq = thm "def_imp_eq";
       
   816   val meta_eq_to_obj_eq = thm "meta_eq_to_obj_eq";
       
   817   val ccontr = thm "ccontr";
       
   818   val impI = thm "impI";
       
   819   val impCE = thm "impCE";
       
   820   val notI = thm "notI";
       
   821   val notE = thm "notE";
       
   822   val iffI = thm "iffI";
       
   823   val iffCE = thm "iffCE";
       
   824   val conjI = thm "conjI";
       
   825   val conjE = thm "conjE";
       
   826   val disjCI = thm "disjCI";
       
   827   val disjE = thm "disjE";
       
   828   val TrueI = thm "TrueI";
       
   829   val FalseE = thm "FalseE";
       
   830   val allI = thm "allI";
       
   831   val allE = thm "allE";
       
   832   val exI = thm "exI";
       
   833   val exE = thm "exE";
       
   834   val ex_ex1I = thm "ex_ex1I";
       
   835   val the_equality = thm "the_equality";
       
   836   val mp = thm "mp";
       
   837   val rev_mp = thm "rev_mp"
       
   838   val classical = thm "classical";
       
   839   val subst = thm "subst";
       
   840   val refl = thm "refl";
       
   841   val sym = thm "sym";
       
   842   val trans = thm "trans";
       
   843   val arg_cong = thm "arg_cong";
       
   844   val iffD1 = thm "iffD1";
       
   845   val iffD2 = thm "iffD2";
       
   846   val disjE = thm "disjE";
       
   847   val conjE = thm "conjE";
       
   848   val exE = thm "exE";
       
   849   val contrapos_nn = thm "contrapos_nn";
       
   850   val contrapos_pp = thm "contrapos_pp";
       
   851   val notnotD = thm "notnotD";
       
   852   val conjunct1 = thm "conjunct1";
       
   853   val conjunct2 = thm "conjunct2";
       
   854   val spec = thm "spec";
       
   855   val imp_cong = thm "imp_cong";
       
   856   val the_sym_eq_trivial = thm "the_sym_eq_trivial";
       
   857   val triv_forall_equality = thm "triv_forall_equality";
       
   858   val case_split = thm "case_split_thm";
       
   859 end
       
   860 *}
       
   861 
       
   862 
       
   863 subsubsection {* Classical Reasoner setup *}
   808 subsubsection {* Classical Reasoner setup *}
   864 
   809 
   865 lemma thin_refl:
   810 lemma thin_refl:
   866   "\<And>X. \<lbrakk> x=x; PROP W \<rbrakk> \<Longrightarrow> PROP W" .
   811   "\<And>X. \<lbrakk> x=x; PROP W \<rbrakk> \<Longrightarrow> PROP W" .
   867 
   812 
   870 struct
   815 struct
   871   structure Simplifier = Simplifier
   816   structure Simplifier = Simplifier
   872   val dest_eq = HOLogic.dest_eq
   817   val dest_eq = HOLogic.dest_eq
   873   val dest_Trueprop = HOLogic.dest_Trueprop
   818   val dest_Trueprop = HOLogic.dest_Trueprop
   874   val dest_imp = HOLogic.dest_imp
   819   val dest_imp = HOLogic.dest_imp
   875   val eq_reflection = HOL.eq_reflection
   820   val eq_reflection = thm "HOL.eq_reflection"
   876   val rev_eq_reflection = HOL.def_imp_eq
   821   val rev_eq_reflection = thm "HOL.def_imp_eq"
   877   val imp_intr = HOL.impI
   822   val imp_intr = thm "HOL.impI"
   878   val rev_mp = HOL.rev_mp
   823   val rev_mp = thm "HOL.rev_mp"
   879   val subst = HOL.subst
   824   val subst = thm "HOL.subst"
   880   val sym = HOL.sym
   825   val sym = thm "HOL.sym"
   881   val thin_refl = thm "thin_refl";
   826   val thin_refl = thm "thin_refl";
   882 end);
   827 end);
   883 
   828 
   884 structure Classical = ClassicalFun(
   829 structure Classical = ClassicalFun(
   885 struct
   830 struct
   886   val mp = HOL.mp
   831   val mp = thm "HOL.mp"
   887   val not_elim = HOL.notE
   832   val not_elim = thm "HOL.notE"
   888   val classical = HOL.classical
   833   val classical = thm "HOL.classical"
   889   val sizef = Drule.size_of_thm
   834   val sizef = Drule.size_of_thm
   890   val hyp_subst_tacs = [Hypsubst.hyp_subst_tac]
   835   val hyp_subst_tacs = [Hypsubst.hyp_subst_tac]
   891 end);
   836 end);
   892 
   837 
   893 structure BasicClassical: BASIC_CLASSICAL = Classical; 
   838 structure BasicClassical: BASIC_CLASSICAL = Classical; 
   929 
   874 
   930 declare exE [elim!]
   875 declare exE [elim!]
   931   allE [elim]
   876   allE [elim]
   932 
   877 
   933 ML {*
   878 ML {*
   934 structure HOL =
   879 val HOL_cs = Classical.claset_of (the_context ());
   935 struct
       
   936 
       
   937 open HOL;
       
   938 
       
   939 val claset = Classical.claset_of (the_context ());
       
   940 
       
   941 end;
       
   942 *}
   880 *}
   943 
   881 
   944 lemma contrapos_np: "~ Q ==> (~ P ==> Q) ==> P"
   882 lemma contrapos_np: "~ Q ==> (~ P ==> Q) ==> P"
   945   apply (erule swap)
   883   apply (erule swap)
   946   apply (erule (1) meta_mp)
   884   apply (erule (1) meta_mp)
   957   assumes major: "\<exists>!x. P x"
   895   assumes major: "\<exists>!x. P x"
   958       and prem: "\<And>x. \<lbrakk> P x; \<forall>y y'. P y \<and> P y' \<longrightarrow> y = y' \<rbrakk> \<Longrightarrow> R"
   896       and prem: "\<And>x. \<lbrakk> P x; \<forall>y y'. P y \<and> P y' \<longrightarrow> y = y' \<rbrakk> \<Longrightarrow> R"
   959   shows R
   897   shows R
   960 apply (rule ex1E [OF major])
   898 apply (rule ex1E [OF major])
   961 apply (rule prem)
   899 apply (rule prem)
   962 apply (tactic "ares_tac [HOL.allI] 1")+
   900 apply (tactic {* ares_tac [thm "allI"] 1 *})+
   963 apply (tactic "etac (Classical.dup_elim HOL.allE) 1")
   901 apply (tactic {* etac (Classical.dup_elim (thm "allE")) 1 *})
   964 by iprover
   902 by iprover
   965 
   903 
   966 ML {*
   904 ML {*
   967 structure Blast = BlastFun(
   905 structure Blast = BlastFun(
   968 struct
   906 struct
   969   type claset = Classical.claset
   907   type claset = Classical.claset
   970   val equality_name = "op ="
   908   val equality_name = "op ="
   971   val not_name = "Not"
   909   val not_name = "Not"
   972   val notE = HOL.notE
   910   val notE = thm "HOL.notE"
   973   val ccontr = HOL.ccontr
   911   val ccontr = thm "HOL.ccontr"
   974   val contr_tac = Classical.contr_tac
   912   val contr_tac = Classical.contr_tac
   975   val dup_intr = Classical.dup_intr
   913   val dup_intr = Classical.dup_intr
   976   val hyp_subst_tac = Hypsubst.blast_hyp_subst_tac
   914   val hyp_subst_tac = Hypsubst.blast_hyp_subst_tac
   977   val claset	= Classical.claset
   915   val claset	= Classical.claset
   978   val rep_cs = Classical.rep_cs
   916   val rep_cs = Classical.rep_cs
   979   val cla_modifiers = Classical.cla_modifiers
   917   val cla_modifiers = Classical.cla_modifiers
   980   val cla_meth' = Classical.cla_meth'
   918   val cla_meth' = Classical.cla_meth'
   981 end);
   919 end);
   982 
       
   983 structure HOL =
       
   984 struct
       
   985 
       
   986 open HOL;
       
   987 
       
   988 val Blast_tac = Blast.Blast_tac;
       
   989 val blast_tac = Blast.blast_tac;
       
   990 
       
   991 fun case_tac a = res_inst_tac [("P", a)] case_split;
       
   992 
       
   993 (* combination of (spec RS spec RS ...(j times) ... spec RS mp) *)
       
   994 local
       
   995   fun wrong_prem (Const ("All", _) $ (Abs (_, _, t))) = wrong_prem t
       
   996     | wrong_prem (Bound _) = true
       
   997     | wrong_prem _ = false;
       
   998   val filter_right = filter (not o wrong_prem o HOLogic.dest_Trueprop o hd o Thm.prems_of);
       
   999 in
       
  1000   fun smp i = funpow i (fn m => filter_right ([spec] RL m)) ([mp]);
       
  1001   fun smp_tac j = EVERY'[dresolve_tac (smp j), atac];
       
  1002 end;
       
  1003 
       
  1004 fun strip_tac i = REPEAT (resolve_tac [impI, allI] i);
       
  1005 
       
  1006 fun Trueprop_conv conv ct = (case term_of ct of
       
  1007     Const ("Trueprop", _) $ _ =>
       
  1008       let val (ct1, ct2) = Thm.dest_comb ct
       
  1009       in Thm.combination (Thm.reflexive ct1) (conv ct2) end
       
  1010   | _ => raise TERM ("Trueprop_conv", []));
       
  1011 
       
  1012 fun Equals_conv conv ct = (case term_of ct of
       
  1013     Const ("op =", _) $ _ $ _ =>
       
  1014       let
       
  1015         val ((ct1, ct2), ct3) = (apfst Thm.dest_comb o Thm.dest_comb) ct;
       
  1016       in Thm.combination (Thm.combination (Thm.reflexive ct1) (conv ct2)) (conv ct3) end
       
  1017   | _ => conv ct);
       
  1018 
       
  1019 fun constrain_op_eq_thms thy thms =
       
  1020   let
       
  1021     fun add_eq (Const ("op =", ty)) =
       
  1022           fold (insert (eq_fst (op =)))
       
  1023             (Term.add_tvarsT ty [])
       
  1024       | add_eq _ =
       
  1025           I
       
  1026     val eqs = fold (fold_aterms add_eq o Thm.prop_of) thms [];
       
  1027     val instT = map (fn (v_i, sort) =>
       
  1028       (Thm.ctyp_of thy (TVar (v_i, sort)),
       
  1029          Thm.ctyp_of thy (TVar (v_i, Sorts.inter_sort (Sign.classes_of thy) (sort, [HOLogic.class_eq]))))) eqs;
       
  1030   in
       
  1031     thms
       
  1032     |> map (Thm.instantiate (instT, []))
       
  1033   end;
       
  1034 
       
  1035 end;
       
  1036 *}
   920 *}
  1037 
   921 
  1038 setup Blast.setup
   922 setup Blast.setup
  1039 
   923 
  1040 
   924 
  1296   by blast
  1180   by blast
  1297 
  1181 
  1298 use "simpdata.ML"
  1182 use "simpdata.ML"
  1299 setup {*
  1183 setup {*
  1300   Simplifier.method_setup Splitter.split_modifiers
  1184   Simplifier.method_setup Splitter.split_modifiers
  1301   #> (fn thy => (change_simpset_of thy (fn _ => HOL.simpset_simprocs); thy))
  1185   #> (fn thy => (change_simpset_of thy (fn _ => Simpdata.simpset_simprocs); thy))
  1302   #> Splitter.setup
  1186   #> Splitter.setup
  1303   #> Clasimp.setup
  1187   #> Clasimp.setup
  1304   #> EqSubst.setup
  1188   #> EqSubst.setup
  1305 *}
  1189 *}
  1306 
  1190 
  1364   and imp_cong [cong]
  1248   and imp_cong [cong]
  1365   and simp_implies_cong [cong]
  1249   and simp_implies_cong [cong]
  1366   and split_if [split]
  1250   and split_if [split]
  1367 
  1251 
  1368 ML {*
  1252 ML {*
  1369 structure HOL =
  1253 val HOL_ss = Simplifier.simpset_of (the_context ());
  1370 struct
       
  1371 
       
  1372 open HOL;
       
  1373 
       
  1374 val simpset = Simplifier.simpset_of (the_context ());
       
  1375 
       
  1376 end;
       
  1377 *}
  1254 *}
  1378 
  1255 
  1379 text {* Simplifies x assuming c and y assuming ~c *}
  1256 text {* Simplifies x assuming c and y assuming ~c *}
  1380 lemma if_cong:
  1257 lemma if_cong:
  1381   assumes "b = c"
  1258   assumes "b = c"
  1404   using prems by simp
  1281   using prems by simp
  1405 
  1282 
  1406 lemma if_distrib:
  1283 lemma if_distrib:
  1407   "f (if c then x else y) = (if c then f x else f y)"
  1284   "f (if c then x else y) = (if c then f x else f y)"
  1408   by simp
  1285   by simp
  1409 
       
  1410 text {* For @{text expand_case_tac} *}
       
  1411 lemma expand_case:
       
  1412   assumes "P \<Longrightarrow> Q True"
       
  1413       and "~P \<Longrightarrow> Q False"
       
  1414   shows "Q P"
       
  1415 proof (tactic {* HOL.case_tac "P" 1 *})
       
  1416   assume P
       
  1417   then show "Q P" by simp
       
  1418 next
       
  1419   assume "\<not> P"
       
  1420   then have "P = False" by simp
       
  1421   with prems show "Q P" by simp
       
  1422 qed
       
  1423 
  1286 
  1424 text {* This lemma restricts the effect of the rewrite rule u=v to the left-hand
  1287 text {* This lemma restricts the effect of the rewrite rule u=v to the left-hand
  1425   side of an equality.  Used in @{text "{Integ,Real}/simproc.ML"} *}
  1288   side of an equality.  Used in @{text "{Integ,Real}/simproc.ML"} *}
  1426 lemma restrict_to_left:
  1289 lemma restrict_to_left:
  1427   assumes "x = y"
  1290   assumes "x = y"
  1527   apply (rule allI)
  1390   apply (rule allI)
  1528   apply (rule_tac P = "xa = x" in case_split_thm)
  1391   apply (rule_tac P = "xa = x" in case_split_thm)
  1529   apply (drule_tac [3] x = x in fun_cong, simp_all)
  1392   apply (drule_tac [3] x = x in fun_cong, simp_all)
  1530   done
  1393   done
  1531 
  1394 
  1532 text {* Needs only HOL-lemmas *}
       
  1533 lemma mk_left_commute:
  1395 lemma mk_left_commute:
  1534   assumes a: "\<And>x y z. f (f x y) z = f x (f y z)" and
  1396   fixes f (infix "\<otimes>" 60)
  1535           c: "\<And>x y. f x y = f y x"
  1397   assumes a: "\<And>x y z. (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)" and
  1536   shows "f x (f y z) = f y (f x z)"
  1398           c: "\<And>x y. x \<otimes> y = y \<otimes> x"
       
  1399   shows "x \<otimes> (y \<otimes> z) = y \<otimes> (x \<otimes> z)"
  1537   by (rule trans [OF trans [OF c a] arg_cong [OF c, of "f y"]])
  1400   by (rule trans [OF trans [OF c a] arg_cong [OF c, of "f y"]])
  1538 
  1401 
  1539 end
  1402 end