(* Title: FOL/ex/Locale_Test/Locale_Test1.thy Author: Clemens Ballarin, TU Muenchen
Test environment for the locale implementation.
*)
theory Locale_Test1 imports FOL begin
typedecl int instance int :: \<open>term\<close> ..
consts plus :: \<open>int => int => int\<close> (infixl \<open>+\<close> 60)
zero :: \<open>int\<close> (\<open>0\<close>)
minus :: \<open>int => int\<close> (\<open>- _\<close>)
axiomatizationwhere
int_assoc: \<open>(x + y::int) + z = x + (y + z)\<close> and
int_zero: \<open>0 + x = x\<close> and
int_minus: \<open>(-x) + x = 0\<close> and
int_minus2: \<open>-(-x) = x\<close>
section \<open>Inference of parameter types\<close>
locale param1 = fixes p print_locale! param1
locale param2 = fixes p :: \<open>'b\<close> print_locale! param2
(* locale param_top = param2 r for r :: "'b :: {}" Fails, cannot generalise parameter.
*)
locale param3 = fixes p (infix\<open>..\<close> 50) print_locale! param3
locale param4 = fixes p :: \<open>'a => 'a => 'a\<close> (infix \<open>..\<close> 50) print_locale! param4
subsection \<open>Incremental type constraints\<close>
locale constraint1 = fixes prod (infixl\<open>**\<close> 65) assumes l_id: \<open>x ** y = x\<close> assumes assoc: \<open>(x ** y) ** z = x ** (y ** z)\<close> print_locale! constraint1
locale constraint2 = fixes p and q assumes\<open>p = q\<close> print_locale! constraint2
locale lgrp = semi + fixes one and inv assumes lone: \<open>one ** x = x\<close> and linv: \<open>inv(x) ** x = one\<close> print_locale! lgrp thm lgrp_def lgrp_axioms_def
locale add_lgrp = semi \<open>(++)\<close> for sum (infixl \<open>++\<close> 60) + fixes zero and neg assumes lzero: \<open>zero ++ x = x\<close> and lneg: \<open>neg(x) ++ x = zero\<close> print_locale! add_lgrp thm add_lgrp_def add_lgrp_axioms_def
locale rev_lgrp = semi \<open>%x y. y ++ x\<close> for sum (infixl \<open>++\<close> 60) print_locale! rev_lgrp thm rev_lgrp_def
locale hom = f: semi \<open>f\<close> + g: semi \<open>g\<close> for f and g print_locale! hom thm hom_def
locale perturbation = semi + d: semi \<open>%x y. delta(x) ** delta(y)\<close> for delta print_locale! perturbation thm perturbation_def
locale pert_hom = d1: perturbation \<open>f\<close> \<open>d1\<close> + d2: perturbation \<open>f\<close> \<open>d2\<close> for f d1 d2 print_locale! pert_hom thm pert_hom_def
section \<open>Foundational versions of theorems\<close>
thm logic.assoc thm logic.lor_def
section \<open>Defines\<close>
locale logic_def = fixes land (infixl\<open>&&\<close> 55) and lor (infixl\<open>||\<close> 50) and lnot (\<open>-- _\<close> [60] 60) assumes assoc: \<open>(x && y) && z = x && (y && z)\<close> and notnot: \<open>-- (-- x) = x\<close> defines\<open>x || y == --(-- x && -- y)\<close> begin
thm lor_def
lemma\<open>x || y = --(-- x && --y)\<close> by (unfold lor_def) (rule refl)
end
(* Inheritance of defines *)
locale logic_def2 = logic_def begin
lemma\<open>x || y = --(-- x && --y)\<close> by (unfold lor_def) (rule refl)
end
section \<open>Notes\<close>
(* A somewhat arcane homomorphism example *)
definition semi_hom where \<open>semi_hom(prod, sum, h) \<longleftrightarrow> (\<forall>x y. h(prod(x, y)) = sum(h(x), h(y)))\<close>
locale semi_hom_loc = prod: semi \<open>prod\<close> + sum: semi \<open>sum\<close> for prod and sum and h + assumes semi_homh: \<open>semi_hom(prod, sum, h)\<close> notes semi_hom_mult = semi_hom_mult [OF semi_homh]
thm semi_hom_loc.semi_hom_mult (* unspecified, attribute not applied in background theory !!! *)
lemma (in semi_hom_loc) \<open>h(prod(x, y)) = sum(h(x), h(y))\<close> by (rule semi_hom_mult)
(* Referring to facts from within a context specification *)
lemma assumes x: \<open>P \<longleftrightarrow> P\<close> notes y = x shows\<open>True\<close> ..
section \<open>Theorem statements\<close>
lemma (in lgrp) lcancel: \<open>x ** y = x ** z \<longleftrightarrow> y = z\<close> proof assume\<open>x ** y = x ** z\<close> thenhave\<open>inv(x) ** x ** y = inv(x) ** x ** z\<close> by (simp add: assoc) thenshow\<open>y = z\<close> by (simp add: lone linv) qed simp print_locale! lgrp
locale rgrp = semi + fixes one and inv assumes rone: \<open>x ** one = x\<close> and rinv: \<open>x ** inv(x) = one\<close> begin
lemma rcancel: \<open>y ** x = z ** x \<longleftrightarrow> y = z\<close> proof assume\<open>y ** x = z ** x\<close> thenhave\<open>y ** (x ** inv(x)) = z ** (x ** inv(x))\<close> by (simp add: assoc [symmetric]) thenshow\<open>y = z\<close> by (simp add: rone rinv) qed simp
end print_locale! rgrp
subsection \<open>Patterns\<close>
lemma (in rgrp) assumes\<open>y ** x = z ** x\<close> (is \<open>?a\<close>) shows\<open>y = z\<close> (is \<open>?t\<close>) proof - txt\<open>Weird proof involving patterns from context element and conclusion.\<close>
{ assume\<open>?a\<close> thenhave\<open>y ** (x ** inv(x)) = z ** (x ** inv(x))\<close> by (simp add: assoc [symmetric]) thenhave\<open>?t\<close> by (simp add: rone rinv)
} note x = this show\<open>?t\<close> by (rule x [OF \<open>?a\<close>]) qed
section \<open>Interpretation between locales: sublocales\<close>
sublocale lgrp < right?: rgrp print_facts proof unfold_locales
{ fix x have\<open>inv(x) ** x ** one = inv(x) ** x\<close> by (simp add: linv lone) thenshow\<open>x ** one = x\<close> by (simp add: assoc lcancel)
} note rone = this
{ fix x have\<open>inv(x) ** x ** inv(x) = inv(x) ** one\<close> by (simp add: linv lone rone) thenshow\<open>x ** inv(x) = one\<close> by (simp add: assoc lcancel)
} qed
(* effect on printed locale *)
print_locale! lgrp
(* use of derived theorem *)
lemma (in lgrp) \<open>y ** x = z ** x \<longleftrightarrow> y = z\<close> apply (rule rcancel) done
(* circular interpretation *)
sublocale rgrp < left: lgrp proof unfold_locales
{ fix x have\<open>one ** (x ** inv(x)) = x ** inv(x)\<close> by (simp add: rinv rone) thenshow\<open>one ** x = x\<close> by (simp add: assoc [symmetric] rcancel)
} note lone = this
{ fix x have\<open>inv(x) ** (x ** inv(x)) = one ** inv(x)\<close> by (simp add: rinv lone rone) thenshow\<open>inv(x) ** x = one\<close> by (simp add: assoc [symmetric] rcancel)
} qed
(* effect on printed locale *)
print_locale! rgrp print_locale! lgrp
(* Duality *)
locale order = fixes less :: \<open>'a => 'a => o\<close> (infix \<open><<\<close> 50) assumes refl: \<open>x << x\<close> and trans: \<open>[| x << y; y << z |] ==> x << z\<close>
sublocale order < dual: order \<open>%x y. y << x\<close> apply unfold_locales apply (rule refl) apply (blast intro: trans) done
print_locale! order (* Only two instances of order. *)
locale order' = fixes less :: \<open>'a => 'a => o\<close> (infix \<open><<\<close> 50) assumes refl: \<open>x << x\<close> and trans: \<open>[| x << y; y << z |] ==> x << z\<close>
locale order_with_def = order' begin
definition greater :: \<open>'a => 'a => o\<close> (infix \<open>>>\<close> 50) where \<open>x >> y \<longleftrightarrow> y << x\<close>
print_locale! order_with_def (* Note that decls come after theorems that make use of them. *)
(* locale with many parameters ---
interpretations generate alternating group A5 *)
locale A5 = fixes A and B and C and D and E assumes eq: \<open>A \<longleftrightarrow> B \<longleftrightarrow> C \<longleftrightarrow> D \<longleftrightarrow> E\<close>
subsection \<open>Rewrite morphisms in expressions\<close>
interpretation y: logic_o \<open>(\<or>)\<close> \<open>Not\<close> rewrites bool_logic_o2: \<open>logic_o.lor_o((\<or>), Not, x, y) \<longleftrightarrow> x \<and> y\<close> proof - show bool_logic_o: \<open>PROP logic_o((\<or>), Not)\<close> by unfold_locales fast+ show\<open>logic_o.lor_o((\<or>), Not, x, y) \<longleftrightarrow> x \<and> y\<close> unfolding logic_o.lor_o_def [OF bool_logic_o] by fast qed
subsection \<open>Inheritance of rewrite morphisms\<close>
locale reflexive = fixes le :: \<open>'a => 'a => o\<close> (infix \<open>\<sqsubseteq>\<close> 50) assumes refl: \<open>x \<sqsubseteq> x\<close> begin
definition less (infix\<open>\<sqsubset>\<close> 50) where \<open>x \<sqsubset> y \<longleftrightarrow> x \<sqsubseteq> y \<and> x \<noteq> y\<close>
end
axiomatization
gle :: \<open>'a => 'a => o\<close> and gless :: \<open>'a => 'a => o\<close> and
gle' :: \'a => 'a => o\ and gless' :: \'a => 'a => o\ where
grefl: \<open>gle(x, x)\<close> and gless_def: \<open>gless(x, y) \<longleftrightarrow> gle(x, y) \<and> x \<noteq> y\<close> and
grefl': \gle'(x, x)\ and gless'_def: \gless'(x, y) \ gle'(x, y) \ x \ y\
text\<open>Setup\<close>
locale mixin = reflexive begin lemmas less_thm = less_def end
interpretation le7: mixin7_inherited \<open>gle\<close> by unfold_locales
lemmas (in mixin7_inherited) less_thm7 = less_def
thm le7.less_thm7 (* before, rewrite morphism not applied *) lemma\<open>reflexive.less(gle, x, y) \<longleftrightarrow> gle(x, y) \<and> x \<noteq> y\<close> by (rule le7.less_thm7)
sublocale mixin7_inherited < mixin7_base by unfold_locales
lemmas (in mixin7_inherited) less_thm7b = less_def
thm le7.less_thm7b (* after, mixin applied *) lemma\<open>gless(x, y) \<longleftrightarrow> gle(x, y) \<and> x \<noteq> y\<close> by (rule le7.less_thm7b)
text\<open>This locale will be interpreted in later theories.\<close>
locale mixin_thy_merge = le: reflexive \<open>le\<close> + le': reflexive \<open>le'\<close> for le le'
subsection \<open>Rewrite morphisms in sublocale\<close>
text\<open>Simulate a specification of left groups where unit and inverse are defined
rather than specified. This is possible, but not in FOL, due to the lack of a
selection operator.\<close>
axiomatization glob_one and glob_inv where glob_lone: \<open>prod(glob_one(prod), x) = x\<close> and glob_linv: \<open>prod(glob_inv(prod, x), x) = glob_one(prod)\<close>
locale dgrp = semi begin
definition one where\<open>one = glob_one(prod)\<close>
lemma lone: \<open>one ** x = x\<close> unfolding one_def by (rule glob_lone)
section \<open>Interpretation in named contexts\<close>
locale container begin interpretation"private": roundup \<open>True\<close> by unfold_locales rule lemmas true_copy = private.true end
context container begin
ML \<open>(Context.>> (fn generic => let val context = Context.proof_of generic
val _ = Proof_Context.get_thms context"private.true"in generic end);
raise Fail "thm private.true was persisted")
handle ERROR _ => ([]:thm list);\<close> thm true_copy end
section \<open>Interpretation in proofs\<close>
notepad begin interpret"local": lgrp \<open>(+)\<close> \<open>0\<close> \<open>minus\<close> by unfold_locales (* subsumed *)
{ fix zero :: \<open>int\<close> assume\<open>!!x. zero + x = x\<close> \<open>!!x. (-x) + x = zero\<close> theninterpret local_fixed: lgrp \<open>(+)\<close> \<open>zero\<close> \<open>minus\<close> by unfold_locales thm local_fixed.lone
} assume\<open>!!x zero. zero + x = x\<close> \<open>!!x zero. (-x) + x = zero\<close> theninterpret local_free: lgrp \<open>(+)\<close> \<open>zero\<close> \<open>minus\<close> for zero by unfold_locales thm local_free.lone [where ?zero = \<open>0\<close>] end
notepad begin
{ fix pand and pnot and por assume passoc: \<open>\<And>x y z. pand(pand(x, y), z) \<longleftrightarrow> pand(x, pand(y, z))\<close> and pnotnot: \<open>\<And>x. pnot(pnot(x)) \<longleftrightarrow> x\<close> and por_def: \<open>\<And>x y. por(x, y) \<longleftrightarrow> pnot(pand(pnot(x), pnot(y)))\<close> interpret loc: logic_o \<open>pand\<close> \<open>pnot\<close>
rewrites por_eq: \<open>\<And>x y. logic_o.lor_o(pand, pnot, x, y) \<longleftrightarrow> por(x, y)\<close> (* FIXME *) proof - show logic_o: \<open>PROP logic_o(pand, pnot)\<close> using passoc pnotnot by unfold_locales fix x y show\<open>logic_o.lor_o(pand, pnot, x, y) \<longleftrightarrow> por(x, y)\<close> by (unfold logic_o.lor_o_def [OF logic_o]) (rule por_def [symmetric]) qed print_interps logic_o have\<open>\<And>x y. por(x, y) \<longleftrightarrow> pnot(pand(pnot(x), pnot(y)))\<close> by (rule loc.lor_o_def)
} end
end
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.18Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.