src/HOL/Algebra/IntRing.thy
author haftmann
Sat, 05 Jul 2014 11:01:53 +0200
changeset 57514 bdc2c6b40bf2
parent 57512 cc97b347b301
child 60112 3eab4acaa035
permissions -rw-r--r--
prefer ac_simps collections over separate name bindings for add and mult
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35849
b5522b51cb1e standard headers;
wenzelm
parents: 35848
diff changeset
     1
(*  Title:      HOL/Algebra/IntRing.thy
b5522b51cb1e standard headers;
wenzelm
parents: 35848
diff changeset
     2
    Author:     Stephan Hohe, TU Muenchen
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
     3
    Author:     Clemens Ballarin
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
     4
*)
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
     5
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
     6
theory IntRing
55157
06897ea77f78 converting to new Number_Theory
paulson <lp15@cam.ac.uk>
parents: 49962
diff changeset
     7
imports QuotRing Lattice Int "~~/src/HOL/Number_Theory/Primes"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
     8
begin
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
     9
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    10
section {* The Ring of Integers *}
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    11
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    12
subsection {* Some properties of @{typ int} *}
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    13
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    14
lemma dvds_eq_abseq:
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    15
  fixes k :: int
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    16
  shows "l dvd k \<and> k dvd l \<longleftrightarrow> abs l = abs k"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    17
apply rule
33657
a4179bf442d1 renamed lemmas "anti_sym" -> "antisym"
nipkow
parents: 32480
diff changeset
    18
 apply (simp add: zdvd_antisym_abs)
33676
802f5e233e48 moved lemma from Algebra/IntRing to Ring_and_Field
nipkow
parents: 33657
diff changeset
    19
apply (simp add: dvd_if_abs_eq)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    20
done
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    21
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    22
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
    23
subsection {* @{text "\<Z>"}: The Set of Integers as Algebraic Structure *}
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    24
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    25
abbreviation int_ring :: "int ring" ("\<Z>")
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    26
  where "int_ring \<equiv> \<lparr>carrier = UNIV, mult = op *, one = 1, zero = 0, add = op +\<rparr>"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    27
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    28
lemma int_Zcarr [intro!, simp]: "k \<in> carrier \<Z>"
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
    29
  by simp
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    30
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    31
lemma int_is_cring: "cring \<Z>"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    32
apply (rule cringI)
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    33
  apply (rule abelian_groupI, simp_all)
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    34
  defer 1
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    35
  apply (rule comm_monoidI, simp_all)
49962
a8cc904a6820 Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents: 44821
diff changeset
    36
 apply (rule distrib_right)
44821
a92f65e174cf avoid using legacy theorem names
huffman
parents: 44655
diff changeset
    37
apply (fast intro: left_minus)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    38
done
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    39
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    40
(*
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    41
lemma int_is_domain:
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    42
  "domain \<Z>"
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    43
apply (intro domain.intro domain_axioms.intro)
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    44
  apply (rule int_is_cring)
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    45
 apply (unfold int_ring_def, simp+)
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    46
done
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    47
*)
35849
b5522b51cb1e standard headers;
wenzelm
parents: 35848
diff changeset
    48
b5522b51cb1e standard headers;
wenzelm
parents: 35848
diff changeset
    49
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
    50
subsection {* Interpretations *}
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    51
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    52
text {* Since definitions of derived operations are global, their
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    53
  interpretation needs to be done as early as possible --- that is,
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    54
  with as few assumptions as possible. *}
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    55
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
    56
interpretation int: monoid \<Z>
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    57
  where "carrier \<Z> = UNIV"
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    58
    and "mult \<Z> x y = x * y"
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    59
    and "one \<Z> = 1"
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    60
    and "pow \<Z> x n = x^n"
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    61
proof -
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    62
  -- "Specification"
44655
fe0365331566 tuned proofs;
wenzelm
parents: 41433
diff changeset
    63
  show "monoid \<Z>" by default auto
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
    64
  then interpret int: monoid \<Z> .
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    65
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    66
  -- "Carrier"
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
    67
  show "carrier \<Z> = UNIV" by simp
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    68
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    69
  -- "Operations"
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
    70
  { fix x y show "mult \<Z> x y = x * y" by simp }
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    71
  show "one \<Z> = 1" by simp
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
    72
  show "pow \<Z> x n = x^n" by (induct n) simp_all
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    73
qed
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    74
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
    75
interpretation int: comm_monoid \<Z>
28524
644b62cf678f arbitrary is undefined
haftmann
parents: 28085
diff changeset
    76
  where "finprod \<Z> f A = (if finite A then setprod f A else undefined)"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    77
proof -
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    78
  -- "Specification"
44655
fe0365331566 tuned proofs;
wenzelm
parents: 41433
diff changeset
    79
  show "comm_monoid \<Z>" by default auto
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
    80
  then interpret int: comm_monoid \<Z> .
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    81
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    82
  -- "Operations"
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
    83
  { fix x y have "mult \<Z> x y = x * y" by simp }
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    84
  note mult = this
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
    85
  have one: "one \<Z> = 1" by simp
28524
644b62cf678f arbitrary is undefined
haftmann
parents: 28085
diff changeset
    86
  show "finprod \<Z> f A = (if finite A then setprod f A else undefined)"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    87
  proof (cases "finite A")
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    88
    case True
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    89
    then show ?thesis
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    90
    proof induct
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    91
      case empty
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    92
      show ?case by (simp add: one)
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    93
    next
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    94
      case insert
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    95
      then show ?case by (simp add: Pi_def mult)
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    96
    qed
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    97
  next
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    98
    case False
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    99
    then show ?thesis by (simp add: finprod_def)
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   100
  qed
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   101
qed
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   102
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   103
interpretation int: abelian_monoid \<Z>
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   104
  where int_carrier_eq: "carrier \<Z> = UNIV"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   105
    and int_zero_eq: "zero \<Z> = 0"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   106
    and int_add_eq: "add \<Z> x y = x + y"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   107
    and int_finsum_eq: "finsum \<Z> f A = (if finite A then setsum f A else undefined)"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   108
proof -
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   109
  -- "Specification"
44655
fe0365331566 tuned proofs;
wenzelm
parents: 41433
diff changeset
   110
  show "abelian_monoid \<Z>" by default auto
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   111
  then interpret int: abelian_monoid \<Z> .
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   112
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   113
  -- "Carrier"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   114
  show "carrier \<Z> = UNIV" by simp
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   115
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   116
  -- "Operations"
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   117
  { fix x y show "add \<Z> x y = x + y" by simp }
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   118
  note add = this
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   119
  show zero: "zero \<Z> = 0"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   120
    by simp
28524
644b62cf678f arbitrary is undefined
haftmann
parents: 28085
diff changeset
   121
  show "finsum \<Z> f A = (if finite A then setsum f A else undefined)"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   122
  proof (cases "finite A")
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   123
    case True
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   124
    then show ?thesis
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   125
    proof induct
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   126
      case empty
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   127
      show ?case by (simp add: zero)
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   128
    next
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   129
      case insert
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   130
      then show ?case by (simp add: Pi_def add)
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   131
    qed
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   132
  next
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   133
    case False
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   134
    then show ?thesis by (simp add: finsum_def finprod_def)
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   135
  qed
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   136
qed
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   137
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   138
interpretation int: abelian_group \<Z>
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   139
  (* The equations from the interpretation of abelian_monoid need to be repeated.
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   140
     Since the morphisms through which the abelian structures are interpreted are
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   141
     not the identity, the equations of these interpretations are not inherited. *)
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   142
  (* FIXME *)
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   143
  where "carrier \<Z> = UNIV"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   144
    and "zero \<Z> = 0"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   145
    and "add \<Z> x y = x + y"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   146
    and "finsum \<Z> f A = (if finite A then setsum f A else undefined)"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   147
    and int_a_inv_eq: "a_inv \<Z> x = - x"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   148
    and int_a_minus_eq: "a_minus \<Z> x y = x - y"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   149
proof -
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   150
  -- "Specification"
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   151
  show "abelian_group \<Z>"
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   152
  proof (rule abelian_groupI)
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   153
    fix x
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   154
    assume "x \<in> carrier \<Z>"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   155
    then show "\<exists>y \<in> carrier \<Z>. y \<oplus>\<^bsub>\<Z>\<^esub> x = \<zero>\<^bsub>\<Z>\<^esub>"
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   156
      by simp arith
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   157
  qed auto
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   158
  then interpret int: abelian_group \<Z> .
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   159
  -- "Operations"
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   160
  { fix x y have "add \<Z> x y = x + y" by simp }
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   161
  note add = this
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   162
  have zero: "zero \<Z> = 0" by simp
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   163
  {
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   164
    fix x
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   165
    have "add \<Z> (- x) x = zero \<Z>"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   166
      by (simp add: add zero)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   167
    then show "a_inv \<Z> x = - x"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   168
      by (simp add: int.minus_equality)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   169
  }
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   170
  note a_inv = this
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   171
  show "a_minus \<Z> x y = x - y"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   172
    by (simp add: int.minus_eq add a_inv)
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   173
qed (simp add: int_carrier_eq int_zero_eq int_add_eq int_finsum_eq)+
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   174
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   175
interpretation int: "domain" \<Z>
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   176
  where "carrier \<Z> = UNIV"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   177
    and "zero \<Z> = 0"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   178
    and "add \<Z> x y = x + y"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   179
    and "finsum \<Z> f A = (if finite A then setsum f A else undefined)"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   180
    and "a_inv \<Z> x = - x"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   181
    and "a_minus \<Z> x y = x - y"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   182
proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   183
  show "domain \<Z>"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   184
    by unfold_locales (auto simp: distrib_right distrib_left)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   185
qed (simp add: int_carrier_eq int_zero_eq int_add_eq int_finsum_eq int_a_inv_eq int_a_minus_eq)+
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   186
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   187
24131
1099f6c73649 Experimental removal of assumptions of the form x : UNIV and the like after interpretation.
ballarin
parents: 23957
diff changeset
   188
text {* Removal of occurrences of @{term UNIV} in interpretation result
1099f6c73649 Experimental removal of assumptions of the form x : UNIV and the like after interpretation.
ballarin
parents: 23957
diff changeset
   189
  --- experimental. *}
1099f6c73649 Experimental removal of assumptions of the form x : UNIV and the like after interpretation.
ballarin
parents: 23957
diff changeset
   190
1099f6c73649 Experimental removal of assumptions of the form x : UNIV and the like after interpretation.
ballarin
parents: 23957
diff changeset
   191
lemma UNIV:
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   192
  "x \<in> UNIV \<longleftrightarrow> True"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   193
  "A \<subseteq> UNIV \<longleftrightarrow> True"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   194
  "(\<forall>x \<in> UNIV. P x) \<longleftrightarrow> (\<forall>x. P x)"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   195
  "(EX x : UNIV. P x) \<longleftrightarrow> (EX x. P x)"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   196
  "(True \<longrightarrow> Q) \<longleftrightarrow> Q"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   197
  "(True \<Longrightarrow> PROP R) \<equiv> PROP R"
24131
1099f6c73649 Experimental removal of assumptions of the form x : UNIV and the like after interpretation.
ballarin
parents: 23957
diff changeset
   198
  by simp_all
1099f6c73649 Experimental removal of assumptions of the form x : UNIV and the like after interpretation.
ballarin
parents: 23957
diff changeset
   199
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   200
interpretation int (* FIXME [unfolded UNIV] *) :
55926
3ef14caf5637 more symbols;
wenzelm
parents: 55242
diff changeset
   201
  partial_order "\<lparr>carrier = UNIV::int set, eq = op =, le = op \<le>\<rparr>"
3ef14caf5637 more symbols;
wenzelm
parents: 55242
diff changeset
   202
  where "carrier \<lparr>carrier = UNIV::int set, eq = op =, le = op \<le>\<rparr> = UNIV"
3ef14caf5637 more symbols;
wenzelm
parents: 55242
diff changeset
   203
    and "le \<lparr>carrier = UNIV::int set, eq = op =, le = op \<le>\<rparr> x y = (x \<le> y)"
3ef14caf5637 more symbols;
wenzelm
parents: 55242
diff changeset
   204
    and "lless \<lparr>carrier = UNIV::int set, eq = op =, le = op \<le>\<rparr> x y = (x < y)"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   205
proof -
55926
3ef14caf5637 more symbols;
wenzelm
parents: 55242
diff changeset
   206
  show "partial_order \<lparr>carrier = UNIV::int set, eq = op =, le = op \<le>\<rparr>"
44655
fe0365331566 tuned proofs;
wenzelm
parents: 41433
diff changeset
   207
    by default simp_all
55926
3ef14caf5637 more symbols;
wenzelm
parents: 55242
diff changeset
   208
  show "carrier \<lparr>carrier = UNIV::int set, eq = op =, le = op \<le>\<rparr> = UNIV"
24131
1099f6c73649 Experimental removal of assumptions of the form x : UNIV and the like after interpretation.
ballarin
parents: 23957
diff changeset
   209
    by simp
55926
3ef14caf5637 more symbols;
wenzelm
parents: 55242
diff changeset
   210
  show "le \<lparr>carrier = UNIV::int set, eq = op =, le = op \<le>\<rparr> x y = (x \<le> y)"
24131
1099f6c73649 Experimental removal of assumptions of the form x : UNIV and the like after interpretation.
ballarin
parents: 23957
diff changeset
   211
    by simp
55926
3ef14caf5637 more symbols;
wenzelm
parents: 55242
diff changeset
   212
  show "lless \<lparr>carrier = UNIV::int set, eq = op =, le = op \<le>\<rparr> x y = (x < y)"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   213
    by (simp add: lless_def) auto
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   214
qed
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   215
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   216
interpretation int (* FIXME [unfolded UNIV] *) :
55926
3ef14caf5637 more symbols;
wenzelm
parents: 55242
diff changeset
   217
  lattice "\<lparr>carrier = UNIV::int set, eq = op =, le = op \<le>\<rparr>"
3ef14caf5637 more symbols;
wenzelm
parents: 55242
diff changeset
   218
  where "join \<lparr>carrier = UNIV::int set, eq = op =, le = op \<le>\<rparr> x y = max x y"
3ef14caf5637 more symbols;
wenzelm
parents: 55242
diff changeset
   219
    and "meet \<lparr>carrier = UNIV::int set, eq = op =, le = op \<le>\<rparr> x y = min x y"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   220
proof -
55926
3ef14caf5637 more symbols;
wenzelm
parents: 55242
diff changeset
   221
  let ?Z = "\<lparr>carrier = UNIV::int set, eq = op =, le = op \<le>\<rparr>"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   222
  show "lattice ?Z"
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   223
    apply unfold_locales
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   224
    apply (simp add: least_def Upper_def)
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   225
    apply arith
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   226
    apply (simp add: greatest_def Lower_def)
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   227
    apply arith
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   228
    done
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   229
  then interpret int: lattice "?Z" .
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   230
  show "join ?Z x y = max x y"
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   231
    apply (rule int.joinI)
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   232
    apply (simp_all add: least_def Upper_def)
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   233
    apply arith
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   234
    done
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   235
  show "meet ?Z x y = min x y"
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   236
    apply (rule int.meetI)
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   237
    apply (simp_all add: greatest_def Lower_def)
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   238
    apply arith
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   239
    done
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   240
qed
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   241
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   242
interpretation int (* [unfolded UNIV] *) :
55926
3ef14caf5637 more symbols;
wenzelm
parents: 55242
diff changeset
   243
  total_order "\<lparr>carrier = UNIV::int set, eq = op =, le = op \<le>\<rparr>"
44655
fe0365331566 tuned proofs;
wenzelm
parents: 41433
diff changeset
   244
  by default clarsimp
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   245
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   246
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
   247
subsection {* Generated Ideals of @{text "\<Z>"} *}
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   248
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   249
lemma int_Idl: "Idl\<^bsub>\<Z>\<^esub> {a} = {x * a | x. True}"
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   250
  apply (subst int.cgenideal_eq_genideal[symmetric]) apply simp
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   251
  apply (simp add: cgenideal_def)
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   252
  done
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   253
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   254
lemma multiples_principalideal: "principalideal {x * a | x. True } \<Z>"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   255
  by (metis UNIV_I int.cgenideal_eq_genideal int.cgenideal_is_principalideal int_Idl)
29700
22faf21db3df added some simp rules
nipkow
parents: 29424
diff changeset
   256
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   257
lemma prime_primeideal:
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55157
diff changeset
   258
  assumes prime: "prime p"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   259
  shows "primeideal (Idl\<^bsub>\<Z>\<^esub> {p}) \<Z>"
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   260
apply (rule primeidealI)
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   261
   apply (rule int.genideal_ideal, simp)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   262
  apply (rule int_is_cring)
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   263
 apply (simp add: int.cgenideal_eq_genideal[symmetric] cgenideal_def)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   264
 apply clarsimp defer 1
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   265
 apply (simp add: int.cgenideal_eq_genideal[symmetric] cgenideal_def)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   266
 apply (elim exE)
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   267
proof -
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   268
  fix a b x
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55157
diff changeset
   269
  assume "a * b = x * int p"
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   270
  then have "p dvd a * b" by simp
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   271
  then have "p dvd a \<or> p dvd b"
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55157
diff changeset
   272
    by (metis prime prime_dvd_mult_eq_int)
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   273
  then show "(\<exists>x. a = x * int p) \<or> (\<exists>x. b = x * int p)"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55991
diff changeset
   274
    by (metis dvd_def mult.commute)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   275
next
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55157
diff changeset
   276
  assume "UNIV = {uu. EX x. uu = x * int p}"
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55157
diff changeset
   277
  then obtain x where "1 = x * int p" by best
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55991
diff changeset
   278
  then have "\<bar>int p * x\<bar> = 1" by (simp add: mult.commute)
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55157
diff changeset
   279
  then show False
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55157
diff changeset
   280
    by (metis abs_of_nat int_1 of_nat_eq_iff abs_zmult_eq_1 one_not_prime_nat prime)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   281
qed
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   282
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   283
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
   284
subsection {* Ideals and Divisibility *}
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   285
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   286
lemma int_Idl_subset_ideal: "Idl\<^bsub>\<Z>\<^esub> {k} \<subseteq> Idl\<^bsub>\<Z>\<^esub> {l} = (k \<in> Idl\<^bsub>\<Z>\<^esub> {l})"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   287
  by (rule int.Idl_subset_ideal') simp_all
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   288
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   289
lemma Idl_subset_eq_dvd: "Idl\<^bsub>\<Z>\<^esub> {k} \<subseteq> Idl\<^bsub>\<Z>\<^esub> {l} \<longleftrightarrow> l dvd k"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   290
  apply (subst int_Idl_subset_ideal, subst int_Idl, simp)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   291
  apply (rule, clarify)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   292
  apply (simp add: dvd_def)
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   293
  apply (simp add: dvd_def ac_simps)
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   294
  done
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   295
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   296
lemma dvds_eq_Idl: "l dvd k \<and> k dvd l \<longleftrightarrow> Idl\<^bsub>\<Z>\<^esub> {k} = Idl\<^bsub>\<Z>\<^esub> {l}"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   297
proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   298
  have a: "l dvd k \<longleftrightarrow> (Idl\<^bsub>\<Z>\<^esub> {k} \<subseteq> Idl\<^bsub>\<Z>\<^esub> {l})"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   299
    by (rule Idl_subset_eq_dvd[symmetric])
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   300
  have b: "k dvd l \<longleftrightarrow> (Idl\<^bsub>\<Z>\<^esub> {l} \<subseteq> Idl\<^bsub>\<Z>\<^esub> {k})"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   301
    by (rule Idl_subset_eq_dvd[symmetric])
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   302
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   303
  have "l dvd k \<and> k dvd l \<longleftrightarrow> Idl\<^bsub>\<Z>\<^esub> {k} \<subseteq> Idl\<^bsub>\<Z>\<^esub> {l} \<and> Idl\<^bsub>\<Z>\<^esub> {l} \<subseteq> Idl\<^bsub>\<Z>\<^esub> {k}"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   304
    by (subst a, subst b, simp)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   305
  also have "Idl\<^bsub>\<Z>\<^esub> {k} \<subseteq> Idl\<^bsub>\<Z>\<^esub> {l} \<and> Idl\<^bsub>\<Z>\<^esub> {l} \<subseteq> Idl\<^bsub>\<Z>\<^esub> {k} \<longleftrightarrow> Idl\<^bsub>\<Z>\<^esub> {k} = Idl\<^bsub>\<Z>\<^esub> {l}"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   306
    by blast
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   307
  finally show ?thesis .
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   308
qed
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   309
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   310
lemma Idl_eq_abs: "Idl\<^bsub>\<Z>\<^esub> {k} = Idl\<^bsub>\<Z>\<^esub> {l} \<longleftrightarrow> abs l = abs k"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   311
  apply (subst dvds_eq_abseq[symmetric])
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   312
  apply (rule dvds_eq_Idl[symmetric])
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   313
  done
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   314
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   315
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
   316
subsection {* Ideals and the Modulus *}
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   317
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   318
definition ZMod :: "int \<Rightarrow> int \<Rightarrow> int set"
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35416
diff changeset
   319
  where "ZMod k r = (Idl\<^bsub>\<Z>\<^esub> {k}) +>\<^bsub>\<Z>\<^esub> r"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   320
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   321
lemmas ZMod_defs =
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   322
  ZMod_def genideal_def
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   323
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   324
lemma rcos_zfact:
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   325
  assumes kIl: "k \<in> ZMod l r"
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   326
  shows "\<exists>x. k = x * l + r"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   327
proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   328
  from kIl[unfolded ZMod_def] have "\<exists>xl\<in>Idl\<^bsub>\<Z>\<^esub> {l}. k = xl + r"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   329
    by (simp add: a_r_coset_defs)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   330
  then obtain xl where xl: "xl \<in> Idl\<^bsub>\<Z>\<^esub> {l}" and k: "k = xl + r"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   331
    by auto
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   332
  from xl obtain x where "xl = x * l"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   333
    by (auto simp: int_Idl)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   334
  with k have "k = x * l + r"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   335
    by simp
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   336
  then show "\<exists>x. k = x * l + r" ..
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   337
qed
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   338
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   339
lemma ZMod_imp_zmod:
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   340
  assumes zmods: "ZMod m a = ZMod m b"
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   341
  shows "a mod m = b mod m"
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   342
proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   343
  interpret ideal "Idl\<^bsub>\<Z>\<^esub> {m}" \<Z>
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   344
    by (rule int.genideal_ideal) fast
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   345
  from zmods have "b \<in> ZMod m a"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   346
    unfolding ZMod_def by (simp add: a_repr_independenceD)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   347
  then have "\<exists>x. b = x * m + a"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   348
    by (rule rcos_zfact)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   349
  then obtain x where "b = x * m + a"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   350
    by fast
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   351
  then have "b mod m = (x * m + a) mod m"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   352
    by simp
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   353
  also have "\<dots> = ((x * m) mod m) + (a mod m)"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   354
    by (simp add: mod_add_eq)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   355
  also have "\<dots> = a mod m"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   356
    by simp
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   357
  finally have "b mod m = a mod m" .
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   358
  then show "a mod m = b mod m" ..
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   359
qed
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   360
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   361
lemma ZMod_mod: "ZMod m a = ZMod m (a mod m)"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   362
proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   363
  interpret ideal "Idl\<^bsub>\<Z>\<^esub> {m}" \<Z>
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   364
    by (rule int.genideal_ideal) fast
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   365
  show ?thesis
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   366
    unfolding ZMod_def
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   367
    apply (rule a_repr_independence'[symmetric])
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   368
    apply (simp add: int_Idl a_r_coset_defs)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   369
  proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   370
    have "a = m * (a div m) + (a mod m)"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   371
      by (simp add: zmod_zdiv_equality)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   372
    then have "a = (a div m) * m + (a mod m)"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   373
      by simp
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   374
    then show "\<exists>h. (\<exists>x. h = x * m) \<and> a = h + a mod m"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   375
      by fast
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   376
  qed simp
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   377
qed
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   378
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   379
lemma zmod_imp_ZMod:
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   380
  assumes modeq: "a mod m = b mod m"
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   381
  shows "ZMod m a = ZMod m b"
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   382
proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   383
  have "ZMod m a = ZMod m (a mod m)"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   384
    by (rule ZMod_mod)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   385
  also have "\<dots> = ZMod m (b mod m)"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   386
    by (simp add: modeq[symmetric])
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   387
  also have "\<dots> = ZMod m b"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   388
    by (rule ZMod_mod[symmetric])
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   389
  finally show ?thesis .
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   390
qed
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   391
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   392
corollary ZMod_eq_mod: "ZMod m a = ZMod m b \<longleftrightarrow> a mod m = b mod m"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   393
  apply (rule iffI)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   394
  apply (erule ZMod_imp_zmod)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   395
  apply (erule zmod_imp_ZMod)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   396
  done
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   397
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   398
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
   399
subsection {* Factorization *}
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   400
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   401
definition ZFact :: "int \<Rightarrow> int set ring"
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35416
diff changeset
   402
  where "ZFact k = \<Z> Quot (Idl\<^bsub>\<Z>\<^esub> {k})"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   403
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   404
lemmas ZFact_defs = ZFact_def FactRing_def
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   405
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   406
lemma ZFact_is_cring: "cring (ZFact k)"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   407
  apply (unfold ZFact_def)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   408
  apply (rule ideal.quotient_is_cring)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   409
   apply (intro ring.genideal_ideal)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   410
    apply (simp add: cring.axioms[OF int_is_cring] ring.intro)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   411
   apply simp
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   412
  apply (rule int_is_cring)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   413
  done
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   414
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   415
lemma ZFact_zero: "carrier (ZFact 0) = (\<Union>a. {{a}})"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   416
  apply (insert int.genideal_zero)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   417
  apply (simp add: ZFact_defs A_RCOSETS_defs r_coset_def)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   418
  done
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   419
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   420
lemma ZFact_one: "carrier (ZFact 1) = {UNIV}"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   421
  apply (simp only: ZFact_defs A_RCOSETS_defs r_coset_def ring_record_simps)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   422
  apply (subst int.genideal_one)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   423
  apply (rule, rule, clarsimp)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   424
   apply (rule, rule, clarsimp)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   425
   apply (rule, clarsimp, arith)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   426
  apply (rule, clarsimp)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   427
  apply (rule exI[of _ "0"], clarsimp)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   428
  done
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   429
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   430
lemma ZFact_prime_is_domain:
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 55157
diff changeset
   431
  assumes pprime: "prime p"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   432
  shows "domain (ZFact p)"
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   433
  apply (unfold ZFact_def)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   434
  apply (rule primeideal.quotient_is_domain)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   435
  apply (rule prime_primeideal[OF pprime])
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   436
  done
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   437
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   438
end