src/HOL/ex/LocaleTest2.thy
changeset 28823 dcbef866c9e2
parent 27556 292098f2efdf
child 29223 e09c53289830
equal deleted inserted replaced
28822:7ca11ecbc4fb 28823:dcbef866c9e2
   433 end
   433 end
   434 
   434 
   435 
   435 
   436 interpretation dlo < dlat
   436 interpretation dlo < dlat
   437 (* TODO: definition syntax is unavailable *)
   437 (* TODO: definition syntax is unavailable *)
   438 proof unfold_locales
   438 proof
   439   fix x y
   439   fix x y
   440   from total have "is_inf x y (if x \<sqsubseteq> y then x else y)" by (auto simp: is_inf_def)
   440   from total have "is_inf x y (if x \<sqsubseteq> y then x else y)" by (auto simp: is_inf_def)
   441   then show "EX inf. is_inf x y inf" by blast
   441   then show "EX inf. is_inf x y inf" by blast
   442 next
   442 next
   443   fix x y
   443   fix x y
   444   from total have "is_sup x y (if x \<sqsubseteq> y then y else x)" by (auto simp: is_sup_def)
   444   from total have "is_sup x y (if x \<sqsubseteq> y then y else x)" by (auto simp: is_sup_def)
   445   then show "EX sup. is_sup x y sup" by blast
   445   then show "EX sup. is_sup x y sup" by blast
   446 qed
   446 qed
   447 
   447 
   448 interpretation dlo < ddlat
   448 interpretation dlo < ddlat
   449 proof unfold_locales
   449 proof
   450   fix x y z
   450   fix x y z
   451   show "x \<sqinter> (y \<squnion> z) = x \<sqinter> y \<squnion> x \<sqinter> z" (is "?l = ?r")
   451   show "x \<sqinter> (y \<squnion> z) = x \<sqinter> y \<squnion> x \<sqinter> z" (is "?l = ?r")
   452     txt {* Jacobson I, p.\ 462 *}
   452     txt {* Jacobson I, p.\ 462 *}
   453   proof -
   453   proof -
   454     { assume c: "y \<sqsubseteq> x" "z \<sqsubseteq> x"
   454     { assume c: "y \<sqsubseteq> x" "z \<sqsubseteq> x"
   473 interpretation int: dpo ["op <= :: [int, int] => bool"]
   473 interpretation int: dpo ["op <= :: [int, int] => bool"]
   474   where "(dpo.less (op <=) (x::int) y) = (x < y)"
   474   where "(dpo.less (op <=) (x::int) y) = (x < y)"
   475   txt {* We give interpretation for less, but not @{text is_inf} and @{text is_sub}. *}
   475   txt {* We give interpretation for less, but not @{text is_inf} and @{text is_sub}. *}
   476 proof -
   476 proof -
   477   show "dpo (op <= :: [int, int] => bool)"
   477   show "dpo (op <= :: [int, int] => bool)"
   478     by unfold_locales auto
   478     proof qed auto
   479   then interpret int: dpo ["op <= :: [int, int] => bool"] .
   479   then interpret int: dpo ["op <= :: [int, int] => bool"] .
   480     txt {* Gives interpreted version of @{text less_def} (without condition). *}
   480     txt {* Gives interpreted version of @{text less_def} (without condition). *}
   481   show "(dpo.less (op <=) (x::int) y) = (x < y)"
   481   show "(dpo.less (op <=) (x::int) y) = (x < y)"
   482     by (unfold int.less_def) auto
   482     by (unfold int.less_def) auto
   483 qed
   483 qed
   512     apply (unfold int.is_sup_def)
   512     apply (unfold int.is_sup_def)
   513     by auto
   513     by auto
   514 qed
   514 qed
   515 
   515 
   516 interpretation int: dlo ["op <= :: [int, int] => bool"]
   516 interpretation int: dlo ["op <= :: [int, int] => bool"]
   517   by unfold_locales arith
   517   proof qed arith
   518 
   518 
   519 text {* Interpreted theorems from the locales, involving defined terms. *}
   519 text {* Interpreted theorems from the locales, involving defined terms. *}
   520 
   520 
   521 thm int.less_def text {* from dpo *}
   521 thm int.less_def text {* from dpo *}
   522 thm int.meet_left text {* from dlat *}
   522 thm int.meet_left text {* from dlat *}
   529 interpretation nat: dpo ["op <= :: [nat, nat] => bool"]
   529 interpretation nat: dpo ["op <= :: [nat, nat] => bool"]
   530   where "dpo.less (op <=) (x::nat) y = (x < y)"
   530   where "dpo.less (op <=) (x::nat) y = (x < y)"
   531   txt {* We give interpretation for less, but not @{text is_inf} and @{text is_sub}. *}
   531   txt {* We give interpretation for less, but not @{text is_inf} and @{text is_sub}. *}
   532 proof -
   532 proof -
   533   show "dpo (op <= :: [nat, nat] => bool)"
   533   show "dpo (op <= :: [nat, nat] => bool)"
   534     by unfold_locales auto
   534     proof qed auto
   535   then interpret nat: dpo ["op <= :: [nat, nat] => bool"] .
   535   then interpret nat: dpo ["op <= :: [nat, nat] => bool"] .
   536     txt {* Gives interpreted version of @{text less_def} (without condition). *}
   536     txt {* Gives interpreted version of @{text less_def} (without condition). *}
   537   show "dpo.less (op <=) (x::nat) y = (x < y)"
   537   show "dpo.less (op <=) (x::nat) y = (x < y)"
   538     apply (unfold nat.less_def)
   538     apply (unfold nat.less_def)
   539     apply auto
   539     apply auto
   563     apply (unfold nat.is_sup_def)
   563     apply (unfold nat.is_sup_def)
   564     by auto
   564     by auto
   565 qed
   565 qed
   566 
   566 
   567 interpretation nat: dlo ["op <= :: [nat, nat] => bool"]
   567 interpretation nat: dlo ["op <= :: [nat, nat] => bool"]
   568   by unfold_locales arith
   568   proof qed arith
   569 
   569 
   570 text {* Interpreted theorems from the locales, involving defined terms. *}
   570 text {* Interpreted theorems from the locales, involving defined terms. *}
   571 
   571 
   572 thm nat.less_def text {* from dpo *}
   572 thm nat.less_def text {* from dpo *}
   573 thm nat.meet_left text {* from dlat *}
   573 thm nat.meet_left text {* from dlat *}
   580 interpretation nat_dvd: dpo ["op dvd :: [nat, nat] => bool"]
   580 interpretation nat_dvd: dpo ["op dvd :: [nat, nat] => bool"]
   581   where "dpo.less (op dvd) (x::nat) y = (x dvd y & x ~= y)"
   581   where "dpo.less (op dvd) (x::nat) y = (x dvd y & x ~= y)"
   582   txt {* We give interpretation for less, but not @{text is_inf} and @{text is_sub}. *}
   582   txt {* We give interpretation for less, but not @{text is_inf} and @{text is_sub}. *}
   583 proof -
   583 proof -
   584   show "dpo (op dvd :: [nat, nat] => bool)"
   584   show "dpo (op dvd :: [nat, nat] => bool)"
   585     by unfold_locales (auto simp: dvd_def)
   585     proof qed (auto simp: dvd_def)
   586   then interpret nat_dvd: dpo ["op dvd :: [nat, nat] => bool"] .
   586   then interpret nat_dvd: dpo ["op dvd :: [nat, nat] => bool"] .
   587     txt {* Gives interpreted version of @{text less_def} (without condition). *}
   587     txt {* Gives interpreted version of @{text less_def} (without condition). *}
   588   show "dpo.less (op dvd) (x::nat) y = (x dvd y & x ~= y)"
   588   show "dpo.less (op dvd) (x::nat) y = (x dvd y & x ~= y)"
   589     apply (unfold nat_dvd.less_def)
   589     apply (unfold nat_dvd.less_def)
   590     apply auto
   590     apply auto
   840 
   840 
   841 interpretation Dfun: Dmonoid ["op o" "id :: 'a => 'a"]
   841 interpretation Dfun: Dmonoid ["op o" "id :: 'a => 'a"]
   842   where "Dmonoid.unit (op o) id f = bij (f::'a => 'a)"
   842   where "Dmonoid.unit (op o) id f = bij (f::'a => 'a)"
   843 (*    and "Dmonoid.inv (op o) id" = "inv :: ('a => 'a) => ('a => 'a)" *)
   843 (*    and "Dmonoid.inv (op o) id" = "inv :: ('a => 'a) => ('a => 'a)" *)
   844 proof -
   844 proof -
   845   show "Dmonoid op o (id :: 'a => 'a)" by unfold_locales (simp_all add: o_assoc)
   845   show "Dmonoid op o (id :: 'a => 'a)" proof qed (simp_all add: o_assoc)
   846   note Dmonoid = this
   846   note Dmonoid = this
   847 (*
   847 (*
   848   from this interpret Dmonoid ["op o" "id :: 'a => 'a"] .
   848   from this interpret Dmonoid ["op o" "id :: 'a => 'a"] .
   849 *)
   849 *)
   850   show "Dmonoid.unit (op o) (id :: 'a => 'a) f = bij f"
   850   show "Dmonoid.unit (op o) (id :: 'a => 'a) f = bij f"
   889   by rule simp
   889   by rule simp
   890 
   890 
   891 interpretation Dfun: Dgrp ["op o" "id :: unit => unit"]
   891 interpretation Dfun: Dgrp ["op o" "id :: unit => unit"]
   892   where "Dmonoid.inv (op o) id f = inv (f :: unit => unit)"
   892   where "Dmonoid.inv (op o) id f = inv (f :: unit => unit)"
   893 proof -
   893 proof -
   894   have "Dmonoid op o (id :: 'a => 'a)" by unfold_locales (simp_all add: o_assoc)
   894   have "Dmonoid op o (id :: 'a => 'a)" ..
   895   note Dmonoid = this
   895   note Dmonoid = this
   896 
   896 
   897   show "Dgrp (op o) (id :: unit => unit)"
   897   show "Dgrp (op o) (id :: unit => unit)"
   898 apply unfold_locales
   898 apply unfold_locales
   899 apply (unfold Dmonoid.unit_def [OF Dmonoid])
   899 apply (unfold Dmonoid.unit_def [OF Dmonoid])