src/FOL/ex/Locale_Test/Locale_Test1.thy
changeset 53366 c8c548d83862
parent 51515 c3eb0b517ced
child 53367 1f383542226b
equal deleted inserted replaced
53365:643e1151ed7e 53366:c8c548d83862
   482 
   482 
   483 sublocale logic_a < logic_b
   483 sublocale logic_a < logic_b
   484   by unfold_locales
   484   by unfold_locales
   485 
   485 
   486 
   486 
   487 subsection {* Equations *}
   487 subsection {* Interpretation *}
       
   488 
       
   489 subsection {* Rewrite morphism *}
   488 
   490 
   489 locale logic_o =
   491 locale logic_o =
   490   fixes land (infixl "&&" 55)
   492   fixes land (infixl "&&" 55)
   491     and lnot ("-- _" [60] 60)
   493     and lnot ("-- _" [60] 60)
   492   assumes assoc_o: "(x && y) && z <-> x && (y && z)"
   494   assumes assoc_o: "(x && y) && z <-> x && (y && z)"
   514 
   516 
   515 thm lor_triv [where z = True] (* Check strict prefix. *)
   517 thm lor_triv [where z = True] (* Check strict prefix. *)
   516   x.lor_triv
   518   x.lor_triv
   517 
   519 
   518 
   520 
   519 subsection {* Inheritance of mixins *}
   521 subsection {* Inheritance of rewrite morphisms *}
   520 
   522 
   521 locale reflexive =
   523 locale reflexive =
   522   fixes le :: "'a => 'a => o" (infix "\<sqsubseteq>" 50)
   524   fixes le :: "'a => 'a => o" (infix "\<sqsubseteq>" 50)
   523   assumes refl: "x \<sqsubseteq> x"
   525   assumes refl: "x \<sqsubseteq> x"
   524 begin
   526 begin
   547   note reflexive = this[unfolded mixin_def]
   549   note reflexive = this[unfolded mixin_def]
   548   show "reflexive.less(gle, x, y) <-> gless(x, y)"
   550   show "reflexive.less(gle, x, y) <-> gless(x, y)"
   549     by (simp add: reflexive.less_def[OF reflexive] gless_def)
   551     by (simp add: reflexive.less_def[OF reflexive] gless_def)
   550 qed
   552 qed
   551 
   553 
   552 text {* Mixin propagated along the locale hierarchy *}
   554 text {* Rewrite morphism propagated along the locale hierarchy *}
   553 
   555 
   554 locale mixin2 = mixin
   556 locale mixin2 = mixin
   555 begin
   557 begin
   556 lemmas less_thm2 = less_def
   558 lemmas less_thm2 = less_def
   557 end
   559 end
   558 
   560 
   559 interpretation le: mixin2 gle
   561 interpretation le: mixin2 gle
   560   by unfold_locales
   562   by unfold_locales
   561 
   563 
   562 thm le.less_thm2  (* mixin applied *)
   564 thm le.less_thm2  (* rewrite morphism applied *)
   563 lemma "gless(x, y) <-> gle(x, y) & x ~= y"
   565 lemma "gless(x, y) <-> gle(x, y) & x ~= y"
   564   by (rule le.less_thm2)
   566   by (rule le.less_thm2)
   565 
   567 
   566 text {* Mixin does not leak to a side branch. *}
   568 text {* Rewrite morphism does not leak to a side branch. *}
   567 
   569 
   568 locale mixin3 = reflexive
   570 locale mixin3 = reflexive
   569 begin
   571 begin
   570 lemmas less_thm3 = less_def
   572 lemmas less_thm3 = less_def
   571 end
   573 end
   572 
   574 
   573 interpretation le: mixin3 gle
   575 interpretation le: mixin3 gle
   574   by unfold_locales
   576   by unfold_locales
   575 
   577 
   576 thm le.less_thm3  (* mixin not applied *)
   578 thm le.less_thm3  (* rewrite morphism not applied *)
   577 lemma "reflexive.less(gle, x, y) <-> gle(x, y) & x ~= y" by (rule le.less_thm3)
   579 lemma "reflexive.less(gle, x, y) <-> gle(x, y) & x ~= y" by (rule le.less_thm3)
   578 
   580 
   579 text {* Mixin only available in original context *}
   581 text {* Rewrite morphism only available in original context *}
   580 
   582 
   581 locale mixin4_base = reflexive
   583 locale mixin4_base = reflexive
   582 
   584 
   583 locale mixin4_mixin = mixin4_base
   585 locale mixin4_mixin = mixin4_base
   584 
   586 
   602 end
   604 end
   603 
   605 
   604 interpretation le4: mixin4_combined gle' gle
   606 interpretation le4: mixin4_combined gle' gle
   605   by unfold_locales (rule grefl')
   607   by unfold_locales (rule grefl')
   606 
   608 
   607 thm le4.less_thm4' (* mixin not applied *)
   609 thm le4.less_thm4' (* rewrite morphism not applied *)
   608 lemma "reflexive.less(gle, x, y) <-> gle(x, y) & x ~= y"
   610 lemma "reflexive.less(gle, x, y) <-> gle(x, y) & x ~= y"
   609   by (rule le4.less_thm4')
   611   by (rule le4.less_thm4')
   610 
   612 
   611 text {* Inherited mixin applied to new theorem *}
   613 text {* Inherited rewrite morphism applied to new theorem *}
   612 
   614 
   613 locale mixin5_base = reflexive
   615 locale mixin5_base = reflexive
   614 
   616 
   615 locale mixin5_inherited = mixin5_base
   617 locale mixin5_inherited = mixin5_base
   616 
   618 
   626 interpretation le5: mixin5_inherited gle
   628 interpretation le5: mixin5_inherited gle
   627   by unfold_locales
   629   by unfold_locales
   628 
   630 
   629 lemmas (in mixin5_inherited) less_thm5 = less_def
   631 lemmas (in mixin5_inherited) less_thm5 = less_def
   630 
   632 
   631 thm le5.less_thm5  (* mixin applied *)
   633 thm le5.less_thm5  (* rewrite morphism applied *)
   632 lemma "gless(x, y) <-> gle(x, y) & x ~= y"
   634 lemma "gless(x, y) <-> gle(x, y) & x ~= y"
   633   by (rule le5.less_thm5)
   635   by (rule le5.less_thm5)
   634 
   636 
   635 text {* Mixin pushed down to existing inherited locale *}
   637 text {* Rewrite morphism pushed down to existing inherited locale *}
   636 
   638 
   637 locale mixin6_base = reflexive
   639 locale mixin6_base = reflexive
   638 
   640 
   639 locale mixin6_inherited = mixin5_base
   641 locale mixin6_inherited = mixin5_base
   640 
   642 
   655 
   657 
   656 thm le6.less_thm6  (* mixin applied *)
   658 thm le6.less_thm6  (* mixin applied *)
   657 lemma "gless(x, y) <-> gle(x, y) & x ~= y"
   659 lemma "gless(x, y) <-> gle(x, y) & x ~= y"
   658   by (rule le6.less_thm6)
   660   by (rule le6.less_thm6)
   659 
   661 
   660 text {* Existing mixin inherited through sublocale relation *}
   662 text {* Existing rewrite morphism inherited through sublocale relation *}
   661 
   663 
   662 locale mixin7_base = reflexive
   664 locale mixin7_base = reflexive
   663 
   665 
   664 locale mixin7_inherited = reflexive
   666 locale mixin7_inherited = reflexive
   665 
   667 
   675 interpretation le7: mixin7_inherited gle
   677 interpretation le7: mixin7_inherited gle
   676   by unfold_locales
   678   by unfold_locales
   677 
   679 
   678 lemmas (in mixin7_inherited) less_thm7 = less_def
   680 lemmas (in mixin7_inherited) less_thm7 = less_def
   679 
   681 
   680 thm le7.less_thm7  (* before, mixin not applied *)
   682 thm le7.less_thm7  (* before, rewrite morphism not applied *)
   681 lemma "reflexive.less(gle, x, y) <-> gle(x, y) & x ~= y"
   683 lemma "reflexive.less(gle, x, y) <-> gle(x, y) & x ~= y"
   682   by (rule le7.less_thm7)
   684   by (rule le7.less_thm7)
   683 
   685 
   684 sublocale mixin7_inherited < mixin7_base
   686 sublocale mixin7_inherited < mixin7_base
   685   by unfold_locales
   687   by unfold_locales
   694 text {* This locale will be interpreted in later theories. *}
   696 text {* This locale will be interpreted in later theories. *}
   695 
   697 
   696 locale mixin_thy_merge = le: reflexive le + le': reflexive le' for le le'
   698 locale mixin_thy_merge = le: reflexive le + le': reflexive le' for le le'
   697 
   699 
   698 
   700 
   699 subsection {* Mixins in sublocale *}
   701 subsection {* Rewrite morphisms in sublocale *}
   700 
   702 
   701 text {* Simulate a specification of left groups where unit and inverse are defined
   703 text {* Simulate a specification of left groups where unit and inverse are defined
   702   rather than specified.  This is possible, but not in FOL, due to the lack of a
   704   rather than specified.  This is possible, but not in FOL, due to the lack of a
   703   selection operator. *}
   705   selection operator. *}
   704 
   706 
   743 text {* Equations stored in target *}
   745 text {* Equations stored in target *}
   744 
   746 
   745 lemma "dgrp.one(prod) = one" by (rule one_equation)
   747 lemma "dgrp.one(prod) = one" by (rule one_equation)
   746 lemma "dgrp.inv(prod, x) = inv(x)" by (rule inv_equation)
   748 lemma "dgrp.inv(prod, x) = inv(x)" by (rule inv_equation)
   747 
   749 
   748 text {* Mixins applied *}
   750 text {* Rewrite morphisms applied *}
   749 
   751 
   750 lemma "one = glob_one(prod)" by (rule one_def)
   752 lemma "one = glob_one(prod)" by (rule one_def)
   751 lemma "inv(x) = glob_inv(prod, x)" by (rule inv_def)
   753 lemma "inv(x) = glob_inv(prod, x)" by (rule inv_def)
   752 
   754 
   753 end
   755 end
   755 text {* Interpreted versions *}
   757 text {* Interpreted versions *}
   756 
   758 
   757 lemma "0 = glob_one (op +)" by (rule int.def.one_def)
   759 lemma "0 = glob_one (op +)" by (rule int.def.one_def)
   758 lemma "- x = glob_inv(op +, x)" by (rule int.def.inv_def)
   760 lemma "- x = glob_inv(op +, x)" by (rule int.def.inv_def)
   759 
   761 
   760 text {* Roundup applies mixins at declaration level in DFS tree *}
   762 text {* Roundup applies rewrite morphisms at declaration level in DFS tree *}
   761 
   763 
   762 locale roundup = fixes x assumes true: "x <-> True"
   764 locale roundup = fixes x assumes true: "x <-> True"
   763 
   765 
   764 sublocale roundup \<subseteq> sub: roundup x where "x <-> True & True"
   766 sublocale roundup \<subseteq> sub: roundup x where "x <-> True & True"
   765   apply unfold_locales apply (simp add: true) done
   767   apply unfold_locales apply (simp add: true) done