src/HOL/Algebra/Multiplicative_Group.thy
author paulson <lp15@cam.ac.uk>
Wed, 10 Apr 2019 21:29:32 +0100
changeset 70113 c8deb8ba6d05
parent 70030 042ae6ca2c40
child 70131 c6e1a4806f49
permissions -rw-r--r--
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
     1
(*  Title:      HOL/Algebra/Multiplicative_Group.thy
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
     2
    Author:     Simon Wimmer
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
     3
    Author:     Lars Noschinski
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
     4
*)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
     5
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
     6
theory Multiplicative_Group
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
     7
imports
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
     8
  Complex_Main
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
     9
  Group
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    10
  Coset
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    11
  UnivPoly
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
    12
  Generated_Groups
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    13
begin
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    14
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
    15
section \<open>Simplification Rules for Polynomials\<close>
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
    16
text_raw \<open>\label{sec:simp-rules}\<close>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    17
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    18
lemma (in ring_hom_cring) hom_sub[simp]:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    19
  assumes "x \<in> carrier R" "y \<in> carrier R"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    20
  shows "h (x \<ominus> y) = h x \<ominus>\<^bsub>S\<^esub> h y"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    21
  using assms by (simp add: R.minus_eq S.minus_eq)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    22
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    23
context UP_ring begin
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    24
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    25
lemma deg_nzero_nzero:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    26
  assumes deg_p_nzero: "deg R p \<noteq> 0"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    27
  shows "p \<noteq> \<zero>\<^bsub>P\<^esub>"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    28
  using deg_zero deg_p_nzero by auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    29
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    30
lemma deg_add_eq:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    31
  assumes c: "p \<in> carrier P" "q \<in> carrier P"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    32
  assumes "deg R q \<noteq> deg R p"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    33
  shows "deg R (p \<oplus>\<^bsub>P\<^esub> q) = max (deg R p) (deg R q)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    34
proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    35
  let ?m = "max (deg R p) (deg R q)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    36
  from assms have "coeff P p ?m = \<zero> \<longleftrightarrow> coeff P q ?m \<noteq> \<zero>"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    37
    by (metis deg_belowI lcoeff_nonzero[OF deg_nzero_nzero] linear max.absorb_iff2 max.absorb1)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    38
  then have "coeff P (p \<oplus>\<^bsub>P\<^esub> q) ?m \<noteq> \<zero>"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    39
    using assms by auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    40
  then have "deg R (p \<oplus>\<^bsub>P\<^esub> q) \<ge> ?m"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    41
    using assms by (blast intro: deg_belowI)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    42
  with deg_add[OF c] show ?thesis by arith
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    43
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    44
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    45
lemma deg_minus_eq:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    46
  assumes "p \<in> carrier P" "q \<in> carrier P" "deg R q \<noteq> deg R p"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    47
  shows "deg R (p \<ominus>\<^bsub>P\<^esub> q) = max (deg R p) (deg R q)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    48
  using assms by (simp add: deg_add_eq a_minus_def)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    49
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    50
end
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    51
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    52
context UP_cring begin
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    53
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    54
lemma evalRR_add:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    55
  assumes "p \<in> carrier P" "q \<in> carrier P"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    56
  assumes x:"x \<in> carrier R"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    57
  shows "eval R R id x (p \<oplus>\<^bsub>P\<^esub> q) = eval R R id x p \<oplus> eval R R id x q"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    58
proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    59
  interpret UP_pre_univ_prop R R id by unfold_locales simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    60
  interpret ring_hom_cring P R "eval R R id x" by unfold_locales (rule eval_ring_hom[OF x])
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    61
  show ?thesis using assms by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    62
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    63
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    64
lemma evalRR_sub:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    65
  assumes "p \<in> carrier P" "q \<in> carrier P"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    66
  assumes x:"x \<in> carrier R"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    67
  shows "eval R R id x (p \<ominus>\<^bsub>P\<^esub> q) = eval R R id x p \<ominus> eval R R id x q"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    68
proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    69
  interpret UP_pre_univ_prop R R id by unfold_locales simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    70
  interpret ring_hom_cring P R "eval R R id x" by unfold_locales (rule eval_ring_hom[OF x])
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    71
  show ?thesis using assms by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    72
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    73
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    74
lemma evalRR_mult:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    75
  assumes "p \<in> carrier P" "q \<in> carrier P"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    76
  assumes x:"x \<in> carrier R"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    77
  shows "eval R R id x (p \<otimes>\<^bsub>P\<^esub> q) = eval R R id x p \<otimes> eval R R id x q"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    78
proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    79
  interpret UP_pre_univ_prop R R id by unfold_locales simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    80
  interpret ring_hom_cring P R "eval R R id x" by unfold_locales (rule eval_ring_hom[OF x])
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    81
  show ?thesis using assms by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    82
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    83
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    84
lemma evalRR_monom:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    85
  assumes a: "a \<in> carrier R" and x: "x \<in> carrier R"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
    86
  shows "eval R R id x (monom P a d) = a \<otimes> x [^] d"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    87
proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    88
  interpret UP_pre_univ_prop R R id by unfold_locales simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    89
  show ?thesis using assms by (simp add: eval_monom)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    90
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    91
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    92
lemma evalRR_one:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    93
  assumes x: "x \<in> carrier R"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    94
  shows "eval R R id x \<one>\<^bsub>P\<^esub> = \<one>"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    95
proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    96
  interpret UP_pre_univ_prop R R id by unfold_locales simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    97
  interpret ring_hom_cring P R "eval R R id x" by unfold_locales (rule eval_ring_hom[OF x])
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    98
  show ?thesis using assms by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
    99
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   100
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   101
lemma carrier_evalRR:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   102
  assumes x: "x \<in> carrier R" and "p \<in> carrier P"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   103
  shows "eval R R id x p \<in> carrier R"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   104
proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   105
  interpret UP_pre_univ_prop R R id by unfold_locales simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   106
  interpret ring_hom_cring P R "eval R R id x" by unfold_locales (rule eval_ring_hom[OF x])
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   107
  show ?thesis using assms by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   108
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   109
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   110
lemmas evalRR_simps = evalRR_add evalRR_sub evalRR_mult evalRR_monom evalRR_one carrier_evalRR
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   111
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   112
end
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   113
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   114
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   115
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   116
section \<open>Properties of the Euler \<open>\<phi>\<close>-function\<close>
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   117
text_raw \<open>\label{sec:euler-phi}\<close>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   118
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   119
text\<open>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   120
  In this section we prove that for every positive natural number the equation
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   121
  $\sum_{d | n}^n \varphi(d) = n$ holds.
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   122
\<close>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   123
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   124
lemma dvd_div_ge_1:
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   125
  fixes a b :: nat
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   126
  assumes "a \<ge> 1" "b dvd a"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   127
  shows "a div b \<ge> 1"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   128
proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   129
  from \<open>b dvd a\<close> obtain c where "a = b * c" ..
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   130
  with \<open>a \<ge> 1\<close> show ?thesis by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   131
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   132
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   133
lemma dvd_nat_bounds:
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   134
 fixes n p :: nat
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   135
 assumes "p > 0" "n dvd p"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   136
 shows "n > 0 \<and> n \<le> p"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   137
 using assms by (simp add: dvd_pos_nat dvd_imp_le)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   138
69785
9e326f6f8a24 More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
Manuel Eberl <eberlm@in.tum.de>
parents: 69749
diff changeset
   139
(* TODO FIXME: This is the "totient" function from HOL-Number_Theory, but since part of
9e326f6f8a24 More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
Manuel Eberl <eberlm@in.tum.de>
parents: 69749
diff changeset
   140
   HOL-Number_Theory depends on HOL-Algebra.Multiplicative_Group, there would be a cyclic
9e326f6f8a24 More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
Manuel Eberl <eberlm@in.tum.de>
parents: 69749
diff changeset
   141
   dependency. *)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   142
definition phi' :: "nat => nat"
67051
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66500
diff changeset
   143
  where "phi' m = card {x. 1 \<le> x \<and> x \<le> m \<and> coprime x m}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   144
66500
ba94aeb02fbc more correct output syntax declaration
haftmann
parents: 65416
diff changeset
   145
notation (latex output)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   146
  phi' ("\<phi> _")
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   147
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   148
lemma phi'_nonzero:
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   149
  assumes "m > 0"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   150
  shows "phi' m > 0"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   151
proof -
67051
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66500
diff changeset
   152
  have "1 \<in> {x. 1 \<le> x \<and> x \<le> m \<and> coprime x m}" using assms by simp
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66500
diff changeset
   153
  hence "card {x. 1 \<le> x \<and> x \<le> m \<and> coprime x m} > 0" by (auto simp: card_gt_0_iff)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   154
  thus ?thesis unfolding phi'_def by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   155
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   156
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   157
lemma dvd_div_eq_1:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   158
  fixes a b c :: nat
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   159
  assumes "c dvd a" "c dvd b" "a div c = b div c"
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   160
  shows "a = b" using assms dvd_mult_div_cancel[OF \<open>c dvd a\<close>] dvd_mult_div_cancel[OF \<open>c dvd b\<close>]
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   161
                by presburger
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   162
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   163
lemma dvd_div_eq_2:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   164
  fixes a b c :: nat
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   165
  assumes "c>0" "a dvd c" "b dvd c" "c div a = c div b"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   166
  shows "a = b"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   167
  proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   168
  have "a > 0" "a \<le> c" using dvd_nat_bounds[OF assms(1-2)] by auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   169
  have "a*(c div a) = c" using assms dvd_mult_div_cancel by fastforce
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   170
  also have "\<dots> = b*(c div a)" using assms dvd_mult_div_cancel by fastforce
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   171
  finally show "a = b" using \<open>c>0\<close> dvd_div_ge_1[OF _ \<open>a dvd c\<close>] by fastforce
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   172
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   173
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   174
lemma div_mult_mono:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   175
  fixes a b c :: nat
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   176
  assumes "a > 0" "a\<le>d"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   177
  shows "a * b div d \<le> b"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   178
proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   179
  have "a*b div d \<le> b*a div a" using assms div_le_mono2 mult.commute[of a b] by presburger
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   180
  thus ?thesis using assms by force
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   181
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   182
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   183
text\<open>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   184
  We arrive at the main result of this section:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   185
  For every positive natural number the equation $\sum_{d | n}^n \varphi(d) = n$ holds.
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   186
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   187
  The outline of the proof for this lemma is as follows:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   188
  We count the $n$ fractions $1/n$, $\ldots$, $(n-1)/n$, $n/n$.
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   189
  We analyze the reduced form $a/d = m/n$ for any of those fractions.
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   190
  We want to know how many fractions $m/n$ have the reduced form denominator $d$.
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   191
  The condition $1 \leq m \leq n$ is equivalent to the condition $1 \leq a \leq d$.
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68583
diff changeset
   192
  Therefore we want to know how many $a$ with $1 \leq a \leq d$ exist, s.t. \<^term>\<open>gcd a d = 1\<close>.
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68583
diff changeset
   193
  This number is exactly \<^term>\<open>phi' d\<close>.
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   194
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   195
  Finally, by counting the fractions $m/n$ according to their reduced form denominator,
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   196
  we get: @{term [display] "(\<Sum>d | d dvd n . phi' d) = n"}.
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   197
  To formalize this proof in Isabelle, we analyze for an arbitrary divisor $d$ of $n$
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   198
  \begin{itemize}
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68583
diff changeset
   199
    \item the set of reduced form numerators \<^term>\<open>{a. (1::nat) \<le> a \<and> a \<le> d \<and> coprime a d}\<close>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   200
    \item the set of numerators $m$, for which $m/n$ has the reduced form denominator $d$,
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68583
diff changeset
   201
      i.e. the set \<^term>\<open>{m \<in> {1::nat .. n}. n div gcd m n = d}\<close>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   202
  \end{itemize}
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68583
diff changeset
   203
  We show that \<^term>\<open>\<lambda>a. a*n div d\<close> with the inverse \<^term>\<open>\<lambda>a. a div gcd a n\<close> is
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   204
  a bijection between theses sets, thus yielding the equality
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   205
  @{term [display] "phi' d = card {m \<in> {1 .. n}. n div gcd m n = d}"}
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   206
  This gives us
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   207
  @{term [display] "(\<Sum>d | d dvd n . phi' d)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   208
          = card (\<Union>d \<in> {d. d dvd n}. {m \<in> {1 .. n}. n div gcd m n = d})"}
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   209
  and by showing
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68583
diff changeset
   210
  \<^term>\<open>(\<Union>d \<in> {d. d dvd n}. {m \<in> {1::nat .. n}. n div gcd m n = d}) \<supseteq> {1 .. n}\<close>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   211
  (this is our counting argument) the thesis follows.
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   212
\<close>
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   213
lemma sum_phi'_factors:
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   214
 fixes n :: nat
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   215
 assumes "n > 0"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   216
 shows "(\<Sum>d | d dvd n. phi' d) = n"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   217
proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   218
  { fix d assume "d dvd n" then obtain q where q: "n = d * q" ..
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   219
    have "card {a. 1 \<le> a \<and> a \<le> d \<and> coprime a d} = card {m \<in> {1 .. n}.  n div gcd m n = d}"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   220
         (is "card ?RF = card ?F")
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   221
    proof (rule card_bij_eq)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   222
      { fix a b assume "a * n div d = b * n div d"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   223
        hence "a * (n div d) = b * (n div d)"
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   224
          using dvd_div_mult[OF \<open>d dvd n\<close>] by (fastforce simp add: mult.commute)
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   225
        hence "a = b" using dvd_div_ge_1[OF _ \<open>d dvd n\<close>] \<open>n>0\<close>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   226
          by (simp add: mult.commute nat_mult_eq_cancel1)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   227
      } thus "inj_on (\<lambda>a. a*n div d) ?RF" unfolding inj_on_def by blast
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   228
      { fix a assume a:"a\<in>?RF"
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   229
        hence "a * (n div d) \<ge> 1" using \<open>n>0\<close> dvd_div_ge_1[OF _ \<open>d dvd n\<close>] by simp
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   230
        hence ge_1:"a * n div d \<ge> 1" by (simp add: \<open>d dvd n\<close> div_mult_swap)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   231
        have le_n:"a * n div d \<le> n" using div_mult_mono a by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   232
        have "gcd (a * n div d) n = n div d * gcd a d"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   233
          by (simp add: gcd_mult_distrib_nat q ac_simps)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   234
        hence "n div gcd (a * n div d) n = d*n div (d*(n div d))" using a by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   235
        hence "a * n div d \<in> ?F"
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   236
          using ge_1 le_n by (fastforce simp add: \<open>d dvd n\<close>)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   237
      } thus "(\<lambda>a. a*n div d) ` ?RF \<subseteq> ?F" by blast
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   238
      { fix m l assume A: "m \<in> ?F" "l \<in> ?F" "m div gcd m n = l div gcd l n"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   239
        hence "gcd m n = gcd l n" using dvd_div_eq_2[OF assms] by fastforce
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   240
        hence "m = l" using dvd_div_eq_1[of "gcd m n" m l] A(3) by fastforce
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   241
      } thus "inj_on (\<lambda>a. a div gcd a n) ?F" unfolding inj_on_def by blast
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   242
      { fix m assume "m \<in> ?F"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   243
        hence "m div gcd m n \<in> ?RF" using dvd_div_ge_1
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   244
          by (fastforce simp add: div_le_mono div_gcd_coprime)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   245
      } thus "(\<lambda>a. a div gcd a n) ` ?F \<subseteq> ?RF" by blast
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   246
    qed force+
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   247
  } hence phi'_eq:"\<And>d. d dvd n \<Longrightarrow> phi' d = card {m \<in> {1 .. n}. n div gcd m n = d}"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   248
      unfolding phi'_def by presburger
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   249
  have fin:"finite {d. d dvd n}" using dvd_nat_bounds[OF \<open>n>0\<close>] by force
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   250
  have "(\<Sum>d | d dvd n. phi' d)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   251
                 = card (\<Union>d \<in> {d. d dvd n}. {m \<in> {1 .. n}. n div gcd m n = d})"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   252
    using card_UN_disjoint[OF fin, of "(\<lambda>d. {m \<in> {1 .. n}. n div gcd m n = d})"] phi'_eq
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   253
    by fastforce
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   254
  also have "(\<Union>d \<in> {d. d dvd n}. {m \<in> {1 .. n}. n div gcd m n = d}) = {1 .. n}" (is "?L = ?R")
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   255
  proof
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   256
    show "?L \<supseteq> ?R"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   257
    proof
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   258
      fix m assume m: "m \<in> ?R"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   259
      thus "m \<in> ?L" using dvd_triv_right[of "n div gcd m n" "gcd m n"]
67051
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66500
diff changeset
   260
        by simp
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   261
    qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   262
  qed fastforce
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   263
  finally show ?thesis by force
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   264
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   265
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   266
section \<open>Order of an Element of a Group\<close>
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   267
text_raw \<open>\label{sec:order-elem}\<close>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   268
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   269
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   270
context group begin
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   271
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   272
definition (in group) ord :: "'a \<Rightarrow> nat" where
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   273
  "ord x \<equiv> (@d. \<forall>n::nat. pow G x n = one G \<longleftrightarrow> d dvd n)"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   274
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   275
lemma (in group) pow_eq_id:
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   276
  assumes "x \<in> carrier G"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   277
  shows "pow G x n = one G \<longleftrightarrow> (ord x) dvd n"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   278
proof (cases "\<forall>n::nat. pow G x n = one G \<longrightarrow> n = 0")
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   279
  case True
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   280
  show ?thesis
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   281
    unfolding ord_def
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   282
    by (rule someI2 [where a=0]) (auto simp: True)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   283
next
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   284
  case False
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   285
  define N where "N \<equiv> LEAST n::nat. x [^] n = \<one> \<and> n > 0"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   286
  have N: "x [^] N = \<one> \<and> N > 0"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   287
    using False
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   288
    apply (simp add: N_def)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   289
    by (metis (mono_tags, lifting) LeastI)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   290
  have eq0: "n = 0" if "x [^] n = \<one>" "n < N" for n
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   291
    using N_def not_less_Least that by fastforce
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   292
  show ?thesis
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   293
    unfolding ord_def
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   294
  proof (rule someI2 [where a = N], rule allI)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   295
    fix n :: "nat"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   296
    show "(x [^] n = \<one>) \<longleftrightarrow> (N dvd n)"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   297
    proof (cases "n = 0")
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   298
      case False
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   299
      show ?thesis
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   300
        unfolding dvd_def
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   301
      proof safe
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   302
        assume 1: "x [^] n = \<one>"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   303
        have "x [^] n = x [^] (n mod N + N * (n div N))"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   304
          by simp
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   305
        also have "\<dots> = x [^] (n mod N) \<otimes> x [^] (N * (n div N))"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   306
          by (simp add: assms nat_pow_mult)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   307
        also have "\<dots> = x [^] (n mod N)"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   308
          by (metis N assms l_cancel_one nat_pow_closed nat_pow_one nat_pow_pow)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   309
        finally have "x [^] (n mod N) = \<one>"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   310
          by (simp add: "1")
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   311
        then have "n mod N = 0"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   312
          using N eq0 mod_less_divisor by blast
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   313
        then show "\<exists>k. n = N * k"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   314
          by blast
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   315
      next
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   316
        fix k :: "nat"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   317
        assume "n = N * k"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   318
        with N show "x [^] (N * k) = \<one>"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   319
          by (metis assms nat_pow_one nat_pow_pow)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   320
      qed
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   321
    qed simp
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   322
  qed blast
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   323
qed
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   324
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   325
lemma (in group) pow_ord_eq_1 [simp]:
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   326
   "x \<in> carrier G \<Longrightarrow> x [^] ord x = \<one>"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   327
  by (simp add: pow_eq_id)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   328
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   329
lemma (in group) int_pow_eq_id:
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   330
  assumes "x \<in> carrier G"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   331
  shows "(pow G x i = one G \<longleftrightarrow> int (ord x) dvd i)"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   332
proof (cases i rule: int_cases2)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   333
  case (nonneg n)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   334
  then show ?thesis
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   335
    by (simp add: int_pow_int pow_eq_id assms)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   336
next
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   337
  case (nonpos n)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   338
  then have "x [^] i = inv (x [^] n)"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   339
    by (simp add: assms int_pow_int int_pow_neg)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   340
  then show ?thesis
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   341
    by (simp add: assms pow_eq_id nonpos)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   342
qed
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   343
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   344
lemma (in group) int_pow_eq:
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   345
   "x \<in> carrier G \<Longrightarrow> (x [^] m = x [^] n) \<longleftrightarrow> int (ord x) dvd (n - m)"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   346
  apply (simp flip: int_pow_eq_id)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   347
  by (metis int_pow_closed int_pow_diff inv_closed r_inv right_cancel)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   348
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   349
lemma (in group) ord_eq_0:
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   350
   "x \<in> carrier G \<Longrightarrow> (ord x = 0 \<longleftrightarrow> (\<forall>n::nat. n \<noteq> 0 \<longrightarrow> x [^] n \<noteq> \<one>))"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   351
  by (auto simp: pow_eq_id)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   352
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   353
lemma (in group) ord_unique:
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   354
   "x \<in> carrier G \<Longrightarrow> ord x = d \<longleftrightarrow> (\<forall>n. pow G x n = one G \<longleftrightarrow> d dvd n)"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   355
  by (meson dvd_antisym dvd_refl pow_eq_id)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   356
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   357
lemma (in group) ord_eq_1:
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   358
   "x \<in> carrier G \<Longrightarrow> (ord x = 1 \<longleftrightarrow> x = \<one>)"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   359
  by (metis pow_eq_id nat_dvd_1_iff_1 nat_pow_eone)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   360
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   361
lemma (in group) ord_id [simp]:
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   362
   "ord (one G) = 1"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   363
  using ord_eq_1 by blast
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   364
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   365
lemma (in group) ord_inv [simp]:
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   366
   "x \<in> carrier G
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   367
        \<Longrightarrow> ord (m_inv G x) = ord x"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   368
  by (simp add: ord_unique pow_eq_id nat_pow_inv)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   369
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   370
lemma (in group) ord_pow:
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   371
  assumes "x \<in> carrier G" "k dvd ord x" "k \<noteq> 0"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   372
  shows "ord (pow G x k) = ord x div k"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   373
proof -
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   374
  have "(x [^] k) [^] (ord x div k) = \<one>"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   375
    using assms by (simp add: nat_pow_pow)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   376
  moreover have "ord x dvd k * ord (x [^] k)"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   377
    by (metis assms(1) pow_ord_eq_1 pow_eq_id nat_pow_closed nat_pow_pow)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   378
  ultimately show ?thesis
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   379
    by (metis assms div_dvd_div dvd_antisym dvd_triv_left pow_eq_id nat_pow_closed nonzero_mult_div_cancel_left)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   380
qed
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   381
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   382
lemma (in group) ord_mul_divides:
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   383
  assumes eq: "x \<otimes> y = y \<otimes> x" and xy: "x \<in> carrier G" "y \<in> carrier G"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   384
  shows "ord (x \<otimes> y) dvd (ord x * ord y)"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   385
apply (simp add: xy flip: pow_eq_id eq)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   386
  by (metis dvd_triv_left dvd_triv_right eq pow_eq_id one_closed pow_mult_distrib r_one xy)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   387
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   388
lemma (in comm_group) abelian_ord_mul_divides:
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   389
   "\<lbrakk>x \<in> carrier G; y \<in> carrier G\<rbrakk>
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   390
        \<Longrightarrow> ord (x \<otimes> y) dvd (ord x * ord y)"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   391
  by (simp add: ord_mul_divides m_comm)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   392
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   393
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   394
definition old_ord where "old_ord a = Min {d \<in> {1 .. order G} . a [^] d = \<one>}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   395
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   396
lemma
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   397
  assumes finite: "finite (carrier G)"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   398
  assumes a: "a \<in> carrier G"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   399
  shows old_ord_ge_1: "1 \<le> old_ord a" and old_ord_le_group_order: "old_ord a \<le> order G"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   400
    and pow_old_ord_eq_1: "a [^] old_ord a = \<one>"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   401
proof -
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   402
  have "\<not>inj_on (\<lambda>x. a [^] x) {0 .. order G}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   403
  proof (rule notI)
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   404
    assume A: "inj_on (\<lambda>x. a [^] x) {0 .. order G}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   405
    have "order G + 1 = card {0 .. order G}" by simp
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   406
    also have "\<dots> = card ((\<lambda>x. a [^] x) ` {0 .. order G})" (is "_ = card ?S")
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   407
      using A by (simp add: card_image)
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   408
    also have "?S = {a [^] x | x. x \<in> {0 .. order G}}" by blast
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   409
    also have "\<dots> \<subseteq> carrier G" (is "?S \<subseteq> _") using a by blast
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   410
    then have "card ?S \<le> order G" unfolding order_def
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   411
      by (rule card_mono[OF finite])
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   412
    finally show False by arith
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   413
  qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   414
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   415
  then obtain x y where x_y:"x \<noteq> y" "x \<in> {0 .. order G}" "y \<in> {0 .. order G}"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   416
                        "a [^] x = a [^] y" unfolding inj_on_def by blast
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   417
  obtain d where "1 \<le> d" "a [^] d = \<one>" "d \<le> order G"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   418
  proof cases
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   419
    assume "y < x" with x_y show ?thesis
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   420
      by (intro that[where d="x - y"]) (auto simp add: pow_eq_div2[OF a])
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   421
  next
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   422
    assume "\<not>y < x" with x_y show ?thesis
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   423
      by (intro that[where d="y - x"]) (auto simp add: pow_eq_div2[OF a])
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   424
  qed
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   425
  hence "old_ord a \<in> {d \<in> {1 .. order G} . a [^] d = \<one>}"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   426
    unfolding old_ord_def using Min_in[of "{d \<in> {1 .. order G} . a [^] d = \<one>}"]
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   427
    by fastforce
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   428
  then show "1 \<le> old_ord a" and "old_ord a \<le> order G" and "a [^] old_ord a = \<one>"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   429
    by (auto simp: order_def)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   430
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   431
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   432
lemma finite_group_elem_finite_ord:
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   433
  assumes "finite (carrier G)" "x \<in> carrier G"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   434
  shows "\<exists> d::nat. d \<ge> 1 \<and> x [^] d = \<one>"
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   435
  using assms old_ord_ge_1 pow_old_ord_eq_1 by auto
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   436
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   437
lemma old_ord_min:
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   438
  assumes  "finite (carrier G)" "1 \<le> d" "a \<in> carrier G" "a [^] d = \<one>" shows "old_ord a \<le> d"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   439
proof -
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   440
  define Ord where "Ord = {d \<in> {1..order G}. a [^] d = \<one>}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   441
  have fin: "finite Ord" by (auto simp: Ord_def)
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   442
  have in_ord: "old_ord a \<in> Ord"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   443
    using assms pow_old_ord_eq_1 old_ord_ge_1 old_ord_le_group_order by (auto simp: Ord_def)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   444
  then have "Ord \<noteq> {}" by auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   445
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   446
  show ?thesis
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   447
  proof (cases "d \<le> order G")
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   448
    case True
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   449
    then have "d \<in> Ord" using assms by (auto simp: Ord_def)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   450
    with fin in_ord show ?thesis
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   451
      unfolding old_ord_def Ord_def[symmetric] by simp
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   452
  next
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   453
    case False
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   454
    then show ?thesis using in_ord by (simp add: Ord_def)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   455
  qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   456
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   457
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   458
lemma old_ord_dvd_pow_eq_1 :
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   459
  assumes "finite (carrier G)" "a \<in> carrier G" "a [^] k = \<one>"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   460
  shows "old_ord a dvd k"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   461
proof -
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   462
  define r where "r = k mod old_ord a"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   463
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   464
  define r q where "r = k mod old_ord a" and "q = k div old_ord a"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   465
  then have q: "k = q * old_ord a + r"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   466
    by (simp add: div_mult_mod_eq)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   467
  hence "a[^]k = (a[^]old_ord a)[^]q \<otimes> a[^]r"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   468
      using assms by (simp add: mult.commute nat_pow_mult nat_pow_pow)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   469
  hence "a[^]k = a[^]r" using assms by (simp add: pow_old_ord_eq_1)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   470
  hence "a[^]r = \<one>" using assms(3) by simp
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   471
  have "r < old_ord a" using old_ord_ge_1[OF assms(1-2)] by (simp add: r_def)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   472
  hence "r = 0" using \<open>a[^]r = \<one>\<close> old_ord_def[of a] old_ord_min[of r a] assms(1-2) by linarith
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   473
  thus ?thesis using q by simp
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   474
qed
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   475
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   476
lemma (in group) ord_iff_old_ord:
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   477
  assumes finite: "finite (carrier G)"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   478
  assumes a: "a \<in> carrier G"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   479
  shows  "ord a = Min {d \<in> {1 .. order G} . a [^] d = \<one>}"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   480
proof -
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   481
  have "a [^] ord a = \<one>"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   482
    using a pow_ord_eq_1 by blast
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   483
  then show ?thesis
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   484
    by (metis a dvd_antisym local.finite old_ord_def old_ord_dvd_pow_eq_1 pow_eq_id pow_old_ord_eq_1)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   485
qed
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   486
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   487
lemma
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   488
  assumes finite: "finite (carrier G)"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   489
  assumes a: "a \<in> carrier G"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   490
  shows ord_ge_1: "1 \<le> ord a" and ord_le_group_order: "ord a \<le> order G"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   491
  using a group.old_ord_ge_1 group.pow_eq_id group.pow_old_ord_eq_1 is_group local.finite apply fastforce
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   492
  by (metis a dvd_antisym group.pow_eq_id is_group local.finite old_ord_dvd_pow_eq_1 old_ord_le_group_order pow_ord_eq_1 pow_old_ord_eq_1)
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   493
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   494
lemma ord_inj:
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   495
  assumes finite: "finite (carrier G)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   496
  assumes a: "a \<in> carrier G"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   497
  shows "inj_on (\<lambda> x . a [^] x) {0 .. ord a - 1}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   498
proof (rule inj_onI, rule ccontr)
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   499
  fix x y assume A: "x \<in> {0 .. ord a - 1}" "y \<in> {0 .. ord a - 1}" "a [^] x= a [^] y" "x \<noteq> y"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   500
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   501
  have "finite {d \<in> {1..order G}. a [^] d = \<one>}" by auto
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   502
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   503
  { fix x y assume A: "x < y" "x \<in> {0 .. ord a - 1}" "y \<in> {0 .. ord a - 1}"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   504
        "a [^] x = a [^] y"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   505
    hence "y - x < ord a" by auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   506
    also have "\<dots> \<le> order G" using assms by (simp add: ord_le_group_order)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   507
    finally have y_x_range:"y - x \<in> {1 .. order G}" using A by force
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   508
    have "a [^] (y-x) = \<one>" using a A by (simp add: pow_eq_div2)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   509
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   510
    hence y_x:"y - x \<in> {d \<in> {1.. order G}. a [^] d = \<one>}" using y_x_range by blast
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   511
    have "min (y - x) (ord a) = ord a"
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   512
      using Min.in_idem[OF \<open>finite {d \<in> {1 .. order G} . a [^] d = \<one>}\<close> y_x]
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   513
      by (simp add: a group.ord_iff_old_ord is_group local.finite) 
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   514
    with \<open>y - x < ord a\<close> have False by linarith
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   515
  }
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   516
  note X = this
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   517
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   518
  { assume "x < y" with A X have False by blast }
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   519
  moreover
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   520
  { assume "x > y" with A X  have False by metis }
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   521
  moreover
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   522
  { assume "x = y" then have False using A by auto}
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   523
  ultimately
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   524
  show False by fastforce
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   525
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   526
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   527
lemma ord_inj':
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   528
  assumes finite: "finite (carrier G)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   529
  assumes a: "a \<in> carrier G"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   530
  shows "inj_on (\<lambda> x . a [^] x) {1 .. ord a}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   531
proof (rule inj_onI, rule ccontr)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   532
  fix x y :: nat
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   533
  assume A:"x \<in> {1 .. ord a}" "y \<in> {1 .. ord a}" "a [^] x = a [^] y" "x\<noteq>y"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   534
  { assume "x < ord a" "y < ord a"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   535
    hence False using ord_inj[OF assms] A unfolding inj_on_def by fastforce
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   536
  }
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   537
  moreover
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   538
  { assume "x = ord a" "y < ord a"
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   539
    hence "a [^] y = a [^] (0::nat)" using pow_ord_eq_1 A by (simp add: a)
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   540
    hence "y=0" using ord_inj[OF assms] \<open>y < ord a\<close> unfolding inj_on_def by force
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   541
    hence False using A by fastforce
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   542
  }
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   543
  moreover
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   544
  { assume "y = ord a" "x < ord a"
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   545
    hence "a [^] x = a [^] (0::nat)" using pow_ord_eq_1 A by (simp add: a)
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   546
    hence "x=0" using ord_inj[OF assms] \<open>x < ord a\<close> unfolding inj_on_def by force
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   547
    hence False using A by fastforce
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   548
  }
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   549
  ultimately show False using A  by force
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   550
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   551
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   552
lemma ord_elems:
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   553
  assumes "finite (carrier G)" "a \<in> carrier G"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   554
  shows "{a[^]x | x. x \<in> (UNIV :: nat set)} = {a[^]x | x. x \<in> {0 .. ord a - 1}}" (is "?L = ?R")
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   555
proof
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   556
  show "?R \<subseteq> ?L" by blast
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   557
  { fix y assume "y \<in> ?L"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   558
    then obtain x::nat where x:"y = a[^]x" by auto
68157
057d5b4ce47e removed some non-essential rules
haftmann
parents: 67399
diff changeset
   559
    define r q where "r = x mod ord a" and "q = x div ord a"
057d5b4ce47e removed some non-essential rules
haftmann
parents: 67399
diff changeset
   560
    then have "x = q * ord a + r"
057d5b4ce47e removed some non-essential rules
haftmann
parents: 67399
diff changeset
   561
      by (simp add: div_mult_mod_eq)
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   562
    hence "y = (a[^]ord a)[^]q \<otimes> a[^]r"
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   563
      using x assms by (metis mult.commute nat_pow_mult nat_pow_pow)
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   564
    hence "y = a[^]r" using assms by (simp add: pow_ord_eq_1)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   565
    have "r < ord a" using ord_ge_1[OF assms] by (simp add: r_def)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   566
    hence "r \<in> {0 .. ord a - 1}" by (force simp: r_def)
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   567
    hence "y \<in> {a[^]x | x. x \<in> {0 .. ord a - 1}}" using \<open>y=a[^]r\<close> by blast
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   568
  }
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   569
  thus "?L \<subseteq> ?R" by auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   570
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   571
69895
6b03a8cf092d more formal contributors (with the help of the history);
wenzelm
parents: 69785
diff changeset
   572
lemma generate_pow_on_finite_carrier: \<^marker>\<open>contributor \<open>Paulo Emílio de Vilhena\<close>\<close>
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   573
  assumes "finite (carrier G)" and "a \<in> carrier G"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   574
  shows "generate G { a } = { a [^] k | k. k \<in> (UNIV :: nat set) }"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   575
proof
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   576
  show "{ a [^] k | k. k \<in> (UNIV :: nat set) } \<subseteq> generate G { a }"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   577
  proof
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   578
    fix b assume "b \<in> { a [^] k | k. k \<in> (UNIV :: nat set) }"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   579
    then obtain k :: nat where "b = a [^] k" by blast
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   580
    hence "b = a [^] (int k)"
69749
10e48c47a549 some new results in group theory
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   581
      by (simp add: int_pow_int)
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   582
    thus "b \<in> generate G { a }"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   583
      unfolding generate_pow[OF assms(2)] by blast
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   584
  qed
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   585
next
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   586
  show "generate G { a } \<subseteq> { a [^] k | k. k \<in> (UNIV :: nat set) }"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   587
  proof
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   588
    fix b assume "b \<in> generate G { a }"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   589
    then obtain k :: int where k: "b = a [^] k"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   590
      unfolding generate_pow[OF assms(2)] by blast
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   591
    show "b \<in> { a [^] k | k. k \<in> (UNIV :: nat set) }"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   592
    proof (cases "k < 0")
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   593
      assume "\<not> k < 0"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   594
      hence "b = a [^] (nat k)"
70027
94494b92d8d0 some new group theory results: integer group, trivial group, etc.
paulson <lp15@cam.ac.uk>
parents: 69895
diff changeset
   595
        by (simp add: k)
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   596
      thus ?thesis by blast
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   597
    next
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   598
      assume "k < 0"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   599
      hence b: "b = inv (a [^] (nat (- k)))"
70027
94494b92d8d0 some new group theory results: integer group, trivial group, etc.
paulson <lp15@cam.ac.uk>
parents: 69895
diff changeset
   600
        using k \<open>a \<in> carrier G\<close> by (auto simp: int_pow_neg)
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   601
      obtain m where m: "ord a * m \<ge> nat (- k)"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   602
        by (metis assms mult.left_neutral mult_le_mono1 ord_ge_1)
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   603
      hence "a [^] (ord a * m) = \<one>"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   604
        by (metis assms nat_pow_one nat_pow_pow pow_ord_eq_1)
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   605
      then obtain k' :: nat where "(a [^] (nat (- k))) \<otimes> (a [^] k') = \<one>"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   606
        using m assms(2) nat_le_iff_add nat_pow_mult by auto
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   607
      hence "b = a [^] k'"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   608
        using b assms(2) by (metis inv_unique' nat_pow_closed nat_pow_comm)
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   609
      thus "b \<in> { a [^] k | k. k \<in> (UNIV :: nat set) }" by blast
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   610
    qed
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   611
  qed
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   612
qed
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   613
69895
6b03a8cf092d more formal contributors (with the help of the history);
wenzelm
parents: 69785
diff changeset
   614
lemma generate_pow_card: \<^marker>\<open>contributor \<open>Paulo Emílio de Vilhena\<close>\<close>
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   615
  assumes "finite (carrier G)" and "a \<in> carrier G"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   616
  shows "ord a = card (generate G { a })"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   617
proof -
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   618
  have "generate G { a } = (([^]) a) ` {0..ord a - 1}"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   619
    using generate_pow_on_finite_carrier[OF assms] unfolding ord_elems[OF assms] by auto
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   620
  thus ?thesis
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   621
    using ord_inj[OF assms] ord_ge_1[OF assms] by (simp add: card_image)
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   622
qed
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   623
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   624
(* This lemma was a suggestion of generalization given by Jeremy Avigad
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   625
   at the end of the theory FiniteProduct. *)
69895
6b03a8cf092d more formal contributors (with the help of the history);
wenzelm
parents: 69785
diff changeset
   626
corollary power_order_eq_one_group_version: \<^marker>\<open>contributor \<open>Paulo Emílio de Vilhena\<close>\<close>
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   627
  assumes "finite (carrier G)" and "a \<in> carrier G"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   628
  shows "a [^] (order G) = \<one>"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   629
proof -
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   630
  have "(ord a) dvd (order G)"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   631
    using lagrange[OF generate_is_subgroup[of " { a }"]] assms(2)
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   632
    unfolding generate_pow_card[OF assms]
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   633
    by (metis dvd_triv_right empty_subsetI insert_subset)
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   634
  then obtain k :: nat where "order G = ord a * k" by blast
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   635
  thus ?thesis
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   636
    using assms(2) pow_ord_eq_1 by (metis nat_pow_one nat_pow_pow)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   637
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   638
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   639
lemma dvd_gcd :
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   640
  fixes a b :: nat
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   641
  obtains q where "a * (b div gcd a b) = b*q"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   642
proof
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   643
  have "a * (b div gcd a b) = (a div gcd a b) * b" by (simp add:  div_mult_swap dvd_div_mult)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   644
  also have "\<dots> = b * (a div gcd a b)" by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   645
  finally show "a * (b div gcd a b) = b * (a div gcd a b) " .
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   646
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   647
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   648
lemma ord_pow_dvd_ord_elem :
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   649
  assumes finite[simp]: "finite (carrier G)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   650
  assumes a[simp]:"a \<in> carrier G"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   651
  shows "ord (a[^]n) = ord a div gcd n (ord a)"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   652
proof -
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   653
  have "(a[^]n) [^] ord a = (a [^] ord a) [^] n"
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   654
    by (simp add: nat_pow_pow pow_eq_id)
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   655
  hence "(a[^]n) [^] ord a = \<one>" by (simp add: pow_ord_eq_1)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   656
  obtain q where "n * (ord a div gcd n (ord a)) = ord a * q" by (rule dvd_gcd)
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   657
  hence "(a[^]n) [^] (ord a div gcd n (ord a)) = (a [^] ord a)[^]q"
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   658
    using a nat_pow_pow by presburger
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   659
  hence pow_eq_1: "(a[^]n) [^] (ord a div gcd n (ord a)) = \<one>"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   660
     by (auto simp add : pow_ord_eq_1[of a])
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   661
  have "ord a \<ge> 1" using ord_ge_1 by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   662
  have ge_1:"ord a div gcd n (ord a) \<ge> 1"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   663
  proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   664
    have "gcd n (ord a) dvd ord a" by blast
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   665
    thus ?thesis by (rule dvd_div_ge_1[OF \<open>ord a \<ge> 1\<close>])
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   666
  qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   667
  have "ord a \<le> order G" by (simp add: ord_le_group_order)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   668
  have "ord a div gcd n (ord a) \<le> order G"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   669
  proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   670
    have "ord a div gcd n (ord a) \<le> ord a" by simp
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   671
    thus ?thesis using \<open>ord a \<le> order G\<close> by linarith
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   672
  qed
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   673
  hence ord_gcd_elem:"ord a div gcd n (ord a) \<in> {d \<in> {1..order G}. (a[^]n) [^] d = \<one>}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   674
    using ge_1 pow_eq_1 by force
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   675
  { fix d :: nat
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   676
    assume d_elem:"d \<in> {d \<in> {1..order G}. (a[^]n) [^] d = \<one>}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   677
    assume d_lt:"d < ord a div gcd n (ord a)"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   678
    hence pow_nd:"a[^](n*d)  = \<one>" using d_elem
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   679
      by (simp add : nat_pow_pow)
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   680
    hence "ord a dvd n*d" using assms pow_eq_id by blast
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   681
    then obtain q where "ord a * q = n*d" by (metis dvd_mult_div_cancel)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   682
    hence prod_eq:"(ord a div gcd n (ord a)) * q = (n div gcd n (ord a)) * d"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   683
      by (simp add: dvd_div_mult)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   684
    have cp:"coprime (ord a div gcd n (ord a)) (n div gcd n (ord a))"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   685
    proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   686
      have "coprime (n div gcd n (ord a)) (ord a div gcd n (ord a))"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   687
        using div_gcd_coprime[of n "ord a"] ge_1 by fastforce
67051
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66500
diff changeset
   688
      thus ?thesis by (simp add: ac_simps)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   689
    qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   690
    have dvd_d:"(ord a div gcd n (ord a)) dvd d"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   691
    proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   692
      have "ord a div gcd n (ord a) dvd (n div gcd n (ord a)) * d" using prod_eq
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   693
        by (metis dvd_triv_right mult.commute)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   694
      hence "ord a div gcd n (ord a) dvd d * (n div gcd n (ord a))"
67051
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66500
diff changeset
   695
        by (simp add: mult.commute)
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66500
diff changeset
   696
      then show ?thesis
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66500
diff changeset
   697
        using cp by (simp add: coprime_dvd_mult_left_iff)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   698
    qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   699
    have "d > 0" using d_elem by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   700
    hence "ord a div gcd n (ord a) \<le> d" using dvd_d by (simp add : Nat.dvd_imp_le)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   701
    hence False using d_lt by simp
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   702
  } hence ord_gcd_min: "\<And> d . d \<in> {d \<in> {1..order G}. (a[^]n) [^] d = \<one>}
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   703
                        \<Longrightarrow> d\<ge>ord a div gcd n (ord a)" by fastforce
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   704
  have fin:"finite {d \<in> {1..order G}. (a[^]n) [^] d = \<one>}" by auto
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   705
  thus ?thesis using Min_eqI[OF fin ord_gcd_min ord_gcd_elem]
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   706
    by (simp add: group.ord_iff_old_ord is_group)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   707
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   708
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   709
lemma element_generates_subgroup:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   710
  assumes finite[simp]: "finite (carrier G)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   711
  assumes a[simp]: "a \<in> carrier G"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   712
  shows "subgroup {a [^] i | i. i \<in> {0 .. ord a - 1}} G"
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   713
  using generate_is_subgroup[of "{ a }"] assms(2)
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   714
        generate_pow_on_finite_carrier[OF assms]
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   715
  unfolding ord_elems[OF assms] by auto
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   716
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   717
lemma ord_dvd_group_order: 
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   718
  assumes "finite (carrier G)" and "a \<in> carrier G"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   719
  shows "(ord a) dvd (order G)"
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   720
  using lagrange[OF generate_is_subgroup[of " { a }"]] assms(2)
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   721
  unfolding generate_pow_card[OF assms]
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   722
  by (metis dvd_triv_right empty_subsetI insert_subset)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   723
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   724
end
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   725
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   726
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   727
section \<open>Number of Roots of a Polynomial\<close>
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   728
text_raw \<open>\label{sec:number-roots}\<close>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   729
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   730
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   731
definition mult_of :: "('a, 'b) ring_scheme \<Rightarrow> 'a monoid" where
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   732
  "mult_of R \<equiv> \<lparr> carrier = carrier R - {\<zero>\<^bsub>R\<^esub>}, mult = mult R, one = \<one>\<^bsub>R\<^esub>\<rparr>"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   733
68583
654e73d05495 even more from Paulo
paulson <lp15@cam.ac.uk>
parents: 68575
diff changeset
   734
lemma carrier_mult_of [simp]: "carrier (mult_of R) = carrier R - {\<zero>\<^bsub>R\<^esub>}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   735
  by (simp add: mult_of_def)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   736
68583
654e73d05495 even more from Paulo
paulson <lp15@cam.ac.uk>
parents: 68575
diff changeset
   737
lemma mult_mult_of [simp]: "mult (mult_of R) = mult R"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   738
 by (simp add: mult_of_def)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   739
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67341
diff changeset
   740
lemma nat_pow_mult_of: "([^]\<^bsub>mult_of R\<^esub>) = (([^]\<^bsub>R\<^esub>) :: _ \<Rightarrow> nat \<Rightarrow> _)"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   741
  by (simp add: mult_of_def fun_eq_iff nat_pow_def)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   742
68583
654e73d05495 even more from Paulo
paulson <lp15@cam.ac.uk>
parents: 68575
diff changeset
   743
lemma one_mult_of [simp]: "\<one>\<^bsub>mult_of R\<^esub> = \<one>\<^bsub>R\<^esub>"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   744
  by (simp add: mult_of_def)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   745
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   746
lemmas mult_of_simps = carrier_mult_of mult_mult_of nat_pow_mult_of one_mult_of
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   747
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   748
context field
68551
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68445
diff changeset
   749
begin
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68445
diff changeset
   750
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   751
lemma mult_of_is_Units: "mult_of R = units_of R"
68551
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68445
diff changeset
   752
  unfolding mult_of_def units_of_def using field_Units by auto
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   753
68561
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68551
diff changeset
   754
lemma m_inv_mult_of :
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68551
diff changeset
   755
"\<And>x. x \<in> carrier (mult_of R) \<Longrightarrow> m_inv (mult_of R) x = m_inv R x"
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68551
diff changeset
   756
  using mult_of_is_Units units_of_inv unfolding units_of_def
68575
d40d03487f64 more lemmas from Paulo
paulson <lp15@cam.ac.uk>
parents: 68561
diff changeset
   757
  by simp
68561
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68551
diff changeset
   758
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   759
lemma field_mult_group :
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   760
  shows "group (mult_of R)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   761
  apply (rule groupI)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   762
  apply (auto simp: mult_of_simps m_assoc dest: integral)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   763
  by (metis Diff_iff Units_inv_Units Units_l_inv field_Units singletonE)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   764
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   765
lemma finite_mult_of: "finite (carrier R) \<Longrightarrow> finite (carrier (mult_of R))"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   766
  by (auto simp: mult_of_simps)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   767
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   768
lemma order_mult_of: "finite (carrier R) \<Longrightarrow> order (mult_of R) = order R - 1"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   769
  unfolding order_def carrier_mult_of by (simp add: card.remove)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   770
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   771
end
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   772
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   773
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   774
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   775
lemma (in monoid) Units_pow_closed :
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   776
  fixes d :: nat
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   777
  assumes "x \<in> Units G"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   778
  shows "x [^] d \<in> Units G"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   779
    by (metis assms group.is_monoid monoid.nat_pow_closed units_group units_of_carrier units_of_pow)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   780
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   781
lemma (in comm_monoid) is_monoid:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   782
  shows "monoid G" by unfold_locales
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   783
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   784
declare comm_monoid.is_monoid[intro?]
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   785
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   786
lemma (in ring) r_right_minus_eq[simp]:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   787
  assumes "a \<in> carrier R" "b \<in> carrier R"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   788
  shows "a \<ominus> b = \<zero> \<longleftrightarrow> a = b"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   789
  using assms by (metis a_minus_def add.inv_closed minus_equality r_neg)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   790
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   791
context UP_cring begin
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   792
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   793
lemma is_UP_cring:"UP_cring R" by (unfold_locales)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   794
lemma is_UP_ring :
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   795
  shows "UP_ring R" by (unfold_locales)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   796
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   797
end
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   798
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   799
context UP_domain begin
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   800
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   801
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   802
lemma roots_bound:
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   803
  assumes f [simp]: "f \<in> carrier P"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   804
  assumes f_not_zero: "f \<noteq> \<zero>\<^bsub>P\<^esub>"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   805
  assumes finite: "finite (carrier R)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   806
  shows "finite {a \<in> carrier R . eval R R id a f = \<zero>} \<and>
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   807
         card {a \<in> carrier R . eval R R id a f = \<zero>} \<le> deg R f" using f f_not_zero
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   808
proof (induction "deg R f" arbitrary: f)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   809
  case 0
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   810
  have "\<And>x. eval R R id x f \<noteq> \<zero>"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   811
  proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   812
    fix x
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   813
    have "(\<Oplus>i\<in>{..deg R f}. id (coeff P f i) \<otimes> x [^] i) \<noteq> \<zero>"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   814
      using 0 lcoeff_nonzero_nonzero[where p = f] by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   815
    thus "eval R R id x f \<noteq> \<zero>" using 0 unfolding eval_def P_def by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   816
  qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   817
  then have *: "{a \<in> carrier R. eval R R (\<lambda>a. a) a f = \<zero>} = {}"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   818
    by (auto simp: id_def)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   819
  show ?case by (simp add: *)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   820
next
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   821
  case (Suc x)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   822
  show ?case
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   823
  proof (cases "\<exists> a \<in> carrier R . eval R R id a f = \<zero>")
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   824
    case True
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   825
    then obtain a where a_carrier[simp]: "a \<in> carrier R" and a_root:"eval R R id a f = \<zero>" by blast
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   826
    have R_not_triv: "carrier R \<noteq> {\<zero>}"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   827
      by (metis R.one_zeroI R.zero_not_one)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   828
    obtain q  where q:"(q \<in> carrier P)" and
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   829
      f:"f = (monom P \<one>\<^bsub>R\<^esub> 1 \<ominus>\<^bsub> P\<^esub> monom P a 0) \<otimes>\<^bsub>P\<^esub> q \<oplus>\<^bsub>P\<^esub> monom P (eval R R id a f) 0"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   830
     using remainder_theorem[OF Suc.prems(1) a_carrier R_not_triv] by auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   831
    hence lin_fac: "f = (monom P \<one>\<^bsub>R\<^esub> 1 \<ominus>\<^bsub> P\<^esub> monom P a 0) \<otimes>\<^bsub>P\<^esub> q" using q by (simp add: a_root)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   832
    have deg:"deg R (monom P \<one>\<^bsub>R\<^esub> 1 \<ominus>\<^bsub> P\<^esub> monom P a 0) = 1"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   833
      using a_carrier by (simp add: deg_minus_eq)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   834
    hence mon_not_zero:"(monom P \<one>\<^bsub>R\<^esub> 1 \<ominus>\<^bsub> P\<^esub> monom P a 0) \<noteq> \<zero>\<^bsub>P\<^esub>"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   835
      by (fastforce simp del: r_right_minus_eq)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   836
    have q_not_zero:"q \<noteq> \<zero>\<^bsub>P\<^esub>" using Suc by (auto simp add : lin_fac)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   837
    hence "deg R q = x" using Suc deg deg_mult[OF mon_not_zero q_not_zero _ q]
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   838
      by (simp add : lin_fac)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   839
    hence q_IH:"finite {a \<in> carrier R . eval R R id a q = \<zero>}
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   840
                \<and> card {a \<in> carrier R . eval R R id a q = \<zero>} \<le> x" using Suc q q_not_zero by blast
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   841
    have subs:"{a \<in> carrier R . eval R R id a f = \<zero>}
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   842
                \<subseteq> {a \<in> carrier R . eval R R id a q = \<zero>} \<union> {a}" (is "?L \<subseteq> ?R \<union> {a}")
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   843
      using a_carrier \<open>q \<in> _\<close>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   844
      by (auto simp: evalRR_simps lin_fac R.integral_iff)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   845
    have "{a \<in> carrier R . eval R R id a f = \<zero>} \<subseteq> insert a {a \<in> carrier R . eval R R id a q = \<zero>}"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   846
     using subs by auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   847
    hence "card {a \<in> carrier R . eval R R id a f = \<zero>} \<le>
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   848
           card (insert a {a \<in> carrier R . eval R R id a q = \<zero>})" using q_IH by (blast intro: card_mono)
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   849
    also have "\<dots> \<le> deg R f" using q_IH \<open>Suc x = _\<close>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   850
      by (simp add: card_insert_if)
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   851
    finally show ?thesis using q_IH \<open>Suc x = _\<close> using finite by force
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   852
  next
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   853
    case False
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   854
    hence "card {a \<in> carrier R. eval R R id a f = \<zero>} = 0" using finite by auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   855
    also have "\<dots> \<le>  deg R f" by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   856
    finally show ?thesis using finite by auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   857
  qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   858
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   859
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   860
end
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   861
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   862
lemma (in domain) num_roots_le_deg :
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   863
  fixes p d :: nat
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   864
  assumes finite:"finite (carrier R)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   865
  assumes d_neq_zero : "d \<noteq> 0"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   866
  shows "card {x \<in> carrier R. x [^] d = \<one>} \<le> d"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   867
proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   868
  let ?f = "monom (UP R) \<one>\<^bsub>R\<^esub> d \<ominus>\<^bsub> (UP R)\<^esub> monom (UP R) \<one>\<^bsub>R\<^esub> 0"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   869
  have one_in_carrier:"\<one> \<in> carrier R" by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   870
  interpret R: UP_domain R "UP R" by (unfold_locales)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   871
  have "deg R ?f = d"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   872
    using d_neq_zero by (simp add: R.deg_minus_eq)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   873
  hence f_not_zero:"?f \<noteq> \<zero>\<^bsub>UP R\<^esub>" using  d_neq_zero by (auto simp add : R.deg_nzero_nzero)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   874
  have roots_bound:"finite {a \<in> carrier R . eval R R id a ?f = \<zero>} \<and>
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   875
                    card {a \<in> carrier R . eval R R id a ?f = \<zero>} \<le> deg R ?f"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   876
                    using finite by (intro R.roots_bound[OF _ f_not_zero]) simp
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   877
  have subs:"{x \<in> carrier R. x [^] d = \<one>} \<subseteq> {a \<in> carrier R . eval R R id a ?f = \<zero>}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   878
    by (auto simp: R.evalRR_simps)
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   879
  then have "card {x \<in> carrier R. x [^] d = \<one>} \<le>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   880
        card {a \<in> carrier R. eval R R id a ?f = \<zero>}" using finite by (simp add : card_mono)
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   881
  thus ?thesis using \<open>deg R ?f = d\<close> roots_bound by linarith
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   882
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   883
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   884
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   885
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   886
section \<open>The Multiplicative Group of a Field\<close>
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   887
text_raw \<open>\label{sec:mult-group}\<close>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   888
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   889
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   890
text \<open>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   891
  In this section we show that the multiplicative group of a finite field
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   892
  is generated by a single element, i.e. it is cyclic. The proof is inspired
67299
ba52a058942f prefer formal citations;
wenzelm
parents: 67226
diff changeset
   893
  by the first proof given in the survey~@{cite "conrad-cyclicity"}.
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   894
\<close>
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   895
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   896
lemma (in group) pow_order_eq_1:
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   897
  assumes "finite (carrier G)" "x \<in> carrier G" shows "x [^] order G = \<one>"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   898
  using assms by (metis nat_pow_pow ord_dvd_group_order pow_ord_eq_1 dvdE nat_pow_one)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   899
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   900
(* XXX remove in AFP devel, replaced by div_eq_dividend_iff *)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   901
lemma nat_div_eq: "a \<noteq> 0 \<Longrightarrow> (a :: nat) div b = a \<longleftrightarrow> b = 1"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   902
  apply rule
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   903
  apply (cases "b = 0")
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   904
  apply simp_all
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   905
  apply (metis (full_types) One_nat_def Suc_lessI div_less_dividend less_not_refl3)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   906
  done
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   907
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   908
lemma (in group)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   909
  assumes finite': "finite (carrier G)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   910
  assumes "a \<in> carrier G"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   911
  shows pow_ord_eq_ord_iff: "group.ord G (a [^] k) = ord a \<longleftrightarrow> coprime k (ord a)" (is "?L \<longleftrightarrow> ?R")
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   912
proof
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   913
  assume A: ?L then show ?R
67051
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66500
diff changeset
   914
    using assms ord_ge_1 [OF assms]
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66500
diff changeset
   915
    by (auto simp: nat_div_eq ord_pow_dvd_ord_elem coprime_iff_gcd_eq_1)
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   916
next
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   917
  assume ?R then show ?L
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   918
    using ord_pow_dvd_ord_elem[OF assms, of k] by auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   919
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   920
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   921
context field begin
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   922
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   923
lemma num_elems_of_ord_eq_phi':
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   924
  assumes finite: "finite (carrier R)" and dvd: "d dvd order (mult_of R)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   925
      and exists: "\<exists>a\<in>carrier (mult_of R). group.ord (mult_of R) a = d"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   926
  shows "card {a \<in> carrier (mult_of R). group.ord (mult_of R) a = d} = phi' d"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   927
proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   928
  note mult_of_simps[simp]
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   929
  have finite': "finite (carrier (mult_of R))" using finite by (rule finite_mult_of)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   930
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67341
diff changeset
   931
  interpret G:group "mult_of R" rewrites "([^]\<^bsub>mult_of R\<^esub>) = (([^]) :: _ \<Rightarrow> nat \<Rightarrow> _)" and "\<one>\<^bsub>mult_of R\<^esub> = \<one>"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   932
    by (rule field_mult_group) simp_all
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   933
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   934
  from exists
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   935
  obtain a where a:"a \<in> carrier (mult_of R)" and ord_a: "group.ord (mult_of R) a = d"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   936
    by (auto simp add: card_gt_0_iff)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   937
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   938
  have set_eq1:"{a[^]n| n. n \<in> {1 .. d}} = {x \<in> carrier (mult_of R). x [^] d = \<one>}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   939
  proof (rule card_seteq)
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   940
    show "finite {x \<in> carrier (mult_of R). x [^] d = \<one>}" using finite by auto
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   941
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   942
    show "{a[^]n| n. n \<in> {1 ..d}} \<subseteq> {x \<in> carrier (mult_of R). x[^]d = \<one>}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   943
    proof
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   944
      fix x assume "x \<in> {a[^]n | n. n \<in> {1 .. d}}"
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   945
      then obtain n where n:"x = a[^]n \<and> n \<in> {1 .. d}" by auto
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   946
      have "x[^]d =(a[^]d)[^]n" using n a ord_a by (simp add:nat_pow_pow mult.commute)
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   947
      hence "x[^]d = \<one>" using ord_a G.pow_ord_eq_1[OF a] by fastforce
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   948
      thus "x \<in> {x \<in> carrier (mult_of R). x[^]d = \<one>}" using G.nat_pow_closed[OF a] n by blast
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   949
    qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   950
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   951
    show "card {x \<in> carrier (mult_of R). x [^] d = \<one>} \<le> card {a[^]n | n. n \<in> {1 .. d}}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   952
    proof -
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   953
      have *:"{a[^]n | n. n \<in> {1 .. d }} = ((\<lambda> n. a[^]n) ` {1 .. d})" by auto
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   954
      have "0 < order (mult_of R)" unfolding order_mult_of[OF finite]
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   955
        using card_mono[OF finite, of "{\<zero>, \<one>}"] by (simp add: order_def)
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   956
      have "card {x \<in> carrier (mult_of R). x [^] d = \<one>} \<le> card {x \<in> carrier R. x [^] d = \<one>}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   957
        using finite by (auto intro: card_mono)
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   958
      also have "\<dots> \<le> d" using \<open>0 < order (mult_of R)\<close> num_roots_le_deg[OF finite, of d]
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   959
        by (simp add : dvd_pos_nat[OF _ \<open>d dvd order (mult_of R)\<close>])
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   960
      finally show ?thesis using G.ord_inj'[OF finite' a] ord_a * by (simp add: card_image)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   961
    qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   962
  qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   963
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   964
  have set_eq2:"{x \<in> carrier (mult_of R) . group.ord (mult_of R) x = d}
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   965
                = (\<lambda> n . a[^]n) ` {n \<in> {1 .. d}. group.ord (mult_of R) (a[^]n) = d}" (is "?L = ?R")
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   966
  proof
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   967
    { fix x assume x:"x \<in> (carrier (mult_of R)) \<and> group.ord (mult_of R) x = d"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   968
      hence "x \<in> {x \<in> carrier (mult_of R). x [^] d = \<one>}"
70030
042ae6ca2c40 The order of a group now follows the HOL Light definition, which is more general
paulson <lp15@cam.ac.uk>
parents: 70027
diff changeset
   969
        by (simp add: G.pow_ord_eq_1[of x, symmetric])
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   970
      then obtain n where n:"x = a[^]n \<and> n \<in> {1 .. d}" using set_eq1 by blast
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   971
      hence "x \<in> ?R" using x by fast
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   972
    } thus "?L \<subseteq> ?R" by blast
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   973
    show "?R \<subseteq> ?L" using a by (auto simp add: carrier_mult_of[symmetric] simp del: carrier_mult_of)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   974
  qed
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   975
  have "inj_on (\<lambda> n . a[^]n) {n \<in> {1 .. d}. group.ord (mult_of R) (a[^]n) = d}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   976
    using G.ord_inj'[OF finite' a, unfolded ord_a] unfolding inj_on_def by fast
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   977
  hence "card ((\<lambda>n. a[^]n) ` {n \<in> {1 .. d}. group.ord (mult_of R) (a[^]n) = d})
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   978
         = card {k \<in> {1 .. d}. group.ord (mult_of R) (a[^]k) = d}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   979
         using card_image by blast
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
   980
  thus ?thesis using set_eq2 G.pow_ord_eq_ord_iff[OF finite' \<open>a \<in> _\<close>, unfolded ord_a]
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   981
    by (simp add: phi'_def)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   982
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   983
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   984
end
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   985
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   986
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   987
theorem (in field) finite_field_mult_group_has_gen :
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   988
  assumes finite:"finite (carrier R)"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
   989
  shows "\<exists> a \<in> carrier (mult_of R) . carrier (mult_of R) = {a[^]i | i::nat . i \<in> UNIV}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   990
proof -
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   991
  note mult_of_simps[simp]
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   992
  have finite': "finite (carrier (mult_of R))" using finite by (rule finite_mult_of)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   993
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   994
  interpret G: group "mult_of R" rewrites
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67341
diff changeset
   995
      "([^]\<^bsub>mult_of R\<^esub>) = (([^]) :: _ \<Rightarrow> nat \<Rightarrow> _)" and "\<one>\<^bsub>mult_of R\<^esub> = \<one>"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   996
    by (rule field_mult_group) (simp_all add: fun_eq_iff nat_pow_def)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   997
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   998
  let ?N = "\<lambda> x . card {a \<in> carrier (mult_of R). group.ord (mult_of R) a  = x}"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
   999
  have "0 < order R - 1" unfolding order_def using card_mono[OF finite, of "{\<zero>, \<one>}"] by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1000
  then have *: "0 < order (mult_of R)" using assms by (simp add: order_mult_of)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1001
  have fin: "finite {d. d dvd order (mult_of R) }" using dvd_nat_bounds[OF *] by force
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1002
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1003
  have "(\<Sum>d | d dvd order (mult_of R). ?N d)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1004
      = card (UN d:{d . d dvd order (mult_of R) }. {a \<in> carrier (mult_of R). group.ord (mult_of R) a  = d})"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1005
      (is "_ = card ?U")
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1006
    using fin finite by (subst card_UN_disjoint) auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1007
  also have "?U = carrier (mult_of R)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1008
  proof
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1009
    { fix x assume x:"x \<in> carrier (mult_of R)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1010
      hence x':"x\<in>carrier (mult_of R)" by simp
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1011
      then have "group.ord (mult_of R) x dvd order (mult_of R)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1012
          using finite' G.ord_dvd_group_order[OF _ x'] by (simp add: order_mult_of)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1013
      hence "x \<in> ?U" using dvd_nat_bounds[of "order (mult_of R)" "group.ord (mult_of R) x"] x by blast
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1014
    } thus "carrier (mult_of R) \<subseteq> ?U" by blast
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1015
  qed auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1016
  also have "card ... = order (mult_of R)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1017
    using order_mult_of finite' by (simp add: order_def)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1018
  finally have sum_Ns_eq: "(\<Sum>d | d dvd order (mult_of R). ?N d) = order (mult_of R)" .
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1019
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1020
  { fix d assume d:"d dvd order (mult_of R)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1021
    have "card {a \<in> carrier (mult_of R). group.ord (mult_of R) a = d} \<le> phi' d"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1022
    proof cases
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1023
      assume "card {a \<in> carrier (mult_of R). group.ord (mult_of R) a = d} = 0" thus ?thesis by presburger
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1024
      next
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1025
      assume "card {a \<in> carrier (mult_of R). group.ord (mult_of R) a = d} \<noteq> 0"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1026
      hence "\<exists>a \<in> carrier (mult_of R). group.ord (mult_of R) a = d" by (auto simp: card_eq_0_iff)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1027
      thus ?thesis using num_elems_of_ord_eq_phi'[OF finite d] by auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1028
    qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1029
  }
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1030
  hence all_le:"\<And>i. i \<in> {d. d dvd order (mult_of R) }
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1031
        \<Longrightarrow> (\<lambda>i. card {a \<in> carrier (mult_of R). group.ord (mult_of R) a = i}) i \<le> (\<lambda>i. phi' i) i" by fast
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1032
  hence le:"(\<Sum>i | i dvd order (mult_of R). ?N i)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1033
            \<le> (\<Sum>i | i dvd order (mult_of R). phi' i)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1034
            using sum_mono[of "{d .  d dvd order (mult_of R)}"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1035
                  "\<lambda>i. card {a \<in> carrier (mult_of R). group.ord (mult_of R) a = i}"] by presburger
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1036
  have "order (mult_of R) = (\<Sum>d | d dvd order (mult_of R). phi' d)" using *
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1037
    by (simp add: sum_phi'_factors)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1038
  hence eq:"(\<Sum>i | i dvd order (mult_of R). ?N i)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1039
          = (\<Sum>i | i dvd order (mult_of R). phi' i)" using le sum_Ns_eq by presburger
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1040
  have "\<And>i. i \<in> {d. d dvd order (mult_of R) } \<Longrightarrow> ?N i = (\<lambda>i. phi' i) i"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1041
  proof (rule ccontr)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1042
    fix i
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1043
    assume i1:"i \<in> {d. d dvd order (mult_of R)}" and "?N i \<noteq> phi' i"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1044
    hence "?N i = 0"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1045
      using num_elems_of_ord_eq_phi'[OF finite, of i] by (auto simp: card_eq_0_iff)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1046
    moreover  have "0 < i" using * i1 by (simp add: dvd_nat_bounds[of "order (mult_of R)" i])
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1047
    ultimately have "?N i < phi' i" using phi'_nonzero by presburger
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1048
    hence "(\<Sum>i | i dvd order (mult_of R). ?N i)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1049
         < (\<Sum>i | i dvd order (mult_of R). phi' i)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1050
      using sum_strict_mono_ex1[OF fin, of "?N" "\<lambda> i . phi' i"]
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1051
            i1 all_le by auto
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1052
    thus False using eq by force
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1053
  qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1054
  hence "?N (order (mult_of R)) > 0" using * by (simp add: phi'_nonzero)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1055
  then obtain a where a:"a \<in> carrier (mult_of R)" and a_ord:"group.ord (mult_of R) a = order (mult_of R)"
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1056
    by (auto simp add: card_gt_0_iff)
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
  1057
  hence set_eq:"{a[^]i | i::nat. i \<in> UNIV} = (\<lambda>x. a[^]x) ` {0 .. group.ord (mult_of R) a - 1}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1058
    using G.ord_elems[OF finite'] by auto
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
  1059
  have card_eq:"card ((\<lambda>x. a[^]x) ` {0 .. group.ord (mult_of R) a - 1}) = card {0 .. group.ord (mult_of R) a - 1}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1060
    by (intro card_image G.ord_inj finite' a)
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
  1061
  hence "card ((\<lambda> x . a[^]x) ` {0 .. group.ord (mult_of R) a - 1}) = card {0 ..order (mult_of R) - 1}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1062
    using assms by (simp add: card_eq a_ord)
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
  1063
  hence card_R_minus_1:"card {a[^]i | i::nat. i \<in> UNIV} =  order (mult_of R)"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1064
    using * by (subst set_eq) auto
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
  1065
  have **:"{a[^]i | i::nat. i \<in> UNIV} \<subseteq> carrier (mult_of R)"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1066
    using G.nat_pow_closed[OF a] by auto
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67299
diff changeset
  1067
  with _ have "carrier (mult_of R) = {a[^]i|i::nat. i \<in> UNIV}"
65416
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1068
    by (rule card_seteq[symmetric]) (simp_all add: card_R_minus_1 finite order_def del: UNIV_I)
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1069
  thus ?thesis using a by blast
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1070
qed
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1071
f707dbcf11e3 more approproiate placement of theories MiscAlgebra and Multiplicate_Group
haftmann
parents:
diff changeset
  1072
end