src/HOL/Library/Polynomial_Factorial.thy
author wenzelm
Wed, 08 Mar 2017 10:50:59 +0100
changeset 65151 a7394aa4d21c
parent 64911 f0e07600de47
child 65366 10ca63a18e56
permissions -rw-r--r--
tuned proofs;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
63764
f3ad26c4b2d9 tuned headers;
wenzelm
parents: 63722
diff changeset
     1
(*  Title:      HOL/Library/Polynomial_Factorial.thy
f3ad26c4b2d9 tuned headers;
wenzelm
parents: 63722
diff changeset
     2
    Author:     Brian Huffman
f3ad26c4b2d9 tuned headers;
wenzelm
parents: 63722
diff changeset
     3
    Author:     Clemens Ballarin
f3ad26c4b2d9 tuned headers;
wenzelm
parents: 63722
diff changeset
     4
    Author:     Amine Chaieb
f3ad26c4b2d9 tuned headers;
wenzelm
parents: 63722
diff changeset
     5
    Author:     Florian Haftmann
f3ad26c4b2d9 tuned headers;
wenzelm
parents: 63722
diff changeset
     6
    Author:     Manuel Eberl
f3ad26c4b2d9 tuned headers;
wenzelm
parents: 63722
diff changeset
     7
*)
f3ad26c4b2d9 tuned headers;
wenzelm
parents: 63722
diff changeset
     8
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
     9
theory Polynomial_Factorial
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    10
imports 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    11
  Complex_Main
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    12
  "~~/src/HOL/Library/Polynomial"
63500
0dac030afd36 Added normalized fractions
eberlm <eberlm@in.tum.de>
parents: 63499
diff changeset
    13
  "~~/src/HOL/Library/Normalized_Fraction"
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    14
  "~~/src/HOL/Library/Field_as_Ring"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    15
begin
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    16
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    17
subsection \<open>Various facts about polynomials\<close>
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    18
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    19
lemma prod_mset_const_poly: "prod_mset (image_mset (\<lambda>x. [:f x:]) A) = [:prod_mset (image_mset f A):]"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    20
  by (induction A) (simp_all add: one_poly_def mult_ac)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    21
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    22
lemma irreducible_const_poly_iff:
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    23
  fixes c :: "'a :: {comm_semiring_1,semiring_no_zero_divisors}"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    24
  shows "irreducible [:c:] \<longleftrightarrow> irreducible c"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    25
proof
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    26
  assume A: "irreducible c"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    27
  show "irreducible [:c:]"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    28
  proof (rule irreducibleI)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    29
    fix a b assume ab: "[:c:] = a * b"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    30
    hence "degree [:c:] = degree (a * b)" by (simp only: )
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    31
    also from A ab have "a \<noteq> 0" "b \<noteq> 0" by auto
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    32
    hence "degree (a * b) = degree a + degree b" by (simp add: degree_mult_eq)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    33
    finally have "degree a = 0" "degree b = 0" by auto
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    34
    then obtain a' b' where ab': "a = [:a':]" "b = [:b':]" by (auto elim!: degree_eq_zeroE)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    35
    from ab have "coeff [:c:] 0 = coeff (a * b) 0" by (simp only: )
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    36
    hence "c = a' * b'" by (simp add: ab' mult_ac)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    37
    from A and this have "a' dvd 1 \<or> b' dvd 1" by (rule irreducibleD)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    38
    with ab' show "a dvd 1 \<or> b dvd 1" by (auto simp: one_poly_def)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    39
  qed (insert A, auto simp: irreducible_def is_unit_poly_iff)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    40
next
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    41
  assume A: "irreducible [:c:]"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    42
  show "irreducible c"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    43
  proof (rule irreducibleI)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    44
    fix a b assume ab: "c = a * b"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    45
    hence "[:c:] = [:a:] * [:b:]" by (simp add: mult_ac)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    46
    from A and this have "[:a:] dvd 1 \<or> [:b:] dvd 1" by (rule irreducibleD)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    47
    thus "a dvd 1 \<or> b dvd 1" by (simp add: one_poly_def)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    48
  qed (insert A, auto simp: irreducible_def one_poly_def)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
    49
qed
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    50
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    51
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    52
subsection \<open>Lifting elements into the field of fractions\<close>
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    53
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    54
definition to_fract :: "'a :: idom \<Rightarrow> 'a fract" where "to_fract x = Fract x 1"
64911
f0e07600de47 isabelle update_cartouches -c -t;
wenzelm
parents: 64860
diff changeset
    55
  \<comment> \<open>FIXME: name \<open>of_idom\<close>, abbreviation\<close>
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    56
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    57
lemma to_fract_0 [simp]: "to_fract 0 = 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    58
  by (simp add: to_fract_def eq_fract Zero_fract_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    59
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    60
lemma to_fract_1 [simp]: "to_fract 1 = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    61
  by (simp add: to_fract_def eq_fract One_fract_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    62
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    63
lemma to_fract_add [simp]: "to_fract (x + y) = to_fract x + to_fract y"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    64
  by (simp add: to_fract_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    65
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    66
lemma to_fract_diff [simp]: "to_fract (x - y) = to_fract x - to_fract y"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    67
  by (simp add: to_fract_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    68
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    69
lemma to_fract_uminus [simp]: "to_fract (-x) = -to_fract x"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    70
  by (simp add: to_fract_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    71
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    72
lemma to_fract_mult [simp]: "to_fract (x * y) = to_fract x * to_fract y"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    73
  by (simp add: to_fract_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    74
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    75
lemma to_fract_eq_iff [simp]: "to_fract x = to_fract y \<longleftrightarrow> x = y"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    76
  by (simp add: to_fract_def eq_fract)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    77
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    78
lemma to_fract_eq_0_iff [simp]: "to_fract x = 0 \<longleftrightarrow> x = 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    79
  by (simp add: to_fract_def Zero_fract_def eq_fract)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    80
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    81
lemma snd_quot_of_fract_nonzero [simp]: "snd (quot_of_fract x) \<noteq> 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    82
  by transfer simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    83
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    84
lemma Fract_quot_of_fract [simp]: "Fract (fst (quot_of_fract x)) (snd (quot_of_fract x)) = x"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    85
  by transfer (simp del: fractrel_iff, subst fractrel_normalize_quot_left, simp)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    86
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    87
lemma to_fract_quot_of_fract:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    88
  assumes "snd (quot_of_fract x) = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    89
  shows   "to_fract (fst (quot_of_fract x)) = x"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    90
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    91
  have "x = Fract (fst (quot_of_fract x)) (snd (quot_of_fract x))" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    92
  also note assms
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    93
  finally show ?thesis by (simp add: to_fract_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    94
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    95
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    96
lemma snd_quot_of_fract_Fract_whole:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    97
  assumes "y dvd x"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    98
  shows   "snd (quot_of_fract (Fract x y)) = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    99
  using assms by transfer (auto simp: normalize_quot_def Let_def gcd_proj2_if_dvd)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   100
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   101
lemma Fract_conv_to_fract: "Fract a b = to_fract a / to_fract b"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   102
  by (simp add: to_fract_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   103
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   104
lemma quot_of_fract_to_fract [simp]: "quot_of_fract (to_fract x) = (x, 1)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   105
  unfolding to_fract_def by transfer (simp add: normalize_quot_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   106
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   107
lemma fst_quot_of_fract_eq_0_iff [simp]: "fst (quot_of_fract x) = 0 \<longleftrightarrow> x = 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   108
  by transfer simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   109
 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   110
lemma snd_quot_of_fract_to_fract [simp]: "snd (quot_of_fract (to_fract x)) = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   111
  unfolding to_fract_def by (rule snd_quot_of_fract_Fract_whole) simp_all
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   112
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   113
lemma coprime_quot_of_fract:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   114
  "coprime (fst (quot_of_fract x)) (snd (quot_of_fract x))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   115
  by transfer (simp add: coprime_normalize_quot)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   116
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   117
lemma unit_factor_snd_quot_of_fract: "unit_factor (snd (quot_of_fract x)) = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   118
  using quot_of_fract_in_normalized_fracts[of x] 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   119
  by (simp add: normalized_fracts_def case_prod_unfold)  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   120
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   121
lemma unit_factor_1_imp_normalized: "unit_factor x = 1 \<Longrightarrow> normalize x = x"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   122
  by (subst (2) normalize_mult_unit_factor [symmetric, of x])
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   123
     (simp del: normalize_mult_unit_factor)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   124
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   125
lemma normalize_snd_quot_of_fract: "normalize (snd (quot_of_fract x)) = snd (quot_of_fract x)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   126
  by (intro unit_factor_1_imp_normalized unit_factor_snd_quot_of_fract)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   127
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   128
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   129
subsection \<open>Lifting polynomial coefficients to the field of fractions\<close>
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   130
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   131
abbreviation (input) fract_poly 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   132
  where "fract_poly \<equiv> map_poly to_fract"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   133
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   134
abbreviation (input) unfract_poly 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   135
  where "unfract_poly \<equiv> map_poly (fst \<circ> quot_of_fract)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   136
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   137
lemma fract_poly_smult [simp]: "fract_poly (smult c p) = smult (to_fract c) (fract_poly p)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   138
  by (simp add: smult_conv_map_poly map_poly_map_poly o_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   139
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   140
lemma fract_poly_0 [simp]: "fract_poly 0 = 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   141
  by (simp add: poly_eqI coeff_map_poly)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   142
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   143
lemma fract_poly_1 [simp]: "fract_poly 1 = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   144
  by (simp add: one_poly_def map_poly_pCons)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   145
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   146
lemma fract_poly_add [simp]:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   147
  "fract_poly (p + q) = fract_poly p + fract_poly q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   148
  by (intro poly_eqI) (simp_all add: coeff_map_poly)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   149
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   150
lemma fract_poly_diff [simp]:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   151
  "fract_poly (p - q) = fract_poly p - fract_poly q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   152
  by (intro poly_eqI) (simp_all add: coeff_map_poly)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   153
64267
b9a1486e79be setsum -> sum
nipkow
parents: 64242
diff changeset
   154
lemma to_fract_sum [simp]: "to_fract (sum f A) = sum (\<lambda>x. to_fract (f x)) A"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   155
  by (cases "finite A", induction A rule: finite_induct) simp_all 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   156
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   157
lemma fract_poly_mult [simp]:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   158
  "fract_poly (p * q) = fract_poly p * fract_poly q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   159
  by (intro poly_eqI) (simp_all add: coeff_map_poly coeff_mult)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   160
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   161
lemma fract_poly_eq_iff [simp]: "fract_poly p = fract_poly q \<longleftrightarrow> p = q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   162
  by (auto simp: poly_eq_iff coeff_map_poly)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   163
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   164
lemma fract_poly_eq_0_iff [simp]: "fract_poly p = 0 \<longleftrightarrow> p = 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   165
  using fract_poly_eq_iff[of p 0] by (simp del: fract_poly_eq_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   166
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   167
lemma fract_poly_dvd: "p dvd q \<Longrightarrow> fract_poly p dvd fract_poly q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   168
  by (auto elim!: dvdE)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   169
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   170
lemma prod_mset_fract_poly: 
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   171
  "prod_mset (image_mset (\<lambda>x. fract_poly (f x)) A) = fract_poly (prod_mset (image_mset f A))"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   172
  by (induction A) (simp_all add: mult_ac)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   173
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   174
lemma is_unit_fract_poly_iff:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   175
  "p dvd 1 \<longleftrightarrow> fract_poly p dvd 1 \<and> content p = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   176
proof safe
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   177
  assume A: "p dvd 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   178
  with fract_poly_dvd[of p 1] show "is_unit (fract_poly p)" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   179
  from A show "content p = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   180
    by (auto simp: is_unit_poly_iff normalize_1_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   181
next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   182
  assume A: "fract_poly p dvd 1" and B: "content p = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   183
  from A obtain c where c: "fract_poly p = [:c:]" by (auto simp: is_unit_poly_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   184
  {
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   185
    fix n :: nat assume "n > 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   186
    have "to_fract (coeff p n) = coeff (fract_poly p) n" by (simp add: coeff_map_poly)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   187
    also note c
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   188
    also from \<open>n > 0\<close> have "coeff [:c:] n = 0" by (simp add: coeff_pCons split: nat.splits)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   189
    finally have "coeff p n = 0" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   190
  }
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   191
  hence "degree p \<le> 0" by (intro degree_le) simp_all
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   192
  with B show "p dvd 1" by (auto simp: is_unit_poly_iff normalize_1_iff elim!: degree_eq_zeroE)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   193
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   194
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   195
lemma fract_poly_is_unit: "p dvd 1 \<Longrightarrow> fract_poly p dvd 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   196
  using fract_poly_dvd[of p 1] by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   197
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   198
lemma fract_poly_smult_eqE:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   199
  fixes c :: "'a :: {idom_divide,ring_gcd} fract"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   200
  assumes "fract_poly p = smult c (fract_poly q)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   201
  obtains a b 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   202
    where "c = to_fract b / to_fract a" "smult a p = smult b q" "coprime a b" "normalize a = a"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   203
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   204
  define a b where "a = fst (quot_of_fract c)" and "b = snd (quot_of_fract c)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   205
  have "smult (to_fract a) (fract_poly q) = smult (to_fract b) (fract_poly p)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   206
    by (subst smult_eq_iff) (simp_all add: a_def b_def Fract_conv_to_fract [symmetric] assms)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   207
  hence "fract_poly (smult a q) = fract_poly (smult b p)" by (simp del: fract_poly_eq_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   208
  hence "smult b p = smult a q" by (simp only: fract_poly_eq_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   209
  moreover have "c = to_fract a / to_fract b" "coprime b a" "normalize b = b"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   210
    by (simp_all add: a_def b_def coprime_quot_of_fract gcd.commute
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   211
          normalize_snd_quot_of_fract Fract_conv_to_fract [symmetric])
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   212
  ultimately show ?thesis by (intro that[of a b])
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   213
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   214
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   215
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   216
subsection \<open>Fractional content\<close>
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   217
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   218
abbreviation (input) Lcm_coeff_denoms 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   219
    :: "'a :: {semiring_Gcd,idom_divide,ring_gcd} fract poly \<Rightarrow> 'a"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   220
  where "Lcm_coeff_denoms p \<equiv> Lcm (snd ` quot_of_fract ` set (coeffs p))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   221
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   222
definition fract_content :: 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   223
      "'a :: {factorial_semiring,semiring_Gcd,ring_gcd,idom_divide} fract poly \<Rightarrow> 'a fract" where
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   224
  "fract_content p = 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   225
     (let d = Lcm_coeff_denoms p in Fract (content (unfract_poly (smult (to_fract d) p))) d)" 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   226
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   227
definition primitive_part_fract :: 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   228
      "'a :: {factorial_semiring,semiring_Gcd,ring_gcd,idom_divide} fract poly \<Rightarrow> 'a poly" where
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   229
  "primitive_part_fract p = 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   230
     primitive_part (unfract_poly (smult (to_fract (Lcm_coeff_denoms p)) p))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   231
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   232
lemma primitive_part_fract_0 [simp]: "primitive_part_fract 0 = 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   233
  by (simp add: primitive_part_fract_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   234
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   235
lemma fract_content_eq_0_iff [simp]:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   236
  "fract_content p = 0 \<longleftrightarrow> p = 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   237
  unfolding fract_content_def Let_def Zero_fract_def
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   238
  by (subst eq_fract) (auto simp: Lcm_0_iff map_poly_eq_0_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   239
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   240
lemma content_primitive_part_fract [simp]: "p \<noteq> 0 \<Longrightarrow> content (primitive_part_fract p) = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   241
  unfolding primitive_part_fract_def
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   242
  by (rule content_primitive_part)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   243
     (auto simp: primitive_part_fract_def map_poly_eq_0_iff Lcm_0_iff)  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   244
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   245
lemma content_times_primitive_part_fract:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   246
  "smult (fract_content p) (fract_poly (primitive_part_fract p)) = p"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   247
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   248
  define p' where "p' = unfract_poly (smult (to_fract (Lcm_coeff_denoms p)) p)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   249
  have "fract_poly p' = 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   250
          map_poly (to_fract \<circ> fst \<circ> quot_of_fract) (smult (to_fract (Lcm_coeff_denoms p)) p)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   251
    unfolding primitive_part_fract_def p'_def 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   252
    by (subst map_poly_map_poly) (simp_all add: o_assoc)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   253
  also have "\<dots> = smult (to_fract (Lcm_coeff_denoms p)) p"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   254
  proof (intro map_poly_idI, unfold o_apply)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   255
    fix c assume "c \<in> set (coeffs (smult (to_fract (Lcm_coeff_denoms p)) p))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   256
    then obtain c' where c: "c' \<in> set (coeffs p)" "c = to_fract (Lcm_coeff_denoms p) * c'"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   257
      by (auto simp add: Lcm_0_iff coeffs_smult split: if_splits)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   258
    note c(2)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   259
    also have "c' = Fract (fst (quot_of_fract c')) (snd (quot_of_fract c'))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   260
      by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   261
    also have "to_fract (Lcm_coeff_denoms p) * \<dots> = 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   262
                 Fract (Lcm_coeff_denoms p * fst (quot_of_fract c')) (snd (quot_of_fract c'))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   263
      unfolding to_fract_def by (subst mult_fract) simp_all
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   264
    also have "snd (quot_of_fract \<dots>) = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   265
      by (intro snd_quot_of_fract_Fract_whole dvd_mult2 dvd_Lcm) (insert c(1), auto)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   266
    finally show "to_fract (fst (quot_of_fract c)) = c"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   267
      by (rule to_fract_quot_of_fract)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   268
  qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   269
  also have "p' = smult (content p') (primitive_part p')" 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   270
    by (rule content_times_primitive_part [symmetric])
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   271
  also have "primitive_part p' = primitive_part_fract p"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   272
    by (simp add: primitive_part_fract_def p'_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   273
  also have "fract_poly (smult (content p') (primitive_part_fract p)) = 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   274
               smult (to_fract (content p')) (fract_poly (primitive_part_fract p))" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   275
  finally have "smult (to_fract (content p')) (fract_poly (primitive_part_fract p)) =
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   276
                      smult (to_fract (Lcm_coeff_denoms p)) p" .
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   277
  thus ?thesis
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   278
    by (subst (asm) smult_eq_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   279
       (auto simp add: Let_def p'_def Fract_conv_to_fract field_simps Lcm_0_iff fract_content_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   280
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   281
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   282
lemma fract_content_fract_poly [simp]: "fract_content (fract_poly p) = to_fract (content p)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   283
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   284
  have "Lcm_coeff_denoms (fract_poly p) = 1"
63905
1c3dcb5fe6cb prefer abbreviation for trivial set conversion
haftmann
parents: 63830
diff changeset
   285
    by (auto simp: set_coeffs_map_poly)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   286
  hence "fract_content (fract_poly p) = 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   287
           to_fract (content (map_poly (fst \<circ> quot_of_fract \<circ> to_fract) p))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   288
    by (simp add: fract_content_def to_fract_def fract_collapse map_poly_map_poly del: Lcm_1_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   289
  also have "map_poly (fst \<circ> quot_of_fract \<circ> to_fract) p = p"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   290
    by (intro map_poly_idI) simp_all
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   291
  finally show ?thesis .
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   292
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   293
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   294
lemma content_decompose_fract:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   295
  fixes p :: "'a :: {factorial_semiring,semiring_Gcd,ring_gcd,idom_divide} fract poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   296
  obtains c p' where "p = smult c (map_poly to_fract p')" "content p' = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   297
proof (cases "p = 0")
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   298
  case True
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   299
  hence "p = smult 0 (map_poly to_fract 1)" "content 1 = 1" by simp_all
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   300
  thus ?thesis ..
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   301
next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   302
  case False
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   303
  thus ?thesis
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   304
    by (rule that[OF content_times_primitive_part_fract [symmetric] content_primitive_part_fract])
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   305
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   306
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   307
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   308
subsection \<open>More properties of content and primitive part\<close>
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   309
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   310
lemma lift_prime_elem_poly:
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   311
  assumes "prime_elem (c :: 'a :: semidom)"
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   312
  shows   "prime_elem [:c:]"
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   313
proof (rule prime_elemI)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   314
  fix a b assume *: "[:c:] dvd a * b"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   315
  from * have dvd: "c dvd coeff (a * b) n" for n
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   316
    by (subst (asm) const_poly_dvd_iff) blast
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   317
  {
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   318
    define m where "m = (GREATEST m. \<not>c dvd coeff b m)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   319
    assume "\<not>[:c:] dvd b"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   320
    hence A: "\<exists>i. \<not>c dvd coeff b i" by (subst (asm) const_poly_dvd_iff) blast
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   321
    have B: "\<forall>i. \<not>c dvd coeff b i \<longrightarrow> i < Suc (degree b)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   322
      by (auto intro: le_degree simp: less_Suc_eq_le)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   323
    have coeff_m: "\<not>c dvd coeff b m" unfolding m_def by (rule GreatestI_ex[OF A B])
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   324
    have "i \<le> m" if "\<not>c dvd coeff b i" for i
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   325
      unfolding m_def by (rule Greatest_le[OF that B])
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   326
    hence dvd_b: "c dvd coeff b i" if "i > m" for i using that by force
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   327
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   328
    have "c dvd coeff a i" for i
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   329
    proof (induction i rule: nat_descend_induct[of "degree a"])
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   330
      case (base i)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   331
      thus ?case by (simp add: coeff_eq_0)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   332
    next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   333
      case (descend i)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   334
      let ?A = "{..i+m} - {i}"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   335
      have "c dvd coeff (a * b) (i + m)" by (rule dvd)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   336
      also have "coeff (a * b) (i + m) = (\<Sum>k\<le>i + m. coeff a k * coeff b (i + m - k))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   337
        by (simp add: coeff_mult)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   338
      also have "{..i+m} = insert i ?A" by auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   339
      also have "(\<Sum>k\<in>\<dots>. coeff a k * coeff b (i + m - k)) =
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   340
                   coeff a i * coeff b m + (\<Sum>k\<in>?A. coeff a k * coeff b (i + m - k))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   341
        (is "_ = _ + ?S")
64267
b9a1486e79be setsum -> sum
nipkow
parents: 64242
diff changeset
   342
        by (subst sum.insert) simp_all
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   343
      finally have eq: "c dvd coeff a i * coeff b m + ?S" .
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   344
      moreover have "c dvd ?S"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 64242
diff changeset
   345
      proof (rule dvd_sum)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   346
        fix k assume k: "k \<in> {..i+m} - {i}"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   347
        show "c dvd coeff a k * coeff b (i + m - k)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   348
        proof (cases "k < i")
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   349
          case False
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   350
          with k have "c dvd coeff a k" by (intro descend.IH) simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   351
          thus ?thesis by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   352
        next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   353
          case True
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   354
          hence "c dvd coeff b (i + m - k)" by (intro dvd_b) simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   355
          thus ?thesis by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   356
        qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   357
      qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   358
      ultimately have "c dvd coeff a i * coeff b m"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   359
        by (simp add: dvd_add_left_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   360
      with assms coeff_m show "c dvd coeff a i"
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   361
        by (simp add: prime_elem_dvd_mult_iff)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   362
    qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   363
    hence "[:c:] dvd a" by (subst const_poly_dvd_iff) blast
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   364
  }
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   365
  thus "[:c:] dvd a \<or> [:c:] dvd b" by blast
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   366
qed (insert assms, simp_all add: prime_elem_def one_poly_def)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   367
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   368
lemma prime_elem_const_poly_iff:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   369
  fixes c :: "'a :: semidom"
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   370
  shows   "prime_elem [:c:] \<longleftrightarrow> prime_elem c"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   371
proof
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   372
  assume A: "prime_elem [:c:]"
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   373
  show "prime_elem c"
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   374
  proof (rule prime_elemI)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   375
    fix a b assume "c dvd a * b"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   376
    hence "[:c:] dvd [:a:] * [:b:]" by (simp add: mult_ac)
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   377
    from A and this have "[:c:] dvd [:a:] \<or> [:c:] dvd [:b:]" by (rule prime_elem_dvd_multD)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   378
    thus "c dvd a \<or> c dvd b" by simp
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   379
  qed (insert A, auto simp: prime_elem_def is_unit_poly_iff)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   380
qed (auto intro: lift_prime_elem_poly)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   381
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   382
context
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   383
begin
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   384
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   385
private lemma content_1_mult:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   386
  fixes f g :: "'a :: {semiring_Gcd,factorial_semiring} poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   387
  assumes "content f = 1" "content g = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   388
  shows   "content (f * g) = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   389
proof (cases "f * g = 0")
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   390
  case False
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   391
  from assms have "f \<noteq> 0" "g \<noteq> 0" by auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   392
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   393
  hence "f * g \<noteq> 0" by auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   394
  {
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   395
    assume "\<not>is_unit (content (f * g))"
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   396
    with False have "\<exists>p. p dvd content (f * g) \<and> prime p"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   397
      by (intro prime_divisor_exists) simp_all
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   398
    then obtain p where "p dvd content (f * g)" "prime p" by blast
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   399
    from \<open>p dvd content (f * g)\<close> have "[:p:] dvd f * g"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   400
      by (simp add: const_poly_dvd_iff_dvd_content)
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   401
    moreover from \<open>prime p\<close> have "prime_elem [:p:]" by (simp add: lift_prime_elem_poly)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   402
    ultimately have "[:p:] dvd f \<or> [:p:] dvd g"
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   403
      by (simp add: prime_elem_dvd_mult_iff)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   404
    with assms have "is_unit p" by (simp add: const_poly_dvd_iff_dvd_content)
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   405
    with \<open>prime p\<close> have False by simp
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   406
  }
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   407
  hence "is_unit (content (f * g))" by blast
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   408
  hence "normalize (content (f * g)) = 1" by (simp add: is_unit_normalize del: normalize_content)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   409
  thus ?thesis by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   410
qed (insert assms, auto)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   411
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   412
lemma content_mult:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   413
  fixes p q :: "'a :: {factorial_semiring, semiring_Gcd} poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   414
  shows "content (p * q) = content p * content q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   415
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   416
  from content_decompose[of p] guess p' . note p = this
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   417
  from content_decompose[of q] guess q' . note q = this
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   418
  have "content (p * q) = content p * content q * content (p' * q')"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   419
    by (subst p, subst q) (simp add: mult_ac normalize_mult)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   420
  also from p q have "content (p' * q') = 1" by (intro content_1_mult)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   421
  finally show ?thesis by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   422
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   423
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   424
lemma primitive_part_mult:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   425
  fixes p q :: "'a :: {factorial_semiring, semiring_Gcd, ring_gcd, idom_divide} poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   426
  shows "primitive_part (p * q) = primitive_part p * primitive_part q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   427
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   428
  have "primitive_part (p * q) = p * q div [:content (p * q):]"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   429
    by (simp add: primitive_part_def div_const_poly_conv_map_poly)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   430
  also have "\<dots> = (p div [:content p:]) * (q div [:content q:])"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   431
    by (subst div_mult_div_if_dvd) (simp_all add: content_mult mult_ac)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   432
  also have "\<dots> = primitive_part p * primitive_part q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   433
    by (simp add: primitive_part_def div_const_poly_conv_map_poly)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   434
  finally show ?thesis .
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   435
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   436
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   437
lemma primitive_part_smult:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   438
  fixes p :: "'a :: {factorial_semiring, semiring_Gcd, ring_gcd, idom_divide} poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   439
  shows "primitive_part (smult a p) = smult (unit_factor a) (primitive_part p)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   440
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   441
  have "smult a p = [:a:] * p" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   442
  also have "primitive_part \<dots> = smult (unit_factor a) (primitive_part p)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   443
    by (subst primitive_part_mult) simp_all
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   444
  finally show ?thesis .
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   445
qed  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   446
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   447
lemma primitive_part_dvd_primitive_partI [intro]:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   448
  fixes p q :: "'a :: {factorial_semiring, semiring_Gcd, ring_gcd, idom_divide} poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   449
  shows "p dvd q \<Longrightarrow> primitive_part p dvd primitive_part q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   450
  by (auto elim!: dvdE simp: primitive_part_mult)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   451
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   452
lemma content_prod_mset: 
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   453
  fixes A :: "'a :: {factorial_semiring, semiring_Gcd} poly multiset"
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   454
  shows "content (prod_mset A) = prod_mset (image_mset content A)"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   455
  by (induction A) (simp_all add: content_mult mult_ac)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   456
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   457
lemma fract_poly_dvdD:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   458
  fixes p :: "'a :: {factorial_semiring,semiring_Gcd,ring_gcd,idom_divide} poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   459
  assumes "fract_poly p dvd fract_poly q" "content p = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   460
  shows   "p dvd q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   461
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   462
  from assms(1) obtain r where r: "fract_poly q = fract_poly p * r" by (erule dvdE)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   463
  from content_decompose_fract[of r] guess c r' . note r' = this
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   464
  from r r' have eq: "fract_poly q = smult c (fract_poly (p * r'))" by simp  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   465
  from fract_poly_smult_eqE[OF this] guess a b . note ab = this
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   466
  have "content (smult a q) = content (smult b (p * r'))" by (simp only: ab(2))
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   467
  hence eq': "normalize b = a * content q" by (simp add: assms content_mult r' ab(4))
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   468
  have "1 = gcd a (normalize b)" by (simp add: ab)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   469
  also note eq'
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   470
  also have "gcd a (a * content q) = a" by (simp add: gcd_proj1_if_dvd ab(4))
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   471
  finally have [simp]: "a = 1" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   472
  from eq ab have "q = p * ([:b:] * r')" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   473
  thus ?thesis by (rule dvdI)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   474
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   475
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   476
lemma content_prod_eq_1_iff: 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   477
  fixes p q :: "'a :: {factorial_semiring, semiring_Gcd} poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   478
  shows "content (p * q) = 1 \<longleftrightarrow> content p = 1 \<and> content q = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   479
proof safe
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   480
  assume A: "content (p * q) = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   481
  {
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   482
    fix p q :: "'a poly" assume "content p * content q = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   483
    hence "1 = content p * content q" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   484
    hence "content p dvd 1" by (rule dvdI)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   485
    hence "content p = 1" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   486
  } note B = this
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   487
  from A B[of p q] B [of q p] show "content p = 1" "content q = 1" 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   488
    by (simp_all add: content_mult mult_ac)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   489
qed (auto simp: content_mult)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   490
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   491
end
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   492
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   493
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   494
subsection \<open>Polynomials over a field are a Euclidean ring\<close>
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   495
63722
b9c8da46443b Deprivatisation of lemmas in Polynomial_Factorial
Manuel Eberl <eberlm@in.tum.de>
parents: 63705
diff changeset
   496
definition unit_factor_field_poly :: "'a :: field poly \<Rightarrow> 'a poly" where
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   497
  "unit_factor_field_poly p = [:lead_coeff p:]"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   498
63722
b9c8da46443b Deprivatisation of lemmas in Polynomial_Factorial
Manuel Eberl <eberlm@in.tum.de>
parents: 63705
diff changeset
   499
definition normalize_field_poly :: "'a :: field poly \<Rightarrow> 'a poly" where
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   500
  "normalize_field_poly p = smult (inverse (lead_coeff p)) p"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   501
63722
b9c8da46443b Deprivatisation of lemmas in Polynomial_Factorial
Manuel Eberl <eberlm@in.tum.de>
parents: 63705
diff changeset
   502
definition euclidean_size_field_poly :: "'a :: field poly \<Rightarrow> nat" where
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   503
  "euclidean_size_field_poly p = (if p = 0 then 0 else 2 ^ degree p)" 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   504
63722
b9c8da46443b Deprivatisation of lemmas in Polynomial_Factorial
Manuel Eberl <eberlm@in.tum.de>
parents: 63705
diff changeset
   505
lemma dvd_field_poly: "dvd.dvd (op * :: 'a :: field poly \<Rightarrow> _) = op dvd"
64784
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   506
  by (intro ext) (simp_all add: dvd.dvd_def dvd_def)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   507
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   508
interpretation field_poly: 
64784
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   509
  unique_euclidean_ring where zero = "0 :: 'a :: field poly"
64164
38c407446400 separate type class for arbitrary quotient and remainder partitions
haftmann
parents: 63954
diff changeset
   510
    and one = 1 and plus = plus and uminus = uminus and minus = minus
38c407446400 separate type class for arbitrary quotient and remainder partitions
haftmann
parents: 63954
diff changeset
   511
    and times = times
38c407446400 separate type class for arbitrary quotient and remainder partitions
haftmann
parents: 63954
diff changeset
   512
    and normalize = normalize_field_poly and unit_factor = unit_factor_field_poly
38c407446400 separate type class for arbitrary quotient and remainder partitions
haftmann
parents: 63954
diff changeset
   513
    and euclidean_size = euclidean_size_field_poly
64784
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   514
    and uniqueness_constraint = top
64164
38c407446400 separate type class for arbitrary quotient and remainder partitions
haftmann
parents: 63954
diff changeset
   515
    and divide = divide and modulo = modulo
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   516
proof (standard, unfold dvd_field_poly)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   517
  fix p :: "'a poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   518
  show "unit_factor_field_poly p * normalize_field_poly p = p"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   519
    by (cases "p = 0") 
64794
6f7391f28197 lead_coeff is more appropriate as abbreviation
haftmann
parents: 64786
diff changeset
   520
       (simp_all add: unit_factor_field_poly_def normalize_field_poly_def)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   521
next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   522
  fix p :: "'a poly" assume "is_unit p"
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64795
diff changeset
   523
  then show "unit_factor_field_poly p = p"
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64795
diff changeset
   524
    by (elim is_unit_polyE) (auto simp: unit_factor_field_poly_def monom_0 one_poly_def field_simps)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   525
next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   526
  fix p :: "'a poly" assume "p \<noteq> 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   527
  thus "is_unit (unit_factor_field_poly p)"
64794
6f7391f28197 lead_coeff is more appropriate as abbreviation
haftmann
parents: 64786
diff changeset
   528
    by (simp add: unit_factor_field_poly_def is_unit_pCons_iff)
64784
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   529
next
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   530
  fix p q s :: "'a poly" assume "s \<noteq> 0"
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   531
  moreover assume "euclidean_size_field_poly p < euclidean_size_field_poly q"
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   532
  ultimately show "euclidean_size_field_poly (p * s) < euclidean_size_field_poly (q * s)"
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   533
    by (auto simp add: euclidean_size_field_poly_def degree_mult_eq)
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   534
next
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   535
  fix p q r :: "'a poly" assume "p \<noteq> 0"
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   536
  moreover assume "euclidean_size_field_poly r < euclidean_size_field_poly p"
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   537
  ultimately show "(q * p + r) div p = q"
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   538
    by (cases "r = 0")
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   539
      (auto simp add: unit_factor_field_poly_def euclidean_size_field_poly_def div_poly_less)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   540
qed (auto simp: unit_factor_field_poly_def normalize_field_poly_def lead_coeff_mult 
64242
93c6f0da5c70 more standardized theorem names for facts involving the div and mod identity
haftmann
parents: 64240
diff changeset
   541
       euclidean_size_field_poly_def Rings.div_mult_mod_eq intro!: degree_mod_less' degree_mult_right_le)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   542
63722
b9c8da46443b Deprivatisation of lemmas in Polynomial_Factorial
Manuel Eberl <eberlm@in.tum.de>
parents: 63705
diff changeset
   543
lemma field_poly_irreducible_imp_prime:
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   544
  assumes "irreducible (p :: 'a :: field poly)"
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   545
  shows   "prime_elem p"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   546
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   547
  have A: "class.comm_semiring_1 op * 1 op + (0 :: 'a poly)" ..
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   548
  from field_poly.irreducible_imp_prime_elem[of p] assms
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   549
    show ?thesis unfolding irreducible_def prime_elem_def dvd_field_poly
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   550
      comm_semiring_1.irreducible_def[OF A] comm_semiring_1.prime_elem_def[OF A] by blast
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   551
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   552
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   553
lemma field_poly_prod_mset_prime_factorization:
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   554
  assumes "(x :: 'a :: field poly) \<noteq> 0"
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   555
  shows   "prod_mset (field_poly.prime_factorization x) = normalize_field_poly x"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   556
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   557
  have A: "class.comm_monoid_mult op * (1 :: 'a poly)" ..
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   558
  have "comm_monoid_mult.prod_mset op * (1 :: 'a poly) = prod_mset"
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   559
    by (intro ext) (simp add: comm_monoid_mult.prod_mset_def[OF A] prod_mset_def)
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   560
  with field_poly.prod_mset_prime_factorization[OF assms] show ?thesis by simp
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   561
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   562
63722
b9c8da46443b Deprivatisation of lemmas in Polynomial_Factorial
Manuel Eberl <eberlm@in.tum.de>
parents: 63705
diff changeset
   563
lemma field_poly_in_prime_factorization_imp_prime:
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   564
  assumes "(p :: 'a :: field poly) \<in># field_poly.prime_factorization x"
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   565
  shows   "prime_elem p"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   566
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   567
  have A: "class.comm_semiring_1 op * 1 op + (0 :: 'a poly)" ..
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   568
  have B: "class.normalization_semidom op div op + op - (0 :: 'a poly) op * 1 
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64795
diff changeset
   569
             unit_factor_field_poly normalize_field_poly" ..
63905
1c3dcb5fe6cb prefer abbreviation for trivial set conversion
haftmann
parents: 63830
diff changeset
   570
  from field_poly.in_prime_factors_imp_prime [of p x] assms
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   571
    show ?thesis unfolding prime_elem_def dvd_field_poly
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   572
      comm_semiring_1.prime_elem_def[OF A] normalization_semidom.prime_def[OF B] by blast
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   573
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   574
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   575
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   576
subsection \<open>Primality and irreducibility in polynomial rings\<close>
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   577
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   578
lemma nonconst_poly_irreducible_iff:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   579
  fixes p :: "'a :: {factorial_semiring,semiring_Gcd,ring_gcd,idom_divide} poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   580
  assumes "degree p \<noteq> 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   581
  shows   "irreducible p \<longleftrightarrow> irreducible (fract_poly p) \<and> content p = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   582
proof safe
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   583
  assume p: "irreducible p"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   584
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   585
  from content_decompose[of p] guess p' . note p' = this
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   586
  hence "p = [:content p:] * p'" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   587
  from p this have "[:content p:] dvd 1 \<or> p' dvd 1" by (rule irreducibleD)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   588
  moreover have "\<not>p' dvd 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   589
  proof
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   590
    assume "p' dvd 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   591
    hence "degree p = 0" by (subst p') (auto simp: is_unit_poly_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   592
    with assms show False by contradiction
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   593
  qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   594
  ultimately show [simp]: "content p = 1" by (simp add: is_unit_const_poly_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   595
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   596
  show "irreducible (map_poly to_fract p)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   597
  proof (rule irreducibleI)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   598
    have "fract_poly p = 0 \<longleftrightarrow> p = 0" by (intro map_poly_eq_0_iff) auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   599
    with assms show "map_poly to_fract p \<noteq> 0" by auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   600
  next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   601
    show "\<not>is_unit (fract_poly p)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   602
    proof
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   603
      assume "is_unit (map_poly to_fract p)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   604
      hence "degree (map_poly to_fract p) = 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   605
        by (auto simp: is_unit_poly_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   606
      hence "degree p = 0" by (simp add: degree_map_poly)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   607
      with assms show False by contradiction
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   608
   qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   609
 next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   610
   fix q r assume qr: "fract_poly p = q * r"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   611
   from content_decompose_fract[of q] guess cg q' . note q = this
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   612
   from content_decompose_fract[of r] guess cr r' . note r = this
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   613
   from qr q r p have nz: "cg \<noteq> 0" "cr \<noteq> 0" by auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   614
   from qr have eq: "fract_poly p = smult (cr * cg) (fract_poly (q' * r'))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   615
     by (simp add: q r)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   616
   from fract_poly_smult_eqE[OF this] guess a b . note ab = this
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   617
   hence "content (smult a p) = content (smult b (q' * r'))" by (simp only:)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   618
   with ab(4) have a: "a = normalize b" by (simp add: content_mult q r)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   619
   hence "normalize b = gcd a b" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   620
   also from ab(3) have "\<dots> = 1" .
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   621
   finally have "a = 1" "is_unit b" by (simp_all add: a normalize_1_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   622
   
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   623
   note eq
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   624
   also from ab(1) \<open>a = 1\<close> have "cr * cg = to_fract b" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   625
   also have "smult \<dots> (fract_poly (q' * r')) = fract_poly (smult b (q' * r'))" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   626
   finally have "p = ([:b:] * q') * r'" by (simp del: fract_poly_smult)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   627
   from p and this have "([:b:] * q') dvd 1 \<or> r' dvd 1" by (rule irreducibleD)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   628
   hence "q' dvd 1 \<or> r' dvd 1" by (auto dest: dvd_mult_right simp del: mult_pCons_left)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   629
   hence "fract_poly q' dvd 1 \<or> fract_poly r' dvd 1" by (auto simp: fract_poly_is_unit)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   630
   with q r show "is_unit q \<or> is_unit r"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   631
     by (auto simp add: is_unit_smult_iff dvd_field_iff nz)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   632
 qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   633
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   634
next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   635
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   636
  assume irred: "irreducible (fract_poly p)" and primitive: "content p = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   637
  show "irreducible p"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   638
  proof (rule irreducibleI)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   639
    from irred show "p \<noteq> 0" by auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   640
  next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   641
    from irred show "\<not>p dvd 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   642
      by (auto simp: irreducible_def dest: fract_poly_is_unit)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   643
  next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   644
    fix q r assume qr: "p = q * r"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   645
    hence "fract_poly p = fract_poly q * fract_poly r" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   646
    from irred and this have "fract_poly q dvd 1 \<or> fract_poly r dvd 1" 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   647
      by (rule irreducibleD)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   648
    with primitive qr show "q dvd 1 \<or> r dvd 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   649
      by (auto simp:  content_prod_eq_1_iff is_unit_fract_poly_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   650
  qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   651
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   652
63722
b9c8da46443b Deprivatisation of lemmas in Polynomial_Factorial
Manuel Eberl <eberlm@in.tum.de>
parents: 63705
diff changeset
   653
context
b9c8da46443b Deprivatisation of lemmas in Polynomial_Factorial
Manuel Eberl <eberlm@in.tum.de>
parents: 63705
diff changeset
   654
begin
b9c8da46443b Deprivatisation of lemmas in Polynomial_Factorial
Manuel Eberl <eberlm@in.tum.de>
parents: 63705
diff changeset
   655
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   656
private lemma irreducible_imp_prime_poly:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   657
  fixes p :: "'a :: {factorial_semiring,semiring_Gcd,ring_gcd,idom_divide} poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   658
  assumes "irreducible p"
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   659
  shows   "prime_elem p"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   660
proof (cases "degree p = 0")
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   661
  case True
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   662
  with assms show ?thesis
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   663
    by (auto simp: prime_elem_const_poly_iff irreducible_const_poly_iff
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   664
             intro!: irreducible_imp_prime_elem elim!: degree_eq_zeroE)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   665
next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   666
  case False
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   667
  from assms False have irred: "irreducible (fract_poly p)" and primitive: "content p = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   668
    by (simp_all add: nonconst_poly_irreducible_iff)
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   669
  from irred have prime: "prime_elem (fract_poly p)" by (rule field_poly_irreducible_imp_prime)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   670
  show ?thesis
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   671
  proof (rule prime_elemI)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   672
    fix q r assume "p dvd q * r"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   673
    hence "fract_poly p dvd fract_poly (q * r)" by (rule fract_poly_dvd)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   674
    hence "fract_poly p dvd fract_poly q * fract_poly r" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   675
    from prime and this have "fract_poly p dvd fract_poly q \<or> fract_poly p dvd fract_poly r"
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   676
      by (rule prime_elem_dvd_multD)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   677
    with primitive show "p dvd q \<or> p dvd r" by (auto dest: fract_poly_dvdD)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   678
  qed (insert assms, auto simp: irreducible_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   679
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   680
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   681
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   682
lemma degree_primitive_part_fract [simp]:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   683
  "degree (primitive_part_fract p) = degree p"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   684
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   685
  have "p = smult (fract_content p) (fract_poly (primitive_part_fract p))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   686
    by (simp add: content_times_primitive_part_fract)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   687
  also have "degree \<dots> = degree (primitive_part_fract p)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   688
    by (auto simp: degree_map_poly)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   689
  finally show ?thesis ..
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   690
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   691
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   692
lemma irreducible_primitive_part_fract:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   693
  fixes p :: "'a :: {idom_divide, ring_gcd, factorial_semiring, semiring_Gcd} fract poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   694
  assumes "irreducible p"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   695
  shows   "irreducible (primitive_part_fract p)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   696
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   697
  from assms have deg: "degree (primitive_part_fract p) \<noteq> 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   698
    by (intro notI) 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   699
       (auto elim!: degree_eq_zeroE simp: irreducible_def is_unit_poly_iff dvd_field_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   700
  hence [simp]: "p \<noteq> 0" by auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   701
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   702
  note \<open>irreducible p\<close>
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   703
  also have "p = [:fract_content p:] * fract_poly (primitive_part_fract p)" 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   704
    by (simp add: content_times_primitive_part_fract)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   705
  also have "irreducible \<dots> \<longleftrightarrow> irreducible (fract_poly (primitive_part_fract p))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   706
    by (intro irreducible_mult_unit_left) (simp_all add: is_unit_poly_iff dvd_field_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   707
  finally show ?thesis using deg
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   708
    by (simp add: nonconst_poly_irreducible_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   709
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   710
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   711
lemma prime_elem_primitive_part_fract:
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   712
  fixes p :: "'a :: {idom_divide, ring_gcd, factorial_semiring, semiring_Gcd} fract poly"
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   713
  shows "irreducible p \<Longrightarrow> prime_elem (primitive_part_fract p)"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   714
  by (intro irreducible_imp_prime_poly irreducible_primitive_part_fract)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   715
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   716
lemma irreducible_linear_field_poly:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   717
  fixes a b :: "'a::field"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   718
  assumes "b \<noteq> 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   719
  shows "irreducible [:a,b:]"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   720
proof (rule irreducibleI)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   721
  fix p q assume pq: "[:a,b:] = p * q"
63539
70d4d9e5707b tuned proofs -- avoid improper use of "this";
wenzelm
parents: 63500
diff changeset
   722
  also from pq assms have "degree \<dots> = degree p + degree q" 
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   723
    by (intro degree_mult_eq) auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   724
  finally have "degree p = 0 \<or> degree q = 0" using assms by auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   725
  with assms pq show "is_unit p \<or> is_unit q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   726
    by (auto simp: is_unit_const_poly_iff dvd_field_iff elim!: degree_eq_zeroE)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   727
qed (insert assms, auto simp: is_unit_poly_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   728
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   729
lemma prime_elem_linear_field_poly:
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   730
  "(b :: 'a :: field) \<noteq> 0 \<Longrightarrow> prime_elem [:a,b:]"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   731
  by (rule field_poly_irreducible_imp_prime, rule irreducible_linear_field_poly)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   732
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   733
lemma irreducible_linear_poly:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   734
  fixes a b :: "'a::{idom_divide,ring_gcd,factorial_semiring,semiring_Gcd}"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   735
  shows "b \<noteq> 0 \<Longrightarrow> coprime a b \<Longrightarrow> irreducible [:a,b:]"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   736
  by (auto intro!: irreducible_linear_field_poly 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   737
           simp:   nonconst_poly_irreducible_iff content_def map_poly_pCons)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   738
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   739
lemma prime_elem_linear_poly:
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   740
  fixes a b :: "'a::{idom_divide,ring_gcd,factorial_semiring,semiring_Gcd}"
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   741
  shows "b \<noteq> 0 \<Longrightarrow> coprime a b \<Longrightarrow> prime_elem [:a,b:]"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   742
  by (rule irreducible_imp_prime_poly, rule irreducible_linear_poly)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   743
63722
b9c8da46443b Deprivatisation of lemmas in Polynomial_Factorial
Manuel Eberl <eberlm@in.tum.de>
parents: 63705
diff changeset
   744
end
b9c8da46443b Deprivatisation of lemmas in Polynomial_Factorial
Manuel Eberl <eberlm@in.tum.de>
parents: 63705
diff changeset
   745
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
   746
 
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   747
subsection \<open>Prime factorisation of polynomials\<close>   
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   748
63722
b9c8da46443b Deprivatisation of lemmas in Polynomial_Factorial
Manuel Eberl <eberlm@in.tum.de>
parents: 63705
diff changeset
   749
context
b9c8da46443b Deprivatisation of lemmas in Polynomial_Factorial
Manuel Eberl <eberlm@in.tum.de>
parents: 63705
diff changeset
   750
begin 
b9c8da46443b Deprivatisation of lemmas in Polynomial_Factorial
Manuel Eberl <eberlm@in.tum.de>
parents: 63705
diff changeset
   751
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   752
private lemma poly_prime_factorization_exists_content_1:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   753
  fixes p :: "'a :: {factorial_semiring,semiring_Gcd,ring_gcd,idom_divide} poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   754
  assumes "p \<noteq> 0" "content p = 1"
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   755
  shows   "\<exists>A. (\<forall>p. p \<in># A \<longrightarrow> prime_elem p) \<and> prod_mset A = normalize p"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   756
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   757
  let ?P = "field_poly.prime_factorization (fract_poly p)"
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   758
  define c where "c = prod_mset (image_mset fract_content ?P)"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   759
  define c' where "c' = c * to_fract (lead_coeff p)"
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   760
  define e where "e = prod_mset (image_mset primitive_part_fract ?P)"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   761
  define A where "A = image_mset (normalize \<circ> primitive_part_fract) ?P"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   762
  have "content e = (\<Prod>x\<in>#field_poly.prime_factorization (map_poly to_fract p). 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   763
                      content (primitive_part_fract x))"
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   764
    by (simp add: e_def content_prod_mset multiset.map_comp o_def)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   765
  also have "image_mset (\<lambda>x. content (primitive_part_fract x)) ?P = image_mset (\<lambda>_. 1) ?P"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   766
    by (intro image_mset_cong content_primitive_part_fract) auto
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
   767
  finally have content_e: "content e = 1"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
   768
    by simp    
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   769
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   770
  have "fract_poly p = unit_factor_field_poly (fract_poly p) * 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   771
          normalize_field_poly (fract_poly p)" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   772
  also have "unit_factor_field_poly (fract_poly p) = [:to_fract (lead_coeff p):]" 
64794
6f7391f28197 lead_coeff is more appropriate as abbreviation
haftmann
parents: 64786
diff changeset
   773
    by (simp add: unit_factor_field_poly_def monom_0 degree_map_poly coeff_map_poly)
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   774
  also from assms have "normalize_field_poly (fract_poly p) = prod_mset ?P" 
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   775
    by (subst field_poly_prod_mset_prime_factorization) simp_all
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   776
  also have "\<dots> = prod_mset (image_mset id ?P)" by simp
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   777
  also have "image_mset id ?P = 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   778
               image_mset (\<lambda>x. [:fract_content x:] * fract_poly (primitive_part_fract x)) ?P"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   779
    by (intro image_mset_cong) (auto simp: content_times_primitive_part_fract)
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   780
  also have "prod_mset \<dots> = smult c (fract_poly e)"
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
   781
    by (subst prod_mset.distrib) (simp_all add: prod_mset_fract_poly prod_mset_const_poly c_def e_def)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   782
  also have "[:to_fract (lead_coeff p):] * \<dots> = smult c' (fract_poly e)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   783
    by (simp add: c'_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   784
  finally have eq: "fract_poly p = smult c' (fract_poly e)" .
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   785
  also obtain b where b: "c' = to_fract b" "is_unit b"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   786
  proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   787
    from fract_poly_smult_eqE[OF eq] guess a b . note ab = this
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   788
    from ab(2) have "content (smult a p) = content (smult b e)" by (simp only: )
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   789
    with assms content_e have "a = normalize b" by (simp add: ab(4))
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   790
    with ab have ab': "a = 1" "is_unit b" by (simp_all add: normalize_1_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   791
    with ab ab' have "c' = to_fract b" by auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   792
    from this and \<open>is_unit b\<close> show ?thesis by (rule that)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   793
  qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   794
  hence "smult c' (fract_poly e) = fract_poly (smult b e)" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   795
  finally have "p = smult b e" by (simp only: fract_poly_eq_iff)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   796
  hence "p = [:b:] * e" by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   797
  with b have "normalize p = normalize e" 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   798
    by (simp only: normalize_mult) (simp add: is_unit_normalize is_unit_poly_iff)
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   799
  also have "normalize e = prod_mset A"
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   800
    by (simp add: multiset.map_comp e_def A_def normalize_prod_mset)
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   801
  finally have "prod_mset A = normalize p" ..
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   802
  
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   803
  have "prime_elem p" if "p \<in># A" for p
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   804
    using that by (auto simp: A_def prime_elem_primitive_part_fract prime_elem_imp_irreducible 
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   805
                        dest!: field_poly_in_prime_factorization_imp_prime )
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   806
  from this and \<open>prod_mset A = normalize p\<close> show ?thesis
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   807
    by (intro exI[of _ A]) blast
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   808
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   809
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   810
lemma poly_prime_factorization_exists:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   811
  fixes p :: "'a :: {factorial_semiring,semiring_Gcd,ring_gcd,idom_divide} poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   812
  assumes "p \<noteq> 0"
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   813
  shows   "\<exists>A. (\<forall>p. p \<in># A \<longrightarrow> prime_elem p) \<and> prod_mset A = normalize p"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   814
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   815
  define B where "B = image_mset (\<lambda>x. [:x:]) (prime_factorization (content p))"
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   816
  have "\<exists>A. (\<forall>p. p \<in># A \<longrightarrow> prime_elem p) \<and> prod_mset A = normalize (primitive_part p)"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   817
    by (rule poly_prime_factorization_exists_content_1) (insert assms, simp_all)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   818
  then guess A by (elim exE conjE) note A = this
63830
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   819
  moreover from assms have "prod_mset B = [:content p:]"
2ea3725a34bd msetsum -> set_mset, msetprod -> prod_mset
nipkow
parents: 63764
diff changeset
   820
    by (simp add: B_def prod_mset_const_poly prod_mset_prime_factorization)
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   821
  moreover have "\<forall>p. p \<in># B \<longrightarrow> prime_elem p"
63905
1c3dcb5fe6cb prefer abbreviation for trivial set conversion
haftmann
parents: 63830
diff changeset
   822
    by (auto simp: B_def intro!: lift_prime_elem_poly dest: in_prime_factors_imp_prime)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   823
  ultimately show ?thesis by (intro exI[of _ "B + A"]) auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   824
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   825
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   826
end
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   827
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   828
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   829
subsection \<open>Typeclass instances\<close>
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   830
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   831
instance poly :: (factorial_ring_gcd) factorial_semiring
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   832
  by standard (rule poly_prime_factorization_exists)  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   833
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   834
instantiation poly :: (factorial_ring_gcd) factorial_ring_gcd
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   835
begin
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   836
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   837
definition gcd_poly :: "'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" where
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   838
  [code del]: "gcd_poly = gcd_factorial"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   839
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   840
definition lcm_poly :: "'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" where
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   841
  [code del]: "lcm_poly = lcm_factorial"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   842
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   843
definition Gcd_poly :: "'a poly set \<Rightarrow> 'a poly" where
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   844
 [code del]: "Gcd_poly = Gcd_factorial"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   845
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   846
definition Lcm_poly :: "'a poly set \<Rightarrow> 'a poly" where
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   847
 [code del]: "Lcm_poly = Lcm_factorial"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   848
 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   849
instance by standard (simp_all add: gcd_poly_def lcm_poly_def Gcd_poly_def Lcm_poly_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   850
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   851
end
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   852
64784
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   853
instantiation poly :: ("{field,factorial_ring_gcd}") unique_euclidean_ring
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   854
begin
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   855
64784
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   856
definition euclidean_size_poly :: "'a poly \<Rightarrow> nat"
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   857
  where "euclidean_size_poly p = (if p = 0 then 0 else 2 ^ degree p)"
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   858
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   859
definition uniqueness_constraint_poly :: "'a poly \<Rightarrow> 'a poly \<Rightarrow> bool"
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   860
  where [simp]: "uniqueness_constraint_poly = top"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   861
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   862
instance 
64784
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   863
  by standard
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   864
   (auto simp: euclidean_size_poly_def Rings.div_mult_mod_eq div_poly_less degree_mult_eq intro!: degree_mod_less' degree_mult_right_le
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   865
    split: if_splits)
5cb5e7ecb284 reshaped euclidean semiring into hierarchy of euclidean semirings culminating in uniquely determined euclidean divion
haftmann
parents: 64591
diff changeset
   866
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   867
end
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   868
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   869
instance poly :: ("{field,factorial_ring_gcd}") euclidean_ring_gcd
64786
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 64784
diff changeset
   870
  by (rule euclidean_ring_gcd_class.intro, rule factorial_euclidean_semiring_gcdI)
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 64784
diff changeset
   871
    standard
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   872
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   873
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   874
subsection \<open>Polynomial GCD\<close>
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   875
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   876
lemma gcd_poly_decompose:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   877
  fixes p q :: "'a :: factorial_ring_gcd poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   878
  shows "gcd p q = 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   879
           smult (gcd (content p) (content q)) (gcd (primitive_part p) (primitive_part q))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   880
proof (rule sym, rule gcdI)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   881
  have "[:gcd (content p) (content q):] * gcd (primitive_part p) (primitive_part q) dvd
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   882
          [:content p:] * primitive_part p" by (intro mult_dvd_mono) simp_all
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   883
  thus "smult (gcd (content p) (content q)) (gcd (primitive_part p) (primitive_part q)) dvd p"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   884
    by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   885
next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   886
  have "[:gcd (content p) (content q):] * gcd (primitive_part p) (primitive_part q) dvd
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   887
          [:content q:] * primitive_part q" by (intro mult_dvd_mono) simp_all
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   888
  thus "smult (gcd (content p) (content q)) (gcd (primitive_part p) (primitive_part q)) dvd q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   889
    by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   890
next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   891
  fix d assume "d dvd p" "d dvd q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   892
  hence "[:content d:] * primitive_part d dvd 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   893
           [:gcd (content p) (content q):] * gcd (primitive_part p) (primitive_part q)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   894
    by (intro mult_dvd_mono) auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   895
  thus "d dvd smult (gcd (content p) (content q)) (gcd (primitive_part p) (primitive_part q))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   896
    by simp
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   897
qed (auto simp: normalize_smult)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   898
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   899
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   900
lemma gcd_poly_pseudo_mod:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   901
  fixes p q :: "'a :: factorial_ring_gcd poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   902
  assumes nz: "q \<noteq> 0" and prim: "content p = 1" "content q = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   903
  shows   "gcd p q = gcd q (primitive_part (pseudo_mod p q))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   904
proof -
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   905
  define r s where "r = fst (pseudo_divmod p q)" and "s = snd (pseudo_divmod p q)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   906
  define a where "a = [:coeff q (degree q) ^ (Suc (degree p) - degree q):]"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   907
  have [simp]: "primitive_part a = unit_factor a"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   908
    by (simp add: a_def unit_factor_poly_def unit_factor_power monom_0)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   909
  from nz have [simp]: "a \<noteq> 0" by (auto simp: a_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   910
  
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   911
  have rs: "pseudo_divmod p q = (r, s)" by (simp add: r_def s_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   912
  have "gcd (q * r + s) q = gcd q s"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   913
    using gcd_add_mult[of q r s] by (simp add: gcd.commute add_ac mult_ac)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   914
  with pseudo_divmod(1)[OF nz rs]
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   915
    have "gcd (p * a) q = gcd q s" by (simp add: a_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   916
  also from prim have "gcd (p * a) q = gcd p q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   917
    by (subst gcd_poly_decompose)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   918
       (auto simp: primitive_part_mult gcd_mult_unit1 primitive_part_prim 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   919
             simp del: mult_pCons_right )
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   920
  also from prim have "gcd q s = gcd q (primitive_part s)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   921
    by (subst gcd_poly_decompose) (simp_all add: primitive_part_prim)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   922
  also have "s = pseudo_mod p q" by (simp add: s_def pseudo_mod_def)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   923
  finally show ?thesis .
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   924
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   925
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   926
lemma degree_pseudo_mod_less:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   927
  assumes "q \<noteq> 0" "pseudo_mod p q \<noteq> 0"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   928
  shows   "degree (pseudo_mod p q) < degree q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   929
  using pseudo_mod(2)[of q p] assms by auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   930
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   931
function gcd_poly_code_aux :: "'a :: factorial_ring_gcd poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" where
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   932
  "gcd_poly_code_aux p q = 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   933
     (if q = 0 then normalize p else gcd_poly_code_aux q (primitive_part (pseudo_mod p q)))" 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   934
by auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   935
termination
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   936
  by (relation "measure ((\<lambda>p. if p = 0 then 0 else Suc (degree p)) \<circ> snd)")
64164
38c407446400 separate type class for arbitrary quotient and remainder partitions
haftmann
parents: 63954
diff changeset
   937
     (auto simp: degree_pseudo_mod_less)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   938
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   939
declare gcd_poly_code_aux.simps [simp del]
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   940
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   941
lemma gcd_poly_code_aux_correct:
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   942
  assumes "content p = 1" "q = 0 \<or> content q = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   943
  shows   "gcd_poly_code_aux p q = gcd p q"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   944
  using assms
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   945
proof (induction p q rule: gcd_poly_code_aux.induct)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   946
  case (1 p q)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   947
  show ?case
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   948
  proof (cases "q = 0")
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   949
    case True
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   950
    thus ?thesis by (subst gcd_poly_code_aux.simps) auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   951
  next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   952
    case False
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   953
    hence "gcd_poly_code_aux p q = gcd_poly_code_aux q (primitive_part (pseudo_mod p q))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   954
      by (subst gcd_poly_code_aux.simps) simp_all
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   955
    also from "1.prems" False 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   956
      have "primitive_part (pseudo_mod p q) = 0 \<or> 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   957
              content (primitive_part (pseudo_mod p q)) = 1"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   958
      by (cases "pseudo_mod p q = 0") auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   959
    with "1.prems" False 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   960
      have "gcd_poly_code_aux q (primitive_part (pseudo_mod p q)) = 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   961
              gcd q (primitive_part (pseudo_mod p q))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   962
      by (intro 1) simp_all
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   963
    also from "1.prems" False 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   964
      have "\<dots> = gcd p q" by (intro gcd_poly_pseudo_mod [symmetric]) auto
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   965
    finally show ?thesis .
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   966
  qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   967
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   968
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   969
definition gcd_poly_code 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   970
    :: "'a :: factorial_ring_gcd poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly" 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   971
  where "gcd_poly_code p q = 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   972
           (if p = 0 then normalize q else if q = 0 then normalize p else
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   973
              smult (gcd (content p) (content q)) 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   974
                (gcd_poly_code_aux (primitive_part p) (primitive_part q)))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   975
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
   976
lemma gcd_poly_code [code]: "gcd p q = gcd_poly_code p q"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
   977
  by (simp add: gcd_poly_code_def gcd_poly_code_aux_correct gcd_poly_decompose [symmetric])
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
   978
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   979
lemma lcm_poly_code [code]: 
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   980
  fixes p q :: "'a :: factorial_ring_gcd poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   981
  shows "lcm p q = normalize (p * q) div gcd p q"
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
   982
  by (fact lcm_gcd)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   983
64850
fc9265882329 gcd/lcm on finite sets
haftmann
parents: 64848
diff changeset
   984
lemmas Gcd_poly_set_eq_fold [code] = Gcd_set_eq_fold [where ?'a = "'a :: factorial_ring_gcd poly"]
fc9265882329 gcd/lcm on finite sets
haftmann
parents: 64848
diff changeset
   985
lemmas Lcm_poly_set_eq_fold [code] = Lcm_set_eq_fold [where ?'a = "'a :: factorial_ring_gcd poly"]
64860
4d56170d97b3 generalized definition
haftmann
parents: 64850
diff changeset
   986
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
   987
text \<open>Example:
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
   988
  @{lemma "Lcm {[:1, 2, 3:], [:2, 3, 4:]} = [:[:2:], [:7:], [:16:], [:17:], [:12 :: int:]:]" by eval}
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64267
diff changeset
   989
\<close>
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   990
  
63764
f3ad26c4b2d9 tuned headers;
wenzelm
parents: 63722
diff changeset
   991
end