paulson@11451: (* Title: HOL/Hilbert_Choice.thy paulson@14760: ID: $Id$ paulson@11451: Author: Lawrence C Paulson paulson@11451: Copyright 2001 University of Cambridge wenzelm@12023: *) paulson@11451: paulson@14760: header {* Hilbert's Epsilon-Operator and the Axiom of Choice *} paulson@11451: nipkow@15131: theory Hilbert_Choice wenzelm@21243: imports Nat haftmann@16417: uses ("Tools/meson.ML") ("Tools/specification_package.ML") nipkow@15131: begin wenzelm@12298: wenzelm@12298: subsection {* Hilbert's epsilon *} wenzelm@12298: wenzelm@22690: axiomatization wenzelm@22690: Eps :: "('a => bool) => 'a" wenzelm@22690: where wenzelm@22690: someI: "P x ==> P (Eps P)" paulson@11451: wenzelm@14872: syntax (epsilon) wenzelm@14872: "_Eps" :: "[pttrn, bool] => 'a" ("(3\_./ _)" [0, 10] 10) paulson@11451: syntax (HOL) wenzelm@12298: "_Eps" :: "[pttrn, bool] => 'a" ("(3@ _./ _)" [0, 10] 10) paulson@11451: syntax wenzelm@12298: "_Eps" :: "[pttrn, bool] => 'a" ("(3SOME _./ _)" [0, 10] 10) paulson@11451: translations wenzelm@22690: "SOME x. P" == "CONST Eps (%x. P)" nipkow@13763: nipkow@13763: print_translation {* nipkow@13763: (* to avoid eta-contraction of body *) wenzelm@22690: [(@{const_syntax Eps}, fn [Abs abs] => nipkow@13763: let val (x,t) = atomic_abs_tr' abs nipkow@13763: in Syntax.const "_Eps" $ x $ t end)] nipkow@13763: *} paulson@11451: wenzelm@12298: constdefs wenzelm@12298: inv :: "('a => 'b) => ('b => 'a)" wenzelm@12298: "inv(f :: 'a => 'b) == %y. SOME x. f x = y" paulson@11454: wenzelm@12298: Inv :: "'a set => ('a => 'b) => ('b => 'a)" paulson@14760: "Inv A f == %x. SOME y. y \ A & f y = x" paulson@14760: paulson@14760: paulson@14760: subsection {*Hilbert's Epsilon-operator*} paulson@14760: paulson@14760: text{*Easier to apply than @{text someI} if the witness comes from an paulson@14760: existential formula*} paulson@14760: lemma someI_ex [elim?]: "\x. P x ==> P (SOME x. P x)" paulson@14760: apply (erule exE) paulson@14760: apply (erule someI) paulson@14760: done paulson@14760: paulson@14760: text{*Easier to apply than @{text someI} because the conclusion has only one paulson@14760: occurrence of @{term P}.*} paulson@14760: lemma someI2: "[| P a; !!x. P x ==> Q x |] ==> Q (SOME x. P x)" paulson@14760: by (blast intro: someI) paulson@14760: paulson@14760: text{*Easier to apply than @{text someI2} if the witness comes from an paulson@14760: existential formula*} paulson@14760: lemma someI2_ex: "[| \a. P a; !!x. P x ==> Q x |] ==> Q (SOME x. P x)" paulson@14760: by (blast intro: someI2) paulson@14760: paulson@14760: lemma some_equality [intro]: paulson@14760: "[| P a; !!x. P x ==> x=a |] ==> (SOME x. P x) = a" paulson@14760: by (blast intro: someI2) paulson@14760: paulson@14760: lemma some1_equality: "[| EX!x. P x; P a |] ==> (SOME x. P x) = a" paulson@14760: by (blast intro: some_equality) paulson@14760: paulson@14760: lemma some_eq_ex: "P (SOME x. P x) = (\x. P x)" paulson@14760: by (blast intro: someI) paulson@14760: paulson@14760: lemma some_eq_trivial [simp]: "(SOME y. y=x) = x" paulson@14760: apply (rule some_equality) paulson@14760: apply (rule refl, assumption) paulson@14760: done paulson@14760: paulson@14760: lemma some_sym_eq_trivial [simp]: "(SOME y. x=y) = x" paulson@14760: apply (rule some_equality) paulson@14760: apply (rule refl) paulson@14760: apply (erule sym) paulson@14760: done paulson@14760: paulson@14760: paulson@14760: subsection{*Axiom of Choice, Proved Using the Description Operator*} paulson@14760: paulson@14760: text{*Used in @{text "Tools/meson.ML"}*} paulson@14760: lemma choice: "\x. \y. Q x y ==> \f. \x. Q x (f x)" paulson@14760: by (fast elim: someI) paulson@14760: paulson@14760: lemma bchoice: "\x\S. \y. Q x y ==> \f. \x\S. Q x (f x)" paulson@14760: by (fast elim: someI) paulson@14760: paulson@14760: paulson@14760: subsection {*Function Inverse*} paulson@14760: paulson@14760: lemma inv_id [simp]: "inv id = id" paulson@14760: by (simp add: inv_def id_def) paulson@14760: paulson@14760: text{*A one-to-one function has an inverse.*} paulson@14760: lemma inv_f_f [simp]: "inj f ==> inv f (f x) = x" paulson@14760: by (simp add: inv_def inj_eq) paulson@14760: paulson@14760: lemma inv_f_eq: "[| inj f; f x = y |] ==> inv f y = x" paulson@14760: apply (erule subst) paulson@14760: apply (erule inv_f_f) paulson@14760: done paulson@14760: paulson@14760: lemma inj_imp_inv_eq: "[| inj f; \x. f(g x) = x |] ==> inv f = g" paulson@14760: by (blast intro: ext inv_f_eq) paulson@14760: paulson@14760: text{*But is it useful?*} paulson@14760: lemma inj_transfer: paulson@14760: assumes injf: "inj f" and minor: "!!y. y \ range(f) ==> P(inv f y)" paulson@14760: shows "P x" paulson@14760: proof - paulson@14760: have "f x \ range f" by auto paulson@14760: hence "P(inv f (f x))" by (rule minor) paulson@14760: thus "P x" by (simp add: inv_f_f [OF injf]) paulson@14760: qed paulson@11451: paulson@11451: paulson@14760: lemma inj_iff: "(inj f) = (inv f o f = id)" paulson@14760: apply (simp add: o_def expand_fun_eq) paulson@14760: apply (blast intro: inj_on_inverseI inv_f_f) paulson@14760: done paulson@14760: nipkow@23433: lemma inv_o_cancel[simp]: "inj f ==> inv f o f = id" nipkow@23433: by (simp add: inj_iff) nipkow@23433: nipkow@23433: lemma o_inv_o_cancel[simp]: "inj f ==> g o inv f o f = g" nipkow@23433: by (simp add: o_assoc[symmetric]) nipkow@23433: nipkow@23433: lemma inv_image_cancel[simp]: nipkow@23433: "inj f ==> inv f ` f ` S = S" nipkow@23433: by (simp add: image_compose[symmetric]) nipkow@23433: paulson@14760: lemma inj_imp_surj_inv: "inj f ==> surj (inv f)" paulson@14760: by (blast intro: surjI inv_f_f) paulson@14760: paulson@14760: lemma f_inv_f: "y \ range(f) ==> f(inv f y) = y" paulson@14760: apply (simp add: inv_def) paulson@14760: apply (fast intro: someI) paulson@14760: done paulson@14760: paulson@14760: lemma surj_f_inv_f: "surj f ==> f(inv f y) = y" paulson@14760: by (simp add: f_inv_f surj_range) paulson@14760: paulson@14760: lemma inv_injective: paulson@14760: assumes eq: "inv f x = inv f y" paulson@14760: and x: "x: range f" paulson@14760: and y: "y: range f" paulson@14760: shows "x=y" paulson@14760: proof - paulson@14760: have "f (inv f x) = f (inv f y)" using eq by simp paulson@14760: thus ?thesis by (simp add: f_inv_f x y) paulson@14760: qed paulson@14760: paulson@14760: lemma inj_on_inv: "A <= range(f) ==> inj_on (inv f) A" paulson@14760: by (fast intro: inj_onI elim: inv_injective injD) paulson@14760: paulson@14760: lemma surj_imp_inj_inv: "surj f ==> inj (inv f)" paulson@14760: by (simp add: inj_on_inv surj_range) paulson@14760: paulson@14760: lemma surj_iff: "(surj f) = (f o inv f = id)" paulson@14760: apply (simp add: o_def expand_fun_eq) paulson@14760: apply (blast intro: surjI surj_f_inv_f) paulson@14760: done paulson@14760: paulson@14760: lemma surj_imp_inv_eq: "[| surj f; \x. g(f x) = x |] ==> inv f = g" paulson@14760: apply (rule ext) paulson@14760: apply (drule_tac x = "inv f x" in spec) paulson@14760: apply (simp add: surj_f_inv_f) paulson@14760: done paulson@14760: paulson@14760: lemma bij_imp_bij_inv: "bij f ==> bij (inv f)" paulson@14760: by (simp add: bij_def inj_imp_surj_inv surj_imp_inj_inv) wenzelm@12372: paulson@14760: lemma inv_equality: "[| !!x. g (f x) = x; !!y. f (g y) = y |] ==> inv f = g" paulson@14760: apply (rule ext) paulson@14760: apply (auto simp add: inv_def) paulson@14760: done paulson@14760: paulson@14760: lemma inv_inv_eq: "bij f ==> inv (inv f) = f" paulson@14760: apply (rule inv_equality) paulson@14760: apply (auto simp add: bij_def surj_f_inv_f) paulson@14760: done paulson@14760: paulson@14760: (** bij(inv f) implies little about f. Consider f::bool=>bool such that paulson@14760: f(True)=f(False)=True. Then it's consistent with axiom someI that paulson@14760: inv f could be any function at all, including the identity function. paulson@14760: If inv f=id then inv f is a bijection, but inj f, surj(f) and paulson@14760: inv(inv f)=f all fail. paulson@14760: **) paulson@14760: paulson@14760: lemma o_inv_distrib: "[| bij f; bij g |] ==> inv (f o g) = inv g o inv f" paulson@14760: apply (rule inv_equality) paulson@14760: apply (auto simp add: bij_def surj_f_inv_f) paulson@14760: done paulson@14760: paulson@14760: paulson@14760: lemma image_surj_f_inv_f: "surj f ==> f ` (inv f ` A) = A" paulson@14760: by (simp add: image_eq_UN surj_f_inv_f) paulson@14760: paulson@14760: lemma image_inv_f_f: "inj f ==> (inv f) ` (f ` A) = A" paulson@14760: by (simp add: image_eq_UN) paulson@14760: paulson@14760: lemma inv_image_comp: "inj f ==> inv f ` (f`X) = X" paulson@14760: by (auto simp add: image_def) paulson@14760: paulson@14760: lemma bij_image_Collect_eq: "bij f ==> f ` Collect P = {y. P (inv f y)}" paulson@14760: apply auto paulson@14760: apply (force simp add: bij_is_inj) paulson@14760: apply (blast intro: bij_is_surj [THEN surj_f_inv_f, symmetric]) paulson@14760: done paulson@14760: paulson@14760: lemma bij_vimage_eq_inv_image: "bij f ==> f -` A = inv f ` A" paulson@14760: apply (auto simp add: bij_is_surj [THEN surj_f_inv_f]) paulson@14760: apply (blast intro: bij_is_inj [THEN inv_f_f, symmetric]) paulson@14760: done paulson@14760: paulson@14760: paulson@14760: subsection {*Inverse of a PI-function (restricted domain)*} paulson@14760: paulson@14760: lemma Inv_f_f: "[| inj_on f A; x \ A |] ==> Inv A f (f x) = x" paulson@14760: apply (simp add: Inv_def inj_on_def) paulson@14760: apply (blast intro: someI2) paulson@14760: done paulson@14760: paulson@14760: lemma f_Inv_f: "y \ f`A ==> f (Inv A f y) = y" paulson@14760: apply (simp add: Inv_def) paulson@13585: apply (fast intro: someI2) paulson@13585: done paulson@11451: paulson@14760: lemma Inv_injective: paulson@14760: assumes eq: "Inv A f x = Inv A f y" paulson@14760: and x: "x: f`A" paulson@14760: and y: "y: f`A" paulson@14760: shows "x=y" paulson@14760: proof - paulson@14760: have "f (Inv A f x) = f (Inv A f y)" using eq by simp paulson@14760: thus ?thesis by (simp add: f_Inv_f x y) paulson@14760: qed paulson@14760: paulson@14760: lemma inj_on_Inv: "B <= f`A ==> inj_on (Inv A f) B" paulson@14760: apply (rule inj_onI) paulson@14760: apply (blast intro: inj_onI dest: Inv_injective injD) paulson@14760: done paulson@14760: paulson@14760: lemma Inv_mem: "[| f ` A = B; x \ B |] ==> Inv A f x \ A" paulson@14760: apply (simp add: Inv_def) paulson@14760: apply (fast intro: someI2) paulson@14760: done paulson@14760: paulson@14760: lemma Inv_f_eq: "[| inj_on f A; f x = y; x \ A |] ==> Inv A f y = x" ballarin@14399: apply (erule subst) paulson@14760: apply (erule Inv_f_f, assumption) ballarin@14399: done ballarin@14399: ballarin@14399: lemma Inv_comp: paulson@14760: "[| inj_on f (g ` A); inj_on g A; x \ f ` g ` A |] ==> ballarin@14399: Inv A (f o g) x = (Inv A g o Inv (g ` A) f) x" ballarin@14399: apply simp ballarin@14399: apply (rule Inv_f_eq) ballarin@14399: apply (fast intro: comp_inj_on) ballarin@14399: apply (simp add: f_Inv_f Inv_mem) ballarin@14399: apply (simp add: Inv_mem) ballarin@14399: done ballarin@14399: paulson@14760: paulson@14760: subsection {*Other Consequences of Hilbert's Epsilon*} paulson@14760: paulson@14760: text {*Hilbert's Epsilon and the @{term split} Operator*} paulson@14760: paulson@14760: text{*Looping simprule*} paulson@14760: lemma split_paired_Eps: "(SOME x. P x) = (SOME (a,b). P(a,b))" paulson@14760: by (simp add: split_Pair_apply) paulson@14760: paulson@14760: lemma Eps_split: "Eps (split P) = (SOME xy. P (fst xy) (snd xy))" paulson@14760: by (simp add: split_def) paulson@14760: paulson@14760: lemma Eps_split_eq [simp]: "(@(x',y'). x = x' & y = y') = (x,y)" paulson@14760: by blast paulson@14760: paulson@14760: paulson@14760: text{*A relation is wellfounded iff it has no infinite descending chain*} paulson@14760: lemma wf_iff_no_infinite_down_chain: paulson@14760: "wf r = (~(\f. \i. (f(Suc i),f i) \ r))" paulson@14760: apply (simp only: wf_eq_minimal) paulson@14760: apply (rule iffI) paulson@14760: apply (rule notI) paulson@14760: apply (erule exE) paulson@14760: apply (erule_tac x = "{w. \i. w=f i}" in allE, blast) paulson@14760: apply (erule contrapos_np, simp, clarify) paulson@14760: apply (subgoal_tac "\n. nat_rec x (%i y. @z. z:Q & (z,y) :r) n \ Q") paulson@14760: apply (rule_tac x = "nat_rec x (%i y. @z. z:Q & (z,y) :r)" in exI) paulson@14760: apply (rule allI, simp) paulson@14760: apply (rule someI2_ex, blast, blast) paulson@14760: apply (rule allI) paulson@14760: apply (induct_tac "n", simp_all) paulson@14760: apply (rule someI2_ex, blast+) paulson@14760: done paulson@14760: paulson@14760: text{*A dynamically-scoped fact for TFL *} wenzelm@12298: lemma tfl_some: "\P x. P x --> P (Eps P)" wenzelm@12298: by (blast intro: someI) paulson@11451: wenzelm@12298: wenzelm@12298: subsection {* Least value operator *} paulson@11451: paulson@11451: constdefs wenzelm@12298: LeastM :: "['a => 'b::ord, 'a => bool] => 'a" paulson@14760: "LeastM m P == SOME x. P x & (\y. P y --> m x <= m y)" paulson@11451: paulson@11451: syntax wenzelm@12298: "_LeastM" :: "[pttrn, 'a => 'b::ord, bool] => 'a" ("LEAST _ WRT _. _" [0, 4, 10] 10) paulson@11451: translations wenzelm@12298: "LEAST x WRT m. P" == "LeastM m (%x. P)" paulson@11451: paulson@11451: lemma LeastMI2: wenzelm@12298: "P x ==> (!!y. P y ==> m x <= m y) wenzelm@12298: ==> (!!x. P x ==> \y. P y --> m x \ m y ==> Q x) wenzelm@12298: ==> Q (LeastM m P)" paulson@14760: apply (simp add: LeastM_def) paulson@14208: apply (rule someI2_ex, blast, blast) wenzelm@12298: done paulson@11451: paulson@11451: lemma LeastM_equality: wenzelm@12298: "P k ==> (!!x. P x ==> m k <= m x) wenzelm@12298: ==> m (LEAST x WRT m. P x) = (m k::'a::order)" paulson@14208: apply (rule LeastMI2, assumption, blast) wenzelm@12298: apply (blast intro!: order_antisym) wenzelm@12298: done paulson@11451: paulson@11454: lemma wf_linord_ex_has_least: paulson@14760: "wf r ==> \x y. ((x,y):r^+) = ((y,x)~:r^*) ==> P k paulson@14760: ==> \x. P x & (!y. P y --> (m x,m y):r^*)" wenzelm@12298: apply (drule wf_trancl [THEN wf_eq_minimal [THEN iffD1]]) paulson@14208: apply (drule_tac x = "m`Collect P" in spec, force) wenzelm@12298: done paulson@11454: paulson@11454: lemma ex_has_least_nat: paulson@14760: "P k ==> \x. P x & (\y. P y --> m x <= (m y::nat))" wenzelm@12298: apply (simp only: pred_nat_trancl_eq_le [symmetric]) wenzelm@12298: apply (rule wf_pred_nat [THEN wf_linord_ex_has_least]) paulson@16796: apply (simp add: less_eq linorder_not_le pred_nat_trancl_eq_le, assumption) wenzelm@12298: done paulson@11454: wenzelm@12298: lemma LeastM_nat_lemma: paulson@14760: "P k ==> P (LeastM m P) & (\y. P y --> m (LeastM m P) <= (m y::nat))" paulson@14760: apply (simp add: LeastM_def) wenzelm@12298: apply (rule someI_ex) wenzelm@12298: apply (erule ex_has_least_nat) wenzelm@12298: done paulson@11454: paulson@11454: lemmas LeastM_natI = LeastM_nat_lemma [THEN conjunct1, standard] paulson@11454: paulson@11454: lemma LeastM_nat_le: "P x ==> m (LeastM m P) <= (m x::nat)" paulson@14208: by (rule LeastM_nat_lemma [THEN conjunct2, THEN spec, THEN mp], assumption, assumption) paulson@11454: paulson@11451: wenzelm@12298: subsection {* Greatest value operator *} paulson@11451: paulson@11451: constdefs wenzelm@12298: GreatestM :: "['a => 'b::ord, 'a => bool] => 'a" paulson@14760: "GreatestM m P == SOME x. P x & (\y. P y --> m y <= m x)" wenzelm@12298: wenzelm@12298: Greatest :: "('a::ord => bool) => 'a" (binder "GREATEST " 10) wenzelm@12298: "Greatest == GreatestM (%x. x)" paulson@11451: paulson@11451: syntax wenzelm@12298: "_GreatestM" :: "[pttrn, 'a=>'b::ord, bool] => 'a" wenzelm@12298: ("GREATEST _ WRT _. _" [0, 4, 10] 10) paulson@11451: paulson@11451: translations wenzelm@12298: "GREATEST x WRT m. P" == "GreatestM m (%x. P)" paulson@11451: paulson@11451: lemma GreatestMI2: wenzelm@12298: "P x ==> (!!y. P y ==> m y <= m x) wenzelm@12298: ==> (!!x. P x ==> \y. P y --> m y \ m x ==> Q x) wenzelm@12298: ==> Q (GreatestM m P)" paulson@14760: apply (simp add: GreatestM_def) paulson@14208: apply (rule someI2_ex, blast, blast) wenzelm@12298: done paulson@11451: paulson@11451: lemma GreatestM_equality: wenzelm@12298: "P k ==> (!!x. P x ==> m x <= m k) wenzelm@12298: ==> m (GREATEST x WRT m. P x) = (m k::'a::order)" paulson@14208: apply (rule_tac m = m in GreatestMI2, assumption, blast) wenzelm@12298: apply (blast intro!: order_antisym) wenzelm@12298: done paulson@11451: paulson@11451: lemma Greatest_equality: wenzelm@12298: "P (k::'a::order) ==> (!!x. P x ==> x <= k) ==> (GREATEST x. P x) = k" paulson@14760: apply (simp add: Greatest_def) paulson@14208: apply (erule GreatestM_equality, blast) wenzelm@12298: done paulson@11451: paulson@11451: lemma ex_has_greatest_nat_lemma: paulson@14760: "P k ==> \x. P x --> (\y. P y & ~ ((m y::nat) <= m x)) paulson@14760: ==> \y. P y & ~ (m y < m k + n)" paulson@15251: apply (induct n, force) wenzelm@12298: apply (force simp add: le_Suc_eq) wenzelm@12298: done paulson@11451: wenzelm@12298: lemma ex_has_greatest_nat: paulson@14760: "P k ==> \y. P y --> m y < b paulson@14760: ==> \x. P x & (\y. P y --> (m y::nat) <= m x)" wenzelm@12298: apply (rule ccontr) wenzelm@12298: apply (cut_tac P = P and n = "b - m k" in ex_has_greatest_nat_lemma) paulson@14208: apply (subgoal_tac [3] "m k <= b", auto) wenzelm@12298: done paulson@11451: wenzelm@12298: lemma GreatestM_nat_lemma: paulson@14760: "P k ==> \y. P y --> m y < b paulson@14760: ==> P (GreatestM m P) & (\y. P y --> (m y::nat) <= m (GreatestM m P))" paulson@14760: apply (simp add: GreatestM_def) wenzelm@12298: apply (rule someI_ex) paulson@14208: apply (erule ex_has_greatest_nat, assumption) wenzelm@12298: done paulson@11451: paulson@11451: lemmas GreatestM_natI = GreatestM_nat_lemma [THEN conjunct1, standard] paulson@11451: wenzelm@12298: lemma GreatestM_nat_le: paulson@14760: "P x ==> \y. P y --> m y < b wenzelm@12298: ==> (m x::nat) <= m (GreatestM m P)" berghofe@21020: apply (blast dest: GreatestM_nat_lemma [THEN conjunct2, THEN spec, of P]) wenzelm@12298: done wenzelm@12298: wenzelm@12298: wenzelm@12298: text {* \medskip Specialization to @{text GREATEST}. *} wenzelm@12298: paulson@14760: lemma GreatestI: "P (k::nat) ==> \y. P y --> y < b ==> P (GREATEST x. P x)" paulson@14760: apply (simp add: Greatest_def) paulson@14208: apply (rule GreatestM_natI, auto) wenzelm@12298: done paulson@11451: wenzelm@12298: lemma Greatest_le: paulson@14760: "P x ==> \y. P y --> y < b ==> (x::nat) <= (GREATEST x. P x)" paulson@14760: apply (simp add: Greatest_def) paulson@14208: apply (rule GreatestM_nat_le, auto) wenzelm@12298: done wenzelm@12298: wenzelm@12298: wenzelm@12298: subsection {* The Meson proof procedure *} paulson@11451: wenzelm@12298: subsubsection {* Negation Normal Form *} wenzelm@12298: wenzelm@12298: text {* de Morgan laws *} wenzelm@12298: wenzelm@12298: lemma meson_not_conjD: "~(P&Q) ==> ~P | ~Q" wenzelm@12298: and meson_not_disjD: "~(P|Q) ==> ~P & ~Q" wenzelm@12298: and meson_not_notD: "~~P ==> P" paulson@14760: and meson_not_allD: "!!P. ~(\x. P(x)) ==> \x. ~P(x)" paulson@14760: and meson_not_exD: "!!P. ~(\x. P(x)) ==> \x. ~P(x)" wenzelm@12298: by fast+ paulson@11451: wenzelm@12298: text {* Removal of @{text "-->"} and @{text "<->"} (positive and wenzelm@12298: negative occurrences) *} wenzelm@12298: wenzelm@12298: lemma meson_imp_to_disjD: "P-->Q ==> ~P | Q" wenzelm@12298: and meson_not_impD: "~(P-->Q) ==> P & ~Q" wenzelm@12298: and meson_iff_to_disjD: "P=Q ==> (~P | Q) & (~Q | P)" wenzelm@12298: and meson_not_iffD: "~(P=Q) ==> (P | Q) & (~P | ~Q)" wenzelm@12298: -- {* Much more efficient than @{prop "(P & ~Q) | (Q & ~P)"} for computing CNF *} paulson@18389: and meson_not_refl_disj_D: "x ~= x | P ==> P" wenzelm@12298: by fast+ wenzelm@12298: wenzelm@12298: wenzelm@12298: subsubsection {* Pulling out the existential quantifiers *} wenzelm@12298: wenzelm@12298: text {* Conjunction *} wenzelm@12298: paulson@14760: lemma meson_conj_exD1: "!!P Q. (\x. P(x)) & Q ==> \x. P(x) & Q" paulson@14760: and meson_conj_exD2: "!!P Q. P & (\x. Q(x)) ==> \x. P & Q(x)" wenzelm@12298: by fast+ wenzelm@12298: paulson@11451: wenzelm@12298: text {* Disjunction *} wenzelm@12298: paulson@14760: lemma meson_disj_exD: "!!P Q. (\x. P(x)) | (\x. Q(x)) ==> \x. P(x) | Q(x)" wenzelm@12298: -- {* DO NOT USE with forall-Skolemization: makes fewer schematic variables!! *} wenzelm@12298: -- {* With ex-Skolemization, makes fewer Skolem constants *} paulson@14760: and meson_disj_exD1: "!!P Q. (\x. P(x)) | Q ==> \x. P(x) | Q" paulson@14760: and meson_disj_exD2: "!!P Q. P | (\x. Q(x)) ==> \x. P | Q(x)" wenzelm@12298: by fast+ wenzelm@12298: paulson@11451: wenzelm@12298: subsubsection {* Generating clauses for the Meson Proof Procedure *} wenzelm@12298: wenzelm@12298: text {* Disjunctions *} wenzelm@12298: wenzelm@12298: lemma meson_disj_assoc: "(P|Q)|R ==> P|(Q|R)" wenzelm@12298: and meson_disj_comm: "P|Q ==> Q|P" wenzelm@12298: and meson_disj_FalseD1: "False|P ==> P" wenzelm@12298: and meson_disj_FalseD2: "P|False ==> P" wenzelm@12298: by fast+ paulson@11451: paulson@14760: paulson@14760: subsection{*Lemmas for Meson, the Model Elimination Procedure*} paulson@14760: paulson@14760: text{* Generation of contrapositives *} paulson@14760: paulson@14760: text{*Inserts negated disjunct after removing the negation; P is a literal. paulson@14760: Model elimination requires assuming the negation of every attempted subgoal, paulson@14760: hence the negated disjuncts.*} paulson@14760: lemma make_neg_rule: "~P|Q ==> ((~P==>P) ==> Q)" paulson@14760: by blast paulson@14760: paulson@14760: text{*Version for Plaisted's "Postive refinement" of the Meson procedure*} paulson@14760: lemma make_refined_neg_rule: "~P|Q ==> (P ==> Q)" paulson@14760: by blast paulson@14760: paulson@14760: text{*@{term P} should be a literal*} paulson@14760: lemma make_pos_rule: "P|Q ==> ((P==>~P) ==> Q)" paulson@14760: by blast paulson@14760: paulson@14760: text{*Versions of @{text make_neg_rule} and @{text make_pos_rule} that don't paulson@14760: insert new assumptions, for ordinary resolution.*} paulson@14760: paulson@14760: lemmas make_neg_rule' = make_refined_neg_rule paulson@14760: paulson@14760: lemma make_pos_rule': "[|P|Q; ~P|] ==> Q" paulson@14760: by blast paulson@14760: paulson@14760: text{* Generation of a goal clause -- put away the final literal *} paulson@14760: paulson@14760: lemma make_neg_goal: "~P ==> ((~P==>P) ==> False)" paulson@14760: by blast paulson@14760: paulson@14760: lemma make_pos_goal: "P ==> ((P==>~P) ==> False)" paulson@14760: by blast paulson@14760: paulson@14760: paulson@14760: subsubsection{* Lemmas for Forward Proof*} paulson@14760: paulson@14760: text{*There is a similarity to congruence rules*} paulson@14760: paulson@14760: (*NOTE: could handle conjunctions (faster?) by paulson@14760: nf(th RS conjunct2) RS (nf(th RS conjunct1) RS conjI) *) paulson@14760: lemma conj_forward: "[| P'&Q'; P' ==> P; Q' ==> Q |] ==> P&Q" paulson@14760: by blast paulson@14760: paulson@14760: lemma disj_forward: "[| P'|Q'; P' ==> P; Q' ==> Q |] ==> P|Q" paulson@14760: by blast paulson@14760: paulson@14760: (*Version of @{text disj_forward} for removal of duplicate literals*) paulson@14760: lemma disj_forward2: paulson@14760: "[| P'|Q'; P' ==> P; [| Q'; P==>False |] ==> Q |] ==> P|Q" paulson@14760: apply blast paulson@14760: done paulson@14760: paulson@14760: lemma all_forward: "[| \x. P'(x); !!x. P'(x) ==> P(x) |] ==> \x. P(x)" paulson@14760: by blast paulson@14760: paulson@14760: lemma ex_forward: "[| \x. P'(x); !!x. P'(x) ==> P(x) |] ==> \x. P(x)" paulson@14760: by blast paulson@14760: paulson@17420: paulson@17420: text{*Many of these bindings are used by the ATP linkup, and not just by paulson@17420: legacy proof scripts.*} paulson@14760: ML paulson@14760: {* paulson@14760: val inv_def = thm "inv_def"; paulson@14760: val Inv_def = thm "Inv_def"; paulson@14760: paulson@14760: val someI = thm "someI"; paulson@14760: val someI_ex = thm "someI_ex"; paulson@14760: val someI2 = thm "someI2"; paulson@14760: val someI2_ex = thm "someI2_ex"; paulson@14760: val some_equality = thm "some_equality"; paulson@14760: val some1_equality = thm "some1_equality"; paulson@14760: val some_eq_ex = thm "some_eq_ex"; paulson@14760: val some_eq_trivial = thm "some_eq_trivial"; paulson@14760: val some_sym_eq_trivial = thm "some_sym_eq_trivial"; paulson@14760: val choice = thm "choice"; paulson@14760: val bchoice = thm "bchoice"; paulson@14760: val inv_id = thm "inv_id"; paulson@14760: val inv_f_f = thm "inv_f_f"; paulson@14760: val inv_f_eq = thm "inv_f_eq"; paulson@14760: val inj_imp_inv_eq = thm "inj_imp_inv_eq"; paulson@14760: val inj_transfer = thm "inj_transfer"; paulson@14760: val inj_iff = thm "inj_iff"; paulson@14760: val inj_imp_surj_inv = thm "inj_imp_surj_inv"; paulson@14760: val f_inv_f = thm "f_inv_f"; paulson@14760: val surj_f_inv_f = thm "surj_f_inv_f"; paulson@14760: val inv_injective = thm "inv_injective"; paulson@14760: val inj_on_inv = thm "inj_on_inv"; paulson@14760: val surj_imp_inj_inv = thm "surj_imp_inj_inv"; paulson@14760: val surj_iff = thm "surj_iff"; paulson@14760: val surj_imp_inv_eq = thm "surj_imp_inv_eq"; paulson@14760: val bij_imp_bij_inv = thm "bij_imp_bij_inv"; paulson@14760: val inv_equality = thm "inv_equality"; paulson@14760: val inv_inv_eq = thm "inv_inv_eq"; paulson@14760: val o_inv_distrib = thm "o_inv_distrib"; paulson@14760: val image_surj_f_inv_f = thm "image_surj_f_inv_f"; paulson@14760: val image_inv_f_f = thm "image_inv_f_f"; paulson@14760: val inv_image_comp = thm "inv_image_comp"; paulson@14760: val bij_image_Collect_eq = thm "bij_image_Collect_eq"; paulson@14760: val bij_vimage_eq_inv_image = thm "bij_vimage_eq_inv_image"; paulson@14760: val Inv_f_f = thm "Inv_f_f"; paulson@14760: val f_Inv_f = thm "f_Inv_f"; paulson@14760: val Inv_injective = thm "Inv_injective"; paulson@14760: val inj_on_Inv = thm "inj_on_Inv"; paulson@14760: val split_paired_Eps = thm "split_paired_Eps"; paulson@14760: val Eps_split = thm "Eps_split"; paulson@14760: val Eps_split_eq = thm "Eps_split_eq"; paulson@14760: val wf_iff_no_infinite_down_chain = thm "wf_iff_no_infinite_down_chain"; paulson@14760: val Inv_mem = thm "Inv_mem"; paulson@14760: val Inv_f_eq = thm "Inv_f_eq"; paulson@14760: val Inv_comp = thm "Inv_comp"; paulson@14760: val tfl_some = thm "tfl_some"; paulson@14760: val make_neg_rule = thm "make_neg_rule"; paulson@14760: val make_refined_neg_rule = thm "make_refined_neg_rule"; paulson@14760: val make_pos_rule = thm "make_pos_rule"; paulson@14760: val make_neg_rule' = thm "make_neg_rule'"; paulson@14760: val make_pos_rule' = thm "make_pos_rule'"; paulson@14760: val make_neg_goal = thm "make_neg_goal"; paulson@14760: val make_pos_goal = thm "make_pos_goal"; paulson@14760: val conj_forward = thm "conj_forward"; paulson@14760: val disj_forward = thm "disj_forward"; paulson@14760: val disj_forward2 = thm "disj_forward2"; paulson@14760: val all_forward = thm "all_forward"; paulson@14760: val ex_forward = thm "ex_forward"; paulson@14760: *} paulson@14760: paulson@14760: paulson@21999: subsection {* Meson package *} wenzelm@17893: paulson@11451: use "Tools/meson.ML" paulson@11451: wenzelm@17893: wenzelm@17893: subsection {* Specification package -- Hilbertized version *} wenzelm@17893: wenzelm@17893: lemma exE_some: "[| Ex P ; c == Eps P |] ==> P c" wenzelm@17893: by (simp only: someI_ex) wenzelm@17893: skalberg@14115: use "Tools/specification_package.ML" skalberg@14115: paulson@11451: end