src/HOL/Number_Theory/MiscAlgebra.thy
changeset 44872 a98ef45122f3
parent 44106 0e018cbcc0de
child 44890 22f665a2e91c
equal deleted inserted replaced
44871:fbfdc5ac86be 44872:a98ef45122f3
    10   "~~/src/HOL/Algebra/FiniteProduct"
    10   "~~/src/HOL/Algebra/FiniteProduct"
    11 begin
    11 begin
    12 
    12 
    13 (* finiteness stuff *)
    13 (* finiteness stuff *)
    14 
    14 
    15 lemma bounded_set1_int [intro]: "finite {(x::int). a < x & x < b & P x}" 
    15 lemma bounded_set1_int [intro]: "finite {(x::int). a < x & x < b & P x}"
    16   apply (subgoal_tac "{x. a < x & x < b & P x} <= {a<..<b}")
    16   apply (subgoal_tac "{x. a < x & x < b & P x} <= {a<..<b}")
    17   apply (erule finite_subset)
    17   apply (erule finite_subset)
    18   apply auto
    18   apply auto
    19 done
    19 done
    20 
    20 
    62   apply auto
    62   apply auto
    63   apply (subst m_assoc)
    63   apply (subst m_assoc)
    64   apply auto
    64   apply auto
    65   apply (rule_tac x = "inv x" in bexI)
    65   apply (rule_tac x = "inv x" in bexI)
    66   apply auto
    66   apply auto
    67 done
    67   done
    68 
    68 
    69 lemma (in comm_monoid) units_comm_group: "comm_group(units_of G)"
    69 lemma (in comm_monoid) units_comm_group: "comm_group(units_of G)"
    70   apply (rule group.group_comm_groupI)
    70   apply (rule group.group_comm_groupI)
    71   apply (rule units_group)
    71   apply (rule units_group)
    72   apply (insert comm_monoid_axioms)
    72   apply (insert comm_monoid_axioms)
    73   apply (unfold units_of_def Units_def comm_monoid_def comm_monoid_axioms_def)
    73   apply (unfold units_of_def Units_def comm_monoid_def comm_monoid_axioms_def)
    74   apply auto
    74   apply auto
    75   done
    75   done
    76 
    76 
    77 lemma units_of_carrier: "carrier (units_of G) = Units G"
    77 lemma units_of_carrier: "carrier (units_of G) = Units G"
    78   by (unfold units_of_def, auto)
    78   unfolding units_of_def by auto
    79 
    79 
    80 lemma units_of_mult: "mult(units_of G) = mult G"
    80 lemma units_of_mult: "mult(units_of G) = mult G"
    81   by (unfold units_of_def, auto)
    81   unfolding units_of_def by auto
    82 
    82 
    83 lemma units_of_one: "one(units_of G) = one G"
    83 lemma units_of_one: "one(units_of G) = one G"
    84   by (unfold units_of_def, auto)
    84   unfolding units_of_def by auto
    85 
    85 
    86 lemma (in monoid) units_of_inv: "x : Units G ==> 
    86 lemma (in monoid) units_of_inv: "x : Units G ==>
    87     m_inv (units_of G) x = m_inv G x"
    87     m_inv (units_of G) x = m_inv G x"
    88   apply (rule sym)
    88   apply (rule sym)
    89   apply (subst m_inv_def)
    89   apply (subst m_inv_def)
    90   apply (rule the1_equality)
    90   apply (rule the1_equality)
    91   apply (rule ex_ex1I)
    91   apply (rule ex_ex1I)
   103   apply (subst units_of_mult [symmetric])
   103   apply (subst units_of_mult [symmetric])
   104   apply (subst units_of_one [symmetric])
   104   apply (subst units_of_one [symmetric])
   105   apply (erule group.l_inv, assumption)
   105   apply (erule group.l_inv, assumption)
   106 done
   106 done
   107 
   107 
   108 lemma (in group) inj_on_const_mult: "a: (carrier G) ==> 
   108 lemma (in group) inj_on_const_mult: "a: (carrier G) ==>
   109     inj_on (%x. a \<otimes> x) (carrier G)"
   109     inj_on (%x. a \<otimes> x) (carrier G)"
   110   by (unfold inj_on_def, auto)
   110   unfolding inj_on_def by auto
   111 
   111 
   112 lemma (in group) surj_const_mult: "a : (carrier G) ==>
   112 lemma (in group) surj_const_mult: "a : (carrier G) ==>
   113     (%x. a \<otimes> x) ` (carrier G) = (carrier G)" 
   113     (%x. a \<otimes> x) ` (carrier G) = (carrier G)"
   114   apply (auto simp add: image_def)
   114   apply (auto simp add: image_def)
   115   apply (rule_tac x = "(m_inv G a) \<otimes> x" in bexI)
   115   apply (rule_tac x = "(m_inv G a) \<otimes> x" in bexI)
   116   apply auto
   116   apply auto
   117 (* auto should get this. I suppose we need "comm_monoid_simprules"
   117 (* auto should get this. I suppose we need "comm_monoid_simprules"
   118    for mult_ac rewriting. *)
   118    for mult_ac rewriting. *)
   119   apply (subst m_assoc [symmetric])
   119   apply (subst m_assoc [symmetric])
   120   apply auto
   120   apply auto
   121 done
   121   done
   122 
   122 
   123 lemma (in group) l_cancel_one [simp]: "x : carrier G \<Longrightarrow> a : carrier G \<Longrightarrow>
   123 lemma (in group) l_cancel_one [simp]: "x : carrier G \<Longrightarrow> a : carrier G \<Longrightarrow>
   124     (x \<otimes> a = x) = (a = one G)"
   124     (x \<otimes> a = x) = (a = one G)"
   125   apply auto
   125   apply auto
   126   apply (subst l_cancel [symmetric])
   126   apply (subst l_cancel [symmetric])
   127   prefer 4
   127   prefer 4
   128   apply (erule ssubst)
   128   apply (erule ssubst)
   129   apply auto
   129   apply auto
   130 done
   130   done
   131 
   131 
   132 lemma (in group) r_cancel_one [simp]: "x : carrier G \<Longrightarrow> a : carrier G \<Longrightarrow>
   132 lemma (in group) r_cancel_one [simp]: "x : carrier G \<Longrightarrow> a : carrier G \<Longrightarrow>
   133     (a \<otimes> x = x) = (a = one G)"
   133     (a \<otimes> x = x) = (a = one G)"
   134   apply auto
   134   apply auto
   135   apply (subst r_cancel [symmetric])
   135   apply (subst r_cancel [symmetric])
   136   prefer 4
   136   prefer 4
   137   apply (erule ssubst)
   137   apply (erule ssubst)
   138   apply auto
   138   apply auto
   139 done
   139   done
   140 
   140 
   141 (* Is there a better way to do this? *)
   141 (* Is there a better way to do this? *)
   142 
   142 
   143 lemma (in group) l_cancel_one' [simp]: "x : carrier G \<Longrightarrow> a : carrier G \<Longrightarrow>
   143 lemma (in group) l_cancel_one' [simp]: "x : carrier G \<Longrightarrow> a : carrier G \<Longrightarrow>
   144     (x = x \<otimes> a) = (a = one G)"
   144     (x = x \<otimes> a) = (a = one G)"
   145   by (subst eq_commute, simp)
   145   apply (subst eq_commute)
       
   146   apply simp
       
   147   done
   146 
   148 
   147 lemma (in group) r_cancel_one' [simp]: "x : carrier G \<Longrightarrow> a : carrier G \<Longrightarrow>
   149 lemma (in group) r_cancel_one' [simp]: "x : carrier G \<Longrightarrow> a : carrier G \<Longrightarrow>
   148     (x = a \<otimes> x) = (a = one G)"
   150     (x = a \<otimes> x) = (a = one G)"
   149   by (subst eq_commute, simp)
   151   apply (subst eq_commute)
       
   152   apply simp
       
   153   done
   150 
   154 
   151 (* This should be generalized to arbitrary groups, not just commutative
   155 (* This should be generalized to arbitrary groups, not just commutative
   152    ones, using Lagrange's theorem. *)
   156    ones, using Lagrange's theorem. *)
   153 
   157 
   154 lemma (in comm_group) power_order_eq_one:
   158 lemma (in comm_group) power_order_eq_one:
   155     assumes fin [simp]: "finite (carrier G)"
   159   assumes fin [simp]: "finite (carrier G)"
   156         and a [simp]: "a : carrier G" 
   160     and a [simp]: "a : carrier G"
   157       shows "a (^) card(carrier G) = one G" 
   161   shows "a (^) card(carrier G) = one G"
   158 proof -
   162 proof -
   159   have "(\<Otimes>x:carrier G. x) = (\<Otimes>x:carrier G. a \<otimes> x)"
   163   have "(\<Otimes>x:carrier G. x) = (\<Otimes>x:carrier G. a \<otimes> x)"
   160     by (subst (2) finprod_reindex [symmetric], 
   164     by (subst (2) finprod_reindex [symmetric],
   161       auto simp add: Pi_def inj_on_const_mult surj_const_mult)
   165       auto simp add: Pi_def inj_on_const_mult surj_const_mult)
   162   also have "\<dots> = (\<Otimes>x:carrier G. a) \<otimes> (\<Otimes>x:carrier G. x)"
   166   also have "\<dots> = (\<Otimes>x:carrier G. a) \<otimes> (\<Otimes>x:carrier G. x)"
   163     by (auto simp add: finprod_multf Pi_def)
   167     by (auto simp add: finprod_multf Pi_def)
   164   also have "(\<Otimes>x:carrier G. a) = a (^) card(carrier G)"
   168   also have "(\<Otimes>x:carrier G. a) = a (^) card(carrier G)"
   165     by (auto simp add: finprod_const)
   169     by (auto simp add: finprod_const)
   176   apply (unfold_locales)
   180   apply (unfold_locales)
   177   apply (insert cring_axioms, auto)
   181   apply (insert cring_axioms, auto)
   178   apply (rule trans)
   182   apply (rule trans)
   179   apply (subgoal_tac "a = (a \<otimes> b) \<otimes> inv b")
   183   apply (subgoal_tac "a = (a \<otimes> b) \<otimes> inv b")
   180   apply assumption
   184   apply assumption
   181   apply (subst m_assoc) 
   185   apply (subst m_assoc)
   182   apply auto
   186   apply auto
   183   apply (unfold Units_def)
   187   apply (unfold Units_def)
   184   apply auto
   188   apply auto
   185   done
   189   done
   186 
   190 
   198 
   202 
   199 lemma (in comm_monoid) comm_inv_char: "x : carrier G \<Longrightarrow> y : carrier G \<Longrightarrow>
   203 lemma (in comm_monoid) comm_inv_char: "x : carrier G \<Longrightarrow> y : carrier G \<Longrightarrow>
   200   x \<otimes> y = \<one> \<Longrightarrow> inv x = y"
   204   x \<otimes> y = \<one> \<Longrightarrow> inv x = y"
   201   apply (rule inv_char)
   205   apply (rule inv_char)
   202   apply auto
   206   apply auto
   203   apply (subst m_comm, auto) 
   207   apply (subst m_comm, auto)
   204   done
   208   done
   205 
   209 
   206 lemma (in ring) inv_neg_one [simp]: "inv (\<ominus> \<one>) = \<ominus> \<one>"  
   210 lemma (in ring) inv_neg_one [simp]: "inv (\<ominus> \<one>) = \<ominus> \<one>"
   207   apply (rule inv_char)
   211   apply (rule inv_char)
   208   apply (auto simp add: l_minus r_minus)
   212   apply (auto simp add: l_minus r_minus)
   209   done
   213   done
   210 
   214 
   211 lemma (in monoid) inv_eq_imp_eq: "x : Units G \<Longrightarrow> y : Units G \<Longrightarrow> 
   215 lemma (in monoid) inv_eq_imp_eq: "x : Units G \<Longrightarrow> y : Units G \<Longrightarrow>
   212     inv x = inv y \<Longrightarrow> x = y"
   216     inv x = inv y \<Longrightarrow> x = y"
   213   apply (subgoal_tac "inv(inv x) = inv(inv y)")
   217   apply (subgoal_tac "inv(inv x) = inv(inv y)")
   214   apply (subst (asm) Units_inv_inv)+
   218   apply (subst (asm) Units_inv_inv)+
   215   apply auto
   219   apply auto
   216 done
   220   done
   217 
   221 
   218 lemma (in ring) Units_minus_one_closed [intro]: "\<ominus> \<one> : Units R"
   222 lemma (in ring) Units_minus_one_closed [intro]: "\<ominus> \<one> : Units R"
   219   apply (unfold Units_def)
   223   apply (unfold Units_def)
   220   apply auto
   224   apply auto
   221   apply (rule_tac x = "\<ominus> \<one>" in bexI)
   225   apply (rule_tac x = "\<ominus> \<one>" in bexI)
   222   apply auto
   226   apply auto
   223   apply (simp add: l_minus r_minus)
   227   apply (simp add: l_minus r_minus)
   224 done
   228   done
   225 
   229 
   226 lemma (in monoid) inv_one [simp]: "inv \<one> = \<one>"
   230 lemma (in monoid) inv_one [simp]: "inv \<one> = \<one>"
   227   apply (rule inv_char)
   231   apply (rule inv_char)
   228   apply auto
   232   apply auto
   229 done
   233   done
   230 
   234 
   231 lemma (in ring) inv_eq_neg_one_eq: "x : Units R \<Longrightarrow> (inv x = \<ominus> \<one>) = (x = \<ominus> \<one>)"
   235 lemma (in ring) inv_eq_neg_one_eq: "x : Units R \<Longrightarrow> (inv x = \<ominus> \<one>) = (x = \<ominus> \<one>)"
   232   apply auto
   236   apply auto
   233   apply (subst Units_inv_inv [symmetric])
   237   apply (subst Units_inv_inv [symmetric])
   234   apply auto
   238   apply auto
   235 done
   239   done
   236 
   240 
   237 lemma (in monoid) inv_eq_one_eq: "x : Units G \<Longrightarrow> (inv x = \<one>) = (x = \<one>)"
   241 lemma (in monoid) inv_eq_one_eq: "x : Units G \<Longrightarrow> (inv x = \<one>) = (x = \<one>)"
   238   apply auto
   242   apply auto
   239   apply (subst Units_inv_inv [symmetric])
   243   apply (subst Units_inv_inv [symmetric])
   240   apply auto
   244   apply auto
   241 done
   245   done
   242 
   246 
   243 
   247 
   244 (* This goes in FiniteProduct *)
   248 (* This goes in FiniteProduct *)
   245 
   249 
   246 lemma (in comm_monoid) finprod_UN_disjoint:
   250 lemma (in comm_monoid) finprod_UN_disjoint:
   254   apply (subst finprod_Un_disjoint)
   258   apply (subst finprod_Un_disjoint)
   255   apply blast
   259   apply blast
   256   apply (erule finite_UN_I)
   260   apply (erule finite_UN_I)
   257   apply blast
   261   apply blast
   258   apply (fastsimp)
   262   apply (fastsimp)
   259   apply (auto intro!: funcsetI finprod_closed) 
   263   apply (auto intro!: funcsetI finprod_closed)
   260 done
   264   done
   261 
   265 
   262 lemma (in comm_monoid) finprod_Union_disjoint:
   266 lemma (in comm_monoid) finprod_Union_disjoint:
   263   "[| finite C; (ALL A:C. finite A & (ALL x:A. f x : carrier G));
   267   "[| finite C; (ALL A:C. finite A & (ALL x:A. f x : carrier G));
   264       (ALL A:C. ALL B:C. A ~= B --> A Int B = {}) |] 
   268       (ALL A:C. ALL B:C. A ~= B --> A Int B = {}) |]
   265    ==> finprod G f (Union C) = finprod G (finprod G f) C" 
   269    ==> finprod G f (Union C) = finprod G (finprod G f) C"
   266   apply (frule finprod_UN_disjoint [of C id f])
   270   apply (frule finprod_UN_disjoint [of C id f])
   267   apply (auto simp add: SUP_def)
   271   apply (auto simp add: SUP_def)
   268 done
   272   done
   269 
   273 
   270 lemma (in comm_monoid) finprod_one [rule_format]: 
   274 lemma (in comm_monoid) finprod_one:
   271   "finite A \<Longrightarrow> (ALL x:A. f x = \<one>) \<longrightarrow>
   275     "finite A \<Longrightarrow> (\<And>x. x:A \<Longrightarrow> f x = \<one>) \<Longrightarrow> finprod G f A = \<one>"
   272      finprod G f A = \<one>"
   276   by (induct set: finite) auto
   273 by (induct set: finite) auto
       
   274 
   277 
   275 
   278 
   276 (* need better simplification rules for rings *)
   279 (* need better simplification rules for rings *)
   277 (* the next one holds more generally for abelian groups *)
   280 (* the next one holds more generally for abelian groups *)
   278 
   281 
   279 lemma (in cring) sum_zero_eq_neg:
   282 lemma (in cring) sum_zero_eq_neg:
   280   "x : carrier R \<Longrightarrow> y : carrier R \<Longrightarrow> x \<oplus> y = \<zero> \<Longrightarrow> x = \<ominus> y"
   283     "x : carrier R \<Longrightarrow> y : carrier R \<Longrightarrow> x \<oplus> y = \<zero> \<Longrightarrow> x = \<ominus> y"
   281   apply (subgoal_tac "\<ominus> y = \<zero> \<oplus> \<ominus> y") 
   284   apply (subgoal_tac "\<ominus> y = \<zero> \<oplus> \<ominus> y")
   282   apply (erule ssubst)back
   285   apply (erule ssubst)back
   283   apply (erule subst)
   286   apply (erule subst)
   284   apply (simp_all add: ring_simprules)
   287   apply (simp_all add: ring_simprules)
   285   done
   288   done
   286 
   289 
   287 (* there's a name conflict -- maybe "domain" should be
   290 (* there's a name conflict -- maybe "domain" should be
   288    "integral_domain" *)
   291    "integral_domain" *)
   289 
   292 
   290 lemma (in Ring.domain) square_eq_one: 
   293 lemma (in Ring.domain) square_eq_one:
   291   fixes x
   294   fixes x
   292   assumes [simp]: "x : carrier R" and
   295   assumes [simp]: "x : carrier R" and
   293     "x \<otimes> x = \<one>"
   296     "x \<otimes> x = \<one>"
   294   shows "x = \<one> | x = \<ominus>\<one>"
   297   shows "x = \<one> | x = \<ominus>\<one>"
   295 proof -
   298 proof -
   296   have "(x \<oplus> \<one>) \<otimes> (x \<oplus> \<ominus> \<one>) = x \<otimes> x \<oplus> \<ominus> \<one>"
   299   have "(x \<oplus> \<one>) \<otimes> (x \<oplus> \<ominus> \<one>) = x \<otimes> x \<oplus> \<ominus> \<one>"
   297     by (simp add: ring_simprules)
   300     by (simp add: ring_simprules)
   298   also with `x \<otimes> x = \<one>` have "\<dots> = \<zero>"
   301   also with `x \<otimes> x = \<one>` have "\<dots> = \<zero>"
   299     by (simp add: ring_simprules)
   302     by (simp add: ring_simprules)
   300   finally have "(x \<oplus> \<one>) \<otimes> (x \<oplus> \<ominus> \<one>) = \<zero>" .
   303   finally have "(x \<oplus> \<one>) \<otimes> (x \<oplus> \<ominus> \<one>) = \<zero>" .
   301   hence "(x \<oplus> \<one>) = \<zero> | (x \<oplus> \<ominus> \<one>) = \<zero>"
   304   then have "(x \<oplus> \<one>) = \<zero> | (x \<oplus> \<ominus> \<one>) = \<zero>"
   302     by (intro integral, auto)
   305     by (intro integral, auto)
   303   thus ?thesis
   306   then show ?thesis
   304     apply auto
   307     apply auto
   305     apply (erule notE)
   308     apply (erule notE)
   306     apply (rule sum_zero_eq_neg)
   309     apply (rule sum_zero_eq_neg)
   307     apply auto
   310     apply auto
   308     apply (subgoal_tac "x = \<ominus> (\<ominus> \<one>)")
   311     apply (subgoal_tac "x = \<ominus> (\<ominus> \<one>)")
   309     apply (simp add: ring_simprules) 
   312     apply (simp add: ring_simprules)
   310     apply (rule sum_zero_eq_neg)
   313     apply (rule sum_zero_eq_neg)
   311     apply auto
   314     apply auto
   312     done
   315     done
   313 qed
   316 qed
   314 
   317 
   316     x = inv x \<Longrightarrow> x = \<one> | x = \<ominus> \<one>"
   319     x = inv x \<Longrightarrow> x = \<one> | x = \<ominus> \<one>"
   317   apply (rule square_eq_one)
   320   apply (rule square_eq_one)
   318   apply auto
   321   apply auto
   319   apply (erule ssubst)back
   322   apply (erule ssubst)back
   320   apply (erule Units_r_inv)
   323   apply (erule Units_r_inv)
   321 done
   324   done
   322 
   325 
   323 
   326 
   324 (*
   327 (*
   325   The following translates theorems about groups to the facts about
   328   The following translates theorems about groups to the facts about
   326   the units of a ring. (The list should be expanded as more things are
   329   the units of a ring. (The list should be expanded as more things are
   327   needed.)
   330   needed.)
   328 *)
   331 *)
   329 
   332 
   330 lemma (in ring) finite_ring_finite_units [intro]: "finite (carrier R) \<Longrightarrow> 
   333 lemma (in ring) finite_ring_finite_units [intro]:
   331     finite (Units R)"
   334     "finite (carrier R) \<Longrightarrow> finite (Units R)"
   332   by (rule finite_subset, auto)
   335   by (rule finite_subset) auto
   333 
   336 
   334 (* this belongs with MiscAlgebra.thy *)
   337 (* this belongs with MiscAlgebra.thy *)
   335 lemma (in monoid) units_of_pow: 
   338 lemma (in monoid) units_of_pow:
   336     "x : Units G \<Longrightarrow> x (^)\<^bsub>units_of G\<^esub> (n::nat) = x (^)\<^bsub>G\<^esub> n"
   339     "x : Units G \<Longrightarrow> x (^)\<^bsub>units_of G\<^esub> (n::nat) = x (^)\<^bsub>G\<^esub> n"
   337   apply (induct n)
   340   apply (induct n)
   338   apply (auto simp add: units_group group.is_monoid  
   341   apply (auto simp add: units_group group.is_monoid
   339     monoid.nat_pow_0 monoid.nat_pow_Suc units_of_one units_of_mult)
   342     monoid.nat_pow_0 monoid.nat_pow_Suc units_of_one units_of_mult)
   340   done
   343   done
   341 
   344 
   342 lemma (in cring) units_power_order_eq_one: "finite (Units R) \<Longrightarrow> a : Units R
   345 lemma (in cring) units_power_order_eq_one: "finite (Units R) \<Longrightarrow> a : Units R
   343     \<Longrightarrow> a (^) card(Units R) = \<one>"
   346     \<Longrightarrow> a (^) card(Units R) = \<one>"