src/HOL/Groups_Big.thy
changeset 69593 3dda49e08b9d
parent 69510 0f31dd2e540d
child 69654 bc758f4f09e5
equal deleted inserted replaced
69592:a80d8ec6c998 69593:3dda49e08b9d
   517 abbreviation Sum ("\<Sum>_" [1000] 999)
   517 abbreviation Sum ("\<Sum>_" [1000] 999)
   518   where "\<Sum>A \<equiv> sum (\<lambda>x. x) A"
   518   where "\<Sum>A \<equiv> sum (\<lambda>x. x) A"
   519 
   519 
   520 end
   520 end
   521 
   521 
   522 text \<open>Now: lots of fancy syntax. First, @{term "sum (\<lambda>x. e) A"} is written \<open>\<Sum>x\<in>A. e\<close>.\<close>
   522 text \<open>Now: lots of fancy syntax. First, \<^term>\<open>sum (\<lambda>x. e) A\<close> is written \<open>\<Sum>x\<in>A. e\<close>.\<close>
   523 
   523 
   524 syntax (ASCII)
   524 syntax (ASCII)
   525   "_sum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::comm_monoid_add"  ("(3SUM (_/:_)./ _)" [0, 51, 10] 10)
   525   "_sum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::comm_monoid_add"  ("(3SUM (_/:_)./ _)" [0, 51, 10] 10)
   526 syntax
   526 syntax
   527   "_sum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::comm_monoid_add"  ("(2\<Sum>(_/\<in>_)./ _)" [0, 51, 10] 10)
   527   "_sum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::comm_monoid_add"  ("(2\<Sum>(_/\<in>_)./ _)" [0, 51, 10] 10)
   528 translations \<comment> \<open>Beware of argument permutation!\<close>
   528 translations \<comment> \<open>Beware of argument permutation!\<close>
   529   "\<Sum>i\<in>A. b" \<rightleftharpoons> "CONST sum (\<lambda>i. b) A"
   529   "\<Sum>i\<in>A. b" \<rightleftharpoons> "CONST sum (\<lambda>i. b) A"
   530 
   530 
   531 text \<open>Instead of @{term"\<Sum>x\<in>{x. P}. e"} we introduce the shorter \<open>\<Sum>x|P. e\<close>.\<close>
   531 text \<open>Instead of \<^term>\<open>\<Sum>x\<in>{x. P}. e\<close> we introduce the shorter \<open>\<Sum>x|P. e\<close>.\<close>
   532 
   532 
   533 syntax (ASCII)
   533 syntax (ASCII)
   534   "_qsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(3SUM _ |/ _./ _)" [0, 0, 10] 10)
   534   "_qsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(3SUM _ |/ _./ _)" [0, 0, 10] 10)
   535 syntax
   535 syntax
   536   "_qsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(2\<Sum>_ | (_)./ _)" [0, 0, 10] 10)
   536   "_qsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(2\<Sum>_ | (_)./ _)" [0, 0, 10] 10)
   537 translations
   537 translations
   538   "\<Sum>x|P. t" => "CONST sum (\<lambda>x. t) {x. P}"
   538   "\<Sum>x|P. t" => "CONST sum (\<lambda>x. t) {x. P}"
   539 
   539 
   540 print_translation \<open>
   540 print_translation \<open>
   541 let
   541 let
   542   fun sum_tr' [Abs (x, Tx, t), Const (@{const_syntax Collect}, _) $ Abs (y, Ty, P)] =
   542   fun sum_tr' [Abs (x, Tx, t), Const (\<^const_syntax>\<open>Collect\<close>, _) $ Abs (y, Ty, P)] =
   543         if x <> y then raise Match
   543         if x <> y then raise Match
   544         else
   544         else
   545           let
   545           let
   546             val x' = Syntax_Trans.mark_bound_body (x, Tx);
   546             val x' = Syntax_Trans.mark_bound_body (x, Tx);
   547             val t' = subst_bound (x', t);
   547             val t' = subst_bound (x', t);
   548             val P' = subst_bound (x', P);
   548             val P' = subst_bound (x', P);
   549           in
   549           in
   550             Syntax.const @{syntax_const "_qsum"} $ Syntax_Trans.mark_bound_abs (x, Tx) $ P' $ t'
   550             Syntax.const \<^syntax_const>\<open>_qsum\<close> $ Syntax_Trans.mark_bound_abs (x, Tx) $ P' $ t'
   551           end
   551           end
   552     | sum_tr' _ = raise Match;
   552     | sum_tr' _ = raise Match;
   553 in [(@{const_syntax sum}, K sum_tr')] end
   553 in [(\<^const_syntax>\<open>sum\<close>, K sum_tr')] end
   554 \<close>
   554 \<close>
   555 
   555 
   556 
   556 
   557 subsubsection \<open>Properties in more restricted classes of structures\<close>
   557 subsubsection \<open>Properties in more restricted classes of structures\<close>
   558 
   558 
   936   with assms(1) show "f x = g x"
   936   with assms(1) show "f x = g x"
   937     by (cases x) (auto intro!: assms(2))
   937     by (cases x) (auto intro!: assms(2))
   938 qed simp_all
   938 qed simp_all
   939 
   939 
   940 
   940 
   941 subsubsection \<open>Cardinality as special case of @{const sum}\<close>
   941 subsubsection \<open>Cardinality as special case of \<^const>\<open>sum\<close>\<close>
   942 
   942 
   943 lemma card_eq_sum: "card A = sum (\<lambda>x. 1) A"
   943 lemma card_eq_sum: "card A = sum (\<lambda>x. 1) A"
   944 proof -
   944 proof -
   945   have "plus \<circ> (\<lambda>_. Suc 0) = (\<lambda>_. Suc)"
   945   have "plus \<circ> (\<lambda>_. Suc 0) = (\<lambda>_. Suc)"
   946     by (simp add: fun_eq_iff)
   946     by (simp add: fun_eq_iff)
  1132 syntax
  1132 syntax
  1133   "_prod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult"  ("(2\<Prod>(_/\<in>_)./ _)" [0, 51, 10] 10)
  1133   "_prod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult"  ("(2\<Prod>(_/\<in>_)./ _)" [0, 51, 10] 10)
  1134 translations \<comment> \<open>Beware of argument permutation!\<close>
  1134 translations \<comment> \<open>Beware of argument permutation!\<close>
  1135   "\<Prod>i\<in>A. b" == "CONST prod (\<lambda>i. b) A"
  1135   "\<Prod>i\<in>A. b" == "CONST prod (\<lambda>i. b) A"
  1136 
  1136 
  1137 text \<open>Instead of @{term"\<Prod>x\<in>{x. P}. e"} we introduce the shorter \<open>\<Prod>x|P. e\<close>.\<close>
  1137 text \<open>Instead of \<^term>\<open>\<Prod>x\<in>{x. P}. e\<close> we introduce the shorter \<open>\<Prod>x|P. e\<close>.\<close>
  1138 
  1138 
  1139 syntax (ASCII)
  1139 syntax (ASCII)
  1140   "_qprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(4PROD _ |/ _./ _)" [0, 0, 10] 10)
  1140   "_qprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(4PROD _ |/ _./ _)" [0, 0, 10] 10)
  1141 syntax
  1141 syntax
  1142   "_qprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(2\<Prod>_ | (_)./ _)" [0, 0, 10] 10)
  1142   "_qprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(2\<Prod>_ | (_)./ _)" [0, 0, 10] 10)