src/HOL/Algebra/IntRing.thy
author nipkow
Sat, 14 Jun 2025 11:45:56 +0200
changeset 82704 e0fb46018187
parent 81438 95c9af7483b1
permissions -rw-r--r--
more minus_list lemmas (incl code via fold instead of foldr)
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
68399
0b71d08528f0 resolution of name clashes in Algebra
paulson <lp15@cam.ac.uk>
parents: 67443
diff changeset
     7
imports "HOL-Computational_Algebra.Primes" QuotRing Lattice 
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
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
    10
section \<open>The Ring of Integers\<close>
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    11
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 69064
diff changeset
    12
subsection \<open>Some properties of \<^typ>\<open>int\<close>\<close>
20318
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
61945
1135b8de26c3 more symbols;
wenzelm
parents: 61566
diff changeset
    16
  shows "l dvd k \<and> k dvd l \<longleftrightarrow> \<bar>l\<bar> = \<bar>k\<bar>"
68561
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
    17
  by (metis dvd_if_abs_eq lcm.commute lcm_proj1_iff_int)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    18
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    19
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62348
diff changeset
    20
subsection \<open>\<open>\<Z>\<close>: The Set of Integers as Algebraic Structure\<close>
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    21
80914
d97fdabd9e2b standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents: 69597
diff changeset
    22
abbreviation int_ring :: "int ring" (\<open>\<Z>\<close>)
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 68561
diff changeset
    23
  where "int_ring \<equiv> \<lparr>carrier = UNIV, mult = (*), one = 1, zero = 0, add = (+)\<rparr>"
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
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
    26
  by simp
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_is_cring: "cring \<Z>"
68561
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
    29
proof (rule cringI)
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
    30
  show "abelian_group \<Z>"
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
    31
    by (rule abelian_groupI) (auto intro: left_minus)
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
    32
  show "Group.comm_monoid \<Z>"
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
    33
    by (simp add: Group.monoid.intro monoid.monoid_comm_monoidI)
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
    34
qed (auto simp: distrib_right)
35849
b5522b51cb1e standard headers;
wenzelm
parents: 35848
diff changeset
    35
b5522b51cb1e standard headers;
wenzelm
parents: 35848
diff changeset
    36
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
    37
subsection \<open>Interpretations\<close>
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    38
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
    39
text \<open>Since definitions of derived operations are global, their
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    40
  interpretation needs to be done as early as possible --- that is,
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
    41
  with as few assumptions as possible.\<close>
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    42
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
    43
interpretation int: monoid \<Z>
61566
c3d6e570ccef Keyword 'rewrites' identifies rewrite morphisms.
ballarin
parents: 61382
diff changeset
    44
  rewrites "carrier \<Z> = UNIV"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    45
    and "mult \<Z> x y = x * y"
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    46
    and "one \<Z> = 1"
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    47
    and "pow \<Z> x n = x^n"
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    48
proof -
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67399
diff changeset
    49
  \<comment> \<open>Specification\<close>
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 60112
diff changeset
    50
  show "monoid \<Z>" by standard auto
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
    51
  then interpret int: monoid \<Z> .
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    52
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67399
diff changeset
    53
  \<comment> \<open>Carrier\<close>
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
    54
  show "carrier \<Z> = UNIV" by simp
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    55
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67399
diff changeset
    56
  \<comment> \<open>Operations\<close>
81438
95c9af7483b1 tuned proofs;
wenzelm
parents: 80914
diff changeset
    57
  show "mult \<Z> x y = x * y" for x y by simp
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
    58
  show "one \<Z> = 1" by simp
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
    59
  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
    60
qed
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    61
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
    62
interpretation int: comm_monoid \<Z>
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
    63
  rewrites "finprod \<Z> f A = prod f A"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    64
proof -
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67399
diff changeset
    65
  \<comment> \<open>Specification\<close>
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 60112
diff changeset
    66
  show "comm_monoid \<Z>" by standard auto
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
    67
  then interpret int: comm_monoid \<Z> .
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    68
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67399
diff changeset
    69
  \<comment> \<open>Operations\<close>
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
    70
  show "finprod \<Z> f A = prod f A"
81438
95c9af7483b1 tuned proofs;
wenzelm
parents: 80914
diff changeset
    71
    by (induct A rule: infinite_finite_induct) auto
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    72
qed
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    73
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
    74
interpretation int: abelian_monoid \<Z>
61566
c3d6e570ccef Keyword 'rewrites' identifies rewrite morphisms.
ballarin
parents: 61382
diff changeset
    75
  rewrites int_carrier_eq: "carrier \<Z> = UNIV"
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
    76
    and int_zero_eq: "zero \<Z> = 0"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
    77
    and int_add_eq: "add \<Z> x y = x + y"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 64246
diff changeset
    78
    and int_finsum_eq: "finsum \<Z> f A = sum f A"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    79
proof -
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67399
diff changeset
    80
  \<comment> \<open>Specification\<close>
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 60112
diff changeset
    81
  show "abelian_monoid \<Z>" by standard auto
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
    82
  then interpret int: abelian_monoid \<Z> .
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
    83
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67399
diff changeset
    84
  \<comment> \<open>Carrier\<close>
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
    85
  show "carrier \<Z> = UNIV" by simp
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
    86
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67399
diff changeset
    87
  \<comment> \<open>Operations\<close>
81438
95c9af7483b1 tuned proofs;
wenzelm
parents: 80914
diff changeset
    88
  show "add \<Z> x y = x + y" for x y by simp
95c9af7483b1 tuned proofs;
wenzelm
parents: 80914
diff changeset
    89
  show zero: "zero \<Z> = 0" by simp
64267
b9a1486e79be setsum -> sum
nipkow
parents: 64246
diff changeset
    90
  show "finsum \<Z> f A = sum f A"
81438
95c9af7483b1 tuned proofs;
wenzelm
parents: 80914
diff changeset
    91
    by (induct A rule: infinite_finite_induct) auto
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    92
qed
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
    93
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
    94
interpretation int: abelian_group \<Z>
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
    95
  (* 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
    96
     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
    97
     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
    98
  (* FIXME *)
61566
c3d6e570ccef Keyword 'rewrites' identifies rewrite morphisms.
ballarin
parents: 61382
diff changeset
    99
  rewrites "carrier \<Z> = UNIV"
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   100
    and "zero \<Z> = 0"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   101
    and "add \<Z> x y = x + y"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 64246
diff changeset
   102
    and "finsum \<Z> f A = sum f A"
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   103
    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
   104
    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
   105
proof -
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67399
diff changeset
   106
  \<comment> \<open>Specification\<close>
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   107
  show "abelian_group \<Z>"
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   108
  proof (rule abelian_groupI)
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   109
    fix x
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   110
    assume "x \<in> carrier \<Z>"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   111
    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
   112
      by simp arith
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   113
  qed auto
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   114
  then interpret int: abelian_group \<Z> .
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67399
diff changeset
   115
  \<comment> \<open>Operations\<close>
81438
95c9af7483b1 tuned proofs;
wenzelm
parents: 80914
diff changeset
   116
  have add: "add \<Z> x y = x + y" for x y by simp
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   117
  have zero: "zero \<Z> = 0" by simp
81438
95c9af7483b1 tuned proofs;
wenzelm
parents: 80914
diff changeset
   118
  show a_inv: "a_inv \<Z> x = - x" for x
95c9af7483b1 tuned proofs;
wenzelm
parents: 80914
diff changeset
   119
  proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   120
    have "add \<Z> (- x) x = zero \<Z>"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   121
      by (simp add: add zero)
81438
95c9af7483b1 tuned proofs;
wenzelm
parents: 80914
diff changeset
   122
    then show ?thesis
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   123
      by (simp add: int.minus_equality)
81438
95c9af7483b1 tuned proofs;
wenzelm
parents: 80914
diff changeset
   124
  qed
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   125
  show "a_minus \<Z> x y = x - y"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   126
    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
   127
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
   128
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   129
interpretation int: "domain" \<Z>
61566
c3d6e570ccef Keyword 'rewrites' identifies rewrite morphisms.
ballarin
parents: 61382
diff changeset
   130
  rewrites "carrier \<Z> = UNIV"
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   131
    and "zero \<Z> = 0"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   132
    and "add \<Z> x y = x + y"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 64246
diff changeset
   133
    and "finsum \<Z> f A = sum f A"
41433
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   134
    and "a_inv \<Z> x = - x"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   135
    and "a_minus \<Z> x y = x - y"
1b8ff770f02c Abelian group facts obtained from group facts via interpretation (sublocale).
ballarin
parents: 35849
diff changeset
   136
proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   137
  show "domain \<Z>"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   138
    by unfold_locales (auto simp: distrib_right distrib_left)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   139
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
   140
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   141
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 69064
diff changeset
   142
text \<open>Removal of occurrences of \<^term>\<open>UNIV\<close> in interpretation result
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   143
  --- experimental.\<close>
24131
1099f6c73649 Experimental removal of assumptions of the form x : UNIV and the like after interpretation.
ballarin
parents: 23957
diff changeset
   144
1099f6c73649 Experimental removal of assumptions of the form x : UNIV and the like after interpretation.
ballarin
parents: 23957
diff changeset
   145
lemma UNIV:
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   146
  "x \<in> UNIV \<longleftrightarrow> True"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   147
  "A \<subseteq> UNIV \<longleftrightarrow> True"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   148
  "(\<forall>x \<in> UNIV. P x) \<longleftrightarrow> (\<forall>x. P x)"
67091
1393c2340eec more symbols;
wenzelm
parents: 67006
diff changeset
   149
  "(\<exists>x \<in> UNIV. P x) \<longleftrightarrow> (\<exists>x. P x)"
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   150
  "(True \<longrightarrow> Q) \<longleftrightarrow> Q"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   151
  "(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
   152
  by simp_all
1099f6c73649 Experimental removal of assumptions of the form x : UNIV and the like after interpretation.
ballarin
parents: 23957
diff changeset
   153
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   154
interpretation int (* FIXME [unfolded UNIV] *) :
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67396
diff changeset
   155
  partial_order "\<lparr>carrier = UNIV::int set, eq = (=), le = (\<le>)\<rparr>"
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67396
diff changeset
   156
  rewrites "carrier \<lparr>carrier = UNIV::int set, eq = (=), le = (\<le>)\<rparr> = UNIV"
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67396
diff changeset
   157
    and "le \<lparr>carrier = UNIV::int set, eq = (=), le = (\<le>)\<rparr> x y = (x \<le> y)"
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67396
diff changeset
   158
    and "lless \<lparr>carrier = UNIV::int set, eq = (=), le = (\<le>)\<rparr> x y = (x < y)"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   159
proof -
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67396
diff changeset
   160
  show "partial_order \<lparr>carrier = UNIV::int set, eq = (=), le = (\<le>)\<rparr>"
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 60112
diff changeset
   161
    by standard simp_all
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67396
diff changeset
   162
  show "carrier \<lparr>carrier = UNIV::int set, eq = (=), le = (\<le>)\<rparr> = UNIV"
24131
1099f6c73649 Experimental removal of assumptions of the form x : UNIV and the like after interpretation.
ballarin
parents: 23957
diff changeset
   163
    by simp
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67396
diff changeset
   164
  show "le \<lparr>carrier = UNIV::int set, eq = (=), le = (\<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
   165
    by simp
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67396
diff changeset
   166
  show "lless \<lparr>carrier = UNIV::int set, eq = (=), le = (\<le>)\<rparr> x y = (x < y)"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   167
    by (simp add: lless_def) auto
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   168
qed
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   169
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   170
interpretation int (* FIXME [unfolded UNIV] *) :
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67396
diff changeset
   171
  lattice "\<lparr>carrier = UNIV::int set, eq = (=), le = (\<le>)\<rparr>"
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67396
diff changeset
   172
  rewrites "join \<lparr>carrier = UNIV::int set, eq = (=), le = (\<le>)\<rparr> x y = max x y"
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67396
diff changeset
   173
    and "meet \<lparr>carrier = UNIV::int set, eq = (=), le = (\<le>)\<rparr> x y = min x y"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   174
proof -
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67396
diff changeset
   175
  let ?Z = "\<lparr>carrier = UNIV::int set, eq = (=), le = (\<le>)\<rparr>"
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   176
  show "lattice ?Z"
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   177
    apply unfold_locales
68561
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   178
    apply (simp_all add: least_def Upper_def greatest_def Lower_def)
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   179
    apply arith+
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   180
    done
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   181
  then interpret int: lattice "?Z" .
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   182
  show "join ?Z x y = max x y"
68561
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   183
    by (metis int.le_iff_meet iso_tuple_UNIV_I join_comm linear max.absorb_iff2 max_def)
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   184
  show "meet ?Z x y = min x y"
68561
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   185
    using int.meet_le int.meet_left int.meet_right by auto
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   186
qed
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   187
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 29948
diff changeset
   188
interpretation int (* [unfolded UNIV] *) :
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67396
diff changeset
   189
  total_order "\<lparr>carrier = UNIV::int set, eq = (=), le = (\<le>)\<rparr>"
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 60112
diff changeset
   190
  by standard clarsimp
23957
54fab60ddc97 Interpretation of rings (as integers) maps defined operations to defined
ballarin
parents: 22063
diff changeset
   191
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   192
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62348
diff changeset
   193
subsection \<open>Generated Ideals of \<open>\<Z>\<close>\<close>
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   194
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   195
lemma int_Idl: "Idl\<^bsub>\<Z>\<^esub> {a} = {x * a | x. True}"
68561
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   196
  by (simp_all add: cgenideal_def int.cgenideal_eq_genideal[symmetric])
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   197
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   198
lemma multiples_principalideal: "principalideal {x * a | x. True } \<Z>"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   199
  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
   200
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   201
lemma prime_primeideal:
68399
0b71d08528f0 resolution of name clashes in Algebra
paulson <lp15@cam.ac.uk>
parents: 67443
diff changeset
   202
  assumes prime: "Factorial_Ring.prime p"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   203
  shows "primeideal (Idl\<^bsub>\<Z>\<^esub> {p}) \<Z>"
68561
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   204
proof (rule primeidealI)
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   205
  show "ideal (Idl\<^bsub>\<Z>\<^esub> {p}) \<Z>"
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   206
    by (rule int.genideal_ideal, simp)
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   207
  show "cring \<Z>"
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   208
    by (rule int_is_cring)
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   209
  have False if "UNIV = {v::int. \<exists>x. v = x * p}"
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   210
  proof -
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   211
    from that
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   212
    obtain i where "1 = i * p"
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   213
      by (blast intro:  elim: )
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   214
    then show False
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   215
      using prime by (auto simp add: abs_mult zmult_eq_1_iff)
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   216
  qed
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   217
  then show "carrier \<Z> \<noteq> Idl\<^bsub>\<Z>\<^esub> {p}"
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   218
    by (auto simp add: int.cgenideal_eq_genideal[symmetric] cgenideal_def)
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   219
  have "p dvd a \<or> p dvd b" if "a * b = x * p" for a b x
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   220
    by (simp add: prime prime_dvd_multD that)
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   221
  then show "\<And>a b. \<lbrakk>a \<in> carrier \<Z>; b \<in> carrier \<Z>; a \<otimes>\<^bsub>\<Z>\<^esub> b \<in> Idl\<^bsub>\<Z>\<^esub> {p}\<rbrakk>
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   222
           \<Longrightarrow> a \<in> Idl\<^bsub>\<Z>\<^esub> {p} \<or> b \<in> Idl\<^bsub>\<Z>\<^esub> {p}"
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   223
    by (auto simp add: int.cgenideal_eq_genideal[symmetric] cgenideal_def dvd_def mult.commute)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   224
qed
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   225
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   226
subsection \<open>Ideals and Divisibility\<close>
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   227
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   228
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
   229
  by (rule int.Idl_subset_ideal') simp_all
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   230
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   231
lemma Idl_subset_eq_dvd: "Idl\<^bsub>\<Z>\<^esub> {k} \<subseteq> Idl\<^bsub>\<Z>\<^esub> {l} \<longleftrightarrow> l dvd k"
68561
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   232
  by (subst int_Idl_subset_ideal) (auto simp: dvd_def int_Idl)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   233
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   234
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
   235
proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   236
  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
   237
    by (rule Idl_subset_eq_dvd[symmetric])
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   238
  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
   239
    by (rule Idl_subset_eq_dvd[symmetric])
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   240
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   241
  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
   242
    by (subst a, subst b, simp)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   243
  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
   244
    by blast
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   245
  finally show ?thesis .
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   246
qed
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   247
61945
1135b8de26c3 more symbols;
wenzelm
parents: 61566
diff changeset
   248
lemma Idl_eq_abs: "Idl\<^bsub>\<Z>\<^esub> {k} = Idl\<^bsub>\<Z>\<^esub> {l} \<longleftrightarrow> \<bar>l\<bar> = \<bar>k\<bar>"
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   249
  apply (subst dvds_eq_abseq[symmetric])
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   250
  apply (rule dvds_eq_Idl[symmetric])
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   251
  done
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   252
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   253
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   254
subsection \<open>Ideals and the Modulus\<close>
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   255
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   256
definition ZMod :: "int \<Rightarrow> int \<Rightarrow> int set"
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35416
diff changeset
   257
  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
   258
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   259
lemmas ZMod_defs =
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   260
  ZMod_def genideal_def
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   261
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   262
lemma rcos_zfact:
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   263
  assumes kIl: "k \<in> ZMod l r"
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   264
  shows "\<exists>x. k = x * l + r"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   265
proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   266
  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
   267
    by (simp add: a_r_coset_defs)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   268
  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
   269
    by auto
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   270
  from xl obtain x where "xl = x * l"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   271
    by (auto simp: int_Idl)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   272
  with k have "k = x * l + r"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   273
    by simp
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   274
  then show "\<exists>x. k = x * l + r" ..
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   275
qed
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   276
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   277
lemma ZMod_imp_zmod:
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   278
  assumes zmods: "ZMod m a = ZMod m b"
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   279
  shows "a mod m = b mod m"
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   280
proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   281
  interpret ideal "Idl\<^bsub>\<Z>\<^esub> {m}" \<Z>
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   282
    by (rule int.genideal_ideal) fast
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   283
  from zmods have "b \<in> ZMod m a"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   284
    unfolding ZMod_def by (simp add: a_repr_independenceD)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   285
  then have "\<exists>x. b = x * m + a"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   286
    by (rule rcos_zfact)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   287
  then obtain x where "b = x * m + a"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   288
    by fast
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   289
  then have "b mod m = (x * m + a) mod m"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   290
    by simp
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   291
  also have "\<dots> = ((x * m) mod m) + (a mod m)"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   292
    by (simp add: mod_add_eq)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   293
  also have "\<dots> = a mod m"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   294
    by simp
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   295
  finally have "b mod m = a mod m" .
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   296
  then show "a mod m = b mod m" ..
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   297
qed
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   298
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   299
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
   300
proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   301
  interpret ideal "Idl\<^bsub>\<Z>\<^esub> {m}" \<Z>
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   302
    by (rule int.genideal_ideal) fast
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   303
  show ?thesis
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   304
    unfolding ZMod_def
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   305
    apply (rule a_repr_independence'[symmetric])
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   306
    apply (simp add: int_Idl a_r_coset_defs)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   307
  proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   308
    have "a = m * (a div m) + (a mod m)"
64246
15d1ee6e847b eliminated irregular aliasses
haftmann
parents: 63633
diff changeset
   309
      by (simp add: mult_div_mod_eq [symmetric])
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   310
    then have "a = (a div m) * m + (a mod m)"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   311
      by simp
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   312
    then show "\<exists>h. (\<exists>x. h = x * m) \<and> a = h + a mod m"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   313
      by fast
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   314
  qed simp
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   315
qed
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   316
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   317
lemma zmod_imp_ZMod:
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   318
  assumes modeq: "a mod m = b mod m"
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   319
  shows "ZMod m a = ZMod m b"
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   320
proof -
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   321
  have "ZMod m a = ZMod m (a mod m)"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   322
    by (rule ZMod_mod)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   323
  also have "\<dots> = ZMod m (b mod m)"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   324
    by (simp add: modeq[symmetric])
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   325
  also have "\<dots> = ZMod m b"
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   326
    by (rule ZMod_mod[symmetric])
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   327
  finally show ?thesis .
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   328
qed
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   329
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   330
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
   331
  apply (rule iffI)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   332
  apply (erule ZMod_imp_zmod)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   333
  apply (erule zmod_imp_ZMod)
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   334
  done
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   335
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   336
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   337
subsection \<open>Factorization\<close>
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   338
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   339
definition ZFact :: "int \<Rightarrow> int set ring"
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35416
diff changeset
   340
  where "ZFact k = \<Z> Quot (Idl\<^bsub>\<Z>\<^esub> {k})"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   341
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   342
lemmas ZFact_defs = ZFact_def FactRing_def
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   343
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   344
lemma ZFact_is_cring: "cring (ZFact k)"
68561
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   345
  by (simp add: ZFact_def ideal.quotient_is_cring int.cring_axioms int.genideal_ideal)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   346
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   347
lemma ZFact_zero: "carrier (ZFact 0) = (\<Union>a. {{a}})"
68561
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   348
  by (simp add: ZFact_defs A_RCOSETS_defs r_coset_def int.genideal_zero)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   349
55991
3fa6e6c81788 tuned proofs;
wenzelm
parents: 55926
diff changeset
   350
lemma ZFact_one: "carrier (ZFact 1) = {UNIV}"
68561
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   351
  unfolding ZFact_defs A_RCOSETS_defs r_coset_def ring_record_simps int.genideal_one
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   352
proof
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   353
  have "\<And>a b::int. \<exists>x. b = x + a"
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   354
    by presburger
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   355
  then show "(\<Union>a::int. {\<Union>h. {h + a}}) \<subseteq> {UNIV}"
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   356
    by force
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   357
  then show "{UNIV} \<subseteq> (\<Union>a::int. {\<Union>h. {h + a}})"
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   358
    by (metis (no_types, lifting) UNIV_I UN_I singletonD singletonI subset_iff)
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   359
qed
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   360
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   361
lemma ZFact_prime_is_domain:
68399
0b71d08528f0 resolution of name clashes in Algebra
paulson <lp15@cam.ac.uk>
parents: 67443
diff changeset
   362
  assumes pprime: "Factorial_Ring.prime p"
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   363
  shows "domain (ZFact p)"
68561
5e85cda58af6 new lemmas, de-applying, etc.
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   364
  by (simp add: ZFact_def pprime prime_primeideal primeideal.quotient_is_domain)
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   365
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
diff changeset
   366
end