src/HOL/Computational_Algebra/Polynomial.thy
author Manuel Eberl <eberlm@in.tum.de>
Wed, 21 May 2025 21:48:42 +0200
changeset 82653 565545b7fe9d
parent 82187 cddce3a4ef84
child 82691 b69e4da2604b
permissions -rw-r--r--
three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
65435
378175f44328 tuned headers;
wenzelm
parents: 65417
diff changeset
     1
(*  Title:      HOL/Computational_Algebra/Polynomial.thy
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
     2
    Author:     Brian Huffman
41959
b460124855b8 tuned headers;
wenzelm
parents: 39302
diff changeset
     3
    Author:     Clemens Ballarin
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
     4
    Author:     Amine Chaieb
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
     5
    Author:     Florian Haftmann
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
     6
*)
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
     7
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
     8
section \<open>Polynomials as type over a ring structure\<close>
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
     9
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
    10
theory Polynomial
65417
fc41a5650fb1 session containing computational algebra
haftmann
parents: 65390
diff changeset
    11
imports
68534
914e1bc7369a Now based on Complex_Main, not HOL.Deriv
paulson <lp15@cam.ac.uk>
parents: 68532
diff changeset
    12
  Complex_Main
66453
cc19f7ca2ed6 session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
wenzelm
parents: 65811
diff changeset
    13
  "HOL-Library.More_List"
cc19f7ca2ed6 session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
wenzelm
parents: 65811
diff changeset
    14
  "HOL-Library.Infinite_Set"
80084
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
    15
  Primes
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
    16
begin
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
    17
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
    18
context semidom_modulo
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
    19
begin
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
    20
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
    21
lemma not_dvd_imp_mod_neq_0:
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
    22
  \<open>a mod b \<noteq> 0\<close> if \<open>\<not> b dvd a\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
    23
  using that mod_0_imp_dvd [of a b] by blast
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
    24
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
    25
end
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
    26
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
    27
subsection \<open>Auxiliary: operations for lists (later) representing coefficients\<close>
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    28
80914
d97fdabd9e2b standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents: 80786
diff changeset
    29
definition cCons :: "'a::zero \<Rightarrow> 'a list \<Rightarrow> 'a list"  (infixr \<open>##\<close> 65)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    30
  where "x ## xs = (if xs = [] \<and> x = 0 then [] else x # xs)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    31
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    32
lemma cCons_0_Nil_eq [simp]: "0 ## [] = []"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    33
  by (simp add: cCons_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    34
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    35
lemma cCons_Cons_eq [simp]: "x ## y # ys = x # y # ys"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    36
  by (simp add: cCons_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    37
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    38
lemma cCons_append_Cons_eq [simp]: "x ## xs @ y # ys = x # xs @ y # ys"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    39
  by (simp add: cCons_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    40
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    41
lemma cCons_not_0_eq [simp]: "x \<noteq> 0 \<Longrightarrow> x ## xs = x # xs"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    42
  by (simp add: cCons_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    43
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    44
lemma strip_while_not_0_Cons_eq [simp]:
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    45
  "strip_while (\<lambda>x. x = 0) (x # xs) = x ## strip_while (\<lambda>x. x = 0) xs"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    46
proof (cases "x = 0")
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    47
  case False
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    48
  then show ?thesis by simp
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    49
next
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    50
  case True
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    51
  show ?thesis
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    52
  proof (induct xs rule: rev_induct)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    53
    case Nil
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    54
    with True show ?case by simp
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    55
  next
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    56
    case (snoc y ys)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    57
    then show ?case
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    58
      by (cases "y = 0") (simp_all add: append_Cons [symmetric] del: append_Cons)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    59
  qed
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    60
qed
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    61
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    62
lemma tl_cCons [simp]: "tl (x ## xs) = xs"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    63
  by (simp add: cCons_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    64
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    65
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61260
diff changeset
    66
subsection \<open>Definition of type \<open>poly\<close>\<close>
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
    67
61260
e6f03fae14d5 explicit indication of overloaded typedefs;
wenzelm
parents: 60686
diff changeset
    68
typedef (overloaded) 'a poly = "{f :: nat \<Rightarrow> 'a::zero. \<forall>\<^sub>\<infinity> n. f n = 0}"
63433
wenzelm
parents: 63317
diff changeset
    69
  morphisms coeff Abs_poly
wenzelm
parents: 63317
diff changeset
    70
  by (auto intro!: ALL_MOST)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
    71
59487
adaa430fc0f7 default abstypes and default abstract equations make technical (no_code) annotation superfluous
haftmann
parents: 58881
diff changeset
    72
setup_lifting type_definition_poly
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    73
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    74
lemma poly_eq_iff: "p = q \<longleftrightarrow> (\<forall>n. coeff p n = coeff q n)"
45694
4a8743618257 prefer typedef without extra definition and alternative name;
wenzelm
parents: 45605
diff changeset
    75
  by (simp add: coeff_inject [symmetric] fun_eq_iff)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
    76
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    77
lemma poly_eqI: "(\<And>n. coeff p n = coeff q n) \<Longrightarrow> p = q"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    78
  by (simp add: poly_eq_iff)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    79
59983
cd2efd7d06bd replace almost_everywhere_zero by Infinite_Set.MOST
hoelzl
parents: 59815
diff changeset
    80
lemma MOST_coeff_eq_0: "\<forall>\<^sub>\<infinity> n. coeff p n = 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    81
  using coeff [of p] by simp
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
    82
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
    83
lemma coeff_Abs_poly:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
    84
  assumes "\<And>i. i > n \<Longrightarrow> f i = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
    85
  shows   "coeff (Abs_poly f) = f"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
    86
proof (rule Abs_poly_inverse, clarify)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
    87
  have "eventually (\<lambda>i. i > n) cofinite"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
    88
    by (auto simp: MOST_nat)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
    89
  thus "eventually (\<lambda>i. f i = 0) cofinite"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
    90
    by eventually_elim (use assms in auto)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
    91
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
    92
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
    93
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
    94
subsection \<open>Degree of a polynomial\<close>
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
    95
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
    96
definition degree :: "'a::zero poly \<Rightarrow> nat"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
    97
  where "degree p = (LEAST n. \<forall>i>n. coeff p i = 0)"
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
    98
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
    99
lemma degree_cong:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   100
  assumes "\<And>i. coeff p i = 0 \<longleftrightarrow> coeff q i = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   101
  shows   "degree p = degree q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   102
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   103
  have "(\<lambda>n. \<forall>i>n. poly.coeff p i = 0) = (\<lambda>n. \<forall>i>n. poly.coeff q i = 0)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   104
    using assms by (auto simp: fun_eq_iff)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   105
  thus ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   106
    by (simp only: degree_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   107
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   108
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   109
lemma coeff_Abs_poly_If_le:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   110
  "coeff (Abs_poly (\<lambda>i. if i \<le> n then f i else 0)) = (\<lambda>i. if i \<le> n then f i else 0)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   111
proof (rule Abs_poly_inverse, clarify)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   112
  have "eventually (\<lambda>i. i > n) cofinite"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   113
    by (auto simp: MOST_nat)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   114
  thus "eventually (\<lambda>i. (if i \<le> n then f i else 0) = 0) cofinite"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   115
    by eventually_elim auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   116
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   117
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   118
lemma coeff_eq_0:
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   119
  assumes "degree p < n"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   120
  shows "coeff p n = 0"
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   121
proof -
59983
cd2efd7d06bd replace almost_everywhere_zero by Infinite_Set.MOST
hoelzl
parents: 59815
diff changeset
   122
  have "\<exists>n. \<forall>i>n. coeff p i = 0"
cd2efd7d06bd replace almost_everywhere_zero by Infinite_Set.MOST
hoelzl
parents: 59815
diff changeset
   123
    using MOST_coeff_eq_0 by (simp add: MOST_nat)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   124
  then have "\<forall>i>degree p. coeff p i = 0"
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   125
    unfolding degree_def by (rule LeastI_ex)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   126
  with assms show ?thesis by simp
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   127
qed
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   128
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   129
lemma le_degree: "coeff p n \<noteq> 0 \<Longrightarrow> n \<le> degree p"
82187
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   130
  using coeff_eq_0 linorder_le_less_linear by blast
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   131
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   132
lemma degree_le: "\<forall>i>n. coeff p i = 0 \<Longrightarrow> degree p \<le> n"
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   133
  unfolding degree_def by (erule Least_le)
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   134
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   135
lemma less_degree_imp: "n < degree p \<Longrightarrow> \<exists>i>n. coeff p i \<noteq> 0"
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   136
  unfolding degree_def by (drule not_less_Least, simp)
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   137
82187
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   138
lemma poly_eqI2:
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   139
  assumes "degree p = degree q" and "\<And>i. i \<le> degree p \<Longrightarrow> coeff p i = coeff q i"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   140
  shows "p = q"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   141
  by (metis assms le_degree poly_eqI)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   142
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   143
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   144
subsection \<open>The zero polynomial\<close>
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   145
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   146
instantiation poly :: (zero) zero
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   147
begin
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   148
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   149
lift_definition zero_poly :: "'a poly"
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   150
  is "\<lambda>_. 0"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   151
  by (rule MOST_I) simp
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   152
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   153
instance ..
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   154
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   155
end
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   156
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   157
lemma coeff_0 [simp]: "coeff 0 n = 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   158
  by transfer rule
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   159
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   160
lemma degree_0 [simp]: "degree 0 = 0"
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   161
  by (rule order_antisym [OF degree_le le0]) simp
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   162
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   163
lemma leading_coeff_neq_0:
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   164
  assumes "p \<noteq> 0"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   165
  shows "coeff p (degree p) \<noteq> 0"
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   166
proof (cases "degree p")
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   167
  case 0
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   168
  from \<open>p \<noteq> 0\<close> obtain n where "coeff p n \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   169
    by (auto simp add: poly_eq_iff)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   170
  then have "n \<le> degree p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   171
    by (rule le_degree)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   172
  with \<open>coeff p n \<noteq> 0\<close> and \<open>degree p = 0\<close> show "coeff p (degree p) \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   173
    by simp
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   174
next
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   175
  case (Suc n)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   176
  from \<open>degree p = Suc n\<close> have "n < degree p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   177
    by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   178
  then have "\<exists>i>n. coeff p i \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   179
    by (rule less_degree_imp)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   180
  then obtain i where "n < i" and "coeff p i \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   181
    by blast
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   182
  from \<open>degree p = Suc n\<close> and \<open>n < i\<close> have "degree p \<le> i"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   183
    by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   184
  also from \<open>coeff p i \<noteq> 0\<close> have "i \<le> degree p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   185
    by (rule le_degree)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   186
  finally have "degree p = i" .
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   187
  with \<open>coeff p i \<noteq> 0\<close> show "coeff p (degree p) \<noteq> 0" by simp
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   188
qed
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   189
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   190
lemma leading_coeff_0_iff [simp]: "coeff p (degree p) = 0 \<longleftrightarrow> p = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   191
  by (cases "p = 0") (simp_all add: leading_coeff_neq_0)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   192
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   193
lemma degree_lessI:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   194
  assumes "p \<noteq> 0 \<or> n > 0" "\<forall>k\<ge>n. coeff p k = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   195
  shows   "degree p < n"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   196
proof (cases "p = 0")
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   197
  case False
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   198
  show ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   199
  proof (rule ccontr)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   200
    assume *: "\<not>(degree p < n)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   201
    define d where "d = degree p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   202
    from \<open>p \<noteq> 0\<close> have "coeff p d \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   203
      by (auto simp: d_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   204
    moreover have "coeff p d = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   205
      using assms(2) * by (auto simp: not_less)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   206
    ultimately show False by contradiction
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   207
  qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   208
qed (use assms in auto)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   209
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
   210
lemma eq_zero_or_degree_less:            
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   211
  assumes "degree p \<le> n" and "coeff p n = 0"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   212
  shows "p = 0 \<or> degree p < n"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   213
proof (cases n)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   214
  case 0
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   215
  with \<open>degree p \<le> n\<close> and \<open>coeff p n = 0\<close> have "coeff p (degree p) = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   216
    by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   217
  then have "p = 0" by simp
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   218
  then show ?thesis ..
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   219
next
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   220
  case (Suc m)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   221
  from \<open>degree p \<le> n\<close> have "\<forall>i>n. coeff p i = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   222
    by (simp add: coeff_eq_0)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   223
  with \<open>coeff p n = 0\<close> have "\<forall>i\<ge>n. coeff p i = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   224
    by (simp add: le_less)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   225
  with \<open>n = Suc m\<close> have "\<forall>i>m. coeff p i = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   226
    by (simp add: less_eq_Suc_le)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   227
  then have "degree p \<le> m"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   228
    by (rule degree_le)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   229
  with \<open>n = Suc m\<close> have "degree p < n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   230
    by (simp add: less_Suc_eq_le)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   231
  then show ?thesis ..
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   232
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   233
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   234
lemma coeff_0_degree_minus_1: "coeff rrr dr = 0 \<Longrightarrow> degree rrr \<le> dr \<Longrightarrow> degree rrr \<le> dr - 1"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   235
  using eq_zero_or_degree_less by fastforce
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   236
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   237
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   238
subsection \<open>List-style constructor for polynomials\<close>
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   239
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   240
lift_definition pCons :: "'a::zero \<Rightarrow> 'a poly \<Rightarrow> 'a poly"
55415
05f5fdb8d093 renamed 'nat_{case,rec}' to '{case,rec}_nat'
blanchet
parents: 54856
diff changeset
   241
  is "\<lambda>a p. case_nat a (coeff p)"
59983
cd2efd7d06bd replace almost_everywhere_zero by Infinite_Set.MOST
hoelzl
parents: 59815
diff changeset
   242
  by (rule MOST_SucD) (simp add: MOST_coeff_eq_0)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   243
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   244
lemmas coeff_pCons = pCons.rep_eq
29455
0139c9a01ca4 add list-style syntax for pCons
huffman
parents: 29454
diff changeset
   245
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   246
lemma coeff_pCons': "poly.coeff (pCons c p) n = (if n = 0 then c else poly.coeff p (n - 1))"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   247
  by transfer'(auto split: nat.splits)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   248
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   249
lemma coeff_pCons_0 [simp]: "coeff (pCons a p) 0 = a"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   250
  by transfer simp
29455
0139c9a01ca4 add list-style syntax for pCons
huffman
parents: 29454
diff changeset
   251
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   252
lemma coeff_pCons_Suc [simp]: "coeff (pCons a p) (Suc n) = coeff p n"
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   253
  by (simp add: coeff_pCons)
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   254
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   255
lemma degree_pCons_le: "degree (pCons a p) \<le> Suc (degree p)"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   256
  by (rule degree_le) (simp add: coeff_eq_0 coeff_pCons split: nat.split)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   257
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   258
lemma degree_pCons_eq: "p \<noteq> 0 \<Longrightarrow> degree (pCons a p) = Suc (degree p)"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   259
  by (simp add: degree_pCons_le le_antisym le_degree)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   260
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   261
lemma degree_pCons_0: "degree (pCons a 0) = 0"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   262
proof -
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   263
  have "degree (pCons a 0) \<le> Suc 0"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   264
    by (metis (no_types) degree_0 degree_pCons_le)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   265
  then show ?thesis
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   266
    by (metis coeff_0 coeff_pCons_Suc degree_0 eq_zero_or_degree_less less_Suc0)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   267
qed
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   268
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   269
lemma degree_pCons_eq_if [simp]: "degree (pCons a p) = (if p = 0 then 0 else Suc (degree p))"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   270
  by (simp add: degree_pCons_0 degree_pCons_eq)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   271
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   272
lemma pCons_0_0 [simp]: "pCons 0 0 = 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   273
  by (rule poly_eqI) (simp add: coeff_pCons split: nat.split)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   274
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   275
lemma pCons_eq_iff [simp]: "pCons a p = pCons b q \<longleftrightarrow> a = b \<and> p = q"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   276
proof safe
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   277
  assume "pCons a p = pCons b q"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   278
  then have "coeff (pCons a p) 0 = coeff (pCons b q) 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   279
    by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   280
  then show "a = b"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   281
    by simp
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   282
next
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   283
  assume "pCons a p = pCons b q"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   284
  then have "coeff (pCons a p) (Suc n) = coeff (pCons b q) (Suc n)" for n
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   285
    by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   286
  then show "p = q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   287
    by (simp add: poly_eq_iff)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   288
qed
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   289
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   290
lemma pCons_eq_0_iff [simp]: "pCons a p = 0 \<longleftrightarrow> a = 0 \<and> p = 0"
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   291
  using pCons_eq_iff [of a p 0 0] by simp
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   292
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   293
lemma pCons_cases [cases type: poly]:
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   294
  obtains (pCons) a q where "p = pCons a q"
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   295
proof
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   296
  show "p = pCons (coeff p 0) (Abs_poly (\<lambda>n. coeff p (Suc n)))"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   297
    by transfer
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   298
      (simp_all add: MOST_inj[where f=Suc and P="\<lambda>n. p n = 0" for p] fun_eq_iff Abs_poly_inverse
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   299
        split: nat.split)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   300
qed
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   301
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   302
lemma pCons_induct [case_names 0 pCons, induct type: poly]:
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   303
  assumes zero: "P 0"
54856
356b4c0a2061 more general induction rule;
haftmann
parents: 54855
diff changeset
   304
  assumes pCons: "\<And>a p. a \<noteq> 0 \<or> p \<noteq> 0 \<Longrightarrow> P p \<Longrightarrow> P (pCons a p)"
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   305
  shows "P p"
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   306
proof (induct p rule: measure_induct_rule [where f=degree])
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   307
  case (less p)
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   308
  obtain a q where "p = pCons a q" by (rule pCons_cases)
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   309
  have "P q"
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   310
  proof (cases "q = 0")
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   311
    case True
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   312
    then show "P q" by (simp add: zero)
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   313
  next
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   314
    case False
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   315
    then have "degree (pCons a q) = Suc (degree q)"
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   316
      by (rule degree_pCons_eq)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   317
    with \<open>p = pCons a q\<close> have "degree q < degree p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   318
      by simp
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   319
    then show "P q"
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   320
      by (rule less.hyps)
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   321
  qed
54856
356b4c0a2061 more general induction rule;
haftmann
parents: 54855
diff changeset
   322
  have "P (pCons a q)"
356b4c0a2061 more general induction rule;
haftmann
parents: 54855
diff changeset
   323
  proof (cases "a \<noteq> 0 \<or> q \<noteq> 0")
356b4c0a2061 more general induction rule;
haftmann
parents: 54855
diff changeset
   324
    case True
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   325
    with \<open>P q\<close> show ?thesis by (auto intro: pCons)
54856
356b4c0a2061 more general induction rule;
haftmann
parents: 54855
diff changeset
   326
  next
356b4c0a2061 more general induction rule;
haftmann
parents: 54855
diff changeset
   327
    case False
356b4c0a2061 more general induction rule;
haftmann
parents: 54855
diff changeset
   328
    with zero show ?thesis by simp
356b4c0a2061 more general induction rule;
haftmann
parents: 54855
diff changeset
   329
  qed
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   330
  with \<open>p = pCons a q\<close> show ?case
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   331
    by simp
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   332
qed
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   333
60570
7ed2cde6806d more theorems
haftmann
parents: 60562
diff changeset
   334
lemma degree_eq_zeroE:
7ed2cde6806d more theorems
haftmann
parents: 60562
diff changeset
   335
  fixes p :: "'a::zero poly"
7ed2cde6806d more theorems
haftmann
parents: 60562
diff changeset
   336
  assumes "degree p = 0"
7ed2cde6806d more theorems
haftmann
parents: 60562
diff changeset
   337
  obtains a where "p = pCons a 0"
7ed2cde6806d more theorems
haftmann
parents: 60562
diff changeset
   338
proof -
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   339
  obtain a q where p: "p = pCons a q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   340
    by (cases p)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   341
  with assms have "q = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   342
    by (cases "q = 0") simp_all
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   343
  with p have "p = pCons a 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   344
    by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   345
  then show thesis ..
60570
7ed2cde6806d more theorems
haftmann
parents: 60562
diff changeset
   346
qed
7ed2cde6806d more theorems
haftmann
parents: 60562
diff changeset
   347
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   348
62422
4aa35fd6c152 Tuned Euclidean rings
eberlm
parents: 62352
diff changeset
   349
subsection \<open>Quickcheck generator for polynomials\<close>
4aa35fd6c152 Tuned Euclidean rings
eberlm
parents: 62352
diff changeset
   350
4aa35fd6c152 Tuned Euclidean rings
eberlm
parents: 62352
diff changeset
   351
quickcheck_generator poly constructors: "0 :: _ poly", pCons
4aa35fd6c152 Tuned Euclidean rings
eberlm
parents: 62352
diff changeset
   352
4aa35fd6c152 Tuned Euclidean rings
eberlm
parents: 62352
diff changeset
   353
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   354
subsection \<open>List-style syntax for polynomials\<close>
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   355
80786
70076ba563d2 more specific "args" syntax, to support more markup for syntax consts;
wenzelm
parents: 80084
diff changeset
   356
syntax
81090
843dba3d307a clarified syntax: use outer block (with indent);
wenzelm
parents: 81019
diff changeset
   357
  "_poly" :: "args \<Rightarrow> 'a poly"  (\<open>(\<open>indent=2 notation=\<open>mixfix polynomial enumeration\<close>\<close>[:_:])\<close>)
81182
fc5066122e68 more inner-syntax markup;
wenzelm
parents: 81175
diff changeset
   358
syntax_consts
fc5066122e68 more inner-syntax markup;
wenzelm
parents: 81175
diff changeset
   359
  "_poly" \<rightleftharpoons> pCons
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   360
translations
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   361
  "[:x, xs:]" \<rightleftharpoons> "CONST pCons x [:xs:]"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   362
  "[:x:]" \<rightleftharpoons> "CONST pCons x 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   363
82187
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   364
lemma degree_0_id: 
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   365
  assumes "degree p = 0"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   366
  shows "[: coeff p 0 :] = p"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   367
  by (metis assms coeff_pCons_0 degree_eq_zeroE) 
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   368
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   369
lemma degree0_coeffs: "degree p = 0 \<Longrightarrow> \<exists> a. p = [: a :]"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   370
  by (meson degree_eq_zeroE)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   371
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   372
lemma degree1_coeffs:
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   373
  fixes p :: "'a::zero poly"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   374
  assumes "degree p = 1"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   375
  obtains a b where "p = [: b, a :]" "a \<noteq> 0"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   376
proof -
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   377
  obtain b a q where "p = pCons b q" "q = pCons a 0"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   378
    by (metis assms degree0_coeffs degree_0 degree_pCons_eq_if lessI less_one pCons_cases)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   379
  then show thesis
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   380
    using assms that by force
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   381
qed
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   382
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   383
lemma degree2_coeffs:
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   384
  fixes p :: "'a::zero poly"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   385
  assumes "degree p = 2"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   386
  obtains a b c where "p = [: c, b, a :]" "a \<noteq> 0"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   387
proof -
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   388
  obtain c q where "p = pCons c q" "degree q = 1"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   389
    by (metis One_nat_def assms degree_0 degree_pCons_eq_if fact_0 fact_2 nat.inject numeral_2_eq_2 pCons_cases)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   390
  then show thesis
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   391
    by (metis degree1_coeffs that)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   392
qed
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   393
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   394
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   395
subsection \<open>Representation of polynomials by lists of coefficients\<close>
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   396
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   397
primrec Poly :: "'a::zero list \<Rightarrow> 'a poly"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   398
  where
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   399
    [code_post]: "Poly [] = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   400
  | [code_post]: "Poly (a # as) = pCons a (Poly as)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   401
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   402
lemma Poly_replicate_0 [simp]: "Poly (replicate n 0) = 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   403
  by (induct n) simp_all
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   404
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   405
lemma Poly_eq_0: "Poly as = 0 \<longleftrightarrow> (\<exists>n. as = replicate n 0)"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   406
  by (induct as) (auto simp add: Cons_replicate_eq)
63027
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
   407
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   408
lemma Poly_append_replicate_zero [simp]: "Poly (as @ replicate n 0) = Poly as"
63027
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
   409
  by (induct as) simp_all
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
   410
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   411
lemma Poly_snoc_zero [simp]: "Poly (as @ [0]) = Poly as"
63027
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
   412
  using Poly_append_replicate_zero [of as 1] by simp
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
   413
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   414
lemma Poly_cCons_eq_pCons_Poly [simp]: "Poly (a ## p) = pCons a (Poly p)"
63027
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
   415
  by (simp add: cCons_def)
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
   416
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   417
lemma Poly_on_rev_starting_with_0 [simp]: "hd as = 0 \<Longrightarrow> Poly (rev (tl as)) = Poly (rev as)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   418
  by (cases as) simp_all
63027
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
   419
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
   420
lemma degree_Poly: "degree (Poly xs) \<le> length xs"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   421
  by (induct xs) simp_all
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   422
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   423
lemma coeff_Poly_eq [simp]: "coeff (Poly xs) = nth_default 0 xs"
63027
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
   424
  by (induct xs) (simp_all add: fun_eq_iff coeff_pCons split: nat.splits)
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
   425
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   426
definition coeffs :: "'a poly \<Rightarrow> 'a::zero list"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   427
  where "coeffs p = (if p = 0 then [] else map (\<lambda>i. coeff p i) [0 ..< Suc (degree p)])"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   428
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   429
lemma coeffs_eq_Nil [simp]: "coeffs p = [] \<longleftrightarrow> p = 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   430
  by (simp add: coeffs_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   431
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   432
lemma not_0_coeffs_not_Nil: "p \<noteq> 0 \<Longrightarrow> coeffs p \<noteq> []"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   433
  by simp
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   434
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   435
lemma coeffs_0_eq_Nil [simp]: "coeffs 0 = []"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   436
  by simp
29454
b0f586f38dd7 add recursion combinator poly_rec; define poly function using poly_rec
huffman
parents: 29453
diff changeset
   437
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   438
lemma coeffs_pCons_eq_cCons [simp]: "coeffs (pCons a p) = a ## coeffs p"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   439
proof -
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   440
  have *: "\<forall>m\<in>set ms. m > 0 \<Longrightarrow> map (case_nat x f) ms = map f (map (\<lambda>n. n - 1) ms)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   441
    for ms :: "nat list" and f :: "nat \<Rightarrow> 'a" and x :: "'a"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   442
    by (induct ms) (auto split: nat.split)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   443
  show ?thesis
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   444
    by (simp add: * coeffs_def upt_conv_Cons coeff_pCons map_decr_upt del: upt_Suc)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   445
qed
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   446
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
   447
lemma length_coeffs: "p \<noteq> 0 \<Longrightarrow> length (coeffs p) = degree p + 1"
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
   448
  by (simp add: coeffs_def)
64860
4d56170d97b3 generalized definition
haftmann
parents: 64849
diff changeset
   449
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   450
lemma coeffs_nth: "p \<noteq> 0 \<Longrightarrow> n \<le> degree p \<Longrightarrow> coeffs p ! n = coeff p n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   451
  by (auto simp: coeffs_def simp del: upt_Suc)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   452
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   453
lemma coeff_in_coeffs: "p \<noteq> 0 \<Longrightarrow> n \<le> degree p \<Longrightarrow> coeff p n \<in> set (coeffs p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   454
  using coeffs_nth [of p n, symmetric] by (simp add: length_coeffs)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   455
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   456
lemma not_0_cCons_eq [simp]: "p \<noteq> 0 \<Longrightarrow> a ## coeffs p = a # coeffs p"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   457
  by (simp add: cCons_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   458
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   459
lemma Poly_coeffs [simp, code abstype]: "Poly (coeffs p) = p"
54856
356b4c0a2061 more general induction rule;
haftmann
parents: 54855
diff changeset
   460
  by (induct p) auto
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   461
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   462
lemma coeffs_Poly [simp]: "coeffs (Poly as) = strip_while (HOL.eq 0) as"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   463
proof (induct as)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   464
  case Nil
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   465
  then show ?case by simp
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   466
next
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   467
  case (Cons a as)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   468
  from replicate_length_same [of as 0] have "(\<forall>n. as \<noteq> replicate n 0) \<longleftrightarrow> (\<exists>a\<in>set as. a \<noteq> 0)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   469
    by (auto dest: sym [of _ as])
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   470
  with Cons show ?case by auto
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   471
qed
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   472
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   473
lemma no_trailing_coeffs [simp]:
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   474
  "no_trailing (HOL.eq 0) (coeffs p)"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   475
  by (induct p)  auto
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   476
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   477
lemma strip_while_coeffs [simp]:
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   478
  "strip_while (HOL.eq 0) (coeffs p) = coeffs p"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   479
  by simp
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   480
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   481
lemma coeffs_eq_iff: "p = q \<longleftrightarrow> coeffs p = coeffs q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   482
  (is "?P \<longleftrightarrow> ?Q")
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   483
proof
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   484
  assume ?P
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   485
  then show ?Q by simp
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   486
next
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   487
  assume ?Q
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   488
  then have "Poly (coeffs p) = Poly (coeffs q)" by simp
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   489
  then show ?P by simp
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   490
qed
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   491
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   492
lemma nth_default_coeffs_eq: "nth_default 0 (coeffs p) = coeff p"
82187
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   493
  by (metis Poly_coeffs coeff_Poly_eq)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   494
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   495
lemma range_coeff: "range (coeff p) = insert 0 (set (coeffs p))" 
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   496
  by (metis nth_default_coeffs_eq range_nth_default)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   497
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   498
lemma [code]: "coeff p = nth_default 0 (coeffs p)"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   499
  by (simp add: nth_default_coeffs_eq)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   500
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   501
lemma coeffs_eqI:
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   502
  assumes coeff: "\<And>n. coeff p n = nth_default 0 xs n"
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   503
  assumes zero: "no_trailing (HOL.eq 0) xs"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   504
  shows "coeffs p = xs"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   505
proof -
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   506
  from coeff have "p = Poly xs"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   507
    by (simp add: poly_eq_iff)
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   508
  with zero show ?thesis by simp
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   509
qed
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   510
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   511
lemma degree_eq_length_coeffs [code]: "degree p = length (coeffs p) - 1"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   512
  by (simp add: coeffs_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   513
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   514
lemma length_coeffs_degree: "p \<noteq> 0 \<Longrightarrow> length (coeffs p) = Suc (degree p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   515
  by (induct p) (auto simp: cCons_def)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   516
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   517
lemma [code abstract]: "coeffs 0 = []"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   518
  by (fact coeffs_0_eq_Nil)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   519
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   520
lemma [code abstract]: "coeffs (pCons a p) = a ## coeffs p"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   521
  by (fact coeffs_pCons_eq_cCons)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   522
65811
2653f1cd8775 more lemmas
haftmann
parents: 65577
diff changeset
   523
lemma set_coeffs_subset_singleton_0_iff [simp]:
2653f1cd8775 more lemmas
haftmann
parents: 65577
diff changeset
   524
  "set (coeffs p) \<subseteq> {0} \<longleftrightarrow> p = 0"
2653f1cd8775 more lemmas
haftmann
parents: 65577
diff changeset
   525
  by (auto simp add: coeffs_def intro: classical)
2653f1cd8775 more lemmas
haftmann
parents: 65577
diff changeset
   526
2653f1cd8775 more lemmas
haftmann
parents: 65577
diff changeset
   527
lemma set_coeffs_not_only_0 [simp]:
2653f1cd8775 more lemmas
haftmann
parents: 65577
diff changeset
   528
  "set (coeffs p) \<noteq> {0}"
2653f1cd8775 more lemmas
haftmann
parents: 65577
diff changeset
   529
  by (auto simp add: set_eq_subset)
2653f1cd8775 more lemmas
haftmann
parents: 65577
diff changeset
   530
2653f1cd8775 more lemmas
haftmann
parents: 65577
diff changeset
   531
lemma forall_coeffs_conv:
2653f1cd8775 more lemmas
haftmann
parents: 65577
diff changeset
   532
  "(\<forall>n. P (coeff p n)) \<longleftrightarrow> (\<forall>c \<in> set (coeffs p). P c)" if "P 0"
2653f1cd8775 more lemmas
haftmann
parents: 65577
diff changeset
   533
  using that by (auto simp add: coeffs_def)
2653f1cd8775 more lemmas
haftmann
parents: 65577
diff changeset
   534
    (metis atLeastLessThan_iff coeff_eq_0 not_less_iff_gr_or_eq zero_le)
2653f1cd8775 more lemmas
haftmann
parents: 65577
diff changeset
   535
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   536
instantiation poly :: ("{zero, equal}") equal
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   537
begin
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   538
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   539
definition [code]: "HOL.equal (p::'a poly) q \<longleftrightarrow> HOL.equal (coeffs p) (coeffs q)"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   540
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   541
instance
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   542
  by standard (simp add: equal equal_poly_def coeffs_eq_iff)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   543
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   544
end
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   545
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   546
lemma [code nbe]: "HOL.equal (p :: _ poly) p \<longleftrightarrow> True"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   547
  by (fact equal_refl)
29454
b0f586f38dd7 add recursion combinator poly_rec; define poly function using poly_rec
huffman
parents: 29453
diff changeset
   548
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   549
definition is_zero :: "'a::zero poly \<Rightarrow> bool"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   550
  where [code]: "is_zero p \<longleftrightarrow> List.null (coeffs p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   551
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   552
lemma is_zero_null [code_abbrev]: "is_zero p \<longleftrightarrow> p = 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   553
  by (simp add: is_zero_def null_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   554
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   555
79672
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
   556
text \<open>Reconstructing the polynomial from the list\<close>
63145
703edebd1d92 isabelle update_cartouches -c -t;
wenzelm
parents: 63060
diff changeset
   557
  \<comment> \<open>contributed by Sebastiaan J.C. Joosten and René Thiemann\<close>
63027
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
   558
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
   559
definition poly_of_list :: "'a::comm_monoid_add list \<Rightarrow> 'a poly"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   560
  where [simp]: "poly_of_list = Poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   561
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   562
lemma poly_of_list_impl [code abstract]: "coeffs (poly_of_list as) = strip_while (HOL.eq 0) as"
63027
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
   563
  by simp
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
   564
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   565
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   566
subsection \<open>Fold combinator for polynomials\<close>
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   567
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   568
definition fold_coeffs :: "('a::zero \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'a poly \<Rightarrow> 'b \<Rightarrow> 'b"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   569
  where "fold_coeffs f p = foldr f (coeffs p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   570
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   571
lemma fold_coeffs_0_eq [simp]: "fold_coeffs f 0 = id"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   572
  by (simp add: fold_coeffs_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   573
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   574
lemma fold_coeffs_pCons_eq [simp]: "f 0 = id \<Longrightarrow> fold_coeffs f (pCons a p) = f a \<circ> fold_coeffs f p"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   575
  by (simp add: fold_coeffs_def cCons_def fun_eq_iff)
29454
b0f586f38dd7 add recursion combinator poly_rec; define poly function using poly_rec
huffman
parents: 29453
diff changeset
   576
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   577
lemma fold_coeffs_pCons_0_0_eq [simp]: "fold_coeffs f (pCons 0 0) = id"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   578
  by (simp add: fold_coeffs_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   579
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   580
lemma fold_coeffs_pCons_coeff_not_0_eq [simp]:
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   581
  "a \<noteq> 0 \<Longrightarrow> fold_coeffs f (pCons a p) = f a \<circ> fold_coeffs f p"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   582
  by (simp add: fold_coeffs_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   583
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   584
lemma fold_coeffs_pCons_not_0_0_eq [simp]:
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   585
  "p \<noteq> 0 \<Longrightarrow> fold_coeffs f (pCons a p) = f a \<circ> fold_coeffs f p"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   586
  by (simp add: fold_coeffs_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   587
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   588
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   589
subsection \<open>Canonical morphism on polynomials -- evaluation\<close>
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   590
72024
9b4135e8bade a generic horner sum operation
haftmann
parents: 71586
diff changeset
   591
definition poly :: \<open>'a::comm_semiring_0 poly \<Rightarrow> 'a \<Rightarrow> 'a\<close>
9b4135e8bade a generic horner sum operation
haftmann
parents: 71586
diff changeset
   592
  where \<open>poly p a = horner_sum id a (coeffs p)\<close>
9b4135e8bade a generic horner sum operation
haftmann
parents: 71586
diff changeset
   593
9b4135e8bade a generic horner sum operation
haftmann
parents: 71586
diff changeset
   594
lemma poly_eq_fold_coeffs:
9b4135e8bade a generic horner sum operation
haftmann
parents: 71586
diff changeset
   595
  \<open>poly p = fold_coeffs (\<lambda>a f x. a + x * f x) p (\<lambda>x. 0)\<close>
9b4135e8bade a generic horner sum operation
haftmann
parents: 71586
diff changeset
   596
  by (induction p) (auto simp add: fun_eq_iff poly_def)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   597
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   598
lemma poly_0 [simp]: "poly 0 x = 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   599
  by (simp add: poly_def)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   600
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   601
lemma poly_pCons [simp]: "poly (pCons a p) x = a + x * poly p x"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   602
  by (cases "p = 0 \<and> a = 0") (auto simp add: poly_def)
29454
b0f586f38dd7 add recursion combinator poly_rec; define poly function using poly_rec
huffman
parents: 29453
diff changeset
   603
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   604
lemma poly_altdef: "poly p x = (\<Sum>i\<le>degree p. coeff p i * x ^ i)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   605
  for x :: "'a::{comm_semiring_0,semiring_1}"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
   606
proof (induction p rule: pCons_induct)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   607
  case 0
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   608
  then show ?case
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   609
    by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   610
next
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
   611
  case (pCons a p)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   612
  show ?case
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   613
  proof (cases "p = 0")
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   614
    case True
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   615
    then show ?thesis by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   616
  next
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   617
    case False
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   618
    let ?p' = "pCons a p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   619
    note poly_pCons[of a p x]
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   620
    also note pCons.IH
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   621
    also have "a + x * (\<Sum>i\<le>degree p. coeff p i * x ^ i) =
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   622
        coeff ?p' 0 * x^0 + (\<Sum>i\<le>degree p. coeff ?p' (Suc i) * x^Suc i)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   623
      by (simp add: field_simps sum_distrib_left coeff_pCons)
70113
c8deb8ba6d05 Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
paulson <lp15@cam.ac.uk>
parents: 70097
diff changeset
   624
    also note sum.atMost_Suc_shift[symmetric]
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   625
    also note degree_pCons_eq[OF \<open>p \<noteq> 0\<close>, of a, symmetric]
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   626
    finally show ?thesis .
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   627
  qed
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   628
qed
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
   629
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
   630
lemma poly_0_coeff_0: "poly p 0 = coeff p 0"
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
   631
  by (cases p) (auto simp: poly_altdef)
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
   632
82187
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   633
lemma poly_zero:
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   634
  fixes p :: "'a :: comm_ring_1 poly"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   635
  assumes x: "poly p x = 0" shows "p = 0 \<longleftrightarrow> degree p = 0"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   636
proof
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   637
  assume degp: "degree p = 0"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   638
  hence "poly p x = coeff p (degree p)" by(subst degree_0_id[OF degp,symmetric], simp)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   639
  hence "coeff p (degree p) = 0" using x by auto
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   640
  thus "p = 0" by auto
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   641
qed auto
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
   642
29454
b0f586f38dd7 add recursion combinator poly_rec; define poly function using poly_rec
huffman
parents: 29453
diff changeset
   643
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   644
subsection \<open>Monomials\<close>
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   645
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   646
lift_definition monom :: "'a \<Rightarrow> nat \<Rightarrow> 'a::zero poly"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   647
  is "\<lambda>a m n. if m = n then a else 0"
59983
cd2efd7d06bd replace almost_everywhere_zero by Infinite_Set.MOST
hoelzl
parents: 59815
diff changeset
   648
  by (simp add: MOST_iff_cofinite)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   649
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   650
lemma coeff_monom [simp]: "coeff (monom a m) n = (if m = n then a else 0)"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   651
  by transfer rule
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   652
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
   653
lemma monom_0: "monom a 0 = [:a:]"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   654
  by (rule poly_eqI) (simp add: coeff_pCons split: nat.split)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   655
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   656
lemma monom_Suc: "monom a (Suc n) = pCons 0 (monom a n)"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   657
  by (rule poly_eqI) (simp add: coeff_pCons split: nat.split)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   658
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   659
lemma monom_eq_0 [simp]: "monom 0 n = 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   660
  by (rule poly_eqI) simp
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   661
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   662
lemma monom_eq_0_iff [simp]: "monom a n = 0 \<longleftrightarrow> a = 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   663
  by (simp add: poly_eq_iff)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   664
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   665
lemma monom_eq_iff [simp]: "monom a n = monom b n \<longleftrightarrow> a = b"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   666
  by (simp add: poly_eq_iff)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   667
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   668
lemma degree_monom_le: "degree (monom a n) \<le> n"
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   669
  by (rule degree_le, simp)
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   670
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   671
lemma degree_monom_eq: "a \<noteq> 0 \<Longrightarrow> degree (monom a n) = n"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   672
  by (metis coeff_monom leading_coeff_0_iff)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   673
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   674
lemma coeffs_monom [code abstract]:
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   675
  "coeffs (monom a n) = (if a = 0 then [] else replicate n 0 @ [a])"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   676
  by (induct n) (simp_all add: monom_0 monom_Suc)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   677
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   678
lemma fold_coeffs_monom [simp]: "a \<noteq> 0 \<Longrightarrow> fold_coeffs f (monom a n) = f 0 ^^ n \<circ> f a"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   679
  by (simp add: fold_coeffs_def coeffs_monom fun_eq_iff)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   680
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   681
lemma poly_monom: "poly (monom a n) x = a * x ^ n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   682
  for a x :: "'a::comm_semiring_1"
72024
9b4135e8bade a generic horner sum operation
haftmann
parents: 71586
diff changeset
   683
  by (cases "a = 0", simp_all) (induct n, simp_all add: mult.left_commute poly_eq_fold_coeffs)
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
   684
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
   685
lemma monom_eq_iff': "monom c n = monom d m \<longleftrightarrow>  c = d \<and> (c = 0 \<or> n = m)"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
   686
  by (auto simp: poly_eq_iff)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   687
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
   688
lemma monom_eq_const_iff: "monom c n = [:d:] \<longleftrightarrow> c = d \<and> (c = 0 \<or> n = 0)"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
   689
  using monom_eq_iff'[of c n d 0] by (simp add: monom_0)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   690
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   691
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   692
subsection \<open>Leading coefficient\<close>
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   693
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   694
abbreviation lead_coeff:: "'a::zero poly \<Rightarrow> 'a"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   695
  where "lead_coeff p \<equiv> coeff p (degree p)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   696
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   697
lemma lead_coeff_pCons[simp]:
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   698
  "p \<noteq> 0 \<Longrightarrow> lead_coeff (pCons a p) = lead_coeff p"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   699
  "p = 0 \<Longrightarrow> lead_coeff (pCons a p) = a"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   700
  by auto
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   701
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   702
lemma lead_coeff_monom [simp]: "lead_coeff (monom c n) = c"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   703
  by (cases "c = 0") (simp_all add: degree_monom_eq)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   704
66799
haftmann
parents: 66550
diff changeset
   705
lemma last_coeffs_eq_coeff_degree:
haftmann
parents: 66550
diff changeset
   706
  "last (coeffs p) = lead_coeff p" if "p \<noteq> 0"
haftmann
parents: 66550
diff changeset
   707
  using that by (simp add: coeffs_def)
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
   708
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   709
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   710
subsection \<open>Addition and subtraction\<close>
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   711
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   712
instantiation poly :: (comm_monoid_add) comm_monoid_add
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   713
begin
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   714
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   715
lift_definition plus_poly :: "'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   716
  is "\<lambda>p q n. coeff p n + coeff q n"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59983
diff changeset
   717
proof -
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   718
  fix q p :: "'a poly"
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   719
  show "\<forall>\<^sub>\<infinity>n. coeff p n + coeff q n = 0"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59983
diff changeset
   720
    using MOST_coeff_eq_0[of p] MOST_coeff_eq_0[of q] by eventually_elim simp
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   721
qed
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   722
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   723
lemma coeff_add [simp]: "coeff (p + q) n = coeff p n + coeff q n"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   724
  by (simp add: plus_poly.rep_eq)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   725
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   726
instance
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   727
proof
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   728
  fix p q r :: "'a poly"
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   729
  show "(p + q) + r = p + (q + r)"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57482
diff changeset
   730
    by (simp add: poly_eq_iff add.assoc)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   731
  show "p + q = q + p"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57482
diff changeset
   732
    by (simp add: poly_eq_iff add.commute)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   733
  show "0 + p = p"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   734
    by (simp add: poly_eq_iff)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   735
qed
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   736
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   737
end
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   738
59815
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59557
diff changeset
   739
instantiation poly :: (cancel_comm_monoid_add) cancel_comm_monoid_add
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59557
diff changeset
   740
begin
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59557
diff changeset
   741
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59557
diff changeset
   742
lift_definition minus_poly :: "'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly"
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59557
diff changeset
   743
  is "\<lambda>p q n. coeff p n - coeff q n"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59983
diff changeset
   744
proof -
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   745
  fix q p :: "'a poly"
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   746
  show "\<forall>\<^sub>\<infinity>n. coeff p n - coeff q n = 0"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59983
diff changeset
   747
    using MOST_coeff_eq_0[of p] MOST_coeff_eq_0[of q] by eventually_elim simp
59815
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59557
diff changeset
   748
qed
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59557
diff changeset
   749
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   750
lemma coeff_diff [simp]: "coeff (p - q) n = coeff p n - coeff q n"
59815
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59557
diff changeset
   751
  by (simp add: minus_poly.rep_eq)
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59557
diff changeset
   752
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   753
instance
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   754
proof
29540
8858d197a9b6 more instance declarations for poly
huffman
parents: 29539
diff changeset
   755
  fix p q r :: "'a poly"
59815
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59557
diff changeset
   756
  show "p + q - p = q"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   757
    by (simp add: poly_eq_iff)
59815
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59557
diff changeset
   758
  show "p - q - r = p - (q + r)"
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59557
diff changeset
   759
    by (simp add: poly_eq_iff diff_diff_eq)
29540
8858d197a9b6 more instance declarations for poly
huffman
parents: 29539
diff changeset
   760
qed
8858d197a9b6 more instance declarations for poly
huffman
parents: 29539
diff changeset
   761
59815
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59557
diff changeset
   762
end
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59557
diff changeset
   763
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   764
instantiation poly :: (ab_group_add) ab_group_add
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   765
begin
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   766
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   767
lift_definition uminus_poly :: "'a poly \<Rightarrow> 'a poly"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   768
  is "\<lambda>p n. - coeff p n"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59983
diff changeset
   769
proof -
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   770
  fix p :: "'a poly"
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   771
  show "\<forall>\<^sub>\<infinity>n. - coeff p n = 0"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59983
diff changeset
   772
    using MOST_coeff_eq_0 by simp
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   773
qed
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   774
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   775
lemma coeff_minus [simp]: "coeff (- p) n = - coeff p n"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   776
  by (simp add: uminus_poly.rep_eq)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   777
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   778
instance
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
   779
proof
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   780
  fix p q :: "'a poly"
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   781
  show "- p + p = 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   782
    by (simp add: poly_eq_iff)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   783
  show "p - q = p + - q"
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 52380
diff changeset
   784
    by (simp add: poly_eq_iff)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   785
qed
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   786
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   787
end
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   788
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   789
lemma add_pCons [simp]: "pCons a p + pCons b q = pCons (a + b) (p + q)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   790
  by (rule poly_eqI) (simp add: coeff_pCons split: nat.split)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   791
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   792
lemma minus_pCons [simp]: "- pCons a p = pCons (- a) (- p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   793
  by (rule poly_eqI) (simp add: coeff_pCons split: nat.split)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   794
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   795
lemma diff_pCons [simp]: "pCons a p - pCons b q = pCons (a - b) (p - q)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   796
  by (rule poly_eqI) (simp add: coeff_pCons split: nat.split)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   797
29539
abfe2af6883e add lemmas about degree
huffman
parents: 29537
diff changeset
   798
lemma degree_add_le_max: "degree (p + q) \<le> max (degree p) (degree q)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   799
  by (rule degree_le) (auto simp add: coeff_eq_0)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   800
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   801
lemma degree_add_le: "degree p \<le> n \<Longrightarrow> degree q \<le> n \<Longrightarrow> degree (p + q) \<le> n"
29539
abfe2af6883e add lemmas about degree
huffman
parents: 29537
diff changeset
   802
  by (auto intro: order_trans degree_add_le_max)
abfe2af6883e add lemmas about degree
huffman
parents: 29537
diff changeset
   803
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   804
lemma degree_add_less: "degree p < n \<Longrightarrow> degree q < n \<Longrightarrow> degree (p + q) < n"
29539
abfe2af6883e add lemmas about degree
huffman
parents: 29537
diff changeset
   805
  by (auto intro: le_less_trans degree_add_le_max)
29453
de4f26f59135 add lemmas degree_{add,diff}_less
huffman
parents: 29451
diff changeset
   806
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   807
lemma degree_add_eq_right: assumes "degree p < degree q" shows "degree (p + q) = degree q"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   808
proof (cases "q = 0")
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   809
  case False
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   810
  show ?thesis
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   811
  proof (rule order_antisym)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   812
    show "degree (p + q) \<le> degree q"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   813
      by (simp add: assms degree_add_le order.strict_implies_order)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   814
    show "degree q \<le> degree (p + q)"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   815
      by (simp add: False assms coeff_eq_0 le_degree)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   816
  qed
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   817
qed (use assms in auto)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   818
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   819
lemma degree_add_eq_left: "degree q < degree p \<Longrightarrow> degree (p + q) = degree p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   820
  using degree_add_eq_right [of q p] by (simp add: add.commute)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   821
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   822
lemma degree_minus [simp]: "degree (- p) = degree p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   823
  by (simp add: degree_def)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   824
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   825
lemma lead_coeff_add_le: "degree p < degree q \<Longrightarrow> lead_coeff (p + q) = lead_coeff q"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   826
  by (metis coeff_add coeff_eq_0 monoid_add_class.add.left_neutral degree_add_eq_right)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   827
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   828
lemma lead_coeff_minus: "lead_coeff (- p) = - lead_coeff p"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   829
  by (metis coeff_minus degree_minus)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
   830
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   831
lemma degree_diff_le_max: "degree (p - q) \<le> max (degree p) (degree q)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   832
  for p q :: "'a::ab_group_add poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   833
  using degree_add_le [where p=p and q="-q"] by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   834
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   835
lemma degree_diff_le: "degree p \<le> n \<Longrightarrow> degree q \<le> n \<Longrightarrow> degree (p - q) \<le> n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   836
  for p q :: "'a::ab_group_add poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   837
  using degree_add_le [of p n "- q"] by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   838
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   839
lemma degree_diff_less: "degree p < n \<Longrightarrow> degree q < n \<Longrightarrow> degree (p - q) < n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   840
  for p q :: "'a::ab_group_add poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   841
  using degree_add_less [of p n "- q"] by simp
29453
de4f26f59135 add lemmas degree_{add,diff}_less
huffman
parents: 29451
diff changeset
   842
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   843
lemma add_monom: "monom a n + monom b n = monom (a + b) n"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   844
  by (rule poly_eqI) simp
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   845
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   846
lemma diff_monom: "monom a n - monom b n = monom (a - b) n"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   847
  by (rule poly_eqI) simp
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   848
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   849
lemma minus_monom: "- monom a n = monom (- a) n"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   850
  by (rule poly_eqI) simp
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   851
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63950
diff changeset
   852
lemma coeff_sum: "coeff (\<Sum>x\<in>A. p x) i = (\<Sum>x\<in>A. coeff (p x) i)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   853
  by (induct A rule: infinite_finite_induct) simp_all
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   854
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63950
diff changeset
   855
lemma monom_sum: "monom (\<Sum>x\<in>A. a x) n = (\<Sum>x\<in>A. monom (a x) n)"
b9a1486e79be setsum -> sum
nipkow
parents: 63950
diff changeset
   856
  by (rule poly_eqI) (simp add: coeff_sum)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   857
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   858
fun plus_coeffs :: "'a::comm_monoid_add list \<Rightarrow> 'a list \<Rightarrow> 'a list"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   859
  where
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   860
    "plus_coeffs xs [] = xs"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   861
  | "plus_coeffs [] ys = ys"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   862
  | "plus_coeffs (x # xs) (y # ys) = (x + y) ## plus_coeffs xs ys"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   863
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   864
lemma coeffs_plus_eq_plus_coeffs [code abstract]:
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   865
  "coeffs (p + q) = plus_coeffs (coeffs p) (coeffs q)"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   866
proof -
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   867
  have *: "nth_default 0 (plus_coeffs xs ys) n = nth_default 0 xs n + nth_default 0 ys n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   868
    for xs ys :: "'a list" and n
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   869
  proof (induct xs ys arbitrary: n rule: plus_coeffs.induct)
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   870
    case (3 x xs y ys n)
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   871
    then show ?case
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   872
      by (cases n) (auto simp add: cCons_def)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   873
  qed simp_all
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   874
  have **: "no_trailing (HOL.eq 0) (plus_coeffs xs ys)"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   875
    if "no_trailing (HOL.eq 0) xs" and "no_trailing (HOL.eq 0) ys"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   876
    for xs ys :: "'a list"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   877
    using that by (induct xs ys rule: plus_coeffs.induct) (simp_all add: cCons_def)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   878
  show ?thesis
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   879
    by (rule coeffs_eqI) (auto simp add: * nth_default_coeffs_eq intro: **)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   880
qed
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   881
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   882
lemma coeffs_uminus [code abstract]:
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   883
  "coeffs (- p) = map uminus (coeffs p)"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   884
proof -
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   885
  have eq_0: "HOL.eq 0 \<circ> uminus = HOL.eq (0::'a)"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   886
    by (simp add: fun_eq_iff)
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   887
  show ?thesis
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   888
    by (rule coeffs_eqI) (simp_all add: nth_default_map_eq nth_default_coeffs_eq no_trailing_map eq_0)
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
   889
qed
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   890
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   891
lemma [code]: "p - q = p + - q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   892
  for p q :: "'a::ab_group_add poly"
59557
ebd8ecacfba6 establish unique preferred fact names
haftmann
parents: 59487
diff changeset
   893
  by (fact diff_conv_add_uminus)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   894
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   895
lemma poly_add [simp]: "poly (p + q) x = poly p x + poly q x"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   896
proof (induction p arbitrary: q)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   897
  case (pCons a p)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   898
  then show ?case
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   899
    by (cases q) (simp add: algebra_simps)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
   900
qed auto
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   901
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   902
lemma poly_minus [simp]: "poly (- p) x = - poly p x"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   903
  for x :: "'a::comm_ring"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   904
  by (induct p) simp_all
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   905
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   906
lemma poly_diff [simp]: "poly (p - q) x = poly p x - poly q x"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   907
  for x :: "'a::comm_ring"
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 52380
diff changeset
   908
  using poly_add [of p "- q" x] by simp
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   909
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63950
diff changeset
   910
lemma poly_sum: "poly (\<Sum>k\<in>A. p k) x = (\<Sum>k\<in>A. poly (p k) x)"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   911
  by (induct A rule: infinite_finite_induct) simp_all
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   912
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   913
lemma poly_sum_list: "poly (\<Sum>p\<leftarrow>ps. p) y = (\<Sum>p\<leftarrow>ps. poly p y)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   914
  by (induction ps) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   915
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   916
lemma poly_sum_mset: "poly (\<Sum>x\<in>#A. p x) y = (\<Sum>x\<in>#A. poly (p x) y)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   917
  by (induction A) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   918
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   919
lemma degree_sum_le: "finite S \<Longrightarrow> (\<And>p. p \<in> S \<Longrightarrow> degree (f p) \<le> n) \<Longrightarrow> degree (sum f S) \<le> n"
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
   920
proof (induct S rule: finite_induct)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   921
  case empty
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   922
  then show ?case by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   923
next
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
   924
  case (insert p S)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   925
  then have "degree (sum f S) \<le> n" "degree (f p) \<le> n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   926
    by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   927
  then show ?case
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   928
    unfolding sum.insert[OF insert(1-2)] by (metis degree_add_le)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   929
qed
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   930
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   931
lemma degree_sum_less:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   932
  assumes "\<And>x. x \<in> A \<Longrightarrow> degree (f x) < n" "n > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   933
  shows   "degree (sum f A) < n"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   934
  using assms by (induction rule: infinite_finite_induct) (auto intro!: degree_add_less)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
   935
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   936
lemma poly_as_sum_of_monoms':
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   937
  assumes "degree p \<le> n"
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
   938
  shows "(\<Sum>i\<le>n. monom (coeff p i) i) = p"
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
   939
proof -
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
   940
  have eq: "\<And>i. {..n} \<inter> {i} = (if i \<le> n then {i} else {})"
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
   941
    by auto
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   942
  from assms show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   943
    by (simp add: poly_eq_iff coeff_sum coeff_eq_0 sum.If_cases eq
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   944
        if_distrib[where f="\<lambda>x. x * a" for a])
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
   945
qed
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
   946
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
   947
lemma poly_as_sum_of_monoms: "(\<Sum>i\<le>degree p. monom (coeff p i) i) = p"
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
   948
  by (intro poly_as_sum_of_monoms' order_refl)
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
   949
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
   950
lemma Poly_snoc: "Poly (xs @ [x]) = Poly xs + monom x (length xs)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   951
  by (induct xs) (simp_all add: monom_0 monom_Suc)
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
   952
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   953
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   954
subsection \<open>Multiplication by a constant, polynomial multiplication and the unit polynomial\<close>
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   955
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   956
lift_definition smult :: "'a::comm_semiring_0 \<Rightarrow> 'a poly \<Rightarrow> 'a poly"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   957
  is "\<lambda>a p n. a * coeff p n"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59983
diff changeset
   958
proof -
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   959
  fix a :: 'a and p :: "'a poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   960
  show "\<forall>\<^sub>\<infinity> i. a * coeff p i = 0"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59983
diff changeset
   961
    using MOST_coeff_eq_0[of p] by eventually_elim simp
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   962
qed
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   963
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   964
lemma coeff_smult [simp]: "coeff (smult a p) n = a * coeff p n"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
   965
  by (simp add: smult.rep_eq)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   966
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   967
lemma degree_smult_le: "degree (smult a p) \<le> degree p"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   968
  by (rule degree_le) (simp add: coeff_eq_0)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   969
29472
a63a2e46cec9 declare smult rules [simp]
huffman
parents: 29471
diff changeset
   970
lemma smult_smult [simp]: "smult a (smult b p) = smult (a * b) p"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   971
  by (rule poly_eqI) (simp add: mult.assoc)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   972
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   973
lemma smult_0_right [simp]: "smult a 0 = 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   974
  by (rule poly_eqI) simp
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   975
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   976
lemma smult_0_left [simp]: "smult 0 p = 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   977
  by (rule poly_eqI) simp
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   978
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
   979
lemma smult_1_left [simp]: "smult (1::'a::comm_semiring_1) p = p"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   980
  by (rule poly_eqI) simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   981
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   982
lemma smult_add_right: "smult a (p + q) = smult a p + smult a q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   983
  by (rule poly_eqI) (simp add: algebra_simps)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   984
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   985
lemma smult_add_left: "smult (a + b) p = smult a p + smult b p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   986
  by (rule poly_eqI) (simp add: algebra_simps)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   987
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   988
lemma smult_minus_right [simp]: "smult a (- p) = - smult a p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   989
  for a :: "'a::comm_ring"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   990
  by (rule poly_eqI) simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   991
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   992
lemma smult_minus_left [simp]: "smult (- a) p = - smult a p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   993
  for a :: "'a::comm_ring"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   994
  by (rule poly_eqI) simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   995
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   996
lemma smult_diff_right: "smult a (p - q) = smult a p - smult a q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   997
  for a :: "'a::comm_ring"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   998
  by (rule poly_eqI) (simp add: algebra_simps)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
   999
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1000
lemma smult_diff_left: "smult (a - b) p = smult a p - smult b p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1001
  for a b :: "'a::comm_ring"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1002
  by (rule poly_eqI) (simp add: algebra_simps)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1003
29472
a63a2e46cec9 declare smult rules [simp]
huffman
parents: 29471
diff changeset
  1004
lemmas smult_distribs =
a63a2e46cec9 declare smult rules [simp]
huffman
parents: 29471
diff changeset
  1005
  smult_add_left smult_add_right
a63a2e46cec9 declare smult rules [simp]
huffman
parents: 29471
diff changeset
  1006
  smult_diff_left smult_diff_right
a63a2e46cec9 declare smult rules [simp]
huffman
parents: 29471
diff changeset
  1007
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1008
lemma smult_pCons [simp]: "smult a (pCons b p) = pCons (a * b) (smult a p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1009
  by (rule poly_eqI) (simp add: coeff_pCons split: nat.split)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1010
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1011
lemma smult_monom: "smult a (monom b n) = monom (a * b) n"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1012
  by (induct n) (simp_all add: monom_0 monom_Suc)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1013
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  1014
lemma smult_Poly: "smult c (Poly xs) = Poly (map ((*) c) xs)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1015
  by (auto simp: poly_eq_iff nth_default_def)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1016
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1017
lemma degree_smult_eq [simp]: "degree (smult a p) = (if a = 0 then 0 else degree p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1018
  for a :: "'a::{comm_semiring_0,semiring_no_zero_divisors}"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1019
  by (cases "a = 0") (simp_all add: degree_def)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1020
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1021
lemma smult_eq_0_iff [simp]: "smult a p = 0 \<longleftrightarrow> a = 0 \<or> p = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1022
  for a :: "'a::{comm_semiring_0,semiring_no_zero_divisors}"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1023
  by (simp add: poly_eq_iff)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1024
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1025
lemma coeffs_smult [code abstract]:
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1026
  "coeffs (smult a p) = (if a = 0 then [] else map (Groups.times a) (coeffs p))"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1027
  for p :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  1028
proof -
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  1029
  have eq_0: "HOL.eq 0 \<circ> times a = HOL.eq (0::'a)" if "a \<noteq> 0"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  1030
    using that by (simp add: fun_eq_iff)
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  1031
  show ?thesis
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  1032
    by (rule coeffs_eqI) (auto simp add: no_trailing_map nth_default_map_eq nth_default_coeffs_eq eq_0)
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  1033
qed
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1034
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1035
lemma smult_eq_iff:
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1036
  fixes b :: "'a :: field"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1037
  assumes "b \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1038
  shows "smult a p = smult b q \<longleftrightarrow> smult (a / b) p = q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1039
    (is "?lhs \<longleftrightarrow> ?rhs")
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1040
proof
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1041
  assume ?lhs
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1042
  also from assms have "smult (inverse b) \<dots> = q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1043
    by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1044
  finally show ?rhs
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1045
    by (simp add: field_simps)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1046
next
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1047
  assume ?rhs
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1048
  with assms show ?lhs by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1049
qed
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1050
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1051
instantiation poly :: (comm_semiring_0) comm_semiring_0
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1052
begin
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1053
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1054
definition "p * q = fold_coeffs (\<lambda>a p. smult a q + pCons 0 p) p 0"
29474
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1055
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1056
lemma mult_poly_0_left: "(0::'a poly) * q = 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1057
  by (simp add: times_poly_def)
29474
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1058
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1059
lemma mult_pCons_left [simp]: "pCons a p * q = smult a q + pCons 0 (p * q)"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1060
  by (cases "p = 0 \<and> a = 0") (auto simp add: times_poly_def)
29474
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1061
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1062
lemma mult_poly_0_right: "p * (0::'a poly) = 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1063
  by (induct p) (simp_all add: mult_poly_0_left)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1064
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1065
lemma mult_pCons_right [simp]: "p * pCons a q = smult a p + pCons 0 (p * q)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1066
  by (induct p) (simp_all add: mult_poly_0_left algebra_simps)
29474
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1067
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1068
lemmas mult_poly_0 = mult_poly_0_left mult_poly_0_right
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1069
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1070
lemma mult_smult_left [simp]: "smult a p * q = smult a (p * q)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1071
  by (induct p) (simp_all add: mult_poly_0 smult_add_right)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1072
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1073
lemma mult_smult_right [simp]: "p * smult a q = smult a (p * q)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1074
  by (induct q) (simp_all add: mult_poly_0 smult_add_right)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1075
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1076
lemma mult_poly_add_left: "(p + q) * r = p * r + q * r"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1077
  for p q r :: "'a poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1078
  by (induct r) (simp_all add: mult_poly_0 smult_distribs algebra_simps)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1079
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
  1080
instance
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
  1081
proof
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1082
  fix p q r :: "'a poly"
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1083
  show 0: "0 * p = 0"
29474
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1084
    by (rule mult_poly_0_left)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1085
  show "p * 0 = 0"
29474
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1086
    by (rule mult_poly_0_right)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1087
  show "(p + q) * r = p * r + q * r"
29474
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1088
    by (rule mult_poly_add_left)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1089
  show "(p * q) * r = p * (q * r)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1090
    by (induct p) (simp_all add: mult_poly_0 mult_poly_add_left)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1091
  show "p * q = q * p"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1092
    by (induct p) (simp_all add: mult_poly_0)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1093
qed
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1094
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1095
end
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1096
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1097
lemma coeff_mult_degree_sum:
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1098
  "coeff (p * q) (degree p + degree q) = coeff p (degree p) * coeff q (degree q)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1099
  by (induct p) (simp_all add: coeff_eq_0)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1100
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1101
instance poly :: ("{comm_semiring_0,semiring_no_zero_divisors}") semiring_no_zero_divisors
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1102
proof
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1103
  fix p q :: "'a poly"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1104
  assume "p \<noteq> 0" and "q \<noteq> 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1105
  have "coeff (p * q) (degree p + degree q) = coeff p (degree p) * coeff q (degree q)"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1106
    by (rule coeff_mult_degree_sum)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1107
  also from \<open>p \<noteq> 0\<close> \<open>q \<noteq> 0\<close> have "coeff p (degree p) * coeff q (degree q) \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1108
    by simp
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1109
  finally have "\<exists>n. coeff (p * q) n \<noteq> 0" ..
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1110
  then show "p * q \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1111
    by (simp add: poly_eq_iff)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1112
qed
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1113
29540
8858d197a9b6 more instance declarations for poly
huffman
parents: 29539
diff changeset
  1114
instance poly :: (comm_semiring_0_cancel) comm_semiring_0_cancel ..
8858d197a9b6 more instance declarations for poly
huffman
parents: 29539
diff changeset
  1115
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1116
lemma coeff_mult: "coeff (p * q) n = (\<Sum>i\<le>n. coeff p i * coeff q (n-i))"
29474
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1117
proof (induct p arbitrary: n)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1118
  case 0
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1119
  show ?case by simp
29474
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1120
next
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1121
  case (pCons a p n)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1122
  then show ?case
70113
c8deb8ba6d05 Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
paulson <lp15@cam.ac.uk>
parents: 70097
diff changeset
  1123
    by (cases n) (simp_all add: sum.atMost_Suc_shift del: sum.atMost_Suc)
29474
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1124
qed
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1125
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1126
lemma coeff_mult_0: "coeff (p * q) 0 = coeff p 0 * coeff q 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1127
  by (simp add: coeff_mult)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1128
29474
674a21226c5a define polynomial multiplication using poly_rec
huffman
parents: 29472
diff changeset
  1129
lemma degree_mult_le: "degree (p * q) \<le> degree p + degree q"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1130
proof (rule degree_le)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1131
  show "\<forall>i>degree p + degree q. coeff (p * q) i = 0"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1132
    by (induct p) (simp_all add: coeff_eq_0 coeff_pCons split: nat.split)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1133
qed
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1134
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1135
lemma mult_monom: "monom a m * monom b n = monom (a * b) (m + n)"
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
  1136
  by (induct m) (simp add: monom_0 smult_monom, simp add: monom_Suc)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1137
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1138
instantiation poly :: (comm_semiring_1) comm_semiring_1
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1139
begin
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1140
65486
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1141
lift_definition one_poly :: "'a poly"
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1142
  is "\<lambda>n. of_bool (n = 0)"
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1143
  by (rule MOST_SucD) simp
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1144
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1145
lemma coeff_1 [simp]:
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1146
  "coeff 1 n = of_bool (n = 0)"
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1147
  by (simp add: one_poly.rep_eq)
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1148
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1149
lemma one_pCons:
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1150
  "1 = [:1:]"
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1151
  by (simp add: poly_eq_iff coeff_pCons split: nat.splits)
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1152
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1153
lemma pCons_one:
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1154
  "[:1:] = 1"
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1155
  by (simp add: one_pCons)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1156
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
  1157
instance
65486
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1158
  by standard (simp_all add: one_pCons)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1159
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1160
end
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1161
65486
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1162
lemma poly_1 [simp]:
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1163
  "poly 1 x = 1"
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1164
  by (simp add: one_pCons)
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1165
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1166
lemma one_poly_eq_simps [simp]:
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1167
  "1 = [:1:] \<longleftrightarrow> True"
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1168
  "[:1:] = 1 \<longleftrightarrow> True"
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1169
  by (simp_all add: one_pCons)
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1170
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1171
lemma degree_1 [simp]:
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1172
  "degree 1 = 0"
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1173
  by (simp add: one_pCons)
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1174
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1175
lemma coeffs_1_eq [simp, code abstract]:
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1176
  "coeffs 1 = [1]"
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1177
  by (simp add: one_pCons)
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1178
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1179
lemma smult_one [simp]:
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1180
  "smult c 1 = [:c:]"
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1181
  by (simp add: one_pCons)
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1182
82187
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1183
lemma smult_sum: "smult (\<Sum>i \<in> S. f i) p = (\<Sum>i \<in> S. smult (f i) p)"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1184
  by (induct S rule: infinite_finite_induct, auto simp: smult_add_left)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1185
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1186
lemma smult_power: "(smult a p) ^ n = smult (a ^ n) (p ^ n)"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1187
  by (induct n, auto simp: field_simps)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1188
65486
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1189
lemma monom_eq_1 [simp]:
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1190
  "monom 1 0 = 1"
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1191
  by (simp add: monom_0 one_pCons)
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1192
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1193
lemma monom_eq_1_iff:
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1194
  "monom c n = 1 \<longleftrightarrow> c = 1 \<and> n = 0"
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1195
  using monom_eq_const_iff [of c n 1] by auto
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1196
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1197
lemma monom_altdef:
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1198
  "monom c n = smult c ([:0, 1:] ^ n)"
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  1199
  by (induct n) (simp_all add: monom_0 monom_Suc)
65486
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1200
82187
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1201
lemma degree_sum_list_le: "(\<And> p . p \<in> set ps \<Longrightarrow> degree p \<le> n)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1202
  \<Longrightarrow> degree (sum_list ps) \<le> n"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1203
proof (induct ps)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1204
  case (Cons p ps)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1205
  hence "degree (sum_list ps) \<le> n" "degree p \<le> n" by auto
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1206
  thus ?case unfolding sum_list.Cons by (metis degree_add_le)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1207
qed simp
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1208
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1209
lemma degree_prod_list_le: "degree (prod_list ps) \<le> sum_list (map degree ps)"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1210
proof (induct ps)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1211
  case (Cons p ps)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1212
  show ?case unfolding prod_list.Cons
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1213
    by (rule order.trans[OF degree_mult_le], insert Cons, auto)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1214
qed simp
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1215
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1216
instance poly :: ("{comm_semiring_1,semiring_1_no_zero_divisors}") semiring_1_no_zero_divisors ..
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1217
instance poly :: (comm_ring) comm_ring ..
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1218
instance poly :: (comm_ring_1) comm_ring_1 ..
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1219
instance poly :: (comm_ring_1) comm_semiring_1_cancel ..
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1220
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1221
lemma prod_smult: "(\<Prod>x\<in>A. smult (c x) (p x)) = smult (prod c A) (prod p A)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1222
  by (induction A rule: infinite_finite_induct) (auto simp: mult_ac)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1223
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1224
lemma degree_power_le: "degree (p ^ n) \<le> degree p * n"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1225
  by (induct n) (auto intro: order_trans degree_mult_le)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1226
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1227
lemma coeff_0_power: "coeff (p ^ n) 0 = coeff p 0 ^ n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1228
  by (induct n) (simp_all add: coeff_mult)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1229
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1230
lemma poly_smult [simp]: "poly (smult a p) x = a * poly p x"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1231
  by (induct p) (simp_all add: algebra_simps)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1232
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1233
lemma poly_mult [simp]: "poly (p * q) x = poly p x * poly q x"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1234
  by (induct p) (simp_all add: algebra_simps)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1235
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1236
lemma poly_power [simp]: "poly (p ^ n) x = poly p x ^ n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1237
  for p :: "'a::comm_semiring_1 poly"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1238
  by (induct n) simp_all
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1239
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1240
lemma poly_prod: "poly (\<Prod>k\<in>A. p k) x = (\<Prod>k\<in>A. poly (p k) x)"
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
  1241
  by (induct A rule: infinite_finite_induct) simp_all
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
  1242
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1243
lemma poly_prod_list: "poly (\<Prod>p\<leftarrow>ps. p) y = (\<Prod>p\<leftarrow>ps. poly p y)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1244
  by (induction ps) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1245
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1246
lemma poly_prod_mset: "poly (\<Prod>x\<in>#A. p x) y = (\<Prod>x\<in>#A. poly (p x) y)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1247
  by (induction A) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1248
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1249
lemma poly_const_pow: "[: c :] ^ n = [: c ^ n :]"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1250
  by (induction n) (auto simp: algebra_simps)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1251
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1252
lemma monom_power: "monom c n ^ k = monom (c ^ k) (n * k)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1253
  by (induction k) (auto simp: mult_monom)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1254
67091
1393c2340eec more symbols;
wenzelm
parents: 66806
diff changeset
  1255
lemma degree_prod_sum_le: "finite S \<Longrightarrow> degree (prod f S) \<le> sum (degree \<circ> f) S"
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
  1256
proof (induct S rule: finite_induct)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1257
  case empty
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1258
  then show ?case by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1259
next
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
  1260
  case (insert a S)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1261
  show ?case
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1262
    unfolding prod.insert[OF insert(1-2)] sum.insert[OF insert(1-2)]
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1263
    by (rule le_trans[OF degree_mult_le]) (use insert in auto)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1264
qed
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1265
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1266
lemma coeff_0_prod_list: "coeff (prod_list xs) 0 = prod_list (map (\<lambda>p. coeff p 0) xs)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1267
  by (induct xs) (simp_all add: coeff_mult)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1268
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1269
lemma coeff_monom_mult: "coeff (monom c n * p) k = (if k < n then 0 else c * coeff p (k - n))"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1270
proof -
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1271
  have "coeff (monom c n * p) k = (\<Sum>i\<le>k. (if n = i then c else 0) * coeff p (k - i))"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1272
    by (simp add: coeff_mult)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1273
  also have "\<dots> = (\<Sum>i\<le>k. (if n = i then c * coeff p (k - i) else 0))"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1274
    by (intro sum.cong) simp_all
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1275
  also have "\<dots> = (if k < n then 0 else c * coeff p (k - n))"
66799
haftmann
parents: 66550
diff changeset
  1276
    by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1277
  finally show ?thesis .
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1278
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1279
82187
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1280
lemma coeff_monom_Suc: "coeff (monom a (Suc d) * p) (Suc i) = coeff (monom a d * p) i"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1281
  by (simp add: monom_Suc)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1282
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1283
lemma monom_1_dvd_iff': "monom 1 n dvd p \<longleftrightarrow> (\<forall>k<n. coeff p k = 0)"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1284
proof
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1285
  assume "monom 1 n dvd p"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1286
  then obtain r where "p = monom 1 n * r"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1287
    by (rule dvdE)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1288
  then show "\<forall>k<n. coeff p k = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1289
    by (simp add: coeff_mult)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1290
next
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1291
  assume zero: "(\<forall>k<n. coeff p k = 0)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1292
  define r where "r = Abs_poly (\<lambda>k. coeff p (k + n))"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1293
  have "\<forall>\<^sub>\<infinity>k. coeff p (k + n) = 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1294
    by (subst cofinite_eq_sequentially, subst eventually_sequentially_seg,
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1295
        subst cofinite_eq_sequentially [symmetric]) transfer
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1296
  then have coeff_r [simp]: "coeff r k = coeff p (k + n)" for k
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1297
    unfolding r_def by (subst poly.Abs_poly_inverse) simp_all
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1298
  have "p = monom 1 n * r"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1299
    by (rule poly_eqI, subst coeff_monom_mult) (simp_all add: zero)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1300
  then show "monom 1 n dvd p" by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1301
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1302
82187
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1303
lemma coeff_sum_monom:
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1304
  assumes n: "n \<le> d"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1305
  shows "coeff (\<Sum>i\<le>d. monom (f i) i) n = f n" (is "?l = _")
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1306
proof -
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1307
  have "?l = (\<Sum>i\<le>d. coeff (monom (f i) i) n)" (is "_ = sum ?cmf _")
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1308
    using coeff_sum.
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1309
  also have "{..d} = insert n ({..d}-{n})" using n by auto
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1310
    hence "sum ?cmf {..d} = sum ?cmf ..." by auto
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1311
  also have "... = sum ?cmf ({..d}-{n}) + ?cmf n" by (subst sum.insert,auto)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1312
  also have "sum ?cmf ({..d}-{n}) = 0" by (subst sum.neutral, auto)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1313
  finally show ?thesis by simp
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1314
qed
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1315
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1316
subsection \<open>Mapping polynomials\<close>
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1317
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1318
definition map_poly :: "('a :: zero \<Rightarrow> 'b :: zero) \<Rightarrow> 'a poly \<Rightarrow> 'b poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1319
  where "map_poly f p = Poly (map f (coeffs p))"
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1320
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1321
lemma map_poly_0 [simp]: "map_poly f 0 = 0"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1322
  by (simp add: map_poly_def)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1323
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1324
lemma map_poly_1: "map_poly f 1 = [:f 1:]"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1325
  by (simp add: map_poly_def)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1326
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1327
lemma map_poly_1' [simp]: "f 1 = 1 \<Longrightarrow> map_poly f 1 = 1"
65486
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1328
  by (simp add: map_poly_def one_pCons)
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1329
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1330
lemma coeff_map_poly:
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1331
  assumes "f 0 = 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1332
  shows "coeff (map_poly f p) n = f (coeff p n)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1333
  by (auto simp: assms map_poly_def nth_default_def coeffs_def not_less Suc_le_eq coeff_eq_0
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1334
      simp del: upt_Suc)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1335
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1336
lemma coeffs_map_poly [code abstract]:
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67369
diff changeset
  1337
  "coeffs (map_poly f p) = strip_while ((=) 0) (map f (coeffs p))"
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1338
  by (simp add: map_poly_def)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1339
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1340
lemma coeffs_map_poly':
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1341
  assumes "\<And>x. x \<noteq> 0 \<Longrightarrow> f x \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1342
  shows "coeffs (map_poly f p) = map f (coeffs p)"
66799
haftmann
parents: 66550
diff changeset
  1343
  using assms
haftmann
parents: 66550
diff changeset
  1344
  by (auto simp add: coeffs_map_poly strip_while_idem_iff
haftmann
parents: 66550
diff changeset
  1345
    last_coeffs_eq_coeff_degree no_trailing_unfold last_map)
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  1346
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  1347
lemma set_coeffs_map_poly:
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  1348
  "(\<And>x. f x = 0 \<longleftrightarrow> x = 0) \<Longrightarrow> set (coeffs (map_poly f p)) = f ` set (coeffs p)"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  1349
  by (simp add: coeffs_map_poly')
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1350
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1351
lemma degree_map_poly:
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1352
  assumes "\<And>x. x \<noteq> 0 \<Longrightarrow> f x \<noteq> 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1353
  shows "degree (map_poly f p) = degree p"
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1354
  by (simp add: degree_eq_length_coeffs coeffs_map_poly' assms)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1355
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1356
lemma map_poly_eq_0_iff:
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1357
  assumes "f 0 = 0" "\<And>x. x \<in> set (coeffs p) \<Longrightarrow> x \<noteq> 0 \<Longrightarrow> f x \<noteq> 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1358
  shows "map_poly f p = 0 \<longleftrightarrow> p = 0"
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1359
proof -
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1360
  have "(coeff (map_poly f p) n = 0) = (coeff p n = 0)" for n
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1361
  proof -
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1362
    have "coeff (map_poly f p) n = f (coeff p n)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1363
      by (simp add: coeff_map_poly assms)
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1364
    also have "\<dots> = 0 \<longleftrightarrow> coeff p n = 0"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1365
    proof (cases "n < length (coeffs p)")
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1366
      case True
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1367
      then have "coeff p n \<in> set (coeffs p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1368
        by (auto simp: coeffs_def simp del: upt_Suc)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1369
      with assms show "f (coeff p n) = 0 \<longleftrightarrow> coeff p n = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1370
        by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1371
    next
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1372
      case False
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1373
      then show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1374
        by (auto simp: assms length_coeffs nth_default_coeffs_eq [symmetric] nth_default_def)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1375
    qed
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1376
    finally show ?thesis .
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1377
  qed
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1378
  then show ?thesis by (auto simp: poly_eq_iff)
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1379
qed
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1380
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1381
lemma map_poly_smult:
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1382
  assumes "f 0 = 0""\<And>c x. f (c * x) = f c * f x"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1383
  shows "map_poly f (smult c p) = smult (f c) (map_poly f p)"
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1384
  by (intro poly_eqI) (simp_all add: assms coeff_map_poly)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1385
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1386
lemma map_poly_pCons:
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1387
  assumes "f 0 = 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1388
  shows "map_poly f (pCons c p) = pCons (f c) (map_poly f p)"
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1389
  by (intro poly_eqI) (simp_all add: assms coeff_map_poly coeff_pCons split: nat.splits)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1390
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1391
lemma map_poly_map_poly:
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1392
  assumes "f 0 = 0" "g 0 = 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1393
  shows "map_poly f (map_poly g p) = map_poly (f \<circ> g) p"
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1394
  by (intro poly_eqI) (simp add: coeff_map_poly assms)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1395
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1396
lemma map_poly_id [simp]: "map_poly id p = p"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1397
  by (simp add: map_poly_def)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1398
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1399
lemma map_poly_id' [simp]: "map_poly (\<lambda>x. x) p = p"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1400
  by (simp add: map_poly_def)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1401
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1402
lemma map_poly_cong:
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1403
  assumes "(\<And>x. x \<in> set (coeffs p) \<Longrightarrow> f x = g x)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1404
  shows "map_poly f p = map_poly g p"
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1405
proof -
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1406
  from assms have "map f (coeffs p) = map g (coeffs p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1407
    by (intro map_cong) simp_all
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1408
  then show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1409
    by (simp only: coeffs_eq_iff coeffs_map_poly)
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1410
qed
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1411
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1412
lemma map_poly_monom: "f 0 = 0 \<Longrightarrow> map_poly f (monom c n) = monom (f c) n"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1413
  by (intro poly_eqI) (simp_all add: coeff_map_poly)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1414
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1415
lemma map_poly_idI:
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1416
  assumes "\<And>x. x \<in> set (coeffs p) \<Longrightarrow> f x = x"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1417
  shows "map_poly f p = p"
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1418
  using map_poly_cong[OF assms, of _ id] by simp
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1419
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1420
lemma map_poly_idI':
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1421
  assumes "\<And>x. x \<in> set (coeffs p) \<Longrightarrow> f x = x"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1422
  shows "p = map_poly f p"
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1423
  using map_poly_cong[OF assms, of _ id] by simp
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1424
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1425
lemma smult_conv_map_poly: "smult c p = map_poly (\<lambda>x. c * x) p"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1426
  by (intro poly_eqI) (simp_all add: coeff_map_poly)
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1427
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1428
lemma poly_cnj: "cnj (poly p z) = poly (map_poly cnj p) (cnj z)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1429
  by (simp add: poly_altdef degree_map_poly coeff_map_poly)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1430
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1431
lemma poly_cnj_real:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1432
  assumes "\<And>n. poly.coeff p n \<in> \<real>"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1433
  shows   "cnj (poly p z) = poly p (cnj z)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1434
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1435
  from assms have "map_poly cnj p = p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1436
    by (intro poly_eqI) (auto simp: coeff_map_poly Reals_cnj_iff)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1437
  with poly_cnj[of p z] show ?thesis by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1438
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1439
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1440
lemma real_poly_cnj_root_iff:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1441
  assumes "\<And>n. poly.coeff p n \<in> \<real>"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1442
  shows   "poly p (cnj z) = 0 \<longleftrightarrow> poly p z = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1443
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1444
  have "poly p (cnj z) = cnj (poly p z)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1445
    by (simp add: poly_cnj_real assms)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1446
  also have "\<dots> = 0 \<longleftrightarrow> poly p z = 0" by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1447
  finally show ?thesis .
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1448
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1449
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1450
lemma sum_to_poly: "(\<Sum>x\<in>A. [:f x:]) = [:\<Sum>x\<in>A. f x:]"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1451
  by (induction A rule: infinite_finite_induct) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1452
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1453
lemma diff_to_poly: "[:c:] - [:d:] = [:c - d:]"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1454
  by (simp add: poly_eq_iff mult_ac)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1455
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1456
lemma mult_to_poly: "[:c:] * [:d:] = [:c * d:]"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1457
  by (simp add: poly_eq_iff mult_ac)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1458
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1459
lemma prod_to_poly: "(\<Prod>x\<in>A. [:f x:]) = [:\<Prod>x\<in>A. f x:]"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1460
  by (induction A rule: infinite_finite_induct) (auto simp: mult_to_poly mult_ac)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1461
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1462
lemma poly_map_poly_cnj [simp]: "poly (map_poly cnj p) x = cnj (poly p (cnj x))"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1463
  by (induction p) (auto simp: map_poly_pCons)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1464
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1465
65484
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1466
subsection \<open>Conversions\<close>
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1467
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1468
lemma of_nat_poly:
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1469
  "of_nat n = [:of_nat n:]"
65486
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1470
  by (induct n) (simp_all add: one_pCons)
65484
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1471
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1472
lemma of_nat_monom:
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1473
  "of_nat n = monom (of_nat n) 0"
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1474
  by (simp add: of_nat_poly monom_0)
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1475
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1476
lemma degree_of_nat [simp]:
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1477
  "degree (of_nat n) = 0"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  1478
  by (simp add: of_nat_poly)
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  1479
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1480
lemma lead_coeff_of_nat [simp]:
65484
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1481
  "lead_coeff (of_nat n) = of_nat n"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1482
  by (simp add: of_nat_poly)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1483
65484
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1484
lemma of_int_poly:
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1485
  "of_int k = [:of_int k:]"
64793
3df00fb1ce0b more lemmas;
haftmann
parents: 64635
diff changeset
  1486
  by (simp only: of_int_of_nat of_nat_poly) simp
3df00fb1ce0b more lemmas;
haftmann
parents: 64635
diff changeset
  1487
65484
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1488
lemma of_int_monom:
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1489
  "of_int k = monom (of_int k) 0"
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1490
  by (simp add: of_int_poly monom_0)
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1491
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1492
lemma degree_of_int [simp]:
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1493
  "degree (of_int k) = 0"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1494
  by (simp add: of_int_poly)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1495
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1496
lemma lead_coeff_of_int [simp]:
65484
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1497
  "lead_coeff (of_int k) = of_int k"
64793
3df00fb1ce0b more lemmas;
haftmann
parents: 64635
diff changeset
  1498
  by (simp add: of_int_poly)
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  1499
79672
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  1500
lemma poly_of_nat [simp]: "poly (of_nat n) x = of_nat n"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  1501
  by (simp add: of_nat_poly)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  1502
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  1503
lemma poly_of_int [simp]: "poly (of_int n) x = of_int n"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  1504
  by (simp add: of_int_poly) 
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  1505
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  1506
lemma poly_numeral [simp]: "poly (numeral n) x = numeral n"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  1507
  by (metis of_nat_numeral poly_of_nat)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  1508
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  1509
lemma numeral_poly: "numeral n = [:numeral n:]"
65484
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1510
proof -
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1511
  have "numeral n = of_nat (numeral n)"
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1512
    by simp
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1513
  also have "\<dots> = [:of_nat (numeral n):]"
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1514
    by (simp add: of_nat_poly)
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1515
  finally show ?thesis
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1516
    by simp
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1517
qed
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1518
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1519
lemma numeral_monom:
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1520
  "numeral n = monom (numeral n) 0"
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1521
  by (simp add: numeral_poly monom_0)
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1522
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1523
lemma degree_numeral [simp]:
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1524
  "degree (numeral n) = 0"
751f9ed8e940 more rules concerning of_nat, of_int, numeral
haftmann
parents: 65435
diff changeset
  1525
  by (simp add: numeral_poly)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1526
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1527
lemma lead_coeff_numeral [simp]:
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1528
  "lead_coeff (numeral n) = numeral n"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1529
  by (simp add: numeral_poly)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1530
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1531
lemma coeff_linear_poly_power:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1532
  fixes c :: "'a :: semiring_1"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1533
  assumes "i \<le> n"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1534
  shows   "coeff ([:a, b:] ^ n) i = of_nat (n choose i) * b ^ i * a ^ (n - i)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1535
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1536
  have "[:a, b:] = monom b 1 + [:a:]"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1537
    by (simp add: monom_altdef)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1538
  also have "coeff (\<dots> ^ n) i = (\<Sum>k\<le>n. a^(n-k) * of_nat (n choose k) * (if k = i then b ^ k else 0))"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1539
    by (subst binomial_ring) (simp add: coeff_sum of_nat_poly monom_power poly_const_pow mult_ac)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1540
  also have "\<dots> = (\<Sum>k\<in>{i}. a ^ (n - i) * b ^ i * of_nat (n choose k))"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1541
    using assms by (intro sum.mono_neutral_cong_right) (auto simp: mult_ac)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1542
  finally show *: ?thesis by (simp add: mult_ac)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1543
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1544
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1545
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1546
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1547
subsection \<open>Lemmas about divisibility\<close>
29979
666f5f72dbb5 add some lemmas, cleaned up
huffman
parents: 29977
diff changeset
  1548
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1549
lemma dvd_smult:
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1550
  assumes "p dvd q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1551
  shows "p dvd smult a q"
29979
666f5f72dbb5 add some lemmas, cleaned up
huffman
parents: 29977
diff changeset
  1552
proof -
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1553
  from assms obtain k where "q = p * k" ..
29979
666f5f72dbb5 add some lemmas, cleaned up
huffman
parents: 29977
diff changeset
  1554
  then have "smult a q = p * smult a k" by simp
666f5f72dbb5 add some lemmas, cleaned up
huffman
parents: 29977
diff changeset
  1555
  then show "p dvd smult a q" ..
666f5f72dbb5 add some lemmas, cleaned up
huffman
parents: 29977
diff changeset
  1556
qed
666f5f72dbb5 add some lemmas, cleaned up
huffman
parents: 29977
diff changeset
  1557
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1558
lemma dvd_smult_cancel: "p dvd smult a q \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> p dvd q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1559
  for a :: "'a::field"
29979
666f5f72dbb5 add some lemmas, cleaned up
huffman
parents: 29977
diff changeset
  1560
  by (drule dvd_smult [where a="inverse a"]) simp
666f5f72dbb5 add some lemmas, cleaned up
huffman
parents: 29977
diff changeset
  1561
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1562
lemma dvd_smult_iff: "a \<noteq> 0 \<Longrightarrow> p dvd smult a q \<longleftrightarrow> p dvd q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1563
  for a :: "'a::field"
29979
666f5f72dbb5 add some lemmas, cleaned up
huffman
parents: 29977
diff changeset
  1564
  by (safe elim!: dvd_smult dvd_smult_cancel)
666f5f72dbb5 add some lemmas, cleaned up
huffman
parents: 29977
diff changeset
  1565
31663
5eb82f064630 smult_dvd lemmas; polynomial gcd
huffman
parents: 31021
diff changeset
  1566
lemma smult_dvd_cancel:
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1567
  assumes "smult a p dvd q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1568
  shows "p dvd q"
31663
5eb82f064630 smult_dvd lemmas; polynomial gcd
huffman
parents: 31021
diff changeset
  1569
proof -
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1570
  from assms obtain k where "q = smult a p * k" ..
31663
5eb82f064630 smult_dvd lemmas; polynomial gcd
huffman
parents: 31021
diff changeset
  1571
  then have "q = p * smult a k" by simp
5eb82f064630 smult_dvd lemmas; polynomial gcd
huffman
parents: 31021
diff changeset
  1572
  then show "p dvd q" ..
5eb82f064630 smult_dvd lemmas; polynomial gcd
huffman
parents: 31021
diff changeset
  1573
qed
5eb82f064630 smult_dvd lemmas; polynomial gcd
huffman
parents: 31021
diff changeset
  1574
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1575
lemma smult_dvd: "p dvd q \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> smult a p dvd q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1576
  for a :: "'a::field"
31663
5eb82f064630 smult_dvd lemmas; polynomial gcd
huffman
parents: 31021
diff changeset
  1577
  by (rule smult_dvd_cancel [where a="inverse a"]) simp
5eb82f064630 smult_dvd lemmas; polynomial gcd
huffman
parents: 31021
diff changeset
  1578
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1579
lemma smult_dvd_iff: "smult a p dvd q \<longleftrightarrow> (if a = 0 then q = 0 else p dvd q)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1580
  for a :: "'a::field"
31663
5eb82f064630 smult_dvd lemmas; polynomial gcd
huffman
parents: 31021
diff changeset
  1581
  by (auto elim: smult_dvd smult_dvd_cancel)
5eb82f064630 smult_dvd lemmas; polynomial gcd
huffman
parents: 31021
diff changeset
  1582
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1583
lemma is_unit_smult_iff: "smult c p dvd 1 \<longleftrightarrow> c dvd 1 \<and> p dvd 1"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1584
proof -
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1585
  have "smult c p = [:c:] * p" by simp
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1586
  also have "\<dots> dvd 1 \<longleftrightarrow> c dvd 1 \<and> p dvd 1"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1587
  proof safe
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1588
    assume *: "[:c:] * p dvd 1"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1589
    then show "p dvd 1"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1590
      by (rule dvd_mult_right)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1591
    from * obtain q where q: "1 = [:c:] * p * q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1592
      by (rule dvdE)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1593
    have "c dvd c * (coeff p 0 * coeff q 0)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1594
      by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1595
    also have "\<dots> = coeff ([:c:] * p * q) 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1596
      by (simp add: mult.assoc coeff_mult)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1597
    also note q [symmetric]
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1598
    finally have "c dvd coeff 1 0" .
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1599
    then show "c dvd 1" by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1600
  next
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1601
    assume "c dvd 1" "p dvd 1"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1602
    from this(1) obtain d where "1 = c * d"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1603
      by (rule dvdE)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1604
    then have "1 = [:c:] * [:d:]"
65486
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  1605
      by (simp add: one_pCons ac_simps)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1606
    then have "[:c:] dvd 1"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1607
      by (rule dvdI)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1608
    from mult_dvd_mono[OF this \<open>p dvd 1\<close>] show "[:c:] * p dvd 1"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1609
      by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1610
  qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1611
  finally show ?thesis .
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1612
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1613
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1614
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1615
subsection \<open>Polynomials form an integral domain\<close>
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1616
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1617
instance poly :: (idom) idom ..
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1618
65577
32d4117ad6e8 instance for polynomial rings with characteristic zero
haftmann
parents: 65486
diff changeset
  1619
instance poly :: ("{ring_char_0, comm_ring_1}") ring_char_0
32d4117ad6e8 instance for polynomial rings with characteristic zero
haftmann
parents: 65486
diff changeset
  1620
  by standard (auto simp add: of_nat_poly intro: injI)
32d4117ad6e8 instance for polynomial rings with characteristic zero
haftmann
parents: 65486
diff changeset
  1621
80084
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  1622
lemma semiring_char_poly [simp]: "CHAR('a :: comm_semiring_1 poly) = CHAR('a)"
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  1623
  by (rule CHAR_eqI) (auto simp: of_nat_poly of_nat_eq_0_iff_char_dvd)
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  1624
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  1625
instance poly :: ("{semiring_prime_char,comm_semiring_1}") semiring_prime_char
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  1626
  by (rule semiring_prime_charI) auto
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  1627
instance poly :: ("{comm_semiring_prime_char,comm_semiring_1}") comm_semiring_prime_char
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  1628
  by standard
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  1629
instance poly :: ("{comm_ring_prime_char,comm_semiring_1}") comm_ring_prime_char
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  1630
  by standard
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  1631
instance poly :: ("{idom_prime_char,comm_semiring_1}") idom_prime_char
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  1632
  by standard
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  1633
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1634
lemma degree_mult_eq: "p \<noteq> 0 \<Longrightarrow> q \<noteq> 0 \<Longrightarrow> degree (p * q) = degree p + degree q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1635
  for p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1636
  by (rule order_antisym [OF degree_mult_le le_degree]) (simp add: coeff_mult_degree_sum)
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1637
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1638
lemma degree_prod_sum_eq:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1639
  "(\<And>x. x \<in> A \<Longrightarrow> f x \<noteq> 0) \<Longrightarrow>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1640
     degree (prod f A :: 'a :: idom poly) = (\<Sum>x\<in>A. degree (f x))"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1641
  by (induction A rule: infinite_finite_induct) (auto simp: degree_mult_eq)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1642
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  1643
lemma dvd_imp_degree:
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  1644
  \<open>degree x \<le> degree y\<close> if \<open>x dvd y\<close> \<open>x \<noteq> 0\<close> \<open>y \<noteq> 0\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  1645
    for x y :: \<open>'a::{comm_semiring_1,semiring_no_zero_divisors} poly\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  1646
proof -
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  1647
  from \<open>x dvd y\<close> obtain z where \<open>y = x * z\<close> ..
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  1648
  with \<open>x \<noteq> 0\<close> \<open>y \<noteq> 0\<close> show ?thesis
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  1649
    by (simp add: degree_mult_eq)
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  1650
qed
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  1651
73109
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  1652
lemma degree_prod_eq_sum_degree:
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  1653
  fixes A :: "'a set"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  1654
  and f :: "'a \<Rightarrow> 'b::idom poly"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  1655
  assumes f0: "\<forall>i\<in>A. f i \<noteq> 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  1656
  shows "degree (\<Prod>i\<in>A. (f i)) = (\<Sum>i\<in>A. degree (f i))"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  1657
  using assms
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  1658
  by (induction A rule: infinite_finite_induct) (auto simp: degree_mult_eq)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  1659
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1660
lemma degree_mult_eq_0:
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1661
  "degree (p * q) = 0 \<longleftrightarrow> p = 0 \<or> q = 0 \<or> (p \<noteq> 0 \<and> q \<noteq> 0 \<and> degree p = 0 \<and> degree q = 0)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1662
  for p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1663
  by (auto simp: degree_mult_eq)
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  1664
66550
e5d82cf3c387 Some small lemmas about polynomials and FPSs
eberlm <eberlm@in.tum.de>
parents: 66453
diff changeset
  1665
lemma degree_power_eq: "p \<noteq> 0 \<Longrightarrow> degree ((p :: 'a :: idom poly) ^ n) = n * degree p"
e5d82cf3c387 Some small lemmas about polynomials and FPSs
eberlm <eberlm@in.tum.de>
parents: 66453
diff changeset
  1666
  by (induction n) (simp_all add: degree_mult_eq)
e5d82cf3c387 Some small lemmas about polynomials and FPSs
eberlm <eberlm@in.tum.de>
parents: 66453
diff changeset
  1667
60570
7ed2cde6806d more theorems
haftmann
parents: 60562
diff changeset
  1668
lemma degree_mult_right_le:
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1669
  fixes p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
60570
7ed2cde6806d more theorems
haftmann
parents: 60562
diff changeset
  1670
  assumes "q \<noteq> 0"
7ed2cde6806d more theorems
haftmann
parents: 60562
diff changeset
  1671
  shows "degree p \<le> degree (p * q)"
7ed2cde6806d more theorems
haftmann
parents: 60562
diff changeset
  1672
  using assms by (cases "p = 0") (simp_all add: degree_mult_eq)
7ed2cde6806d more theorems
haftmann
parents: 60562
diff changeset
  1673
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1674
lemma coeff_degree_mult: "coeff (p * q) (degree (p * q)) = coeff q (degree q) * coeff p (degree p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1675
  for p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1676
  by (cases "p = 0 \<or> q = 0") (auto simp: degree_mult_eq coeff_mult_degree_sum mult_ac)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1677
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1678
lemma dvd_imp_degree_le: "p dvd q \<Longrightarrow> q \<noteq> 0 \<Longrightarrow> degree p \<le> degree q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1679
  for p q :: "'a::{comm_semiring_1,semiring_no_zero_divisors} poly"
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
  1680
  by (erule dvdE, hypsubst, subst degree_mult_eq) auto
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1681
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
  1682
lemma divides_degree:
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1683
  fixes p q :: "'a ::{comm_semiring_1,semiring_no_zero_divisors} poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1684
  assumes "p dvd q"
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
  1685
  shows "degree p \<le> degree q \<or> q = 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1686
  by (metis dvd_imp_degree_le assms)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1687
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1688
lemma const_poly_dvd_iff:
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1689
  fixes c :: "'a::{comm_semiring_1,semiring_no_zero_divisors}"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1690
  shows "[:c:] dvd p \<longleftrightarrow> (\<forall>n. c dvd coeff p n)"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1691
proof (cases "c = 0 \<or> p = 0")
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1692
  case True
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1693
  then show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1694
    by (auto intro!: poly_eqI)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1695
next
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1696
  case False
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1697
  show ?thesis
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1698
  proof
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1699
    assume "[:c:] dvd p"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1700
    then show "\<forall>n. c dvd coeff p n"
76121
f58ad163bb75 putting together related theorems
haftmann
parents: 74362
diff changeset
  1701
      by (auto simp: coeffs_def)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1702
  next
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1703
    assume *: "\<forall>n. c dvd coeff p n"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1704
    define mydiv where "mydiv x y = (SOME z. x = y * z)" for x y :: 'a
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1705
    have mydiv: "x = y * mydiv x y" if "y dvd x" for x y
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1706
      using that unfolding mydiv_def dvd_def by (rule someI_ex)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1707
    define q where "q = Poly (map (\<lambda>a. mydiv a c) (coeffs p))"
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1708
    from False * have "p = q * [:c:]"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1709
      by (intro poly_eqI)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1710
        (auto simp: q_def nth_default_def not_less length_coeffs_degree coeffs_nth
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1711
          intro!: coeff_eq_0 mydiv)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1712
    then show "[:c:] dvd p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1713
      by (simp only: dvd_triv_right)
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1714
  qed
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1715
qed
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1716
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1717
lemma const_poly_dvd_const_poly_iff [simp]: "[:a:] dvd [:b:] \<longleftrightarrow> a dvd b"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1718
  for a b :: "'a::{comm_semiring_1,semiring_no_zero_divisors}"
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1719
  by (subst const_poly_dvd_iff) (auto simp: coeff_pCons split: nat.splits)
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1720
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1721
lemma lead_coeff_mult: "lead_coeff (p * q) = lead_coeff p * lead_coeff q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1722
  for p q :: "'a::{comm_semiring_0, semiring_no_zero_divisors} poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1723
  by (cases "p = 0 \<or> q = 0") (auto simp: coeff_mult_degree_sum degree_mult_eq)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1724
73109
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  1725
lemma lead_coeff_prod: "lead_coeff (prod f A) = (\<Prod>x\<in>A. lead_coeff (f x))"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  1726
  for f :: "'a \<Rightarrow> 'b::{comm_semiring_1, semiring_no_zero_divisors} poly"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  1727
  by (induction A rule: infinite_finite_induct) (auto simp: lead_coeff_mult)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  1728
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1729
lemma lead_coeff_smult: "lead_coeff (smult c p) = c * lead_coeff p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1730
  for p :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1731
proof -
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1732
  have "smult c p = [:c:] * p" by simp
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1733
  also have "lead_coeff \<dots> = c * lead_coeff p"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1734
    by (subst lead_coeff_mult) simp_all
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1735
  finally show ?thesis .
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1736
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1737
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1738
lemma lead_coeff_1 [simp]: "lead_coeff 1 = 1"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1739
  by simp
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1740
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1741
lemma lead_coeff_power: "lead_coeff (p ^ n) = lead_coeff p ^ n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1742
  for p :: "'a::{comm_semiring_1,semiring_no_zero_divisors} poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1743
  by (induct n) (simp_all add: lead_coeff_mult)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1744
29451
5f0cb3fa530d new theory of polynomials
huffman
parents:
diff changeset
  1745
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1746
subsection \<open>Polynomials form an ordered integral domain\<close>
29878
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1747
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  1748
definition pos_poly :: "'a::linordered_semidom poly \<Rightarrow> bool"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1749
  where "pos_poly p \<longleftrightarrow> 0 < coeff p (degree p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1750
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1751
lemma pos_poly_pCons: "pos_poly (pCons a p) \<longleftrightarrow> pos_poly p \<or> (p = 0 \<and> 0 < a)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1752
  by (simp add: pos_poly_def)
29878
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1753
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1754
lemma not_pos_poly_0 [simp]: "\<not> pos_poly 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1755
  by (simp add: pos_poly_def)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1756
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1757
lemma pos_poly_add: "pos_poly p \<Longrightarrow> pos_poly q \<Longrightarrow> pos_poly (p + q)"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1758
proof (induction p arbitrary: q)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1759
  case (pCons a p)
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  1760
  then show ?case
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1761
    by (cases q; force simp add: pos_poly_pCons add_pos_pos)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1762
qed auto
29878
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1763
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1764
lemma pos_poly_mult: "pos_poly p \<Longrightarrow> pos_poly q \<Longrightarrow> pos_poly (p * q)"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1765
  by (simp add: pos_poly_def coeff_degree_mult)
29878
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1766
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1767
lemma pos_poly_total: "p = 0 \<or> pos_poly p \<or> pos_poly (- p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1768
  for p :: "'a::linordered_idom poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1769
  by (induct p) (auto simp: pos_poly_pCons)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1770
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1771
lemma pos_poly_coeffs [code]: "pos_poly p \<longleftrightarrow> (let as = coeffs p in as \<noteq> [] \<and> last as > 0)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1772
  (is "?lhs \<longleftrightarrow> ?rhs")
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1773
proof
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1774
  assume ?rhs
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1775
  then show ?lhs
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1776
    by (auto simp add: pos_poly_def last_coeffs_eq_coeff_degree)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1777
next
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1778
  assume ?lhs
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1779
  then have *: "0 < coeff p (degree p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1780
    by (simp add: pos_poly_def)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1781
  then have "p \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1782
    by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1783
  with * show ?rhs
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1784
    by (simp add: last_coeffs_eq_coeff_degree)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1785
qed
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1786
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34973
diff changeset
  1787
instantiation poly :: (linordered_idom) linordered_idom
29878
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1788
begin
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1789
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1790
definition "x < y \<longleftrightarrow> pos_poly (y - x)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1791
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1792
definition "x \<le> y \<longleftrightarrow> x = y \<or> pos_poly (y - x)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1793
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1794
definition "\<bar>x::'a poly\<bar> = (if x < 0 then - x else x)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1795
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1796
definition "sgn (x::'a poly) = (if x = 0 then 0 else if 0 < x then 1 else - 1)"
29878
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1797
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
  1798
instance
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
  1799
proof
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
  1800
  fix x y z :: "'a poly"
29878
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1801
  show "x < y \<longleftrightarrow> x \<le> y \<and> \<not> y \<le> x"
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1802
    unfolding less_eq_poly_def less_poly_def
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1803
    using pos_poly_add by force
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1804
  then show "x \<le> y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1805
    using less_eq_poly_def less_poly_def by force
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
  1806
  show "x \<le> x"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1807
    by (simp add: less_eq_poly_def)
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
  1808
  show "x \<le> y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1809
    using less_eq_poly_def pos_poly_add by fastforce
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
  1810
  show "x \<le> y \<Longrightarrow> z + x \<le> z + y"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1811
    by (simp add: less_eq_poly_def)
29878
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1812
  show "x \<le> y \<or> y \<le> x"
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1813
    unfolding less_eq_poly_def
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1814
    using pos_poly_total [of "x - y"]
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1815
    by auto
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60570
diff changeset
  1816
  show "x < y \<Longrightarrow> 0 < z \<Longrightarrow> z * x < z * y"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1817
    by (simp add: less_poly_def right_diff_distrib [symmetric] pos_poly_mult)
29878
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1818
  show "\<bar>x\<bar> = (if x < 0 then - x else x)"
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1819
    by (rule abs_poly_def)
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1820
  show "sgn x = (if x = 0 then 0 else if 0 < x then 1 else - 1)"
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1821
    by (rule sgn_poly_def)
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1822
qed
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1823
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1824
end
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1825
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1826
text \<open>TODO: Simplification rules for comparisons\<close>
29878
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1827
06efd6e731c6 ordered_idom instance for polynomials
huffman
parents: 29668
diff changeset
  1828
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1829
subsection \<open>Synthetic division and polynomial roots\<close>
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1830
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1831
subsubsection \<open>Synthetic division\<close>
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1832
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 69064
diff changeset
  1833
text \<open>Synthetic division is simply division by the linear polynomial \<^term>\<open>x - c\<close>.\<close>
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1834
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1835
definition synthetic_divmod :: "'a::comm_semiring_0 poly \<Rightarrow> 'a \<Rightarrow> 'a poly \<times> 'a"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1836
  where "synthetic_divmod p c = fold_coeffs (\<lambda>a (q, r). (pCons r q, a + c * r)) p (0, 0)"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1837
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1838
definition synthetic_div :: "'a::comm_semiring_0 poly \<Rightarrow> 'a \<Rightarrow> 'a poly"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1839
  where "synthetic_div p c = fst (synthetic_divmod p c)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1840
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1841
lemma synthetic_divmod_0 [simp]: "synthetic_divmod 0 c = (0, 0)"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1842
  by (simp add: synthetic_divmod_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1843
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1844
lemma synthetic_divmod_pCons [simp]:
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1845
  "synthetic_divmod (pCons a p) c = (\<lambda>(q, r). (pCons r q, a + c * r)) (synthetic_divmod p c)"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1846
  by (cases "p = 0 \<and> a = 0") (auto simp add: synthetic_divmod_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1847
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1848
lemma synthetic_div_0 [simp]: "synthetic_div 0 c = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1849
  by (simp add: synthetic_div_def)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1850
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1851
lemma synthetic_div_unique_lemma: "smult c p = pCons a p \<Longrightarrow> p = 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1852
  by (induct p arbitrary: a) simp_all
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1853
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1854
lemma snd_synthetic_divmod: "snd (synthetic_divmod p c) = poly p c"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1855
  by (induct p) (simp_all add: split_def)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1856
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1857
lemma synthetic_div_pCons [simp]:
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1858
  "synthetic_div (pCons a p) c = pCons (poly p c) (synthetic_div p c)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1859
  by (simp add: synthetic_div_def split_def snd_synthetic_divmod)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1860
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1861
lemma synthetic_div_eq_0_iff: "synthetic_div p c = 0 \<longleftrightarrow> degree p = 0"
63649
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  1862
proof (induct p)
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  1863
  case 0
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  1864
  then show ?case by simp
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  1865
next
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  1866
  case (pCons a p)
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  1867
  then show ?case by (cases p) simp
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  1868
qed
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1869
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1870
lemma degree_synthetic_div: "degree (synthetic_div p c) = degree p - 1"
63649
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  1871
  by (induct p) (simp_all add: synthetic_div_eq_0_iff)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1872
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1873
lemma synthetic_div_correct:
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1874
  "p + smult c (synthetic_div p c) = pCons (poly p c) (synthetic_div p c)"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1875
  by (induct p) simp_all
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1876
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1877
lemma synthetic_div_unique: "p + smult c q = pCons r q \<Longrightarrow> r = poly p c \<and> q = synthetic_div p c"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1878
proof (induction p arbitrary: q r)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1879
  case 0
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1880
  then show ?case
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1881
    using synthetic_div_unique_lemma by fastforce
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1882
next
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1883
  case (pCons a p)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1884
  then show ?case
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1885
    by (cases q; force)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1886
qed
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1887
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1888
lemma synthetic_div_correct': "[:-c, 1:] * synthetic_div p c + [:poly p c:] = p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1889
  for c :: "'a::comm_ring_1"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1890
  using synthetic_div_correct [of p c] by (simp add: algebra_simps)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1891
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1892
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  1893
subsubsection \<open>Polynomial roots\<close>
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1894
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1895
lemma poly_eq_0_iff_dvd: "poly p c = 0 \<longleftrightarrow> [:- c, 1:] dvd p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1896
  (is "?lhs \<longleftrightarrow> ?rhs")
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1897
  for c :: "'a::comm_ring_1"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1898
proof
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1899
  assume ?lhs
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1900
  with synthetic_div_correct' [of c p] have "p = [:-c, 1:] * synthetic_div p c" by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1901
  then show ?rhs ..
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1902
next
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1903
  assume ?rhs
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1904
  then obtain k where "p = [:-c, 1:] * k" by (rule dvdE)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1905
  then show ?lhs by simp
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1906
qed
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1907
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1908
lemma dvd_iff_poly_eq_0: "[:c, 1:] dvd p \<longleftrightarrow> poly p (- c) = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1909
  for c :: "'a::comm_ring_1"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1910
  by (simp add: poly_eq_0_iff_dvd)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1911
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1912
lemma poly_roots_finite: "p \<noteq> 0 \<Longrightarrow> finite {x. poly p x = 0}"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1913
  for p :: "'a::{comm_ring_1,ring_no_zero_divisors} poly"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1914
proof (induct n \<equiv> "degree p" arbitrary: p)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1915
  case 0
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1916
  then obtain a where "a \<noteq> 0" and "p = [:a:]"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1917
    by (cases p) (simp split: if_splits)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1918
  then show "finite {x. poly p x = 0}"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1919
    by simp
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1920
next
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1921
  case (Suc n)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1922
  show "finite {x. poly p x = 0}"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1923
  proof (cases "\<exists>x. poly p x = 0")
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1924
    case False
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1925
    then show "finite {x. poly p x = 0}" by simp
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1926
  next
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1927
    case True
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1928
    then obtain a where "poly p a = 0" ..
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1929
    then have "[:-a, 1:] dvd p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1930
      by (simp only: poly_eq_0_iff_dvd)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1931
    then obtain k where k: "p = [:-a, 1:] * k" ..
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1932
    with \<open>p \<noteq> 0\<close> have "k \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1933
      by auto
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1934
    with k have "degree p = Suc (degree k)"
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1935
      by (simp add: degree_mult_eq del: mult_pCons_left)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1936
    with \<open>Suc n = degree p\<close> have "n = degree k"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1937
      by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1938
    from this \<open>k \<noteq> 0\<close> have "finite {x. poly k x = 0}"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1939
      by (rule Suc.hyps)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1940
    then have "finite (insert a {x. poly k x = 0})"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1941
      by simp
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1942
    then show "finite {x. poly p x = 0}"
57862
8f074e6e22fc tuned proofs;
wenzelm
parents: 57512
diff changeset
  1943
      by (simp add: k Collect_disj_eq del: mult_pCons_left)
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1944
  qed
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1945
qed
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1946
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1947
lemma poly_eq_poly_eq_iff: "poly p = poly q \<longleftrightarrow> p = q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1948
  (is "?lhs \<longleftrightarrow> ?rhs")
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1949
  for p q :: "'a::{comm_ring_1,ring_no_zero_divisors,ring_char_0} poly"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1950
proof
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1951
  assume ?rhs
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1952
  then show ?lhs by simp
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1953
next
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1954
  assume ?lhs
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1955
  have "poly p = poly 0 \<longleftrightarrow> p = 0" for p :: "'a poly"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1956
  proof (cases "p = 0")
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1957
    case False
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1958
    then show ?thesis
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1959
      by (auto simp add: infinite_UNIV_char_0 dest: poly_roots_finite)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  1960
  qed auto
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1961
  from \<open>?lhs\<close> and this [of "p - q"] show ?rhs
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1962
    by auto
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1963
qed
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1964
82187
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1965
text \<open>A nice extension rule for polynomials.\<close>
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1966
lemma poly_ext:
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1967
  fixes p q :: "'a :: {ring_char_0, idom} poly"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1968
  assumes "\<And>x. poly p x = poly q x" shows "p = q"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1969
  unfolding poly_eq_poly_eq_iff[symmetric]
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1970
  using assms by (rule ext)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1971
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1972
text \<open>Copied from non-negative variants.\<close>
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1973
lemma coeff_linear_power_neg[simp]:
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1974
  fixes a :: "'a::comm_ring_1"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1975
  shows "coeff ([:a, -1:] ^ n) n = (-1)^n"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1976
proof (induct n)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1977
  case 0
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1978
  then show ?case by simp
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1979
next
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1980
  case (Suc n)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1981
  then have "degree ([:a, - 1:] ^ n) < Suc n"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1982
    by (auto intro: le_less_trans degree_power_le)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1983
  with Suc show ?case
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1984
    by (simp add: coeff_eq_0)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1985
qed
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1986
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1987
lemma degree_linear_power_neg[simp]:
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1988
  fixes a :: "'a::{idom,comm_ring_1}"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1989
  shows "degree ([:a, -1:] ^ n) = n"
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1990
  by (simp add: degree_power_eq)
cddce3a4ef84 A few lemmas brought in from Polynomial_Interpolation
paulson <lp15@cam.ac.uk>
parents: 81182
diff changeset
  1991
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1992
lemma poly_all_0_iff_0: "(\<forall>x. poly p x = 0) \<longleftrightarrow> p = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  1993
  for p :: "'a::{ring_char_0,comm_ring_1,ring_no_zero_divisors} poly"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1994
  by (auto simp add: poly_eq_poly_eq_iff [symmetric])
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  1995
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1996
lemma card_poly_roots_bound:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1997
  fixes p :: "'a::{comm_ring_1,ring_no_zero_divisors} poly"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1998
  assumes "p \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  1999
  shows   "card {x. poly p x = 0} \<le> degree p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2000
using assms
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2001
proof (induction "degree p" arbitrary: p rule: less_induct)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2002
  case (less p)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2003
  show ?case
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2004
  proof (cases "\<exists>x. poly p x = 0")
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2005
    case False
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2006
    hence "{x. poly p x = 0} = {}" by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2007
    thus ?thesis by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2008
  next
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2009
    case True
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2010
    then obtain x where x: "poly p x = 0" by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2011
    hence "[:-x, 1:] dvd p" by (subst (asm) poly_eq_0_iff_dvd)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2012
    then obtain q where q: "p = [:-x, 1:] * q" by (auto simp: dvd_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2013
    with \<open>p \<noteq> 0\<close> have [simp]: "q \<noteq> 0" by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2014
    have deg: "degree p = Suc (degree q)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2015
      by (subst q, subst degree_mult_eq) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2016
    have "card {x. poly p x = 0} \<le> card (insert x {x. poly q x = 0})"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2017
      by (intro card_mono) (auto intro: poly_roots_finite simp: q)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2018
    also have "\<dots> \<le> Suc (card {x. poly q x = 0})"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2019
      by (rule card_insert_le_m1) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2020
    also from deg have  "card {x. poly q x = 0} \<le> degree q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2021
      using \<open>p \<noteq> 0\<close> and q by (intro less) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2022
    also have "Suc \<dots> = degree p" by (simp add: deg)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2023
    finally show ?thesis by - simp_all
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2024
  qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2025
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2026
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2027
lemma poly_eqI_degree:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2028
  fixes p q :: "'a :: {comm_ring_1, ring_no_zero_divisors} poly"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2029
  assumes "\<And>x. x \<in> A \<Longrightarrow> poly p x = poly q x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2030
  assumes "card A > degree p" "card A > degree q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2031
  shows   "p = q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2032
proof (rule ccontr)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2033
  assume neq: "p \<noteq> q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2034
  have "degree (p - q) \<le> max (degree p) (degree q)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2035
    by (rule degree_diff_le_max)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2036
  also from assms have "\<dots> < card A" by linarith
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2037
  also have "\<dots> \<le> card {x. poly (p - q) x = 0}"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2038
    using neq and assms by (intro card_mono poly_roots_finite) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2039
  finally have "degree (p - q) < card {x. poly (p - q) x = 0}" .
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2040
  moreover have "degree (p - q) \<ge> card {x. poly (p - q) x = 0}"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2041
    using neq by (intro card_poly_roots_bound) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2042
  ultimately show False by linarith
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2043
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2044
82653
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2045
lemma poly_eqI_degree_lead_coeff:
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2046
  fixes p q :: "'a :: {comm_ring_1, ring_no_zero_divisors} poly"
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2047
  assumes "poly.coeff p n = poly.coeff q n" "card A \<ge> n" "degree p \<le> n" "degree q \<le> n"
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2048
  assumes "\<And>z. z \<in> A \<Longrightarrow> poly p z = poly q z"
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2049
  shows   "p = q"
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2050
proof (rule ccontr)
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2051
  assume "p \<noteq> q"
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2052
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2053
  have "n > 0"
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2054
  proof (rule ccontr)
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2055
    assume "\<not>(n > 0)"
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2056
    thus False
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2057
      using assms \<open>p \<noteq> q\<close> by (auto elim!: degree_eq_zeroE)
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2058
  qed
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2059
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2060
  have "n \<le> card A"
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2061
    by fact
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2062
  also have "card A \<le> card {x. poly (p - q) x = 0}"
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2063
    by (intro card_mono poly_roots_finite) (use \<open>p \<noteq> q\<close> assms in auto)
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2064
  also have "card {x. poly (p - q) x = 0} \<le> degree (p - q)"
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2065
    by (rule card_poly_roots_bound) (use \<open>p \<noteq> q\<close> in auto)
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2066
  also have "degree (p - q) < n"
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2067
  proof (intro degree_lessI allI impI)
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2068
    fix k assume "k \<ge> n"
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2069
    show "poly.coeff (p - q) k = 0"
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2070
    proof (cases "k = n")
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2071
      case False
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2072
      hence "poly.coeff p k = 0" "poly.coeff q k = 0"
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2073
        using assms \<open>k \<ge> n\<close> by (auto simp: coeff_eq_0)
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2074
      thus ?thesis
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2075
        by simp
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2076
    qed (use assms in auto)
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2077
  qed (use \<open>n > 0\<close> in auto)
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2078
  finally show False
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2079
    by simp
565545b7fe9d three lemmas for HOL-Complex_Analysis, HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 82187
diff changeset
  2080
qed
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2081
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2082
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2083
subsubsection \<open>Order of polynomial roots\<close>
29977
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2084
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  2085
definition order :: "'a::idom \<Rightarrow> 'a poly \<Rightarrow> nat"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2086
  where "order a p = (LEAST n. \<not> [:-a, 1:] ^ Suc n dvd p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2087
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2088
lemma coeff_linear_power: "coeff ([:a, 1:] ^ n) n = 1"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2089
  for a :: "'a::comm_semiring_1"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2090
proof (induct n)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2091
  case (Suc n)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2092
  have "degree ([:a, 1:] ^ n) \<le> 1 * n"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2093
    by (metis One_nat_def degree_pCons_eq_if degree_power_le one_neq_zero one_pCons)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2094
  then have "coeff ([:a, 1:] ^ n) (Suc n) = 0"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2095
    by (simp add: coeff_eq_0)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2096
  then show ?case
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2097
    using Suc.hyps by fastforce
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2098
qed auto
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2099
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2100
lemma degree_linear_power: "degree ([:a, 1:] ^ n) = n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2101
  for a :: "'a::comm_semiring_1"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2102
proof (rule order_antisym)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2103
  show "degree ([:a, 1:] ^ n) \<le> n"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2104
    by (metis One_nat_def degree_pCons_eq_if degree_power_le mult.left_neutral one_neq_zero one_pCons)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2105
qed (simp add: coeff_linear_power le_degree)
29977
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2106
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2107
lemma order_1: "[:-a, 1:] ^ order a p dvd p"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2108
proof (cases "p = 0")
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2109
  case False
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  2110
  show ?thesis
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2111
  proof (cases "order a p")
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2112
    case (Suc n)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2113
    then show ?thesis
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2114
      by (metis lessI not_less_Least order_def)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2115
  qed auto
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2116
qed auto
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2117
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  2118
lemma order_2:
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  2119
  assumes "p \<noteq> 0"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2120
  shows "\<not> [:-a, 1:] ^ Suc (order a p) dvd p"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2121
proof -
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2122
  have False if "[:- a, 1:] ^ Suc (degree p) dvd p"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2123
    using dvd_imp_degree_le [OF that]
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2124
    by (metis Suc_n_not_le_n assms degree_linear_power)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2125
  then show ?thesis
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2126
    unfolding order_def
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2127
    by (metis (no_types, lifting) LeastI)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2128
qed
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2129
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2130
lemma order: "p \<noteq> 0 \<Longrightarrow> [:-a, 1:] ^ order a p dvd p \<and> \<not> [:-a, 1:] ^ Suc (order a p) dvd p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2131
  by (rule conjI [OF order_1 order_2])
29977
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2132
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2133
lemma order_degree:
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2134
  assumes p: "p \<noteq> 0"
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2135
  shows "order a p \<le> degree p"
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2136
proof -
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2137
  have "order a p = degree ([:-a, 1:] ^ order a p)"
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2138
    by (simp only: degree_linear_power)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2139
  also from order_1 p have "\<dots> \<le> degree p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2140
    by (rule dvd_imp_degree_le)
29977
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2141
  finally show ?thesis .
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2142
qed
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2143
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2144
lemma order_root: "poly p a = 0 \<longleftrightarrow> p = 0 \<or> order a p \<noteq> 0" (is "?lhs = ?rhs")
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2145
proof
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2146
  show "?lhs \<Longrightarrow> ?rhs"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2147
    by (metis One_nat_def order_2 poly_eq_0_iff_dvd power_one_right)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2148
  show "?rhs \<Longrightarrow> ?lhs"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2149
    by (meson dvd_power dvd_trans neq0_conv order_1 poly_0 poly_eq_0_iff_dvd)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2150
qed
29977
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2151
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2152
lemma order_0I: "poly p a \<noteq> 0 \<Longrightarrow> order a p = 0"
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2153
  by (subst (asm) order_root) auto
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2154
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2155
lemma order_unique_lemma:
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2156
  fixes p :: "'a::idom poly"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2157
  assumes "[:-a, 1:] ^ n dvd p" "\<not> [:-a, 1:] ^ Suc n dvd p"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2158
  shows "order a p = n"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2159
  unfolding Polynomial.order_def
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2160
  by (metis (mono_tags, lifting) Least_equality assms not_less_eq_eq power_le_dvd)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2161
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  2162
lemma order_mult:
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2163
  assumes "p * q \<noteq> 0" shows "order a (p * q) = order a p + order a q"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2164
proof -
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2165
  define i where "i \<equiv> order a p"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2166
  define j where "j \<equiv> order a q"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2167
  define t where "t \<equiv> [:-a, 1:]"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2168
  have t_dvd_iff: "\<And>u. t dvd u \<longleftrightarrow> poly u a = 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2169
    by (simp add: t_def dvd_iff_poly_eq_0)
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2170
  have dvd: "t ^ i dvd p" "t ^ j dvd q" and "\<not> t ^ Suc i dvd p" "\<not> t ^ Suc j dvd q"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2171
    using assms i_def j_def order_1 order_2 t_def by auto
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2172
  then have "\<not> t ^ Suc(i + j) dvd p * q"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2173
    by (elim dvdE) (simp add: power_add t_dvd_iff)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2174
  moreover have "t ^ (i + j) dvd p * q"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2175
    using dvd by (simp add: mult_dvd_mono power_add)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2176
  ultimately show "order a (p * q) = i + j"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2177
    using order_unique_lemma t_def by blast
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2178
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2179
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2180
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2181
lemma order_smult:
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2182
  assumes "c \<noteq> 0"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2183
  shows "order x (smult c p) = order x p"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2184
proof (cases "p = 0")
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2185
  case True
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2186
  then show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2187
    by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2188
next
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2189
  case False
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2190
  have "smult c p = [:c:] * p" by simp
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2191
  also from assms False have "order x \<dots> = order x [:c:] + order x p"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2192
    by (subst order_mult) simp_all
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2193
  also have "order x [:c:] = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2194
    by (rule order_0I) (use assms in auto)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2195
  finally show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2196
    by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2197
qed
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2198
79672
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2199
lemma order_gt_0_iff: "p \<noteq> 0 \<Longrightarrow> order x p > 0 \<longleftrightarrow> poly p x = 0"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2200
  by (subst order_root) auto
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2201
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2202
lemma order_eq_0_iff: "p \<noteq> 0 \<Longrightarrow> order x p = 0 \<longleftrightarrow> poly p x \<noteq> 0"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2203
  by (subst order_root) auto
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2204
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2205
text \<open>Next three lemmas contributed by Wenda Li\<close>
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2206
lemma order_1_eq_0 [simp]:"order x 1 = 0"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2207
  by (metis order_root poly_1 zero_neq_one)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2208
68532
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  2209
lemma order_uminus[simp]: "order x (-p) = order x p"
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  2210
  by (metis neg_equal_0_iff_equal order_smult smult_1_left smult_minus_left)
68532
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  2211
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2212
lemma order_power_n_n: "order a ([:-a,1:]^n)=n"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2213
proof (induct n) (*might be proved more concisely using nat_less_induct*)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2214
  case 0
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2215
  then show ?case
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2216
    by (metis order_root poly_1 power_0 zero_neq_one)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2217
next
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2218
  case (Suc n)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2219
  have "order a ([:- a, 1:] ^ Suc n) = order a ([:- a, 1:] ^ n) + order a [:-a,1:]"
73932
fd21b4a93043 added opaque_combs and renamed hide_lams to opaque_lifting
desharna
parents: 73510
diff changeset
  2220
    by (metis (no_types, opaque_lifting) One_nat_def add_Suc_right monoid_add_class.add.right_neutral
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2221
      one_neq_zero order_mult pCons_eq_0_iff power_add power_eq_0_iff power_one_right)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2222
  moreover have "order a [:-a,1:] = 1"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2223
    unfolding order_def
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2224
  proof (rule Least_equality, rule notI)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2225
    assume "[:- a, 1:] ^ Suc 1 dvd [:- a, 1:]"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2226
    then have "degree ([:- a, 1:] ^ Suc 1) \<le> degree ([:- a, 1:])"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2227
      by (rule dvd_imp_degree_le) auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2228
    then show False
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2229
      by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2230
  next
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2231
    fix y
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2232
    assume *: "\<not> [:- a, 1:] ^ Suc y dvd [:- a, 1:]"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2233
    show "1 \<le> y"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2234
    proof (rule ccontr)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2235
      assume "\<not> 1 \<le> y"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2236
      then have "y = 0" by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2237
      then have "[:- a, 1:] ^ Suc y dvd [:- a, 1:]" by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2238
      with * show False by auto
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2239
    qed
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2240
  qed
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2241
  ultimately show ?case
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2242
    using Suc by auto
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2243
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2244
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2245
lemma order_0_monom [simp]: "c \<noteq> 0 \<Longrightarrow> order 0 (monom c n) = n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2246
  using order_power_n_n[of 0 n] by (simp add: monom_altdef order_smult)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2247
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2248
lemma dvd_imp_order_le: "q \<noteq> 0 \<Longrightarrow> p dvd q \<Longrightarrow> Polynomial.order a p \<le> Polynomial.order a q"
76121
f58ad163bb75 putting together related theorems
haftmann
parents: 74362
diff changeset
  2249
  by (auto simp: order_mult)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2250
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2251
text \<open>Now justify the standard squarefree decomposition, i.e. \<open>f / gcd f f'\<close>.\<close>
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2252
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2253
lemma order_divides: "[:-a, 1:] ^ n dvd p \<longleftrightarrow> p = 0 \<or> n \<le> order a p"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2254
  by (meson dvd_0_right not_less_eq_eq order_1 order_2 power_le_dvd)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2255
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2256
lemma order_decomp:
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2257
  assumes "p \<noteq> 0"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2258
  shows "\<exists>q. p = [:- a, 1:] ^ order a p * q \<and> \<not> [:- a, 1:] dvd q"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2259
proof -
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2260
  from assms have *: "[:- a, 1:] ^ order a p dvd p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2261
    and **: "\<not> [:- a, 1:] ^ Suc (order a p) dvd p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2262
    by (auto dest: order)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2263
  from * obtain q where q: "p = [:- a, 1:] ^ order a p * q" ..
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2264
  with ** have "\<not> [:- a, 1:] ^ Suc (order a p) dvd [:- a, 1:] ^ order a p * q"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2265
    by simp
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2266
  then have "\<not> [:- a, 1:] ^ order a p * [:- a, 1:] dvd [:- a, 1:] ^ order a p * q"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2267
    by simp
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2268
  with idom_class.dvd_mult_cancel_left [of "[:- a, 1:] ^ order a p" "[:- a, 1:]" q]
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2269
  have "\<not> [:- a, 1:] dvd q" by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2270
  with q show ?thesis by blast
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2271
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2272
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2273
lemma monom_1_dvd_iff: "p \<noteq> 0 \<Longrightarrow> monom 1 n dvd p \<longleftrightarrow> n \<le> order 0 p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2274
  using order_divides[of 0 n p] by (simp add: monom_altdef)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2275
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2276
lemma poly_root_order_induct [case_names 0 no_roots root]:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2277
  fixes p :: "'a :: idom poly"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2278
  assumes "P 0" "\<And>p. (\<And>x. poly p x \<noteq> 0) \<Longrightarrow> P p" 
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2279
          "\<And>p x n. n > 0 \<Longrightarrow> poly p x \<noteq> 0 \<Longrightarrow> P p \<Longrightarrow> P ([:-x, 1:] ^ n * p)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2280
  shows   "P p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2281
proof (induction "degree p" arbitrary: p rule: less_induct)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2282
  case (less p)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2283
  consider "p = 0" | "p \<noteq> 0" "\<exists>x. poly p x = 0" | "\<And>x. poly p x \<noteq> 0" by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2284
  thus ?case
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2285
  proof cases
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2286
    case 3
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2287
    with assms(2)[of p] show ?thesis by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2288
  next
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2289
    case 2
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2290
    then obtain x where x: "poly p x = 0" by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2291
    have "[:-x, 1:] ^ order x p dvd p" by (intro order_1)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2292
    then obtain q where q: "p = [:-x, 1:] ^ order x p * q" by (auto simp: dvd_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2293
    with 2 have [simp]: "q \<noteq> 0" by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2294
    have order_pos: "order x p > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2295
      using \<open>p \<noteq> 0\<close> and x by (auto simp: order_root)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2296
    have "order x p = order x p + order x q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2297
      by (subst q, subst order_mult) (auto simp: order_power_n_n)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2298
    hence [simp]: "order x q = 0" by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2299
    have deg: "degree p = order x p + degree q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2300
      by (subst q, subst degree_mult_eq) (auto simp: degree_power_eq)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2301
    with order_pos have "degree q < degree p" by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2302
    hence "P q" by (rule less)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2303
    with order_pos have "P ([:-x, 1:] ^ order x p * q)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2304
      by (intro assms(3)) (auto simp: order_root)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2305
    with q show ?thesis by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2306
  qed (simp_all add: assms(1))
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2307
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2308
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2309
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2310
context
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2311
  includes multiset.lifting
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2312
begin
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2313
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2314
lift_definition proots :: "('a :: idom) poly \<Rightarrow> 'a multiset" is
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2315
  "\<lambda>(p :: 'a poly) (x :: 'a). if p = 0 then 0 else order x p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2316
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2317
  fix p :: "'a poly"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2318
  show "finite {x. 0 < (if p = 0 then 0 else order x p)}"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2319
    by (cases "p = 0")
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2320
       (auto simp: order_gt_0_iff intro: finite_subset[OF _ poly_roots_finite[of p]])
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2321
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2322
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2323
lemma proots_0 [simp]: "proots (0 :: 'a :: idom poly) = {#}"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2324
  by transfer' auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2325
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2326
lemma proots_1 [simp]: "proots (1 :: 'a :: idom poly) = {#}"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2327
  by transfer' auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2328
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2329
lemma proots_const [simp]: "proots [: x :] = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2330
  by transfer' (auto split: if_splits simp: fun_eq_iff order_eq_0_iff)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2331
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2332
lemma proots_numeral [simp]: "proots (numeral n) = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2333
  by (simp add: numeral_poly)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2334
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2335
lemma count_proots [simp]:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2336
  "p \<noteq> 0 \<Longrightarrow> count (proots p) a = order a p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2337
  by transfer' auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2338
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2339
lemma set_count_proots [simp]:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2340
   "p \<noteq> 0 \<Longrightarrow> set_mset (proots p) = {x. poly p x = 0}"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2341
  by (auto simp: set_mset_def order_gt_0_iff)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2342
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2343
lemma proots_uminus [simp]: "proots (-p) = proots p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2344
  by (cases "p = 0"; rule multiset_eqI) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2345
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2346
lemma proots_smult [simp]: "c \<noteq> 0 \<Longrightarrow> proots (smult c p) = proots p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2347
  by (cases "p = 0"; rule multiset_eqI) (auto simp: order_smult)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2348
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2349
lemma proots_mult:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2350
  assumes "p \<noteq> 0" "q \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2351
  shows   "proots (p * q) = proots p + proots q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2352
  using assms by (intro multiset_eqI) (auto simp: order_mult)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2353
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2354
lemma proots_prod:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2355
  assumes "\<And>x. x \<in> A \<Longrightarrow> f x \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2356
  shows   "proots (\<Prod>x\<in>A. f x) = (\<Sum>x\<in>A. proots (f x))"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2357
  using assms by (induction A rule: infinite_finite_induct) (auto simp: proots_mult)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2358
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2359
lemma proots_prod_mset:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2360
  assumes "0 \<notin># A"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2361
  shows   "proots (\<Prod>p\<in>#A. p) = (\<Sum>p\<in>#A. proots p)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2362
  using assms by (induction A) (auto simp: proots_mult)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2363
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2364
lemma proots_prod_list:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2365
  assumes "0 \<notin> set ps"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2366
  shows   "proots (\<Prod>p\<leftarrow>ps. p) = (\<Sum>p\<leftarrow>ps. proots p)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2367
  using assms by (induction ps) (auto simp: proots_mult prod_list_zero_iff)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2368
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2369
lemma proots_power: "proots (p ^ n) = repeat_mset n (proots p)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2370
proof (cases "p = 0")
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2371
  case False
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2372
  thus ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2373
    by (induction n) (auto simp: proots_mult)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2374
qed (auto simp: power_0_left)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2375
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2376
lemma proots_linear_factor [simp]: "proots [:x, 1:] = {#-x#}"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2377
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2378
  have "order (-x) [:x, 1:] > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2379
    by (subst order_gt_0_iff) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2380
  moreover have "order (-x) [:x, 1:] \<le> degree [:x, 1:]"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2381
    by (rule order_degree) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2382
  moreover have "order y [:x, 1:] = 0" if "y \<noteq> -x" for y
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2383
    by (rule order_0I) (use that in \<open>auto simp: add_eq_0_iff\<close>)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2384
  ultimately show ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2385
    by (intro multiset_eqI) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2386
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2387
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2388
lemma size_proots_le: "size (proots p) \<le> degree p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2389
proof (induction p rule: poly_root_order_induct)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2390
  case (no_roots p)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2391
  hence "proots p = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2392
    by (simp add: multiset_eqI order_root)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2393
  thus ?case by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2394
next
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2395
  case (root p x n)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2396
  have [simp]: "p \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2397
    using root.hyps by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2398
  from root.IH show ?case
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2399
    by (auto simp: proots_mult proots_power degree_mult_eq degree_power_eq)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2400
qed auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2401
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2402
end
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2403
29977
d76b830366bc move polynomial order stuff from Fundamental_Theorem_Algebra to Polynomial
huffman
parents: 29904
diff changeset
  2404
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2405
subsection \<open>Additional induction rules on polynomials\<close>
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2406
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2407
text \<open>
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2408
  An induction rule for induction over the roots of a polynomial with a certain property.
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2409
  (e.g. all positive roots)
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2410
\<close>
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2411
lemma poly_root_induct [case_names 0 no_roots root]:
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2412
  fixes p :: "'a :: idom poly"
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2413
  assumes "Q 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2414
    and "\<And>p. (\<And>a. P a \<Longrightarrow> poly p a \<noteq> 0) \<Longrightarrow> Q p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2415
    and "\<And>a p. P a \<Longrightarrow> Q p \<Longrightarrow> Q ([:a, -1:] * p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2416
  shows "Q p"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2417
proof (induction "degree p" arbitrary: p rule: less_induct)
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2418
  case (less p)
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2419
  show ?case
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2420
  proof (cases "p = 0")
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2421
    case True
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2422
    with assms(1) show ?thesis by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2423
  next
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2424
    case False
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2425
    show ?thesis
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2426
    proof (cases "\<exists>a. P a \<and> poly p a = 0")
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2427
      case False
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2428
      then show ?thesis by (intro assms(2)) blast
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2429
    next
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2430
      case True
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2431
      then obtain a where a: "P a" "poly p a = 0"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2432
        by blast
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2433
      then have "-[:-a, 1:] dvd p"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2434
        by (subst minus_dvd_iff) (simp add: poly_eq_0_iff_dvd)
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2435
      then obtain q where q: "p = [:a, -1:] * q" by (elim dvdE) simp
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2436
      with False have "q \<noteq> 0" by auto
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2437
      have "degree p = Suc (degree q)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2438
        by (subst q, subst degree_mult_eq) (simp_all add: \<open>q \<noteq> 0\<close>)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2439
      then have "Q q" by (intro less) simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2440
      with a(1) have "Q ([:a, -1:] * q)"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2441
        by (rule assms(3))
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2442
      with q show ?thesis by simp
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2443
    qed
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2444
  qed
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2445
qed
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2446
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2447
lemma dropWhile_replicate_append:
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67369
diff changeset
  2448
  "dropWhile ((=) a) (replicate n a @ ys) = dropWhile ((=) a) ys"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2449
  by (induct n) simp_all
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2450
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2451
lemma Poly_append_replicate_0: "Poly (xs @ replicate n 0) = Poly xs"
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2452
  by (subst coeffs_eq_iff) (simp_all add: strip_while_def dropWhile_replicate_append)
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2453
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2454
text \<open>
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2455
  An induction rule for simultaneous induction over two polynomials,
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2456
  prepending one coefficient in each step.
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2457
\<close>
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2458
lemma poly_induct2 [case_names 0 pCons]:
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2459
  assumes "P 0 0" "\<And>a p b q. P p q \<Longrightarrow> P (pCons a p) (pCons b q)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2460
  shows "P p q"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2461
proof -
63040
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 63035
diff changeset
  2462
  define n where "n = max (length (coeffs p)) (length (coeffs q))"
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 63035
diff changeset
  2463
  define xs where "xs = coeffs p @ (replicate (n - length (coeffs p)) 0)"
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 63035
diff changeset
  2464
  define ys where "ys = coeffs q @ (replicate (n - length (coeffs q)) 0)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2465
  have "length xs = length ys"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2466
    by (simp add: xs_def ys_def n_def)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2467
  then have "P (Poly xs) (Poly ys)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2468
    by (induct rule: list_induct2) (simp_all add: assms)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2469
  also have "Poly xs = p"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2470
    by (simp add: xs_def Poly_append_replicate_0)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2471
  also have "Poly ys = q"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2472
    by (simp add: ys_def Poly_append_replicate_0)
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2473
  finally show ?thesis .
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2474
qed
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2475
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2476
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  2477
subsection \<open>Composition of polynomials\<close>
29478
4a2482e16934 code generation for polynomials
huffman
parents: 29475
diff changeset
  2478
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
  2479
(* Several lemmas contributed by René Thiemann and Akihisa Yamada *)
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
  2480
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  2481
definition pcompose :: "'a::comm_semiring_0 poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2482
  where "pcompose p q = fold_coeffs (\<lambda>a c. [:a:] + q * c) p 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  2483
80914
d97fdabd9e2b standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents: 80786
diff changeset
  2484
notation pcompose (infixl \<open>\<circ>\<^sub>p\<close> 71)
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
  2485
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2486
lemma pcompose_0 [simp]: "pcompose 0 q = 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  2487
  by (simp add: pcompose_def)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2488
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2489
lemma pcompose_pCons: "pcompose (pCons a p) q = [:a:] + q * pcompose p q"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  2490
  by (cases "p = 0 \<and> a = 0") (auto simp add: pcompose_def)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  2491
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2492
lemma pcompose_altdef: "pcompose p q = poly (map_poly (\<lambda>x. [:x:]) p) q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2493
  by (induction p) (simp_all add: map_poly_pCons pcompose_pCons)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2494
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2495
lemma coeff_pcompose_0 [simp]:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2496
  "coeff (pcompose p q) 0 = poly p (coeff q 0)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2497
  by (induction p) (simp_all add: coeff_mult_0 pcompose_pCons)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2498
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2499
lemma pcompose_1: "pcompose 1 p = 1"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2500
  for p :: "'a::comm_semiring_1 poly"
65486
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  2501
  by (auto simp: one_pCons pcompose_pCons)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2502
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2503
lemma poly_pcompose: "poly (pcompose p q) x = poly p (poly q x)"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  2504
  by (induct p) (simp_all add: pcompose_pCons)
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  2505
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2506
lemma degree_pcompose_le: "degree (pcompose p q) \<le> degree p * degree q"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2507
proof (induction p)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2508
  case (pCons a p)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2509
  then show ?case
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2510
  proof (clarsimp simp add: pcompose_pCons)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2511
    assume "degree (p \<circ>\<^sub>p q) \<le> degree p * degree q" "p \<noteq> 0"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2512
    then have "degree (q * p \<circ>\<^sub>p q) \<le> degree q + degree p * degree q"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2513
      by (meson add_le_cancel_left degree_mult_le dual_order.trans pCons.IH)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2514
    then show "degree ([:a:] + q * p \<circ>\<^sub>p q) \<le> degree q + degree p * degree q"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2515
      by (simp add: degree_add_le)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2516
  qed
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2517
qed auto
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2518
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2519
lemma pcompose_add: "pcompose (p + q) r = pcompose p r + pcompose q r"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2520
  for p q r :: "'a::{comm_semiring_0, ab_semigroup_add} poly"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2521
proof (induction p q rule: poly_induct2)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2522
  case 0
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2523
  then show ?case by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2524
next
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2525
  case (pCons a p b q)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2526
  have "pcompose (pCons a p + pCons b q) r = [:a + b:] + r * pcompose p r + r * pcompose q r"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2527
    by (simp_all add: pcompose_pCons pCons.IH algebra_simps)
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2528
  also have "[:a + b:] = [:a:] + [:b:]" by simp
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  2529
  also have "\<dots> + r * pcompose p r + r * pcompose q r = pcompose (pCons a p) r + pcompose (pCons b q) r"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2530
    by (simp only: pcompose_pCons add_ac)
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2531
  finally show ?case .
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2532
qed
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2533
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2534
lemma pcompose_uminus: "pcompose (-p) r = -pcompose p r"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2535
  for p r :: "'a::comm_ring poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2536
  by (induct p) (simp_all add: pcompose_pCons)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2537
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2538
lemma pcompose_diff: "pcompose (p - q) r = pcompose p r - pcompose q r"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2539
  for p q r :: "'a::comm_ring poly"
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
  2540
  using pcompose_add[of p "-q"] by (simp add: pcompose_uminus)
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2541
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2542
lemma pcompose_smult: "pcompose (smult a p) r = smult a (pcompose p r)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2543
  for p r :: "'a::comm_semiring_0 poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2544
  by (induct p) (simp_all add: pcompose_pCons pcompose_add smult_add_right)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2545
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2546
lemma pcompose_mult: "pcompose (p * q) r = pcompose p r * pcompose q r"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2547
  for p q r :: "'a::comm_semiring_0 poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2548
  by (induct p arbitrary: q) (simp_all add: pcompose_add pcompose_smult pcompose_pCons algebra_simps)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2549
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2550
lemma pcompose_assoc: "pcompose p (pcompose q r) = pcompose (pcompose p q) r"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2551
  for p q r :: "'a::comm_semiring_0 poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2552
  by (induct p arbitrary: q) (simp_all add: pcompose_pCons pcompose_add pcompose_mult)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2553
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2554
lemma pcompose_idR[simp]: "pcompose p [: 0, 1 :] = p"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2555
  for p :: "'a::comm_semiring_1 poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2556
  by (induct p) (simp_all add: pcompose_pCons)
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
  2557
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63950
diff changeset
  2558
lemma pcompose_sum: "pcompose (sum f A) p = sum (\<lambda>i. pcompose (f i) p) A"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2559
  by (induct A rule: infinite_finite_induct) (simp_all add: pcompose_1 pcompose_add)
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2560
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  2561
lemma pcompose_prod: "pcompose (prod f A) p = prod (\<lambda>i. pcompose (f i) p) A"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2562
  by (induct A rule: infinite_finite_induct) (simp_all add: pcompose_1 pcompose_mult)
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2563
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  2564
lemma pcompose_const [simp]: "pcompose [:a:] q = [:a:]"
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  2565
  by (subst pcompose_pCons) simp
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2566
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
  2567
lemma pcompose_0': "pcompose p 0 = [:coeff p 0:]"
64591
240a39af9ec4 restructured matter on polynomials and normalized fractions
haftmann
parents: 64272
diff changeset
  2568
  by (induct p) (auto simp add: pcompose_pCons)
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2569
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2570
lemma degree_pcompose: "degree (pcompose p q) = degree p * degree q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2571
  for p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2572
proof (induct p)
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2573
  case 0
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2574
  then show ?case by auto
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2575
next
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2576
  case (pCons a p)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2577
  consider "degree (q * pcompose p q) = 0" | "degree (q * pcompose p q) > 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2578
    by blast
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2579
  then show ?case
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2580
  proof cases
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2581
    case prems: 1
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2582
    show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2583
    proof (cases "p = 0")
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2584
      case True
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2585
      then show ?thesis by auto
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2586
    next
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2587
      case False
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2588
      from prems have "degree q = 0 \<or> pcompose p q = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2589
        by (auto simp add: degree_mult_eq_0)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2590
      moreover have False if "pcompose p q = 0" "degree q \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2591
      proof -
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2592
        from pCons.hyps(2) that have "degree p = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2593
          by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2594
        then obtain a1 where "p = [:a1:]"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2595
          by (metis degree_pCons_eq_if old.nat.distinct(2) pCons_cases)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2596
        with \<open>pcompose p q = 0\<close> \<open>p \<noteq> 0\<close> show False
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2597
          by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2598
      qed
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2599
      ultimately have "degree (pCons a p) * degree q = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2600
        by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2601
      moreover have "degree (pcompose (pCons a p) q) = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2602
      proof -
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2603
        from prems have "0 = max (degree [:a:]) (degree (q * pcompose p q))"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2604
          by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2605
        also have "\<dots> \<ge> degree ([:a:] + q * pcompose p q)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2606
          by (rule degree_add_le_max)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2607
        finally show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2608
          by (auto simp add: pcompose_pCons)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2609
      qed
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2610
      ultimately show ?thesis by simp
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2611
    qed
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2612
  next
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2613
    case prems: 2
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2614
    then have "p \<noteq> 0" "q \<noteq> 0" "pcompose p q \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2615
      by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2616
    from prems degree_add_eq_right [of "[:a:]"]
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2617
    have "degree (pcompose (pCons a p) q) = degree (q * pcompose p q)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2618
      by (auto simp: pcompose_pCons)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2619
    with pCons.hyps(2) degree_mult_eq[OF \<open>q\<noteq>0\<close> \<open>pcompose p q\<noteq>0\<close>] show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2620
      by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2621
  qed
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2622
qed
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2623
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2624
lemma pcompose_eq_0:
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2625
  fixes p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2626
  assumes "pcompose p q = 0" "degree q > 0"
62128
3201ddb00097 Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
eberlm
parents: 62072
diff changeset
  2627
  shows "p = 0"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2628
proof -
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2629
  from assms degree_pcompose [of p q] have "degree p = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2630
    by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2631
  then obtain a where "p = [:a:]"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2632
    by (metis degree_pCons_eq_if gr0_conv_Suc neq0_conv pCons_cases)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2633
  with assms(1) have "a = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2634
    by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2635
  with \<open>p = [:a:]\<close> show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2636
    by simp
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2637
qed
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2638
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2639
lemma pcompose_eq_0_iff:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2640
  fixes p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2641
  assumes "degree q > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2642
  shows "pcompose p q = 0 \<longleftrightarrow> p = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2643
  using pcompose_eq_0[OF _ assms] by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2644
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2645
lemma coeff_pcompose_linear:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2646
  "coeff (pcompose p [:0, a :: 'a :: comm_semiring_1:]) i = a ^ i * coeff p i"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2647
  by (induction p arbitrary: i) (auto simp: pcompose_pCons coeff_pCons mult_ac split: nat.splits)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2648
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2649
lemma lead_coeff_comp:
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2650
  fixes p q :: "'a::{comm_semiring_1,semiring_no_zero_divisors} poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2651
  assumes "degree q > 0"
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2652
  shows "lead_coeff (pcompose p q) = lead_coeff p * lead_coeff q ^ (degree p)"
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2653
proof (induct p)
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2654
  case 0
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2655
  then show ?case by auto
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2656
next
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2657
  case (pCons a p)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2658
  consider "degree (q * pcompose p q) = 0" | "degree (q * pcompose p q) > 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2659
    by blast
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2660
  then show ?case
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2661
  proof cases
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2662
    case prems: 1
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2663
    then have "pcompose p q = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2664
      by (metis assms degree_0 degree_mult_eq_0 neq0_conv)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2665
    with pcompose_eq_0[OF _ \<open>degree q > 0\<close>] have "p = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2666
      by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2667
    then show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2668
      by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2669
  next
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2670
    case prems: 2
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2671
    then have "degree [:a:] < degree (q * pcompose p q)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2672
      by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2673
    then have "lead_coeff ([:a:] + q * p \<circ>\<^sub>p q) = lead_coeff (q * p \<circ>\<^sub>p q)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2674
      by (rule lead_coeff_add_le)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2675
    then have "lead_coeff (pcompose (pCons a p) q) = lead_coeff (q * pcompose p q)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2676
      by (simp add: pcompose_pCons)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2677
    also have "\<dots> = lead_coeff q * (lead_coeff p * lead_coeff q ^ degree p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2678
      using pCons.hyps(2) lead_coeff_mult[of q "pcompose p q"] by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2679
    also have "\<dots> = lead_coeff p * lead_coeff q ^ (degree p + 1)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2680
      by (auto simp: mult_ac)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2681
    finally show ?thesis by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2682
  qed
62065
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2683
qed
1546a042e87b Added some facts about polynomials
eberlm
parents: 61945
diff changeset
  2684
79672
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2685
lemma coeff_pcompose_monom_linear [simp]:
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2686
  fixes p :: "'a :: comm_ring_1 poly"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2687
  shows "coeff (pcompose p (monom c (Suc 0))) k = c ^ k * coeff p k"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2688
  by (induction p arbitrary: k)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2689
     (auto simp: coeff_pCons coeff_monom_mult pcompose_pCons split: nat.splits)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2690
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2691
lemma of_nat_mult_conv_smult: "of_nat n * P = smult (of_nat n) P"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2692
  by (simp add: monom_0 of_nat_monom)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2693
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2694
lemma numeral_mult_conv_smult: "numeral n * P = smult (numeral n) P"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2695
  by (simp add: numeral_poly)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2696
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2697
lemma sum_order_le_degree:
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2698
  assumes "p \<noteq> 0"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2699
  shows   "(\<Sum>x | poly p x = 0. order x p) \<le> degree p"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2700
  using assms
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2701
proof (induction "degree p" arbitrary: p rule: less_induct)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2702
  case (less p)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2703
  show ?case
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2704
  proof (cases "\<exists>x. poly p x = 0")
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2705
    case False
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2706
    thus ?thesis
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2707
      by auto
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2708
  next
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2709
    case True
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2710
    then obtain x where x: "poly p x = 0"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2711
      by auto
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2712
    have "[:-x, 1:] ^ order x p dvd p"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2713
      by (simp add: order_1)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2714
    then obtain q where q: "p = [:-x, 1:] ^ order x p * q"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2715
      by (elim dvdE)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2716
    have [simp]: "q \<noteq> 0"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2717
      using q less.prems by auto
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2718
    have "order x p = order x p + order x q"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2719
      by (subst q, subst order_mult) (auto simp: order_power_n_n)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2720
    hence "order x q = 0"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2721
      by auto
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2722
    hence [simp]: "poly q x \<noteq> 0"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2723
      by (simp add: order_root)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2724
    have deg_p: "degree p = degree q + order x p"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2725
      by (subst q, subst degree_mult_eq) (auto simp: degree_power_eq)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2726
    moreover have "order x p > 0"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2727
      using x less.prems by (simp add: order_root)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2728
    ultimately have "degree q < degree p"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2729
      by linarith
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2730
    hence "(\<Sum>x | poly q x = 0. order x q) \<le> degree q"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2731
      by (intro less.hyps) auto
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2732
    hence "order x p + (\<Sum>x | poly q x = 0. order x q) \<le> degree p"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2733
      by (simp add: deg_p)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2734
    also have "{y. poly q y = 0} = {y. poly p y = 0} - {x}"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2735
      by (subst q) auto
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2736
    also have "(\<Sum>y \<in> {y. poly p y = 0} - {x}. order y q) =
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2737
               (\<Sum>y \<in> {y. poly p y = 0} - {x}. order y p)"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2738
      by (intro sum.cong refl, subst q)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2739
         (auto simp: order_mult order_power_n_n intro!: order_0I)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2740
    also have "order x p + \<dots> = (\<Sum>y \<in> insert x ({y. poly p y = 0} - {x}). order y p)"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2741
      using \<open>p \<noteq> 0\<close> by (subst sum.insert) (auto simp: poly_roots_finite)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2742
    also have "insert x ({y. poly p y = 0} - {x}) = {y. poly p y = 0}"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2743
      using \<open>poly p x = 0\<close> by auto
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2744
    finally show ?thesis .
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2745
  qed
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  2746
qed
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  2747
73109
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2748
subsection \<open>Closure properties of coefficients\<close>
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2749
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2750
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2751
context
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2752
  fixes R :: "'a :: comm_semiring_1 set"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2753
  assumes R_0: "0 \<in> R"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2754
  assumes R_plus: "\<And>x y. x \<in> R \<Longrightarrow> y \<in> R \<Longrightarrow> x + y \<in> R"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2755
  assumes R_mult: "\<And>x y. x \<in> R \<Longrightarrow> y \<in> R \<Longrightarrow> x * y \<in> R"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2756
begin
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2757
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2758
lemma coeff_mult_semiring_closed:
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2759
  assumes "\<And>i. coeff p i \<in> R" "\<And>i. coeff q i \<in> R"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2760
  shows   "coeff (p * q) i \<in> R"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2761
proof -
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2762
  have R_sum: "sum f A \<in> R" if "\<And>x. x \<in> A \<Longrightarrow> f x \<in> R" for A and f :: "nat \<Rightarrow> 'a"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2763
    using that by (induction A rule: infinite_finite_induct) (auto intro: R_0 R_plus)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2764
  show ?thesis
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2765
    unfolding coeff_mult by (auto intro!: R_sum R_mult assms)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2766
qed
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2767
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2768
lemma coeff_pcompose_semiring_closed:
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2769
  assumes "\<And>i. coeff p i \<in> R" "\<And>i. coeff q i \<in> R"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2770
  shows   "coeff (pcompose p q) i \<in> R"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2771
  using assms(1)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2772
proof (induction p arbitrary: i)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2773
  case (pCons a p i)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2774
  have [simp]: "a \<in> R"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2775
    using pCons.prems[of 0] by auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2776
  have "coeff p i \<in> R" for i
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2777
    using pCons.prems[of "Suc i"] by auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2778
  hence "coeff (p \<circ>\<^sub>p q) i \<in> R" for i
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2779
    using pCons.prems by (intro pCons.IH)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2780
  thus ?case
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2781
    by (auto simp: pcompose_pCons coeff_pCons split: nat.splits
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2782
             intro!: assms R_plus coeff_mult_semiring_closed)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2783
qed auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2784
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2785
end
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2786
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  2787
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2788
subsection \<open>Shifting polynomials\<close>
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2789
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2790
definition poly_shift :: "nat \<Rightarrow> 'a::zero poly \<Rightarrow> 'a poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2791
  where "poly_shift n p = Abs_poly (\<lambda>i. coeff p (i + n))"
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2792
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2793
lemma nth_default_drop: "nth_default x (drop n xs) m = nth_default x xs (m + n)"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2794
  by (auto simp add: nth_default_def add_ac)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2795
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2796
lemma nth_default_take: "nth_default x (take n xs) m = (if m < n then nth_default x xs m else x)"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2797
  by (auto simp add: nth_default_def add_ac)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2798
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2799
lemma coeff_poly_shift: "coeff (poly_shift n p) i = coeff p (i + n)"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2800
proof -
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2801
  from MOST_coeff_eq_0[of p] obtain m where "\<forall>k>m. coeff p k = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2802
    by (auto simp: MOST_nat)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2803
  then have "\<forall>k>m. coeff p (k + n) = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2804
    by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2805
  then have "\<forall>\<^sub>\<infinity>k. coeff p (k + n) = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2806
    by (auto simp: MOST_nat)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2807
  then show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2808
    by (simp add: poly_shift_def poly.Abs_poly_inverse)
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2809
qed
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2810
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2811
lemma poly_shift_id [simp]: "poly_shift 0 = (\<lambda>x. x)"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2812
  by (simp add: poly_eq_iff fun_eq_iff coeff_poly_shift)
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2813
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2814
lemma poly_shift_0 [simp]: "poly_shift n 0 = 0"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2815
  by (simp add: poly_eq_iff coeff_poly_shift)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2816
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2817
lemma poly_shift_1: "poly_shift n 1 = (if n = 0 then 1 else 0)"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2818
  by (simp add: poly_eq_iff coeff_poly_shift)
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2819
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2820
lemma poly_shift_monom: "poly_shift n (monom c m) = (if m \<ge> n then monom c (m - n) else 0)"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2821
  by (auto simp add: poly_eq_iff coeff_poly_shift)
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2822
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  2823
lemma coeffs_shift_poly [code abstract]:
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  2824
  "coeffs (poly_shift n p) = drop n (coeffs p)"
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2825
proof (cases "p = 0")
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2826
  case True
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2827
  then show ?thesis by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2828
next
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2829
  case False
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2830
  then show ?thesis
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2831
    by (intro coeffs_eqI)
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  2832
      (simp_all add: coeff_poly_shift nth_default_drop nth_default_coeffs_eq)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2833
qed
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2834
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2835
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2836
subsection \<open>Truncating polynomials\<close>
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2837
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2838
definition poly_cutoff
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2839
  where "poly_cutoff n p = Abs_poly (\<lambda>k. if k < n then coeff p k else 0)"
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2840
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2841
lemma coeff_poly_cutoff: "coeff (poly_cutoff n p) k = (if k < n then coeff p k else 0)"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2842
  unfolding poly_cutoff_def
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2843
  by (subst poly.Abs_poly_inverse) (auto simp: MOST_nat intro: exI[of _ n])
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2844
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2845
lemma poly_cutoff_0 [simp]: "poly_cutoff n 0 = 0"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2846
  by (simp add: poly_eq_iff coeff_poly_cutoff)
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2847
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2848
lemma poly_cutoff_1 [simp]: "poly_cutoff n 1 = (if n = 0 then 0 else 1)"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2849
  by (simp add: poly_eq_iff coeff_poly_cutoff)
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2850
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2851
lemma coeffs_poly_cutoff [code abstract]:
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67369
diff changeset
  2852
  "coeffs (poly_cutoff n p) = strip_while ((=) 0) (take n (coeffs p))"
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67369
diff changeset
  2853
proof (cases "strip_while ((=) 0) (take n (coeffs p)) = []")
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2854
  case True
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2855
  then have "coeff (poly_cutoff n p) k = 0" for k
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2856
    unfolding coeff_poly_cutoff
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2857
    by (auto simp: nth_default_coeffs_eq [symmetric] nth_default_def set_conv_nth)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2858
  then have "poly_cutoff n p = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2859
    by (simp add: poly_eq_iff)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2860
  then show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2861
    by (subst True) simp_all
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2862
next
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2863
  case False
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67369
diff changeset
  2864
  have "no_trailing ((=) 0) (strip_while ((=) 0) (take n (coeffs p)))"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2865
    by simp
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67369
diff changeset
  2866
  with False have "last (strip_while ((=) 0) (take n (coeffs p))) \<noteq> 0"
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2867
    unfolding no_trailing_unfold by auto
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2868
  then show ?thesis
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2869
    by (intro coeffs_eqI)
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  2870
      (simp_all add: coeff_poly_cutoff nth_default_take nth_default_coeffs_eq)
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2871
qed
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2872
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2873
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2874
subsection \<open>Reflecting polynomials\<close>
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2875
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2876
definition reflect_poly :: "'a::zero poly \<Rightarrow> 'a poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2877
  where "reflect_poly p = Poly (rev (coeffs p))"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2878
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2879
lemma coeffs_reflect_poly [code abstract]:
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67369
diff changeset
  2880
  "coeffs (reflect_poly p) = rev (dropWhile ((=) 0) (coeffs p))"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2881
  by (simp add: reflect_poly_def)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2882
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2883
lemma reflect_poly_0 [simp]: "reflect_poly 0 = 0"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2884
  by (simp add: reflect_poly_def)
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2885
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2886
lemma reflect_poly_1 [simp]: "reflect_poly 1 = 1"
65486
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  2887
  by (simp add: reflect_poly_def one_pCons)
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2888
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2889
lemma coeff_reflect_poly:
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2890
  "coeff (reflect_poly p) n = (if n > degree p then 0 else coeff p (degree p - n))"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2891
  by (cases "p = 0")
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2892
    (auto simp add: reflect_poly_def nth_default_def
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2893
      rev_nth degree_eq_length_coeffs coeffs_nth not_less
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2894
      dest: le_imp_less_Suc)
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2895
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2896
lemma coeff_0_reflect_poly_0_iff [simp]: "coeff (reflect_poly p) 0 = 0 \<longleftrightarrow> p = 0"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2897
  by (simp add: coeff_reflect_poly)
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2898
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2899
lemma reflect_poly_at_0_eq_0_iff [simp]: "poly (reflect_poly p) 0 = 0 \<longleftrightarrow> p = 0"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2900
  by (simp add: coeff_reflect_poly poly_0_coeff_0)
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2901
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2902
lemma reflect_poly_pCons':
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2903
  "p \<noteq> 0 \<Longrightarrow> reflect_poly (pCons c p) = reflect_poly p + monom c (Suc (degree p))"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2904
  by (intro poly_eqI)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2905
    (auto simp: coeff_reflect_poly coeff_pCons not_less Suc_diff_le split: nat.split)
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2906
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2907
lemma reflect_poly_const [simp]: "reflect_poly [:a:] = [:a:]"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2908
  by (cases "a = 0") (simp_all add: reflect_poly_def)
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2909
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2910
lemma poly_reflect_poly_nz:
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2911
  "x \<noteq> 0 \<Longrightarrow> poly (reflect_poly p) x = x ^ degree p * poly p (inverse x)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2912
  for x :: "'a::field"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2913
  by (induct rule: pCons_induct) (simp_all add: field_simps reflect_poly_pCons' poly_monom)
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2914
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2915
lemma coeff_0_reflect_poly [simp]: "coeff (reflect_poly p) 0 = lead_coeff p"
64794
6f7391f28197 lead_coeff is more appropriate as abbreviation
haftmann
parents: 64793
diff changeset
  2916
  by (simp add: coeff_reflect_poly)
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2917
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2918
lemma poly_reflect_poly_0 [simp]: "poly (reflect_poly p) 0 = lead_coeff p"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2919
  by (simp add: poly_0_coeff_0)
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2920
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2921
lemma reflect_poly_reflect_poly [simp]: "coeff p 0 \<noteq> 0 \<Longrightarrow> reflect_poly (reflect_poly p) = p"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2922
  by (cases p rule: pCons_cases) (simp add: reflect_poly_def )
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2923
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2924
lemma degree_reflect_poly_le: "degree (reflect_poly p) \<le> degree p"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2925
  by (simp add: degree_eq_length_coeffs coeffs_reflect_poly length_dropWhile_le diff_le_mono)
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2926
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2927
lemma reflect_poly_pCons: "a \<noteq> 0 \<Longrightarrow> reflect_poly (pCons a p) = Poly (rev (a # coeffs p))"
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2928
  by (subst coeffs_eq_iff) (simp add: coeffs_reflect_poly)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2929
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2930
lemma degree_reflect_poly_eq [simp]: "coeff p 0 \<noteq> 0 \<Longrightarrow> degree (reflect_poly p) = degree p"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2931
  by (cases p rule: pCons_cases) (simp add: reflect_poly_pCons degree_eq_length_coeffs)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2932
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2933
lemma reflect_poly_eq_0_iff [simp]: "reflect_poly p = 0 \<longleftrightarrow> p = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2934
  using coeff_0_reflect_poly_0_iff by fastforce
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  2935
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  2936
(* TODO: does this work with zero divisors as well? Probably not. *)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2937
lemma reflect_poly_mult: "reflect_poly (p * q) = reflect_poly p * reflect_poly q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2938
  for p q :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2939
proof (cases "p = 0 \<or> q = 0")
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2940
  case False
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2941
  then have [simp]: "p \<noteq> 0" "q \<noteq> 0" by auto
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2942
  show ?thesis
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2943
  proof (rule poly_eqI)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2944
    show "coeff (reflect_poly (p * q)) i = coeff (reflect_poly p * reflect_poly q) i" for i
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2945
    proof (cases "i \<le> degree (p * q)")
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2946
      case True
64811
5477d6b1222f obsolete
haftmann
parents: 64795
diff changeset
  2947
      define A where "A = {..i} \<inter> {i - degree q..degree p}"
5477d6b1222f obsolete
haftmann
parents: 64795
diff changeset
  2948
      define B where "B = {..degree p} \<inter> {degree p - i..degree (p*q) - i}"
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2949
      let ?f = "\<lambda>j. degree p - j"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2950
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2951
      from True have "coeff (reflect_poly (p * q)) i = coeff (p * q) (degree (p * q) - i)"
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2952
        by (simp add: coeff_reflect_poly)
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2953
      also have "\<dots> = (\<Sum>j\<le>degree (p * q) - i. coeff p j * coeff q (degree (p * q) - i - j))"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2954
        by (simp add: coeff_mult)
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2955
      also have "\<dots> = (\<Sum>j\<in>B. coeff p j * coeff q (degree (p * q) - i - j))"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63950
diff changeset
  2956
        by (intro sum.mono_neutral_right) (auto simp: B_def degree_mult_eq not_le coeff_eq_0)
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2957
      also from True have "\<dots> = (\<Sum>j\<in>A. coeff p (degree p - j) * coeff q (degree q - (i - j)))"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63950
diff changeset
  2958
        by (intro sum.reindex_bij_witness[of _ ?f ?f])
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2959
          (auto simp: A_def B_def degree_mult_eq add_ac)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2960
      also have "\<dots> =
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2961
        (\<Sum>j\<le>i.
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2962
          if j \<in> {i - degree q..degree p}
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2963
          then coeff p (degree p - j) * coeff q (degree q - (i - j))
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2964
          else 0)"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63950
diff changeset
  2965
        by (subst sum.inter_restrict [symmetric]) (simp_all add: A_def)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2966
      also have "\<dots> = coeff (reflect_poly p * reflect_poly q) i"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2967
        by (fastforce simp: coeff_mult coeff_reflect_poly intro!: sum.cong)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2968
      finally show ?thesis .
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63950
diff changeset
  2969
    qed (auto simp: coeff_mult coeff_reflect_poly coeff_eq_0 degree_mult_eq intro!: sum.neutral)
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2970
  qed
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2971
qed auto
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2972
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2973
lemma reflect_poly_smult: "reflect_poly (smult c p) = smult c (reflect_poly p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2974
  for p :: "'a::{comm_semiring_0,semiring_no_zero_divisors} poly"
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2975
  using reflect_poly_mult[of "[:c:]" p] by simp
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2976
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2977
lemma reflect_poly_power: "reflect_poly (p ^ n) = reflect_poly p ^ n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2978
  for p :: "'a::{comm_semiring_1,semiring_no_zero_divisors} poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2979
  by (induct n) (simp_all add: reflect_poly_mult)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2980
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2981
lemma reflect_poly_prod: "reflect_poly (prod f A) = prod (\<lambda>x. reflect_poly (f x)) A"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2982
  for f :: "_ \<Rightarrow> _::{comm_semiring_0,semiring_no_zero_divisors} poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2983
  by (induct A rule: infinite_finite_induct) (simp_all add: reflect_poly_mult)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2984
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2985
lemma reflect_poly_prod_list: "reflect_poly (prod_list xs) = prod_list (map reflect_poly xs)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2986
  for xs :: "_::{comm_semiring_0,semiring_no_zero_divisors} poly list"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2987
  by (induct xs) (simp_all add: reflect_poly_mult)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2988
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  2989
lemma reflect_poly_Poly_nz:
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  2990
  "no_trailing (HOL.eq 0) xs \<Longrightarrow> reflect_poly (Poly xs) = Poly (rev xs)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2991
  by (simp add: reflect_poly_def)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2992
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  2993
lemmas reflect_poly_simps =
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2994
  reflect_poly_0 reflect_poly_1 reflect_poly_const reflect_poly_smult reflect_poly_mult
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  2995
  reflect_poly_power reflect_poly_prod reflect_poly_prod_list
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2996
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  2997
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  2998
subsection \<open>Derivatives\<close>
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  2999
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  3000
function pderiv :: "('a :: {comm_semiring_1,semiring_no_zero_divisors}) poly \<Rightarrow> 'a poly"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3001
  where "pderiv (pCons a p) = (if p = 0 then 0 else p + pCons 0 (pderiv p))"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3002
  by (auto intro: pCons_cases)
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3003
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3004
termination pderiv
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3005
  by (relation "measure degree") simp_all
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3006
63027
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
  3007
declare pderiv.simps[simp del]
8de0ebee3f1c several updates on polynomial long division and pseudo division
Rene Thiemann <rene.thiemann@uibk.ac.at>
parents: 62422
diff changeset
  3008
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3009
lemma pderiv_0 [simp]: "pderiv 0 = 0"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3010
  using pderiv.simps [of 0 0] by simp
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3011
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3012
lemma pderiv_pCons: "pderiv (pCons a p) = p + pCons 0 (pderiv p)"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3013
  by (simp add: pderiv.simps)
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3014
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3015
lemma pderiv_1 [simp]: "pderiv 1 = 0"
65486
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  3016
  by (simp add: one_pCons pderiv_pCons)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3017
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3018
lemma pderiv_of_nat [simp]: "pderiv (of_nat n) = 0"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3019
  and pderiv_numeral [simp]: "pderiv (numeral m) = 0"
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3020
  by (simp_all add: of_nat_poly numeral_poly pderiv_pCons)
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3021
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3022
lemma coeff_pderiv: "coeff (pderiv p) n = of_nat (Suc n) * coeff p (Suc n)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3023
  by (induct p arbitrary: n)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3024
    (auto simp add: pderiv_pCons coeff_pCons algebra_simps split: nat.split)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3025
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3026
fun pderiv_coeffs_code :: "'a::{comm_semiring_1,semiring_no_zero_divisors} \<Rightarrow> 'a list \<Rightarrow> 'a list"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3027
  where
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3028
    "pderiv_coeffs_code f (x # xs) = cCons (f * x) (pderiv_coeffs_code (f+1) xs)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3029
  | "pderiv_coeffs_code f [] = []"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3030
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3031
definition pderiv_coeffs :: "'a::{comm_semiring_1,semiring_no_zero_divisors} list \<Rightarrow> 'a list"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3032
  where "pderiv_coeffs xs = pderiv_coeffs_code 1 (tl xs)"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3033
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3034
(* Efficient code for pderiv contributed by René Thiemann and Akihisa Yamada *)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3035
lemma pderiv_coeffs_code:
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3036
  "nth_default 0 (pderiv_coeffs_code f xs) n = (f + of_nat n) * nth_default 0 xs n"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3037
proof (induct xs arbitrary: f n)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3038
  case Nil
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3039
  then show ?case by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3040
next
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3041
  case (Cons x xs)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3042
  show ?case
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3043
  proof (cases n)
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3044
    case 0
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3045
    then show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3046
      by (cases "pderiv_coeffs_code (f + 1) xs = [] \<and> f * x = 0") (auto simp: cCons_def)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3047
  next
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3048
    case n: (Suc m)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3049
    show ?thesis
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3050
    proof (cases "pderiv_coeffs_code (f + 1) xs = [] \<and> f * x = 0")
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3051
      case False
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3052
      then have "nth_default 0 (pderiv_coeffs_code f (x # xs)) n =
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3053
          nth_default 0 (pderiv_coeffs_code (f + 1) xs) m"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3054
        by (auto simp: cCons_def n)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3055
      also have "\<dots> = (f + of_nat n) * nth_default 0 xs m"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3056
        by (simp add: Cons n add_ac)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3057
      finally show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3058
        by (simp add: n)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3059
    next
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3060
      case True
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3061
      have empty: "pderiv_coeffs_code g xs = [] \<Longrightarrow> g + of_nat m = 0 \<or> nth_default 0 xs m = 0" for g
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3062
      proof (induct xs arbitrary: g m)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3063
        case Nil
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3064
        then show ?case by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3065
      next
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3066
        case (Cons x xs)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3067
        from Cons(2) have empty: "pderiv_coeffs_code (g + 1) xs = []" and g: "g = 0 \<or> x = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3068
          by (auto simp: cCons_def split: if_splits)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3069
        note IH = Cons(1)[OF empty]
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3070
        from IH[of m] IH[of "m - 1"] g show ?case
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3071
          by (cases m) (auto simp: field_simps)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3072
      qed
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3073
      from True have "nth_default 0 (pderiv_coeffs_code f (x # xs)) n = 0"
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3074
        by (auto simp: cCons_def n)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3075
      moreover from True have "(f + of_nat n) * nth_default 0 (x # xs) n = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3076
        by (simp add: n) (use empty[of "f+1"] in \<open>auto simp: field_simps\<close>)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3077
      ultimately show ?thesis by simp
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3078
    qed
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3079
  qed
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3080
qed
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3081
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3082
lemma coeffs_pderiv_code [code abstract]: "coeffs (pderiv p) = pderiv_coeffs (coeffs p)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3083
  unfolding pderiv_coeffs_def
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3084
proof (rule coeffs_eqI, unfold pderiv_coeffs_code coeff_pderiv, goal_cases)
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3085
  case (1 n)
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3086
  have id: "coeff p (Suc n) = nth_default 0 (map (\<lambda>i. coeff p (Suc i)) [0..<degree p]) n"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3087
    by (cases "n < degree p") (auto simp: nth_default_def coeff_eq_0)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3088
  show ?case
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3089
    unfolding coeffs_def map_upt_Suc by (auto simp: id)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3090
next
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3091
  case 2
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3092
  obtain n :: 'a and xs where defs: "tl (coeffs p) = xs" "1 = n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3093
    by simp
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3094
  from 2 show ?case
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3095
    unfolding defs by (induct xs arbitrary: n) (auto simp: cCons_def)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3096
qed
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3097
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3098
lemma pderiv_eq_0_iff: "pderiv p = 0 \<longleftrightarrow> degree p = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3099
  for p :: "'a::{comm_semiring_1,semiring_no_zero_divisors,semiring_char_0} poly"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3100
proof (cases "degree p")
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3101
  case 0
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  3102
  then show ?thesis
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3103
    by (metis degree_eq_zeroE pderiv.simps)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3104
next
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3105
  case (Suc n)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3106
  then show ?thesis
73109
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3107
    using coeff_0 coeff_pderiv degree_0 leading_coeff_0_iff mult_eq_0_iff nat.distinct(1) of_nat_eq_0_iff
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3108
    by (metis coeff_0 coeff_pderiv degree_0 leading_coeff_0_iff mult_eq_0_iff nat.distinct(1) of_nat_eq_0_iff)
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3109
qed
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3110
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3111
lemma degree_pderiv: "degree (pderiv p) = degree p - 1"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3112
  for p :: "'a::{comm_semiring_1,semiring_no_zero_divisors,semiring_char_0} poly"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3113
proof -
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3114
  have "degree p - 1 \<le> degree (pderiv p)"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3115
  proof (cases "degree p")
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3116
    case (Suc n)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3117
    then show ?thesis
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  3118
      by (metis coeff_pderiv degree_0 diff_Suc_1 le_degree leading_coeff_0_iff mult_eq_0_iff nat.distinct(1) of_nat_eq_0_iff)
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3119
  qed auto
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3120
  moreover have "\<forall>i>degree p - 1. coeff (pderiv p) i = 0"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3121
    by (simp add: coeff_eq_0 coeff_pderiv)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3122
  ultimately show ?thesis
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3123
    using order_antisym [OF degree_le] by blast
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3124
qed
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3125
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3126
lemma not_dvd_pderiv:
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3127
  fixes p :: "'a::{comm_semiring_1,semiring_no_zero_divisors,semiring_char_0} poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3128
  assumes "degree p \<noteq> 0"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3129
  shows "\<not> p dvd pderiv p"
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3130
proof
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3131
  assume dvd: "p dvd pderiv p"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3132
  then obtain q where p: "pderiv p = p * q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3133
    unfolding dvd_def by auto
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3134
  from dvd have le: "degree p \<le> degree (pderiv p)"
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3135
    by (simp add: assms dvd_imp_degree_le pderiv_eq_0_iff)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3136
  from assms and this [unfolded degree_pderiv]
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3137
    show False by auto
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3138
qed
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3139
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3140
lemma dvd_pderiv_iff [simp]: "p dvd pderiv p \<longleftrightarrow> degree p = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3141
  for p :: "'a::{comm_semiring_1,semiring_no_zero_divisors,semiring_char_0} poly"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3142
  using not_dvd_pderiv[of p] by (auto simp: pderiv_eq_0_iff [symmetric])
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3143
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3144
lemma pderiv_singleton [simp]: "pderiv [:a:] = 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3145
  by (simp add: pderiv_pCons)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3146
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3147
lemma pderiv_add: "pderiv (p + q) = pderiv p + pderiv q"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3148
  by (rule poly_eqI) (simp add: coeff_pderiv algebra_simps)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3149
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3150
lemma pderiv_minus: "pderiv (- p :: 'a :: idom poly) = - pderiv p"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3151
  by (rule poly_eqI) (simp add: coeff_pderiv algebra_simps)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3152
63498
a3fe3250d05d Reformed factorial rings
eberlm <eberlm@in.tum.de>
parents: 63433
diff changeset
  3153
lemma pderiv_diff: "pderiv ((p :: _ :: idom poly) - q) = pderiv p - pderiv q"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3154
  by (rule poly_eqI) (simp add: coeff_pderiv algebra_simps)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3155
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3156
lemma pderiv_smult: "pderiv (smult a p) = smult a (pderiv p)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3157
  by (rule poly_eqI) (simp add: coeff_pderiv algebra_simps)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3158
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3159
lemma pderiv_mult: "pderiv (p * q) = p * pderiv q + q * pderiv p"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3160
  by (induct p) (auto simp: pderiv_add pderiv_smult pderiv_pCons algebra_simps)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3161
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3162
lemma pderiv_power_Suc: "pderiv (p ^ Suc n) = smult (of_nat (Suc n)) (p ^ n) * pderiv p"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3163
proof (induction n)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3164
  case (Suc n)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3165
  then show ?case
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3166
    by (simp add: pderiv_mult smult_add_left algebra_simps)
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  3167
qed auto
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3168
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3169
lemma pderiv_power:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3170
  "pderiv (p ^ n) = smult (of_nat n) (p ^ (n - 1) * pderiv p)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3171
  by (cases n) (simp_all add: pderiv_power_Suc del: power_Suc)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3172
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3173
lemma pderiv_monom:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3174
  "pderiv (monom c n) = monom (of_nat n * c) (n - 1)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3175
  by (cases n)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3176
     (simp_all add: monom_altdef pderiv_power_Suc pderiv_smult pderiv_pCons mult_ac del: power_Suc)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3177
66550
e5d82cf3c387 Some small lemmas about polynomials and FPSs
eberlm <eberlm@in.tum.de>
parents: 66453
diff changeset
  3178
lemma pderiv_pcompose: "pderiv (pcompose p q) = pcompose (pderiv p) q * pderiv q"
e5d82cf3c387 Some small lemmas about polynomials and FPSs
eberlm <eberlm@in.tum.de>
parents: 66453
diff changeset
  3179
  by (induction p rule: pCons_induct)
e5d82cf3c387 Some small lemmas about polynomials and FPSs
eberlm <eberlm@in.tum.de>
parents: 66453
diff changeset
  3180
     (auto simp: pcompose_pCons pderiv_add pderiv_mult pderiv_pCons pcompose_add algebra_simps)
e5d82cf3c387 Some small lemmas about polynomials and FPSs
eberlm <eberlm@in.tum.de>
parents: 66453
diff changeset
  3181
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3182
lemma pderiv_prod: "pderiv (prod f (as)) = (\<Sum>a\<in>as. prod f (as - {a}) * pderiv (f a))"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3183
proof (induct as rule: infinite_finite_induct)
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3184
  case (insert a as)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3185
  then have id: "prod f (insert a as) = f a * prod f as"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3186
    "\<And>g. sum g (insert a as) = g a + sum g as"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3187
    "insert a as - {a} = as"
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3188
    by auto
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3189
  have "prod f (insert a as - {b}) = f a * prod f (as - {b})" if "b \<in> as" for b
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3190
  proof -
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3191
    from \<open>a \<notin> as\<close> that have *: "insert a as - {b} = insert a (as - {b})"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3192
      by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3193
    show ?thesis
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3194
      unfolding * by (subst prod.insert) (use insert in auto)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3195
  qed
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3196
  then show ?case
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63950
diff changeset
  3197
    unfolding id pderiv_mult insert(3) sum_distrib_left
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3198
    by (auto simp add: ac_simps intro!: sum.cong)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3199
qed auto
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3200
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3201
lemma coeff_higher_pderiv:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3202
  "coeff ((pderiv ^^ m) f) n = pochhammer (of_nat (Suc n)) m * coeff f (n + m)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3203
  by (induction m arbitrary: n) (simp_all add: coeff_pderiv pochhammer_rec algebra_simps)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3204
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3205
lemma higher_pderiv_0 [simp]: "(pderiv ^^ n) 0 = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3206
  by (induction n) simp_all
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3207
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3208
lemma higher_pderiv_add: "(pderiv ^^ n) (p + q) = (pderiv ^^ n) p + (pderiv ^^ n) q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3209
  by (induction n arbitrary: p q) (simp_all del: funpow.simps add: funpow_Suc_right pderiv_add)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3210
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3211
lemma higher_pderiv_smult: "(pderiv ^^ n) (smult c p) = smult c ((pderiv ^^ n) p)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3212
  by (induction n arbitrary: p) (simp_all del: funpow.simps add: funpow_Suc_right pderiv_smult)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3213
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3214
lemma higher_pderiv_monom:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3215
  "m \<le> n + 1 \<Longrightarrow> (pderiv ^^ m) (monom c n) = monom (pochhammer (int n - int m + 1) m * c) (n - m)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3216
proof (induction m arbitrary: c n)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3217
  case (Suc m)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3218
  thus ?case
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3219
    by (cases n)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3220
       (simp_all del: funpow.simps add: funpow_Suc_right pderiv_monom pochhammer_rec' Suc.IH)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3221
qed simp_all
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3222
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3223
lemma higher_pderiv_monom_eq_zero:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3224
  "m > n + 1 \<Longrightarrow> (pderiv ^^ m) (monom c n) = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3225
proof (induction m arbitrary: c n)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3226
  case (Suc m)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3227
  thus ?case
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3228
    by (cases n)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3229
       (simp_all del: funpow.simps add: funpow_Suc_right pderiv_monom pochhammer_rec' Suc.IH)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3230
qed simp_all
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3231
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3232
lemma higher_pderiv_sum: "(pderiv ^^ n) (sum f A) = (\<Sum>x\<in>A. (pderiv ^^ n) (f x))"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3233
  by (induction A rule: infinite_finite_induct) (simp_all add: higher_pderiv_add)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3234
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3235
lemma higher_pderiv_sum_mset: "(pderiv ^^ n) (sum_mset A) = (\<Sum>p\<in>#A. (pderiv ^^ n) p)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3236
  by (induction A) (simp_all add: higher_pderiv_add)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3237
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3238
lemma higher_pderiv_sum_list: "(pderiv ^^ n) (sum_list ps) = (\<Sum>p\<leftarrow>ps. (pderiv ^^ n) p)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3239
  by (induction ps) (simp_all add: higher_pderiv_add)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3240
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3241
lemma degree_higher_pderiv: "Polynomial.degree ((pderiv ^^ n) p) = Polynomial.degree p - n"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3242
  for p :: "'a::{comm_semiring_1,semiring_no_zero_divisors,semiring_char_0} poly"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3243
  by (induction n) (auto simp: degree_pderiv)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3244
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3245
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3246
lemma DERIV_pow2: "DERIV (\<lambda>x. x ^ Suc n) x :> real (Suc n) * (x ^ n)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3247
  by (rule DERIV_cong, rule DERIV_pow) simp
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3248
declare DERIV_pow2 [simp] DERIV_pow [simp]
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3249
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3250
lemma DERIV_add_const: "DERIV f x :> D \<Longrightarrow> DERIV (\<lambda>x. a + f x :: 'a::real_normed_field) x :> D"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3251
  by (rule DERIV_cong, rule DERIV_add) auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3252
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3253
lemma poly_DERIV [simp]: "DERIV (\<lambda>x. poly p x) x :> poly (pderiv p) x"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3254
  by (induct p) (auto intro!: derivative_eq_intros simp add: pderiv_pCons)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3255
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  3256
lemma poly_isCont[simp]:
68532
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  3257
  fixes x::"'a::real_normed_field"
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  3258
  shows "isCont (\<lambda>x. poly p x) x"
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  3259
by (rule poly_DERIV [THEN DERIV_isCont])
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  3260
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  3261
lemma tendsto_poly [tendsto_intros]: "(f \<longlongrightarrow> a) F \<Longrightarrow> ((\<lambda>x. poly p (f x)) \<longlongrightarrow> poly p a) F"
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  3262
  for f :: "_ \<Rightarrow> 'a::real_normed_field"
68532
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  3263
  by (rule isCont_tendsto_compose [OF poly_isCont])
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  3264
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  3265
lemma continuous_within_poly: "continuous (at z within s) (poly p)"
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  3266
  for z :: "'a::{real_normed_field}"
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  3267
  by (simp add: continuous_within tendsto_poly)
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  3268
68532
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  3269
lemma continuous_poly [continuous_intros]: "continuous F f \<Longrightarrow> continuous F (\<lambda>x. poly p (f x))"
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  3270
  for f :: "_ \<Rightarrow> 'a::real_normed_field"
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  3271
  unfolding continuous_def by (rule tendsto_poly)
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  3272
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3273
lemma continuous_on_poly [continuous_intros]:
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3274
  fixes p :: "'a :: {real_normed_field} poly"
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3275
  assumes "continuous_on A f"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3276
  shows "continuous_on A (\<lambda>x. poly p (f x))"
68532
f8b98d31ad45 Incorporating new/strengthened proofs from Library and AFP entries
paulson <lp15@cam.ac.uk>
parents: 67399
diff changeset
  3277
  by (metis DERIV_continuous_on assms continuous_on_compose2 poly_DERIV subset_UNIV)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3278
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3279
text \<open>Consequences of the derivative theorem above.\<close>
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3280
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3281
lemma poly_differentiable[simp]: "(\<lambda>x. poly p x) differentiable (at x)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3282
  for x :: real
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3283
  by (simp add: real_differentiable_def) (blast intro: poly_DERIV)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3284
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3285
lemma poly_IVT_pos: "a < b \<Longrightarrow> poly p a < 0 \<Longrightarrow> 0 < poly p b \<Longrightarrow> \<exists>x. a < x \<and> x < b \<and> poly p x = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3286
  for a b :: real
72219
0f38c96a0a74 tidying up some theorem statements
paulson <lp15@cam.ac.uk>
parents: 72024
diff changeset
  3287
  using IVT [of "poly p" a 0 b] by (auto simp add: order_le_less)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3288
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3289
lemma poly_IVT_neg: "a < b \<Longrightarrow> 0 < poly p a \<Longrightarrow> poly p b < 0 \<Longrightarrow> \<exists>x. a < x \<and> x < b \<and> poly p x = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3290
  for a b :: real
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3291
  using poly_IVT_pos [where p = "- p"] by simp
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3292
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3293
lemma poly_IVT: "a < b \<Longrightarrow> poly p a * poly p b < 0 \<Longrightarrow> \<exists>x>a. x < b \<and> poly p x = 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3294
  for p :: "real poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3295
  by (metis less_not_sym mult_less_0_iff poly_IVT_neg poly_IVT_pos)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3296
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3297
lemma poly_MVT: "a < b \<Longrightarrow> \<exists>x. a < x \<and> x < b \<and> poly p b - poly p a = (b - a) * poly (pderiv p) x"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3298
  for a b :: real
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3299
  by (simp add: MVT2)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3300
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3301
lemma poly_MVT':
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3302
  fixes a b :: real
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3303
  assumes "{min a b..max a b} \<subseteq> A"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3304
  shows "\<exists>x\<in>A. poly p b - poly p a = (b - a) * poly (pderiv p) x"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3305
proof (cases a b rule: linorder_cases)
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3306
  case less
74362
0135a0c77b64 tuned proofs --- avoid 'guess';
wenzelm
parents: 73932
diff changeset
  3307
  from poly_MVT[OF less, of p] obtain x
0135a0c77b64 tuned proofs --- avoid 'guess';
wenzelm
parents: 73932
diff changeset
  3308
    where "a < x" "x < b" "poly p b - poly p a = (b - a) * poly (pderiv p) x"
0135a0c77b64 tuned proofs --- avoid 'guess';
wenzelm
parents: 73932
diff changeset
  3309
    by auto
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3310
  then show ?thesis by (intro bexI[of _ x]) (auto intro!: subsetD[OF assms])
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3311
next
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3312
  case greater
74362
0135a0c77b64 tuned proofs --- avoid 'guess';
wenzelm
parents: 73932
diff changeset
  3313
  from poly_MVT[OF greater, of p] obtain x
0135a0c77b64 tuned proofs --- avoid 'guess';
wenzelm
parents: 73932
diff changeset
  3314
    where "b < x" "x < a" "poly p a - poly p b = (a - b) * poly (pderiv p) x" by auto
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3315
  then show ?thesis by (intro bexI[of _ x]) (auto simp: algebra_simps intro!: subsetD[OF assms])
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3316
qed (use assms in auto)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3317
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3318
lemma poly_pinfty_gt_lc:
63649
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3319
  fixes p :: "real poly"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3320
  assumes "lead_coeff p > 0"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3321
  shows "\<exists>n. \<forall> x \<ge> n. poly p x \<ge> lead_coeff p"
63649
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3322
  using assms
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3323
proof (induct p)
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3324
  case 0
63649
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3325
  then show ?case by auto
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3326
next
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3327
  case (pCons a p)
63649
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3328
  from this(1) consider "a \<noteq> 0" "p = 0" | "p \<noteq> 0" by auto
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3329
  then show ?case
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3330
  proof cases
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3331
    case 1
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3332
    then show ?thesis by auto
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3333
  next
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3334
    case 2
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3335
    with pCons obtain n1 where gte_lcoeff: "\<forall>x\<ge>n1. lead_coeff p \<le> poly p x"
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3336
      by auto
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3337
    from pCons(3) \<open>p \<noteq> 0\<close> have gt_0: "lead_coeff p > 0" by auto
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3338
    define n where "n = max n1 (1 + \<bar>a\<bar> / lead_coeff p)"
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3339
    have "lead_coeff (pCons a p) \<le> poly (pCons a p) x" if "n \<le> x" for x
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3340
    proof -
63649
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3341
      from gte_lcoeff that have "lead_coeff p \<le> poly p x"
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3342
        by (auto simp: n_def)
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3343
      with gt_0 have "\<bar>a\<bar> / lead_coeff p \<ge> \<bar>a\<bar> / poly p x" and "poly p x > 0"
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3344
        by (auto intro: frac_le)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3345
      with \<open>n \<le> x\<close>[unfolded n_def] have "x \<ge> 1 + \<bar>a\<bar> / poly p x"
63649
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3346
        by auto
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3347
      with \<open>lead_coeff p \<le> poly p x\<close> \<open>poly p x > 0\<close> \<open>p \<noteq> 0\<close>
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3348
      show "lead_coeff (pCons a p) \<le> poly (pCons a p) x"
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3349
        by (auto simp: field_simps)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3350
    qed
63649
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3351
    then show ?thesis by blast
e690d6f2185b tuned proofs;
wenzelm
parents: 63498
diff changeset
  3352
  qed
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3353
qed
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3354
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3355
lemma lemma_order_pderiv1:
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3356
  "pderiv ([:- a, 1:] ^ Suc n * q) = [:- a, 1:] ^ Suc n * pderiv q +
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3357
    smult (of_nat (Suc n)) (q * [:- a, 1:] ^ n)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3358
  by (simp only: pderiv_mult pderiv_power_Suc) (simp del: power_Suc of_nat_Suc add: pderiv_pCons)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3359
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3360
lemma lemma_order_pderiv:
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3361
  fixes p :: "'a :: field_char_0 poly"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3362
  assumes n: "0 < n"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3363
    and pd: "pderiv p \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3364
    and pe: "p = [:- a, 1:] ^ n * q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3365
    and nd: "\<not> [:- a, 1:] dvd q"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3366
  shows "n = Suc (order a (pderiv p))"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3367
proof -
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3368
  from assms have "pderiv ([:- a, 1:] ^ n * q) \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3369
    by auto
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3370
  from assms obtain n' where "n = Suc n'" "0 < Suc n'" "pderiv ([:- a, 1:] ^ Suc n' * q) \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3371
    by (cases n) auto
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3372
  have "order a (pderiv ([:- a, 1:] ^ Suc n' * q)) = n'"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3373
  proof (rule order_unique_lemma)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3374
    show "[:- a, 1:] ^ n' dvd pderiv ([:- a, 1:] ^ Suc n' * q)"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3375
      unfolding lemma_order_pderiv1
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3376
    proof (rule dvd_add)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3377
      show "[:- a, 1:] ^ n' dvd [:- a, 1:] ^ Suc n' * pderiv q"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3378
        by (metis dvdI dvd_mult2 power_Suc2)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3379
      show "[:- a, 1:] ^ n' dvd smult (of_nat (Suc n')) (q * [:- a, 1:] ^ n')"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3380
        by (metis dvd_smult dvd_triv_right)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3381
    qed
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3382
    have "k dvd k * pderiv q + smult (of_nat (Suc n')) l \<Longrightarrow> k dvd l" for k l
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3383
      by (auto simp del: of_nat_Suc simp: dvd_add_right_iff dvd_smult_iff)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3384
    then show "\<not> [:- a, 1:] ^ Suc n' dvd pderiv ([:- a, 1:] ^ Suc n' * q)"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3385
      unfolding lemma_order_pderiv1
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3386
      by (metis nd dvd_mult_cancel_right power_not_zero pCons_eq_0_iff power_Suc zero_neq_one)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3387
  qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3388
  then show ?thesis
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3389
    by (metis \<open>n = Suc n'\<close> pe)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3390
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3391
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3392
lemma order_pderiv: "order a p = Suc (order a (pderiv p))"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3393
  if "pderiv p \<noteq> 0" "order a p \<noteq> 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3394
  for p :: "'a::field_char_0 poly"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3395
proof (cases "p = 0")
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3396
  case False
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3397
  obtain q where "p = [:- a, 1:] ^ order a p * q \<and> \<not> [:- a, 1:] dvd q"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3398
    using False order_decomp by blast
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3399
  then show ?thesis
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3400
    using lemma_order_pderiv that by blast
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3401
qed (use that in auto)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3402
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3403
lemma poly_squarefree_decomp_order:
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3404
  fixes p :: "'a::field_char_0 poly"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3405
  assumes "pderiv p \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3406
    and p: "p = q * d"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3407
    and p': "pderiv p = e * d"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3408
    and d: "d = r * p + s * pderiv p"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3409
  shows "order a q = (if order a p = 0 then 0 else 1)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3410
proof (rule classical)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3411
  assume 1: "\<not> ?thesis"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3412
  from \<open>pderiv p \<noteq> 0\<close> have "p \<noteq> 0" by auto
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3413
  with p have "order a p = order a q + order a d"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3414
    by (simp add: order_mult)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3415
  with 1 have "order a p \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3416
    by (auto split: if_splits)
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3417
  from \<open>pderiv p \<noteq> 0\<close> \<open>pderiv p = e * d\<close> have oapp: "order a (pderiv p) = order a e + order a d"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3418
    by (simp add: order_mult)
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3419
  from \<open>pderiv p \<noteq> 0\<close> \<open>order a p \<noteq> 0\<close> have oap: "order a p = Suc (order a (pderiv p))"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3420
    by (rule order_pderiv)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3421
  from \<open>p \<noteq> 0\<close> \<open>p = q * d\<close> have "d \<noteq> 0"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3422
    by simp
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3423
  have "[:- a, 1:] ^ order a (pderiv p) dvd r * p"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3424
    by (metis dvd_trans dvd_triv_right oap order_1 power_Suc)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3425
  then have "([:-a, 1:] ^ (order a (pderiv p))) dvd d"
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3426
    by (simp add: d order_1)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3427
  with \<open>d \<noteq> 0\<close> have "order a (pderiv p) \<le> order a d"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3428
    by (simp add: order_divides)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3429
  show ?thesis
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3430
    using \<open>order a p = order a q + order a d\<close>
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3431
      and oapp oap
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3432
      and \<open>order a (pderiv p) \<le> order a d\<close>
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3433
    by auto
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3434
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3435
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3436
lemma poly_squarefree_decomp_order2:
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3437
  "pderiv p \<noteq> 0 \<Longrightarrow> p = q * d \<Longrightarrow> pderiv p = e * d \<Longrightarrow>
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3438
    d = r * p + s * pderiv p \<Longrightarrow> \<forall>a. order a q = (if order a p = 0 then 0 else 1)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3439
  for p :: "'a::field_char_0 poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3440
  by (blast intro: poly_squarefree_decomp_order)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3441
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3442
lemma order_pderiv2:
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3443
  "pderiv p \<noteq> 0 \<Longrightarrow> order a p \<noteq> 0 \<Longrightarrow> order a (pderiv p) = n \<longleftrightarrow> order a p = Suc n"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3444
  for p :: "'a::field_char_0 poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3445
  by (auto dest: order_pderiv)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3446
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3447
definition rsquarefree :: "'a::idom poly \<Rightarrow> bool"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3448
  where "rsquarefree p \<longleftrightarrow> p \<noteq> 0 \<and> (\<forall>a. order a p = 0 \<or> order a p = 1)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3449
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3450
lemma pderiv_iszero: "pderiv p = 0 \<Longrightarrow> \<exists>h. p = [:h:]"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3451
  for p :: "'a::{semidom,semiring_char_0} poly"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3452
  by (cases p) (auto simp: pderiv_eq_0_iff split: if_splits)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3453
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3454
lemma rsquarefree_roots: "rsquarefree p \<longleftrightarrow> (\<forall>a. \<not> (poly p a = 0 \<and> poly (pderiv p) a = 0))"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3455
  for p :: "'a::field_char_0 poly"
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3456
proof (cases "p = 0")
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3457
  case False
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3458
  show ?thesis
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3459
  proof (cases "pderiv p = 0")
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3460
    case True
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3461
    with \<open>p \<noteq> 0\<close> pderiv_iszero show ?thesis
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3462
      by (force simp add: order_0I rsquarefree_def)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3463
  next
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3464
    case False
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3465
    with \<open>p \<noteq> 0\<close> order_pderiv2 show ?thesis
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3466
      by (force simp add: rsquarefree_def order_root)
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3467
  qed
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  3468
qed (simp add: rsquarefree_def)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3469
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3470
lemma rsquarefree_root_order:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3471
  assumes "rsquarefree p" "poly p z = 0" "p \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3472
  shows   "order z p = 1"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3473
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3474
  from assms have "order z p \<in> {0, 1}" by (auto simp: rsquarefree_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3475
  moreover from assms have "order z p > 0" by (auto simp: order_root)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3476
  ultimately show "order z p = 1" by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3477
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3478
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3479
lemma poly_squarefree_decomp:
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3480
  fixes p :: "'a::field_char_0 poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3481
  assumes "pderiv p \<noteq> 0"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3482
    and "p = q * d"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3483
    and "pderiv p = e * d"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3484
    and "d = r * p + s * pderiv p"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3485
  shows "rsquarefree q \<and> (\<forall>a. poly q a = 0 \<longleftrightarrow> poly p a = 0)"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3486
proof -
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3487
  from \<open>pderiv p \<noteq> 0\<close> have "p \<noteq> 0" by auto
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3488
  with \<open>p = q * d\<close> have "q \<noteq> 0" by simp
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3489
  from assms have "\<forall>a. order a q = (if order a p = 0 then 0 else 1)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3490
    by (rule poly_squarefree_decomp_order2)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3491
  with \<open>p \<noteq> 0\<close> \<open>q \<noteq> 0\<close> show ?thesis
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3492
    by (simp add: rsquarefree_def order_root)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3493
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  3494
79672
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  3495
lemma has_field_derivative_poly [derivative_intros]:
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  3496
  assumes "(f has_field_derivative f') (at x within A)"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  3497
  shows   "((\<lambda>x. poly p (f x)) has_field_derivative
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  3498
             (f' * poly (pderiv p) (f x))) (at x within A)"
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  3499
  using DERIV_chain[OF poly_DERIV assms, of p] by (simp add: o_def mult_ac)
76720aeab21e New material about transcendental functions, polynomials, et cetera, thanks to Manuel Eberl
paulson <lp15@cam.ac.uk>
parents: 76386
diff changeset
  3500
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3501
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3502
subsection \<open>Algebraic numbers\<close>
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3503
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3504
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3505
lemma intpolyE:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3506
  assumes "\<And>i. poly.coeff p i \<in> \<int>"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3507
  obtains q where "p = map_poly of_int q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3508
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3509
  have "\<forall>i\<in>{..Polynomial.degree p}. \<exists>x. poly.coeff p i = of_int x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3510
    using assms by (auto simp: Ints_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3511
  from bchoice[OF this] obtain f
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3512
    where f: "\<And>i. i \<le> Polynomial.degree p \<Longrightarrow> poly.coeff p i = of_int (f i)" by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3513
  define q where "q = Poly (map f [0..<Suc (Polynomial.degree p)])"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3514
  have "p = map_poly of_int q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3515
    by (intro poly_eqI) 
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3516
       (auto simp: coeff_map_poly q_def nth_default_def f coeff_eq_0 simp del: upt_Suc)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3517
  with that show ?thesis by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3518
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3519
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3520
lemma ratpolyE:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3521
  assumes "\<And>i. poly.coeff p i \<in> \<rat>"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3522
  obtains q where "p = map_poly of_rat q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3523
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3524
  have "\<forall>i\<in>{..Polynomial.degree p}. \<exists>x. poly.coeff p i = of_rat x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3525
    using assms by (auto simp: Rats_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3526
  from bchoice[OF this] obtain f
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3527
    where f: "\<And>i. i \<le> Polynomial.degree p \<Longrightarrow> poly.coeff p i = of_rat (f i)" by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3528
  define q where "q = Poly (map f [0..<Suc (Polynomial.degree p)])"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3529
  have "p = map_poly of_rat q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3530
    by (intro poly_eqI) 
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3531
       (auto simp: coeff_map_poly q_def nth_default_def f coeff_eq_0 simp del: upt_Suc)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3532
  with that show ?thesis by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3533
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3534
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3535
text \<open>
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3536
  Algebraic numbers can be defined in two equivalent ways: all real numbers that are
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3537
  roots of rational polynomials or of integer polynomials. The Algebraic-Numbers AFP entry
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3538
  uses the rational definition, but we need the integer definition.
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3539
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3540
  The equivalence is obvious since any rational polynomial can be multiplied with the
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3541
  LCM of its coefficients, yielding an integer polynomial with the same roots.
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3542
\<close>
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3543
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3544
definition algebraic :: "'a :: field_char_0 \<Rightarrow> bool"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3545
  where "algebraic x \<longleftrightarrow> (\<exists>p. (\<forall>i. coeff p i \<in> \<int>) \<and> p \<noteq> 0 \<and> poly p x = 0)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3546
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3547
lemma algebraicI: "(\<And>i. coeff p i \<in> \<int>) \<Longrightarrow> p \<noteq> 0 \<Longrightarrow> poly p x = 0 \<Longrightarrow> algebraic x"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3548
  unfolding algebraic_def by blast
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3549
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3550
lemma algebraicE:
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3551
  assumes "algebraic x"
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3552
  obtains p where "\<And>i. coeff p i \<in> \<int>" "p \<noteq> 0" "poly p x = 0"
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3553
  using assms unfolding algebraic_def by blast
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3554
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3555
lemma algebraic_altdef: "algebraic x \<longleftrightarrow> (\<exists>p. (\<forall>i. coeff p i \<in> \<rat>) \<and> p \<noteq> 0 \<and> poly p x = 0)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3556
  for p :: "'a::field_char_0 poly"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3557
proof safe
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3558
  fix p
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3559
  assume rat: "\<forall>i. coeff p i \<in> \<rat>" and root: "poly p x = 0" and nz: "p \<noteq> 0"
63040
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 63035
diff changeset
  3560
  define cs where "cs = coeffs p"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3561
  from rat have "\<forall>c\<in>range (coeff p). \<exists>c'. c = of_rat c'"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3562
    unfolding Rats_def by blast
63060
293ede07b775 some uses of 'obtain' with structure statement;
wenzelm
parents: 63040
diff changeset
  3563
  then obtain f where f: "coeff p i = of_rat (f (coeff p i))" for i
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3564
    by (subst (asm) bchoice_iff) blast
63040
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 63035
diff changeset
  3565
  define cs' where "cs' = map (quotient_of \<circ> f) (coeffs p)"
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 63035
diff changeset
  3566
  define d where "d = Lcm (set (map snd cs'))"
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 63035
diff changeset
  3567
  define p' where "p' = smult (of_int d) p"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3568
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3569
  have "coeff p' n \<in> \<int>" for n
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3570
  proof (cases "n \<le> degree p")
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3571
    case True
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3572
    define c where "c = coeff p n"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3573
    define a where "a = fst (quotient_of (f (coeff p n)))"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3574
    define b where "b = snd (quotient_of (f (coeff p n)))"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3575
    have b_pos: "b > 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3576
      unfolding b_def using quotient_of_denom_pos' by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3577
    have "coeff p' n = of_int d * coeff p n"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3578
      by (simp add: p'_def)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3579
    also have "coeff p n = of_rat (of_int a / of_int b)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3580
      unfolding a_def b_def
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3581
      by (subst quotient_of_div [of "f (coeff p n)", symmetric]) (simp_all add: f [symmetric])
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3582
    also have "of_int d * \<dots> = of_rat (of_int (a*d) / of_int b)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3583
      by (simp add: of_rat_mult of_rat_divide)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3584
    also from nz True have "b \<in> snd ` set cs'"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3585
      by (force simp: cs'_def o_def b_def coeffs_def simp del: upt_Suc)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3586
    then have "b dvd (a * d)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3587
      by (simp add: d_def)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3588
    then have "of_int (a * d) / of_int b \<in> (\<int> :: rat set)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3589
      by (rule of_int_divide_in_Ints)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3590
    then have "of_rat (of_int (a * d) / of_int b) \<in> \<int>" by (elim Ints_cases) auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3591
    finally show ?thesis .
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3592
  next
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3593
    case False
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3594
    then show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3595
      by (auto simp: p'_def not_le coeff_eq_0)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3596
  qed
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3597
  moreover have "set (map snd cs') \<subseteq> {0<..}"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  3598
    unfolding cs'_def using quotient_of_denom_pos' by (auto simp: coeffs_def simp del: upt_Suc)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3599
  then have "d \<noteq> 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3600
    unfolding d_def by (induct cs') simp_all
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3601
  with nz have "p' \<noteq> 0" by (simp add: p'_def)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3602
  moreover from root have "poly p' x = 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3603
    by (simp add: p'_def)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3604
  ultimately show "algebraic x"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3605
    unfolding algebraic_def by blast
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3606
next
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3607
  assume "algebraic x"
63060
293ede07b775 some uses of 'obtain' with structure statement;
wenzelm
parents: 63040
diff changeset
  3608
  then obtain p where p: "coeff p i \<in> \<int>" "poly p x = 0" "p \<noteq> 0" for i
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3609
    by (force simp: algebraic_def)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3610
  moreover have "coeff p i \<in> \<int> \<Longrightarrow> coeff p i \<in> \<rat>" for i
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3611
    by (elim Ints_cases) simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  3612
  ultimately show "\<exists>p. (\<forall>i. coeff p i \<in> \<rat>) \<and> p \<noteq> 0 \<and> poly p x = 0" by auto
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3613
qed
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3614
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3615
lemma algebraicI': "(\<And>i. coeff p i \<in> \<rat>) \<Longrightarrow> p \<noteq> 0 \<Longrightarrow> poly p x = 0 \<Longrightarrow> algebraic x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3616
  unfolding algebraic_altdef by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3617
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3618
lemma algebraicE':
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3619
  assumes "algebraic (x :: 'a :: field_char_0)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3620
  obtains p where "p \<noteq> 0" "poly (map_poly of_int p) x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3621
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3622
  from assms obtain q where q: "\<And>i. coeff q i \<in> \<int>" "q \<noteq> 0" "poly q x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3623
    by (erule algebraicE)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3624
  moreover from this(1) obtain q' where q': "q = map_poly of_int q'" by (erule intpolyE)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3625
  moreover have "q' \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3626
    using q' q by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3627
  ultimately show ?thesis by (intro that[of q']) simp_all
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3628
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3629
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3630
lemma algebraicE'_nonzero:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3631
  assumes "algebraic (x :: 'a :: field_char_0)" "x \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3632
  obtains p where "p \<noteq> 0" "coeff p 0 \<noteq> 0" "poly (map_poly of_int p) x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3633
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3634
  from assms(1) obtain p where p: "p \<noteq> 0" "poly (map_poly of_int p) x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3635
    by (erule algebraicE')
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3636
  define n :: nat where "n = order 0 p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3637
  have "monom 1 n dvd p" by (simp add: monom_1_dvd_iff p n_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3638
  then obtain q where q: "p = monom 1 n * q" by (erule dvdE)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3639
  have [simp]: "map_poly of_int (monom 1 n * q) = monom (1 :: 'a) n * map_poly of_int q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3640
    by (induction n) (auto simp: monom_0 monom_Suc map_poly_pCons)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3641
  from p have "q \<noteq> 0" "poly (map_poly of_int q) x = 0" by (auto simp: q poly_monom assms(2))
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3642
  moreover from this have "order 0 p = n + order 0 q" by (simp add: q order_mult)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3643
  hence "order 0 q = 0" by (simp add: n_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3644
  with \<open>q \<noteq> 0\<close> have "poly q 0 \<noteq> 0" by (simp add: order_root)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3645
  ultimately show ?thesis using that[of q] by (auto simp: poly_0_coeff_0)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3646
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3647
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3648
lemma rat_imp_algebraic: "x \<in> \<rat> \<Longrightarrow> algebraic x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3649
proof (rule algebraicI')
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3650
  show "poly [:-x, 1:] x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3651
    by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3652
qed (auto simp: coeff_pCons split: nat.splits)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3653
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3654
lemma algebraic_0 [simp, intro]: "algebraic 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3655
  and algebraic_1 [simp, intro]: "algebraic 1"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3656
  and algebraic_numeral [simp, intro]: "algebraic (numeral n)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3657
  and algebraic_of_nat [simp, intro]: "algebraic (of_nat k)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3658
  and algebraic_of_int [simp, intro]: "algebraic (of_int m)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3659
  by (simp_all add: rat_imp_algebraic)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3660
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3661
lemma algebraic_ii [simp, intro]: "algebraic \<i>"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3662
proof (rule algebraicI)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3663
  show "poly [:1, 0, 1:] \<i> = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3664
    by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3665
qed (auto simp: coeff_pCons split: nat.splits)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3666
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3667
lemma algebraic_minus [intro]:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3668
  assumes "algebraic x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3669
  shows   "algebraic (-x)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3670
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3671
  from assms obtain p where p: "\<forall>i. coeff p i \<in> \<int>" "poly p x = 0" "p \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3672
    by (elim algebraicE) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3673
  define s where "s = (if even (degree p) then 1 else -1 :: 'a)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3674
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3675
  define q where "q = Polynomial.smult s (pcompose p [:0, -1:])"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3676
  have "poly q (-x) = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3677
    using p by (auto simp: q_def poly_pcompose s_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3678
  moreover have "q \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3679
    using p by (auto simp: q_def s_def pcompose_eq_0_iff)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3680
  find_theorems "pcompose _ _ = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3681
  moreover have "coeff q i \<in> \<int>" for i
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3682
  proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3683
    have "coeff (pcompose p [:0, -1:]) i \<in> \<int>"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3684
      using p by (intro coeff_pcompose_semiring_closed) (auto simp: coeff_pCons split: nat.splits)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3685
    thus ?thesis by (simp add: q_def s_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3686
  qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3687
  ultimately show ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3688
    by (auto simp: algebraic_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3689
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3690
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3691
lemma algebraic_minus_iff [simp]:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3692
  "algebraic (-x) \<longleftrightarrow> algebraic (x :: 'a :: field_char_0)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3693
  using algebraic_minus[of x] algebraic_minus[of "-x"] by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3694
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3695
lemma algebraic_inverse [intro]:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3696
  assumes "algebraic x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3697
  shows   "algebraic (inverse x)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3698
proof (cases "x = 0")
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3699
  case [simp]: False
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3700
  from assms obtain p where p: "\<forall>i. coeff p i \<in> \<int>" "poly p x = 0" "p \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3701
    by (elim algebraicE) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3702
  show ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3703
  proof (rule algebraicI)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3704
    show "poly (reflect_poly p) (inverse x) = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3705
      using assms p by (simp add: poly_reflect_poly_nz)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3706
  qed (use assms p in \<open>auto simp: coeff_reflect_poly\<close>)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3707
qed auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3708
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3709
lemma algebraic_root:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3710
  assumes "algebraic y"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3711
      and "poly p x = y" and "\<forall>i. coeff p i \<in> \<int>" and "lead_coeff p = 1" and "degree p > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3712
  shows   "algebraic x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3713
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3714
  from assms obtain q where q: "poly q y = 0" "\<forall>i. coeff q i \<in> \<int>" "q \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3715
    by (elim algebraicE) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3716
  show ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3717
  proof (rule algebraicI)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3718
    from assms q show "pcompose q p \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3719
      by (auto simp: pcompose_eq_0_iff)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3720
    from assms q show "coeff (pcompose q p) i \<in> \<int>" for i
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3721
      by (intro allI coeff_pcompose_semiring_closed) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3722
    show "poly (pcompose q p) x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3723
      using assms q by (simp add: poly_pcompose)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3724
  qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3725
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3726
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3727
lemma algebraic_abs_real [simp]:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3728
  "algebraic \<bar>x :: real\<bar> \<longleftrightarrow> algebraic x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3729
  by (auto simp: abs_if)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3730
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3731
lemma algebraic_nth_root_real [intro]:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3732
  assumes "algebraic x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3733
  shows   "algebraic (root n x)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3734
proof (cases "n = 0")
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3735
  case False
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3736
  show ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3737
  proof (rule algebraic_root)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3738
    show "poly (monom 1 n) (root n x) = (if even n then \<bar>x\<bar> else x)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3739
      using sgn_power_root[of n x] False
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3740
      by (auto simp add: poly_monom sgn_if split: if_splits)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3741
  qed (use False assms in \<open>auto simp: degree_monom_eq\<close>)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3742
qed auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3743
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3744
lemma algebraic_sqrt [intro]: "algebraic x \<Longrightarrow> algebraic (sqrt x)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3745
  by (auto simp: sqrt_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3746
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3747
lemma algebraic_csqrt [intro]: "algebraic x \<Longrightarrow> algebraic (csqrt x)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3748
  by (rule algebraic_root[where p = "monom 1 2"])
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3749
     (auto simp: poly_monom degree_monom_eq)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3750
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3751
lemma algebraic_cnj [intro]:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3752
  assumes "algebraic x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3753
  shows   "algebraic (cnj x)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3754
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3755
  from assms obtain p where p: "poly p x = 0" "\<forall>i. coeff p i \<in> \<int>" "p \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3756
    by (elim algebraicE) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3757
  show ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3758
  proof (rule algebraicI)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3759
    show "poly (map_poly cnj p) (cnj x) = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3760
      using p by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3761
    show "map_poly cnj p \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3762
      using p by (auto simp: map_poly_eq_0_iff)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3763
    show "coeff (map_poly cnj p) i \<in> \<int>" for i
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3764
      using p by (auto simp: coeff_map_poly)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3765
  qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3766
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3767
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3768
lemma algebraic_cnj_iff [simp]: "algebraic (cnj x) \<longleftrightarrow> algebraic x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3769
  using algebraic_cnj[of x] algebraic_cnj[of "cnj x"] by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3770
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3771
lemma algebraic_of_real [intro]:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3772
  assumes "algebraic x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3773
  shows   "algebraic (of_real x)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3774
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3775
  from assms obtain p where p: "p \<noteq> 0" "poly (map_poly of_int p) x = 0" by (erule algebraicE')
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3776
  have 1: "map_poly of_int p \<noteq> (0 :: 'a poly)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3777
    using p by (metis coeff_0 coeff_map_poly leading_coeff_0_iff of_int_eq_0_iff)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3778
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3779
  have "poly (map_poly of_int p) (of_real x :: 'a) = of_real (poly (map_poly of_int p) x)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3780
    by (simp add: poly_altdef degree_map_poly coeff_map_poly)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3781
  also note p(2)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3782
  finally have 2: "poly (map_poly of_int p) (of_real x :: 'a) = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3783
    by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3784
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3785
  from 1 2 show "algebraic (of_real x :: 'a)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3786
    by (intro algebraicI[of "map_poly of_int p"]) (auto simp: coeff_map_poly)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3787
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3788
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3789
lemma algebraic_of_real_iff [simp]:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3790
   "algebraic (of_real x :: 'a :: {real_algebra_1,field_char_0}) \<longleftrightarrow> algebraic x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3791
proof
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3792
  assume "algebraic (of_real x :: 'a)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3793
  then obtain p where p: "p \<noteq> 0" "poly (map_poly of_int p) (of_real x :: 'a) = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3794
    by (erule algebraicE')
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3795
  have 1: "(map_poly of_int p :: real poly) \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3796
    using p by (metis coeff_0 coeff_map_poly leading_coeff_0_iff of_int_0 of_int_eq_iff)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3797
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3798
  note p(2)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3799
  also have "poly (map_poly of_int p) (of_real x :: 'a) = of_real (poly (map_poly of_int p) x)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3800
    by (simp add: poly_altdef degree_map_poly coeff_map_poly)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3801
  also have "\<dots> = 0 \<longleftrightarrow> poly (map_poly of_int p) x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3802
    using of_real_eq_0_iff by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3803
  finally have 2: "poly (map_poly real_of_int p) x = 0" .
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3804
    
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3805
  from 1 and 2 show "algebraic x"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3806
    by (intro algebraicI[of "map_poly of_int p"]) (auto simp: coeff_map_poly)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3807
qed auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  3808
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  3809
73109
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3810
subsection \<open>Algebraic integers\<close>
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3811
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3812
inductive algebraic_int :: "'a :: field \<Rightarrow> bool" where
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3813
  "\<lbrakk>lead_coeff p = 1; \<forall>i. coeff p i \<in> \<int>; poly p x = 0\<rbrakk> \<Longrightarrow> algebraic_int x"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3814
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3815
lemma algebraic_int_altdef_ipoly:
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3816
  fixes x :: "'a :: field_char_0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3817
  shows "algebraic_int x \<longleftrightarrow> (\<exists>p. poly (map_poly of_int p) x = 0 \<and> lead_coeff p = 1)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3818
proof
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3819
  assume "algebraic_int x"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3820
  then obtain p where p: "lead_coeff p = 1" "\<forall>i. coeff p i \<in> \<int>" "poly p x = 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3821
    by (auto elim: algebraic_int.cases)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3822
  define the_int where "the_int = (\<lambda>x::'a. THE r. x = of_int r)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3823
  define p' where "p' = map_poly the_int p"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3824
  have of_int_the_int: "of_int (the_int x) = x" if "x \<in> \<int>" for x
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3825
    unfolding the_int_def by (rule sym, rule theI') (insert that, auto simp: Ints_def)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3826
  have the_int_0_iff: "the_int x = 0 \<longleftrightarrow> x = 0" if "x \<in> \<int>" for x
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3827
    using of_int_the_int[OF that] by auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3828
  have [simp]: "the_int 0 = 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3829
    by (subst the_int_0_iff) auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3830
  have "map_poly of_int p' = map_poly (of_int \<circ> the_int) p"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3831
    by (simp add: p'_def map_poly_map_poly)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3832
  also from p of_int_the_int have "\<dots> = p"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3833
    by (subst poly_eq_iff) (auto simp: coeff_map_poly)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3834
  finally have p_p': "map_poly of_int p' = p" .
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3835
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3836
  show "(\<exists>p. poly (map_poly of_int p) x = 0 \<and> lead_coeff p = 1)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3837
  proof (intro exI conjI notI)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3838
    from p show "poly (map_poly of_int p') x = 0" by (simp add: p_p')
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3839
  next
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3840
    show "lead_coeff p' = 1"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3841
      using p by (simp flip: p_p' add: degree_map_poly coeff_map_poly)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3842
  qed
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3843
next
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3844
  assume "\<exists>p. poly (map_poly of_int p) x = 0 \<and> lead_coeff p = 1"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3845
  then obtain p where p: "poly (map_poly of_int p) x = 0" "lead_coeff p = 1"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3846
    by auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3847
  define p' where "p' = (map_poly of_int p :: 'a poly)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3848
  from p have "lead_coeff p' = 1" "poly p' x = 0" "\<forall>i. coeff p' i \<in> \<int>"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3849
    by (auto simp: p'_def coeff_map_poly degree_map_poly)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3850
  thus "algebraic_int x"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3851
    by (intro algebraic_int.intros)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3852
qed
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3853
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3854
theorem rational_algebraic_int_is_int:
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3855
  assumes "algebraic_int x" and "x \<in> \<rat>"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3856
  shows   "x \<in> \<int>"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3857
proof -
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3858
  from assms(2) obtain a b where ab: "b > 0" "Rings.coprime a b" and x_eq: "x = of_int a / of_int b"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3859
    by (auto elim: Rats_cases')
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3860
  from \<open>b > 0\<close> have [simp]: "b \<noteq> 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3861
    by auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3862
  from assms(1) obtain p
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3863
    where p: "lead_coeff p = 1" "\<forall>i. coeff p i \<in> \<int>" "poly p x = 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3864
    by (auto simp: algebraic_int.simps)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3865
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3866
  define q :: "'a poly" where "q = [:-of_int a, of_int b:]"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3867
  have "poly q x = 0" "q \<noteq> 0" "\<forall>i. coeff q i \<in> \<int>"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3868
    by (auto simp: x_eq q_def coeff_pCons split: nat.splits)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3869
  define n where "n = degree p"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3870
  have "n > 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3871
    using p by (intro Nat.gr0I) (auto simp: n_def elim!: degree_eq_zeroE)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3872
  have "(\<Sum>i<n. coeff p i * of_int (a ^ i * b ^ (n - i - 1))) \<in> \<int>"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3873
    using p by auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3874
  then obtain R where R: "of_int R = (\<Sum>i<n. coeff p i * of_int (a ^ i * b ^ (n - i - 1)))"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3875
    by (auto simp: Ints_def)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3876
  have [simp]: "coeff p n = 1"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3877
    using p by (auto simp: n_def)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3878
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3879
  have "0 = poly p x * of_int b ^ n"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3880
    using p by simp
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3881
  also have "\<dots> = (\<Sum>i\<le>n. coeff p i * x ^ i * of_int b ^ n)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3882
    by (simp add: poly_altdef n_def sum_distrib_right)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3883
  also have "\<dots> = (\<Sum>i\<le>n. coeff p i * of_int (a ^ i * b ^ (n - i)))"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3884
    by (intro sum.cong) (auto simp: x_eq field_simps simp flip: power_add)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3885
  also have "{..n} = insert n {..<n}"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3886
    using \<open>n > 0\<close> by auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3887
  also have "(\<Sum>i\<in>\<dots>. coeff p i * of_int (a ^ i * b ^ (n - i))) =
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3888
               coeff p n * of_int (a ^ n) + (\<Sum>i<n. coeff p i * of_int (a ^ i * b ^ (n - i)))"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3889
    by (subst sum.insert) auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3890
  also have "(\<Sum>i<n. coeff p i * of_int (a ^ i * b ^ (n - i))) =
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3891
             (\<Sum>i<n. coeff p i * of_int (a ^ i * b * b ^ (n - i - 1)))"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3892
    by (intro sum.cong) (auto simp flip: power_add power_Suc simp: Suc_diff_Suc)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3893
  also have "\<dots> = of_int (b * R)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3894
    by (simp add: R sum_distrib_left sum_distrib_right mult_ac)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3895
  finally have "of_int (a ^ n) = (-of_int (b * R) :: 'a)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3896
    by (auto simp: add_eq_0_iff)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3897
  hence "a ^ n = -b * R"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3898
    by (simp flip: of_int_mult of_int_power of_int_minus)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3899
  hence "b dvd a ^ n"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3900
    by simp
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3901
  with \<open>Rings.coprime a b\<close> have "b dvd 1"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3902
    by (meson coprime_power_left_iff dvd_refl not_coprimeI)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3903
  with x_eq and \<open>b > 0\<close> show ?thesis
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3904
    by auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3905
qed
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3906
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3907
lemma algebraic_int_imp_algebraic [dest]: "algebraic_int x \<Longrightarrow> algebraic x"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3908
  by (auto simp: algebraic_int.simps algebraic_def)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3909
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3910
lemma int_imp_algebraic_int:
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3911
  assumes "x \<in> \<int>"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3912
  shows   "algebraic_int x"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3913
proof
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3914
  show "\<forall>i. coeff [:-x, 1:] i \<in> \<int>"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3915
    using assms by (auto simp: coeff_pCons split: nat.splits)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3916
qed auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3917
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3918
lemma algebraic_int_0 [simp, intro]: "algebraic_int 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3919
  and algebraic_int_1 [simp, intro]: "algebraic_int 1"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3920
  and algebraic_int_numeral [simp, intro]: "algebraic_int (numeral n)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3921
  and algebraic_int_of_nat [simp, intro]: "algebraic_int (of_nat k)"
73114
9bf36baa8686 Corrected lemma that was too specific in HOL-Computational_Algebra
Manuel Eberl <eberlm@in.tum.de>
parents: 73109
diff changeset
  3922
  and algebraic_int_of_int [simp, intro]: "algebraic_int (of_int m)"
73109
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3923
  by (simp_all add: int_imp_algebraic_int)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3924
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3925
lemma algebraic_int_ii [simp, intro]: "algebraic_int \<i>"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3926
proof
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3927
  show "poly [:1, 0, 1:] \<i> = 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3928
    by simp
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3929
qed (auto simp: coeff_pCons split: nat.splits)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3930
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3931
lemma algebraic_int_minus [intro]:
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3932
  assumes "algebraic_int x"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3933
  shows   "algebraic_int (-x)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3934
proof -
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3935
  from assms obtain p where p: "lead_coeff p = 1" "\<forall>i. coeff p i \<in> \<int>" "poly p x = 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3936
    by (auto simp: algebraic_int.simps)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3937
  define s where "s = (if even (degree p) then 1 else -1 :: 'a)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3938
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3939
  define q where "q = Polynomial.smult s (pcompose p [:0, -1:])"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3940
  have "lead_coeff q = s * lead_coeff (pcompose p [:0, -1:])"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3941
    by (simp add: q_def)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3942
  also have "lead_coeff (pcompose p [:0, -1:]) = lead_coeff p * (- 1) ^ degree p"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3943
    by (subst lead_coeff_comp) auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3944
  finally have "poly q (-x) = 0" and "lead_coeff q = 1"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3945
    using p by (auto simp: q_def poly_pcompose s_def)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3946
  moreover have "coeff q i \<in> \<int>" for i
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3947
  proof -
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3948
    have "coeff (pcompose p [:0, -1:]) i \<in> \<int>"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3949
      using p by (intro coeff_pcompose_semiring_closed) (auto simp: coeff_pCons split: nat.splits)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3950
    thus ?thesis by (simp add: q_def s_def)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3951
  qed
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3952
  ultimately show ?thesis
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3953
    by (auto simp: algebraic_int.simps)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3954
qed
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3955
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3956
lemma algebraic_int_minus_iff [simp]:
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3957
  "algebraic_int (-x) \<longleftrightarrow> algebraic_int (x :: 'a :: field_char_0)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3958
  using algebraic_int_minus[of x] algebraic_int_minus[of "-x"] by auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3959
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3960
lemma algebraic_int_inverse [intro]:
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3961
  assumes "poly p x = 0" and "\<forall>i. coeff p i \<in> \<int>" and "coeff p 0 = 1"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3962
  shows   "algebraic_int (inverse x)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3963
proof
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3964
  from assms have [simp]: "x \<noteq> 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3965
    by (auto simp: poly_0_coeff_0)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3966
  show "poly (reflect_poly p) (inverse x) = 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3967
    using assms by (simp add: poly_reflect_poly_nz)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3968
qed (use assms in \<open>auto simp: coeff_reflect_poly\<close>)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3969
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3970
lemma algebraic_int_root:
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  3971
  assumes "algebraic_int y"
73109
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3972
      and "poly p x = y" and "\<forall>i. coeff p i \<in> \<int>" and "lead_coeff p = 1" and "degree p > 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3973
  shows   "algebraic_int x"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3974
proof -
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3975
  from assms obtain q where q: "poly q y = 0" "\<forall>i. coeff q i \<in> \<int>" "lead_coeff q = 1"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3976
    by (auto simp: algebraic_int.simps)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3977
  show ?thesis
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3978
  proof
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3979
    from assms q show "lead_coeff (pcompose q p) = 1"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3980
      by (subst lead_coeff_comp) auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3981
    from assms q show "\<forall>i. coeff (pcompose q p) i \<in> \<int>"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3982
      by (intro allI coeff_pcompose_semiring_closed) auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3983
    show "poly (pcompose q p) x = 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3984
      using assms q by (simp add: poly_pcompose)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3985
  qed
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3986
qed
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3987
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3988
lemma algebraic_int_abs_real [simp]:
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3989
  "algebraic_int \<bar>x :: real\<bar> \<longleftrightarrow> algebraic_int x"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3990
  by (auto simp: abs_if)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3991
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3992
lemma algebraic_int_nth_root_real [intro]:
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3993
  assumes "algebraic_int x"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3994
  shows   "algebraic_int (root n x)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3995
proof (cases "n = 0")
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3996
  case False
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3997
  show ?thesis
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3998
  proof (rule algebraic_int_root)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  3999
    show "poly (monom 1 n) (root n x) = (if even n then \<bar>x\<bar> else x)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4000
      using sgn_power_root[of n x] False
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4001
      by (auto simp add: poly_monom sgn_if split: if_splits)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4002
  qed (use False assms in \<open>auto simp: degree_monom_eq\<close>)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4003
qed auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4004
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4005
lemma algebraic_int_sqrt [intro]: "algebraic_int x \<Longrightarrow> algebraic_int (sqrt x)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4006
  by (auto simp: sqrt_def)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4007
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4008
lemma algebraic_int_csqrt [intro]: "algebraic_int x \<Longrightarrow> algebraic_int (csqrt x)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4009
  by (rule algebraic_int_root[where p = "monom 1 2"])
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4010
     (auto simp: poly_monom degree_monom_eq)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4011
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4012
lemma algebraic_int_cnj [intro]:
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4013
  assumes "algebraic_int x"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4014
  shows   "algebraic_int (cnj x)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4015
proof -
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4016
  from assms obtain p where p: "lead_coeff p = 1" "\<forall>i. coeff p i \<in> \<int>" "poly p x = 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4017
    by (auto simp: algebraic_int.simps)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4018
  show ?thesis
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4019
  proof
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4020
    show "poly (map_poly cnj p) (cnj x) = 0"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4021
      using p by simp
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4022
    show "lead_coeff (map_poly cnj p) = 1"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4023
      using p by (simp add: coeff_map_poly degree_map_poly)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4024
    show "\<forall>i. coeff (map_poly cnj p) i \<in> \<int>"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4025
      using p by (auto simp: coeff_map_poly)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4026
  qed
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4027
qed
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4028
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4029
lemma algebraic_int_cnj_iff [simp]: "algebraic_int (cnj x) \<longleftrightarrow> algebraic_int x"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4030
  using algebraic_int_cnj[of x] algebraic_int_cnj[of "cnj x"] by auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4031
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4032
lemma algebraic_int_of_real [intro]:
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4033
  assumes "algebraic_int x"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4034
  shows   "algebraic_int (of_real x)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4035
proof -
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4036
  from assms obtain p where p: "poly p x = 0" "\<forall>i. coeff p i \<in> \<int>" "lead_coeff p = 1"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4037
    by (auto simp: algebraic_int.simps)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4038
  show "algebraic_int (of_real x :: 'a)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4039
  proof
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4040
    have "poly (map_poly of_real p) (of_real x) = (of_real (poly p x) :: 'a)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4041
      by (induction p) (auto simp: map_poly_pCons)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4042
    thus "poly (map_poly of_real p) (of_real x) = (0 :: 'a)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4043
      using p by simp
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4044
  qed (use p in \<open>auto simp: coeff_map_poly degree_map_poly\<close>)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4045
qed
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4046
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4047
lemma algebraic_int_of_real_iff [simp]:
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4048
  "algebraic_int (of_real x :: 'a :: {field_char_0, real_algebra_1}) \<longleftrightarrow> algebraic_int x"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4049
proof
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4050
  assume "algebraic_int (of_real x :: 'a)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4051
  then obtain p
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4052
    where p: "poly (map_poly of_int p) (of_real x :: 'a) = 0" "lead_coeff p = 1"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4053
    by (auto simp: algebraic_int_altdef_ipoly)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4054
  show "algebraic_int x"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4055
    unfolding algebraic_int_altdef_ipoly
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4056
  proof (intro exI[of _ p] conjI)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4057
    have "of_real (poly (map_poly real_of_int p) x) = poly (map_poly of_int p) (of_real x :: 'a)"
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4058
      by (induction p) (auto simp: map_poly_pCons)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4059
    also note p(1)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4060
    finally show "poly (map_poly real_of_int p) x = 0" by simp
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4061
  qed (use p in auto)
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4062
qed auto
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4063
783406dd051e some algebra material for HOL: characteristic of a ring, algebraic integers
Manuel Eberl <eberlm@in.tum.de>
parents: 72750
diff changeset
  4064
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4065
subsection \<open>Division of polynomials\<close>
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4066
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4067
subsubsection \<open>Division in general\<close>
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4068
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4069
instantiation poly :: (idom_divide) idom_divide
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4070
begin
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4071
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4072
fun divide_poly_main :: "'a \<Rightarrow> 'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> 'a poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4073
  where
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4074
    "divide_poly_main lc q r d dr (Suc n) =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4075
      (let cr = coeff r dr; a = cr div lc; mon = monom a n in
67369
7360fe6bb423 prefer formal comments;
wenzelm
parents: 67091
diff changeset
  4076
        if False \<or> a * lc = cr then \<comment> \<open>\<open>False \<or>\<close> is only because of problem in function-package\<close>
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4077
          divide_poly_main
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4078
            lc
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4079
            (q + mon)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4080
            (r - mon * d)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4081
            d (dr - 1) n else 0)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4082
  | "divide_poly_main lc q r d dr 0 = q"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4083
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4084
definition divide_poly :: "'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4085
  where "divide_poly f g =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4086
    (if g = 0 then 0
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4087
     else
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4088
      divide_poly_main (coeff g (degree g)) 0 f g (degree f)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4089
        (1 + length (coeffs f) - length (coeffs g)))"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4090
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4091
lemma divide_poly_main:
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4092
  assumes d: "d \<noteq> 0" "lc = coeff d (degree d)"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4093
    and "degree (d * r) \<le> dr" "divide_poly_main lc q (d * r) d dr n = q'"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4094
    and "n = 1 + dr - degree d \<or> dr = 0 \<and> n = 0 \<and> d * r = 0"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4095
  shows "q' = q + r"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4096
  using assms(3-)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4097
proof (induct n arbitrary: q r dr)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4098
  case (Suc n)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4099
  let ?rr = "d * r"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4100
  let ?a = "coeff ?rr dr"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4101
  let ?qq = "?a div lc"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4102
  define b where [simp]: "b = monom ?qq n"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4103
  let ?rrr =  "d * (r - b)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4104
  let ?qqq = "q + b"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4105
  note res = Suc(3)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4106
  from Suc(4) have dr: "dr = n + degree d" by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4107
  from d have lc: "lc \<noteq> 0" by auto
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4108
  have "coeff (b * d) dr = coeff b n * coeff d (degree d)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4109
  proof (cases "?qq = 0")
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4110
    case True
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4111
    then show ?thesis by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4112
  next
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4113
    case False
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4114
    then have n: "n = degree b"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4115
      by (simp add: degree_monom_eq)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4116
    show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4117
      unfolding n dr by (simp add: coeff_mult_degree_sum)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4118
  qed
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4119
  also have "\<dots> = lc * coeff b n"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4120
    by (simp add: d)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4121
  finally have c2: "coeff (b * d) dr = lc * coeff b n" .
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4122
  have rrr: "?rrr = ?rr - b * d"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4123
    by (simp add: field_simps)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4124
  have c1: "coeff (d * r) dr = lc * coeff r n"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4125
  proof (cases "degree r = n")
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4126
    case True
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4127
    with Suc(2) show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4128
      unfolding dr using coeff_mult_degree_sum[of d r] d by (auto simp: ac_simps)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  4129
  next
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4130
    case False
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4131
    from dr Suc(2) have "degree r \<le> n"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4132
      by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4133
        (metis add.commute add_le_cancel_left d(1) degree_0 degree_mult_eq
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4134
          diff_is_0_eq diff_zero le_cases)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4135
    with False have r_n: "degree r < n"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4136
      by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4137
    then have right: "lc * coeff r n = 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4138
      by (simp add: coeff_eq_0)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4139
    have "coeff (d * r) dr = coeff (d * r) (degree d + n)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4140
      by (simp add: dr ac_simps)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4141
    also from r_n have "\<dots> = 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4142
      by (metis False Suc.prems(1) add.commute add_left_imp_eq coeff_degree_mult coeff_eq_0
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4143
        coeff_mult_degree_sum degree_mult_le dr le_eq_less_or_eq)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4144
    finally show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4145
      by (simp only: right)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4146
  qed
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4147
  have c0: "coeff ?rrr dr = 0"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4148
    and id: "lc * (coeff (d * r) dr div lc) = coeff (d * r) dr"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4149
    unfolding rrr coeff_diff c2
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4150
    unfolding b_def coeff_monom coeff_smult c1 using lc by auto
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4151
  from res[unfolded divide_poly_main.simps[of lc q] Let_def] id
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4152
  have res: "divide_poly_main lc ?qqq ?rrr d (dr - 1) n = q'"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4153
    by (simp del: divide_poly_main.simps add: field_simps)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4154
  note IH = Suc(1)[OF _ res]
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4155
  from Suc(4) have dr: "dr = n + degree d" by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4156
  from Suc(2) have deg_rr: "degree ?rr \<le> dr" by auto
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4157
  have deg_bd: "degree (b * d) \<le> dr"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4158
    unfolding dr b_def by (rule order.trans[OF degree_mult_le]) (auto simp: degree_monom_le)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4159
  have "degree ?rrr \<le> dr"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4160
    unfolding rrr by (rule degree_diff_le[OF deg_rr deg_bd])
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4161
  with c0 have deg_rrr: "degree ?rrr \<le> (dr - 1)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4162
    by (rule coeff_0_degree_minus_1)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4163
  have "n = 1 + (dr - 1) - degree d \<or> dr - 1 = 0 \<and> n = 0 \<and> ?rrr = 0"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4164
  proof (cases dr)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4165
    case 0
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4166
    with Suc(4) have 0: "dr = 0" "n = 0" "degree d = 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4167
      by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4168
    with deg_rrr have "degree ?rrr = 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4169
      by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4170
    from degree_eq_zeroE[OF this] obtain a where rrr: "?rrr = [:a:]"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4171
      by metis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4172
    show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4173
      unfolding 0 using c0 unfolding rrr 0 by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4174
  next
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4175
    case _: Suc
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4176
    with Suc(4) show ?thesis by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4177
  qed
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4178
  from IH[OF deg_rrr this] show ?case
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4179
    by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4180
next
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4181
  case 0
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4182
  show ?case
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4183
  proof (cases "r = 0")
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4184
    case True
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4185
    with 0 show ?thesis by auto
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4186
  next
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4187
    case False
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4188
    from d False have "degree (d * r) = degree d + degree r"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4189
      by (subst degree_mult_eq) auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4190
    with 0 d show ?thesis by auto
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4191
  qed
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4192
qed
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4193
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4194
lemma divide_poly_main_0: "divide_poly_main 0 0 r d dr n = 0"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4195
proof (induct n arbitrary: r d dr)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4196
  case 0
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4197
  then show ?case by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4198
next
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4199
  case Suc
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4200
  show ?case
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4201
    unfolding divide_poly_main.simps[of _ _ r] Let_def
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4202
    by (simp add: Suc del: divide_poly_main.simps)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4203
qed
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4204
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4205
lemma divide_poly:
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4206
  assumes g: "g \<noteq> 0"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4207
  shows "(f * g) div g = (f :: 'a poly)"
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4208
proof -
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4209
  have len: "length (coeffs f) = Suc (degree f)" if "f \<noteq> 0" for f :: "'a poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4210
    using that unfolding degree_eq_length_coeffs by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4211
  have "divide_poly_main (coeff g (degree g)) 0 (g * f) g (degree (g * f))
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4212
    (1 + length (coeffs (g * f)) - length (coeffs  g)) = (f * g) div g"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4213
    by (simp add: divide_poly_def Let_def ac_simps)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4214
  note main = divide_poly_main[OF g refl le_refl this]
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4215
  have "(f * g) div g = 0 + f"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4216
  proof (rule main, goal_cases)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4217
    case 1
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4218
    show ?case
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4219
    proof (cases "f = 0")
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4220
      case True
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4221
      with g show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4222
        by (auto simp: degree_eq_length_coeffs)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4223
    next
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4224
      case False
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4225
      with g have fg: "g * f \<noteq> 0" by auto
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4226
      show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4227
        unfolding len[OF fg] len[OF g] by auto
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4228
    qed
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  4229
  qed
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4230
  then show ?thesis by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4231
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4232
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4233
lemma divide_poly_0: "f div 0 = 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4234
  for f :: "'a poly"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4235
  by (simp add: divide_poly_def Let_def divide_poly_main_0)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4236
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4237
instance
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4238
  by standard (auto simp: divide_poly divide_poly_0)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4239
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4240
end
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4241
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4242
instance poly :: (idom_divide) algebraic_semidom ..
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4243
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4244
lemma div_const_poly_conv_map_poly:
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4245
  assumes "[:c:] dvd p"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4246
  shows "p div [:c:] = map_poly (\<lambda>x. x div c) p"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4247
proof (cases "c = 0")
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4248
  case True
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4249
  then show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4250
    by (auto intro!: poly_eqI simp: coeff_map_poly)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4251
next
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4252
  case False
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4253
  from assms obtain q where p: "p = [:c:] * q" by (rule dvdE)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4254
  moreover {
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4255
    have "smult c q = [:c:] * q"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4256
      by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4257
    also have "\<dots> div [:c:] = q"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4258
      by (rule nonzero_mult_div_cancel_left) (use False in auto)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4259
    finally have "smult c q div [:c:] = q" .
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4260
  }
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4261
  ultimately show ?thesis by (intro poly_eqI) (auto simp: coeff_map_poly False)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4262
qed
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4263
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4264
lemma is_unit_monom_0:
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4265
  fixes a :: "'a::field"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4266
  assumes "a \<noteq> 0"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4267
  shows "is_unit (monom a 0)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4268
proof
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4269
  from assms show "1 = monom a 0 * monom (inverse a) 0"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4270
    by (simp add: mult_monom)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  4271
qed
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  4272
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4273
lemma is_unit_triv: "a \<noteq> 0 \<Longrightarrow> is_unit [:a:]"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4274
  for a :: "'a::field"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4275
  by (simp add: is_unit_monom_0 monom_0 [symmetric])
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4276
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4277
lemma is_unit_iff_degree:
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4278
  fixes p :: "'a::field poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4279
  assumes "p \<noteq> 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4280
  shows "is_unit p \<longleftrightarrow> degree p = 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4281
    (is "?lhs \<longleftrightarrow> ?rhs")
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4282
proof
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4283
  assume ?rhs
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4284
  then obtain a where "p = [:a:]"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4285
    by (rule degree_eq_zeroE)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4286
  with assms show ?lhs
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4287
    by (simp add: is_unit_triv)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4288
next
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4289
  assume ?lhs
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4290
  then obtain q where "q \<noteq> 0" "p * q = 1" ..
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4291
  then have "degree (p * q) = degree 1"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4292
    by simp
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4293
  with \<open>p \<noteq> 0\<close> \<open>q \<noteq> 0\<close> have "degree p + degree q = 0"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4294
    by (simp add: degree_mult_eq)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4295
  then show ?rhs by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4296
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4297
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4298
lemma is_unit_pCons_iff: "is_unit (pCons a p) \<longleftrightarrow> p = 0 \<and> a \<noteq> 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4299
  for p :: "'a::field poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4300
  by (cases "p = 0") (auto simp: is_unit_triv is_unit_iff_degree)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4301
72610
paulson <lp15@cam.ac.uk>
parents: 72219
diff changeset
  4302
lemma is_unit_monom_trivial: "is_unit p \<Longrightarrow> monom (coeff p (degree p)) 0 = p"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4303
  for p :: "'a::field poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4304
  by (cases p) (simp_all add: monom_0 is_unit_pCons_iff)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4305
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4306
lemma is_unit_const_poly_iff: "[:c:] dvd 1 \<longleftrightarrow> c dvd 1"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4307
  for c :: "'a::{comm_semiring_1,semiring_no_zero_divisors}"
65486
d801126a14cb more systematic treatment of polynomial 1
haftmann
parents: 65484
diff changeset
  4308
  by (auto simp: one_pCons)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4309
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4310
lemma is_unit_polyE:
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4311
  fixes p :: "'a :: {comm_semiring_1,semiring_no_zero_divisors} poly"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4312
  assumes "p dvd 1"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4313
  obtains c where "p = [:c:]" "c dvd 1"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  4314
proof -
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4315
  from assms obtain q where "1 = p * q"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4316
    by (rule dvdE)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4317
  then have "p \<noteq> 0" and "q \<noteq> 0"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4318
    by auto
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4319
  from \<open>1 = p * q\<close> have "degree 1 = degree (p * q)"
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  4320
    by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4321
  also from \<open>p \<noteq> 0\<close> and \<open>q \<noteq> 0\<close> have "\<dots> = degree p + degree q"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4322
    by (simp add: degree_mult_eq)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4323
  finally have "degree p = 0" by simp
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4324
  with degree_eq_zeroE obtain c where c: "p = [:c:]" .
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4325
  with \<open>p dvd 1\<close> have "c dvd 1"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4326
    by (simp add: is_unit_const_poly_iff)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4327
  with c show thesis ..
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4328
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4329
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4330
lemma is_unit_polyE':
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4331
  fixes p :: "'a::field poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4332
  assumes "is_unit p"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4333
  obtains a where "p = monom a 0" and "a \<noteq> 0"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4334
proof -
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4335
  obtain a q where "p = pCons a q"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4336
    by (cases p)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4337
  with assms have "p = [:a:]" and "a \<noteq> 0"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4338
    by (simp_all add: is_unit_pCons_iff)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4339
  with that show thesis by (simp add: monom_0)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  4340
qed
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  4341
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4342
lemma is_unit_poly_iff: "p dvd 1 \<longleftrightarrow> (\<exists>c. p = [:c:] \<and> c dvd 1)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4343
  for p :: "'a::{comm_semiring_1,semiring_no_zero_divisors} poly"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4344
  by (auto elim: is_unit_polyE simp add: is_unit_const_poly_iff)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4345
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4346
lemma root_imp_reducible_poly:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4347
  fixes x :: "'a :: field"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4348
  assumes "poly p x = 0" and "degree p > 1"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4349
  shows   "\<not>irreducible p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4350
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4351
  from assms have "p \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4352
    by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4353
  define q where "q = [:-x, 1:]"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4354
  have "q dvd p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4355
    using assms by (simp add: poly_eq_0_iff_dvd q_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4356
  then obtain r where p_eq: "p = q * r"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4357
    by (elim dvdE)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4358
  have [simp]: "q \<noteq> 0" "r \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4359
    using \<open>p \<noteq> 0\<close> by (auto simp: p_eq)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4360
  have "degree p = Suc (degree r)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4361
    unfolding p_eq by (subst degree_mult_eq) (auto simp: q_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4362
  with assms(2) have "degree r > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4363
    by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4364
  hence "\<not>r dvd 1"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4365
    by (auto simp: is_unit_poly_iff)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4366
  moreover have "\<not>q dvd 1"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4367
    by (auto simp: is_unit_poly_iff q_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4368
  ultimately show ?thesis using p_eq
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4369
    by (auto simp: irreducible_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4370
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4371
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4372
lemma reducible_polyI:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4373
  fixes p :: "'a :: field poly"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4374
  assumes "p = q * r" "degree q > 0" "degree r > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4375
  shows   "\<not>irreducible p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4376
  using assms unfolding irreducible_def
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4377
  by (metis (no_types, opaque_lifting) is_unitE is_unit_iff_degree not_gr0)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  4378
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4379
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4380
subsubsection \<open>Pseudo-Division\<close>
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4381
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4382
text \<open>This part is by René Thiemann and Akihisa Yamada.\<close>
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4383
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4384
fun pseudo_divmod_main ::
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4385
  "'a :: comm_ring_1  \<Rightarrow> 'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> 'a poly \<times> 'a poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4386
  where
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4387
    "pseudo_divmod_main lc q r d dr (Suc n) =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4388
      (let
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4389
        rr = smult lc r;                                       
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4390
        qq = coeff r dr;
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4391
        rrr = rr - monom qq n * d;
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4392
        qqq = smult lc q + monom qq n
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4393
       in pseudo_divmod_main lc qqq rrr d (dr - 1) n)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4394
  | "pseudo_divmod_main lc q r d dr 0 = (q,r)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4395
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4396
definition pseudo_divmod :: "'a :: comm_ring_1 poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly \<times> 'a poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4397
  where "pseudo_divmod p q \<equiv>
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4398
    if q = 0 then (0, p)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4399
    else
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4400
      pseudo_divmod_main (coeff q (degree q)) 0 p q (degree p)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4401
        (1 + length (coeffs p) - length (coeffs q))"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4402
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4403
lemma pseudo_divmod_main:
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4404
  assumes d: "d \<noteq> 0" "lc = coeff d (degree d)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4405
    and "degree r \<le> dr" "pseudo_divmod_main lc q r d dr n = (q',r')"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4406
    and "n = 1 + dr - degree d \<or> dr = 0 \<and> n = 0 \<and> r = 0"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4407
  shows "(r' = 0 \<or> degree r' < degree d) \<and> smult (lc^n) (d * q + r) = d * q' + r'"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4408
  using assms(3-)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4409
proof (induct n arbitrary: q r dr)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4410
  case 0
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4411
  then show ?case by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4412
next
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4413
  case (Suc n)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4414
  let ?rr = "smult lc r"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4415
  let ?qq = "coeff r dr"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4416
  define b where [simp]: "b = monom ?qq n"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4417
  let ?rrr = "?rr - b * d"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4418
  let ?qqq = "smult lc q + b"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4419
  note res = Suc(3)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4420
  from res[unfolded pseudo_divmod_main.simps[of lc q] Let_def]
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4421
  have res: "pseudo_divmod_main lc ?qqq ?rrr d (dr - 1) n = (q',r')"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4422
    by (simp del: pseudo_divmod_main.simps)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4423
  from Suc(4) have dr: "dr = n + degree d" by auto
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4424
  have "coeff (b * d) dr = coeff b n * coeff d (degree d)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4425
  proof (cases "?qq = 0")
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4426
    case True
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4427
    then show ?thesis by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4428
  next
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4429
    case False
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4430
    then have n: "n = degree b"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4431
      by (simp add: degree_monom_eq)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4432
    show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4433
      unfolding n dr by (simp add: coeff_mult_degree_sum)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4434
  qed
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4435
  also have "\<dots> = lc * coeff b n" by (simp add: d)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4436
  finally have "coeff (b * d) dr = lc * coeff b n" .
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4437
  moreover have "coeff ?rr dr = lc * coeff r dr"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4438
    by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4439
  ultimately have c0: "coeff ?rrr dr = 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4440
    by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4441
  from Suc(4) have dr: "dr = n + degree d" by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4442
  have deg_rr: "degree ?rr \<le> dr"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4443
    using Suc(2) degree_smult_le dual_order.trans by blast
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4444
  have deg_bd: "degree (b * d) \<le> dr"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4445
    unfolding dr by (rule order.trans[OF degree_mult_le]) (auto simp: degree_monom_le)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4446
  have "degree ?rrr \<le> dr"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4447
    using degree_diff_le[OF deg_rr deg_bd] by auto
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4448
  with c0 have deg_rrr: "degree ?rrr \<le> (dr - 1)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4449
    by (rule coeff_0_degree_minus_1)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4450
  have "n = 1 + (dr - 1) - degree d \<or> dr - 1 = 0 \<and> n = 0 \<and> ?rrr = 0"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4451
  proof (cases dr)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4452
    case 0
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4453
    with Suc(4) have 0: "dr = 0" "n = 0" "degree d = 0" by auto
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4454
    with deg_rrr have "degree ?rrr = 0" by simp
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4455
    then have "\<exists>a. ?rrr = [:a:]"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4456
      by (metis degree_pCons_eq_if old.nat.distinct(2) pCons_cases)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4457
    from this obtain a where rrr: "?rrr = [:a:]"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4458
      by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4459
    show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4460
      unfolding 0 using c0 unfolding rrr 0 by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4461
  next
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4462
    case _: Suc
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4463
    with Suc(4) show ?thesis by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4464
  qed
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4465
  note IH = Suc(1)[OF deg_rrr res this]
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4466
  show ?case
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4467
  proof (intro conjI)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4468
    from IH show "r' = 0 \<or> degree r' < degree d"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4469
      by blast
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4470
    show "smult (lc ^ Suc n) (d * q + r) = d * q' + r'"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4471
      unfolding IH[THEN conjunct2,symmetric]
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4472
      by (simp add: field_simps smult_add_right)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4473
  qed
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4474
qed
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4475
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4476
lemma pseudo_divmod:
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4477
  assumes g: "g \<noteq> 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4478
    and *: "pseudo_divmod f g = (q,r)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4479
  shows "smult (coeff g (degree g) ^ (Suc (degree f) - degree g)) f = g * q + r"  (is ?A)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4480
    and "r = 0 \<or> degree r < degree g"  (is ?B)
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  4481
proof -
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4482
  from *[unfolded pseudo_divmod_def Let_def]
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4483
  have "pseudo_divmod_main (coeff g (degree g)) 0 f g (degree f)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4484
      (1 + length (coeffs f) - length (coeffs g)) = (q, r)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4485
    by (auto simp: g)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4486
  note main = pseudo_divmod_main[OF _ _ _ this, OF g refl le_refl]
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4487
  from g have "1 + length (coeffs f) - length (coeffs g) = 1 + degree f - degree g \<or>
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4488
    degree f = 0 \<and> 1 + length (coeffs f) - length (coeffs g) = 0 \<and> f = 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4489
    by (cases "f = 0"; cases "coeffs g") (auto simp: degree_eq_length_coeffs)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4490
  note main' = main[OF this]
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4491
  then show "r = 0 \<or> degree r < degree g" by auto
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4492
  show "smult (coeff g (degree g) ^ (Suc (degree f) - degree g)) f = g * q + r"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4493
    by (subst main'[THEN conjunct2, symmetric], simp add: degree_eq_length_coeffs,
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4494
        cases "f = 0"; cases "coeffs g", use g in auto)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4495
qed
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4496
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4497
definition "pseudo_mod_main lc r d dr n = snd (pseudo_divmod_main lc 0 r d dr n)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4498
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4499
lemma snd_pseudo_divmod_main:
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4500
  "snd (pseudo_divmod_main lc q r d dr n) = snd (pseudo_divmod_main lc q' r d dr n)"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4501
  by (induct n arbitrary: q q' lc r d dr) (simp_all add: Let_def)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4502
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4503
definition pseudo_mod :: "'a::{comm_ring_1,semiring_1_no_zero_divisors} poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4504
  where "pseudo_mod f g = snd (pseudo_divmod f g)"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4505
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4506
lemma pseudo_mod:
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4507
  fixes f g :: "'a::{comm_ring_1,semiring_1_no_zero_divisors} poly"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4508
  defines "r \<equiv> pseudo_mod f g"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4509
  assumes g: "g \<noteq> 0"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4510
  shows "\<exists>a q. a \<noteq> 0 \<and> smult a f = g * q + r" "r = 0 \<or> degree r < degree g"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4511
proof -
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4512
  let ?cg = "coeff g (degree g)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4513
  let ?cge = "?cg ^ (Suc (degree f) - degree g)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4514
  define a where "a = ?cge"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4515
  from r_def[unfolded pseudo_mod_def] obtain q where pdm: "pseudo_divmod f g = (q, r)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4516
    by (cases "pseudo_divmod f g") auto
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4517
  from pseudo_divmod[OF g pdm] have id: "smult a f = g * q + r" and "r = 0 \<or> degree r < degree g"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4518
    by (auto simp: a_def)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4519
  show "r = 0 \<or> degree r < degree g" by fact
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4520
  from g have "a \<noteq> 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4521
    by (auto simp: a_def)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4522
  with id show "\<exists>a q. a \<noteq> 0 \<and> smult a f = g * q + r"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4523
    by auto
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4524
qed
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  4525
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4526
lemma fst_pseudo_divmod_main_as_divide_poly_main:
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4527
  assumes d: "d \<noteq> 0"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4528
  defines lc: "lc \<equiv> coeff d (degree d)"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4529
  shows "fst (pseudo_divmod_main lc q r d dr n) =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4530
    divide_poly_main lc (smult (lc^n) q) (smult (lc^n) r) d dr n"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4531
proof (induct n arbitrary: q r dr)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4532
  case 0
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4533
  then show ?case by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4534
next
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4535
  case (Suc n)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4536
  note lc0 = leading_coeff_neq_0[OF d, folded lc]
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4537
  then have "pseudo_divmod_main lc q r d dr (Suc n) =
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4538
    pseudo_divmod_main lc (smult lc q + monom (coeff r dr) n)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4539
      (smult lc r - monom (coeff r dr) n * d) d (dr - 1) n"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4540
    by (simp add: Let_def ac_simps)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4541
  also have "fst \<dots> = divide_poly_main lc
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4542
     (smult (lc^n) (smult lc q + monom (coeff r dr) n))
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4543
     (smult (lc^n) (smult lc r - monom (coeff r dr) n * d))
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4544
     d (dr - 1) n"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4545
    by (simp only: Suc[unfolded divide_poly_main.simps Let_def])
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4546
  also have "\<dots> = divide_poly_main lc (smult (lc ^ Suc n) q) (smult (lc ^ Suc n) r) d dr (Suc n)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4547
    unfolding smult_monom smult_distribs mult_smult_left[symmetric]
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4548
    using lc0 by (simp add: Let_def ac_simps)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4549
  finally show ?case .
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  4550
qed
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  4551
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4552
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4553
subsubsection \<open>Division in polynomials over fields\<close>
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4554
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4555
lemma pseudo_divmod_field:
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4556
  fixes g :: "'a::field poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4557
  assumes g: "g \<noteq> 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4558
    and *: "pseudo_divmod f g = (q,r)"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4559
  defines "c \<equiv> coeff g (degree g) ^ (Suc (degree f) - degree g)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4560
  shows "f = g * smult (1/c) q + smult (1/c) r"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4561
proof -
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4562
  from leading_coeff_neq_0[OF g] have c0: "c \<noteq> 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4563
    by (auto simp: c_def)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4564
  from pseudo_divmod(1)[OF g *, folded c_def] have "smult c f = g * q + r"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4565
    by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4566
  also have "smult (1 / c) \<dots> = g * smult (1 / c) q + smult (1 / c) r"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4567
    by (simp add: smult_add_right)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4568
  finally show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4569
    using c0 by auto
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4570
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4571
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4572
lemma divide_poly_main_field:
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4573
  fixes d :: "'a::field poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4574
  assumes d: "d \<noteq> 0"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4575
  defines lc: "lc \<equiv> coeff d (degree d)"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4576
  shows "divide_poly_main lc q r d dr n =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4577
    fst (pseudo_divmod_main lc (smult ((1 / lc)^n) q) (smult ((1 / lc)^n) r) d dr n)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4578
  unfolding lc by (subst fst_pseudo_divmod_main_as_divide_poly_main) (auto simp: d power_one_over)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4579
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4580
lemma divide_poly_field:
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4581
  fixes f g :: "'a::field poly"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4582
  defines "f' \<equiv> smult ((1 / coeff g (degree g)) ^ (Suc (degree f) - degree g)) f"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4583
  shows "f div g = fst (pseudo_divmod f' g)"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4584
proof (cases "g = 0")
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4585
  case True
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4586
  show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4587
    unfolding divide_poly_def pseudo_divmod_def Let_def f'_def True
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4588
    by (simp add: divide_poly_main_0)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4589
next
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4590
  case False
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4591
  from leading_coeff_neq_0[OF False] have "degree f' = degree f"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4592
    by (auto simp: f'_def)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4593
  then show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4594
    using length_coeffs_degree[of f'] length_coeffs_degree[of f]
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4595
    unfolding divide_poly_def pseudo_divmod_def Let_def
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4596
      divide_poly_main_field[OF False]
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4597
      length_coeffs_degree[OF False]
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4598
      f'_def
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4599
    by force
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4600
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4601
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4602
instantiation poly :: ("{semidom_divide_unit_factor,idom_divide}") normalization_semidom
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4603
begin
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4604
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4605
definition unit_factor_poly :: "'a poly \<Rightarrow> 'a poly"
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4606
  where "unit_factor_poly p = [:unit_factor (lead_coeff p):]"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4607
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4608
definition normalize_poly :: "'a poly \<Rightarrow> 'a poly"
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4609
  where "normalize p = p div [:unit_factor (lead_coeff p):]"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4610
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4611
instance
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4612
proof
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4613
  fix p :: "'a poly"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4614
  show "unit_factor p * normalize p = p"
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4615
  proof (cases "p = 0")
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4616
    case True
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4617
    then show ?thesis
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4618
      by (simp add: unit_factor_poly_def normalize_poly_def)
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4619
  next
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4620
    case False
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4621
    then have "lead_coeff p \<noteq> 0"
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4622
      by simp
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4623
    then have *: "unit_factor (lead_coeff p) \<noteq> 0"
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4624
      using unit_factor_is_unit [of "lead_coeff p"] by auto
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4625
    then have "unit_factor (lead_coeff p) dvd 1"
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4626
      by (auto intro: unit_factor_is_unit)
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4627
    then have **: "unit_factor (lead_coeff p) dvd c" for c
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4628
      by (rule dvd_trans) simp
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4629
    have ***: "unit_factor (lead_coeff p) * (c div unit_factor (lead_coeff p)) = c" for c
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4630
    proof -
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4631
      from ** obtain b where "c = unit_factor (lead_coeff p) * b" ..
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4632
      with False * show ?thesis by simp
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4633
    qed
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4634
    have "p div [:unit_factor (lead_coeff p):] =
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4635
      map_poly (\<lambda>c. c div unit_factor (lead_coeff p)) p"
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4636
      by (simp add: const_poly_dvd_iff div_const_poly_conv_map_poly **)
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4637
    then show ?thesis
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4638
      by (simp add: normalize_poly_def unit_factor_poly_def
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4639
        smult_conv_map_poly map_poly_map_poly o_def ***)
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4640
  qed
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4641
next
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4642
  fix p :: "'a poly"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4643
  assume "is_unit p"
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4644
  then obtain c where p: "p = [:c:]" "c dvd 1"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4645
    by (auto simp: is_unit_poly_iff)
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4646
  then show "unit_factor p = p"
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4647
    by (simp add: unit_factor_poly_def monom_0 is_unit_unit_factor)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4648
next
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4649
  fix p :: "'a poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4650
  assume "p \<noteq> 0"
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4651
  then show "is_unit (unit_factor p)"
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4652
    by (simp add: unit_factor_poly_def monom_0 is_unit_poly_iff unit_factor_is_unit)
71398
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  4653
next
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  4654
  fix a b :: "'a poly" assume "is_unit a"
71398
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  4655
  thus "unit_factor (a * b) = a * unit_factor b"
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  4656
    by (auto simp: unit_factor_poly_def lead_coeff_mult unit_factor_mult elim!: is_unit_polyE)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4657
qed (simp_all add: normalize_poly_def unit_factor_poly_def monom_0 lead_coeff_mult unit_factor_mult)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4658
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4659
end
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4660
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  4661
instance poly :: ("{semidom_divide_unit_factor,idom_divide,normalization_semidom_multiplicative}")
71398
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  4662
  normalization_semidom_multiplicative
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  4663
  by intro_classes (auto simp: unit_factor_poly_def lead_coeff_mult unit_factor_mult)
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  4664
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4665
lemma normalize_poly_eq_map_poly: "normalize p = map_poly (\<lambda>x. x div unit_factor (lead_coeff p)) p"
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4666
proof -
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4667
  have "[:unit_factor (lead_coeff p):] dvd p"
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4668
    by (metis unit_factor_poly_def unit_factor_self)
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4669
  then show ?thesis
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4670
    by (simp add: normalize_poly_def div_const_poly_conv_map_poly)
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4671
qed
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4672
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4673
lemma coeff_normalize [simp]:
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4674
  "coeff (normalize p) n = coeff p n div unit_factor (lead_coeff p)"
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4675
  by (simp add: normalize_poly_eq_map_poly coeff_map_poly)
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4676
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4677
class field_unit_factor = field + unit_factor +
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4678
  assumes unit_factor_field [simp]: "unit_factor = id"
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4679
begin
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4680
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4681
subclass semidom_divide_unit_factor
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4682
proof
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4683
  fix a
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4684
  assume "a \<noteq> 0"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4685
  then have "1 = a * inverse a" by simp
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4686
  then have "a dvd 1" ..
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4687
  then show "unit_factor a dvd 1" by simp
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4688
qed simp_all
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4689
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4690
end
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4691
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4692
lemma unit_factor_pCons:
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4693
  "unit_factor (pCons a p) = (if p = 0 then [:unit_factor a:] else unit_factor p)"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4694
  by (simp add: unit_factor_poly_def)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4695
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4696
lemma normalize_monom [simp]: "normalize (monom a n) = monom (normalize a) n"
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4697
  by (cases "a = 0") (simp_all add: map_poly_monom normalize_poly_eq_map_poly degree_monom_eq)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4698
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  4699
lemma unit_factor_monom [simp]: "unit_factor (monom a n) = [:unit_factor a:]"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4700
  by (cases "a = 0") (simp_all add: unit_factor_poly_def degree_monom_eq)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4701
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4702
lemma normalize_const_poly: "normalize [:c:] = [:normalize c:]"
64848
c50db2128048 slightly generalized type class hierarchy concerning unit factors, to allow for lean polynomial normalization
haftmann
parents: 64811
diff changeset
  4703
  by (simp add: normalize_poly_eq_map_poly map_poly_pCons)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4704
71398
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  4705
lemma normalize_smult:
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  4706
  fixes c :: "'a :: {normalization_semidom_multiplicative, idom_divide}"
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  4707
  shows "normalize (smult c p) = smult (normalize c) (normalize p)"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4708
proof -
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  4709
  have "smult c p = [:c:] * p" by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4710
  also have "normalize \<dots> = smult (normalize c) (normalize p)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4711
    by (subst normalize_mult) (simp add: normalize_const_poly)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4712
  finally show ?thesis .
62352
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  4713
qed
35a9e1cbb5b3 separated potentially conflicting type class instance into separate theory
haftmann
parents: 62351
diff changeset
  4714
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4715
instantiation poly :: (field) idom_modulo
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4716
begin
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4717
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4718
definition modulo_poly :: "'a poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly"
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4719
  where mod_poly_def: "f mod g =
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4720
    (if g = 0 then f else pseudo_mod (smult ((1 / lead_coeff g) ^ (Suc (degree f) - degree g)) f) g)"
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4721
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4722
instance
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4723
proof
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4724
  fix x y :: "'a poly"
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4725
  show "x div y * y + x mod y = x"
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4726
  proof (cases "y = 0")
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4727
    case True
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4728
    then show ?thesis
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4729
      by (simp add: divide_poly_0 mod_poly_def)
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4730
  next
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4731
    case False
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4732
    then have "pseudo_divmod (smult ((1 / lead_coeff y) ^ (Suc (degree x) - degree y)) x) y =
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4733
        (x div y, x mod y)"
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4734
      by (simp add: divide_poly_field mod_poly_def pseudo_mod_def)
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4735
    with False pseudo_divmod [OF False this] show ?thesis
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4736
      by (simp add: power_mult_distrib [symmetric] ac_simps)
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4737
  qed
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4738
qed
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4739
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4740
end
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4741
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4742
lemma pseudo_divmod_eq_div_mod:
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4743
  \<open>pseudo_divmod f g = (f div g, f mod g)\<close> if \<open>lead_coeff g = 1\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4744
  using that by (auto simp add: divide_poly_field mod_poly_def pseudo_mod_def)
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4745
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4746
lemma degree_mod_less_degree:
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4747
  \<open>degree (x mod y) < degree y\<close> if \<open>y \<noteq> 0\<close> \<open>\<not> y dvd x\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4748
proof -
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4749
  from pseudo_mod(2) [of y] \<open>y \<noteq> 0\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4750
  have *: \<open>pseudo_mod f y \<noteq> 0 \<Longrightarrow> degree (pseudo_mod f y) < degree y\<close> for f
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4751
    by blast
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4752
  from \<open>\<not> y dvd x\<close> have \<open>x mod y \<noteq> 0\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4753
    by blast
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4754
  with \<open>y \<noteq> 0\<close> show ?thesis
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4755
    by (auto simp add: mod_poly_def intro: *)
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4756
qed
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4757
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4758
instantiation poly :: (field) unique_euclidean_ring
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4759
begin
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4760
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4761
definition euclidean_size_poly :: "'a poly \<Rightarrow> nat"
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4762
  where "euclidean_size_poly p = (if p = 0 then 0 else 2 ^ degree p)"
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4763
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4764
definition division_segment_poly :: "'a poly \<Rightarrow> 'a poly"
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4765
  where [simp]: "division_segment_poly p = 1"
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4766
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4767
instance proof
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4768
  show \<open>(q * p + r) div p = q\<close> if \<open>p \<noteq> 0\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4769
    and \<open>euclidean_size r < euclidean_size p\<close> for q p r :: \<open>'a poly\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4770
  proof (cases \<open>r = 0\<close>)
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4771
    case True
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4772
    with that show ?thesis
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4773
      by simp
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4774
  next
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4775
    case False
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4776
    with \<open>p \<noteq> 0\<close> \<open>euclidean_size r < euclidean_size p\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4777
    have \<open>degree r < degree p\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4778
      by (simp add: euclidean_size_poly_def)
76208
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4779
    with \<open>r \<noteq> 0\<close> have \<open>\<not> p dvd r\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4780
      by (auto dest: dvd_imp_degree)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4781
    have \<open>(q * p + r) div p = q \<and> (q * p + r) mod p = r\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4782
    proof (rule ccontr)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4783
      assume \<open>\<not> ?thesis\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4784
      moreover have *: \<open>((q * p + r) div p - q) * p = r - (q * p + r) mod p\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4785
        by (simp add: algebra_simps)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4786
      ultimately have \<open>(q * p + r) div p \<noteq> q\<close> and \<open>(q * p + r) mod p \<noteq> r\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4787
        using \<open>p \<noteq> 0\<close> by auto
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4788
      from \<open>\<not> p dvd r\<close> have \<open>\<not> p dvd (q * p + r)\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4789
        by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4790
      with \<open>p \<noteq> 0\<close> have \<open>degree ((q * p + r) mod p) < degree p\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4791
        by (rule degree_mod_less_degree)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4792
      with \<open>degree r < degree p\<close> \<open>(q * p + r) mod p \<noteq> r\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4793
      have \<open>degree (r - (q * p + r) mod p) < degree p\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4794
        by (auto intro: degree_diff_less)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4795
      also have \<open>degree p \<le> degree ((q * p + r) div p - q) + degree p\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4796
        by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4797
      also from \<open>(q * p + r) div p \<noteq> q\<close> \<open>p \<noteq> 0\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4798
      have \<open>\<dots> = degree (((q * p + r) div p - q) * p)\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4799
        by (simp add: degree_mult_eq)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4800
      also from * have \<open>\<dots> = degree (r - (q * p + r) mod p)\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4801
        by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4802
      finally have \<open>degree (r - (q * p + r) mod p) < degree (r - (q * p + r) mod p)\<close> .
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4803
      then show False
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4804
        by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4805
    qed
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4806
    then show \<open>(q * p + r) div p = q\<close> ..
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4807
  qed
76208
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4808
qed (auto simp: euclidean_size_poly_def degree_mult_eq power_add intro: degree_mod_less_degree)
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4809
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4810
end
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4811
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4812
lemma euclidean_relation_polyI [case_names by0 divides euclidean_relation]:
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4813
  \<open>(x div y, x mod y) = (q, r)\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4814
    if by0: \<open>y = 0 \<Longrightarrow> q = 0 \<and> r = x\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4815
    and divides: \<open>y \<noteq> 0 \<Longrightarrow> y dvd x \<Longrightarrow> r = 0 \<and> x = q * y\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4816
    and euclidean_relation: \<open>y \<noteq> 0 \<Longrightarrow> \<not> y dvd x \<Longrightarrow> degree r < degree y \<and> x = q * y + r\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4817
  by (rule euclidean_relationI)
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4818
    (use that in \<open>simp_all add: euclidean_size_poly_def\<close>)
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4819
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4820
lemma div_poly_eq_0_iff:
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4821
  \<open>x div y = 0 \<longleftrightarrow> x = 0 \<or> y = 0 \<or> degree x < degree y\<close> for x y :: \<open>'a::field poly\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4822
  by (simp add: unique_euclidean_semiring_class.div_eq_0_iff euclidean_size_poly_def)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4823
76208
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4824
lemma div_poly_less:
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4825
  \<open>x div y = 0\<close> if \<open>degree x < degree y\<close> for x y :: \<open>'a::field poly\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4826
  using that by (simp add: div_poly_eq_0_iff)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4827
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4828
lemma mod_poly_less:
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4829
  \<open>x mod y = x\<close> if \<open>degree x < degree y\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4830
  using that by (simp add: mod_eq_self_iff_div_eq_0 div_poly_eq_0_iff)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4831
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4832
lemma degree_div_less:
76208
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4833
  \<open>degree (x div y) < degree x\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4834
    if \<open>degree x > 0\<close> \<open>degree y > 0\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4835
    for x y :: \<open>'a::field poly\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4836
proof (cases \<open>x div y = 0\<close>)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4837
  case True
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4838
  with \<open>degree x > 0\<close> show ?thesis
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4839
    by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4840
next
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4841
  case False
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4842
  from that have \<open>x \<noteq> 0\<close> \<open>y \<noteq> 0\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4843
    and *: \<open>degree (x div y * y + x mod y) > 0\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4844
    by auto
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4845
  show ?thesis
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4846
  proof (cases \<open>y dvd x\<close>)
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4847
    case True
76208
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4848
    then obtain z where \<open>x = y * z\<close> ..
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4849
    then have \<open>degree (x div y) < degree (x div y * y)\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4850
      using \<open>y \<noteq> 0\<close> \<open>x \<noteq> 0\<close> \<open>degree y > 0\<close> by (simp add: degree_mult_eq)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4851
    with \<open>y dvd x\<close> show ?thesis
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4852
      by simp
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4853
  next
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4854
    case False
76208
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4855
    with \<open>y \<noteq> 0\<close> have \<open>degree (x mod y) < degree y\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4856
      by (rule degree_mod_less_degree)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4857
    with \<open>y \<noteq> 0\<close> \<open>x div y \<noteq> 0\<close> have \<open>degree (x mod y) < degree (x div y * y)\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4858
      by (simp add: degree_mult_eq)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4859
    then have \<open>degree (x div y * y + x mod y) = degree (x div y * y)\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4860
      by (rule degree_add_eq_left)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4861
    with \<open>y \<noteq> 0\<close> \<open>x div y \<noteq> 0\<close> \<open>degree y > 0\<close> show ?thesis
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4862
      by (simp add: degree_mult_eq)
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4863
  qed
76208
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4864
qed
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4865
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  4866
lemma degree_mod_less': "b \<noteq> 0 \<Longrightarrow> a mod b \<noteq> 0 \<Longrightarrow> degree (a mod b) < degree b"
76208
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4867
  by (rule degree_mod_less_degree) auto
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4868
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4869
lemma degree_mod_less: "y \<noteq> 0 \<Longrightarrow> x mod y = 0 \<or> degree (x mod y) < degree y"
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  4870
  using degree_mod_less' by blast
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  4871
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4872
lemma div_smult_left: \<open>smult a x div y = smult a (x div y)\<close> (is ?Q)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4873
  and mod_smult_left: \<open>smult a x mod y = smult a (x mod y)\<close> (is ?R)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4874
  for x y :: \<open>'a::field poly\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4875
proof -
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4876
  have \<open>(smult a x div y, smult a x mod y) = (smult a (x div y), smult a (x mod y))\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4877
  proof (cases \<open>a = 0\<close>)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4878
    case True
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4879
    then show ?thesis
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4880
      by simp
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4881
  next
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4882
    case False
76245
4111c94657b4 slightly less abusive proof pattern
haftmann
parents: 76208
diff changeset
  4883
    show ?thesis
4111c94657b4 slightly less abusive proof pattern
haftmann
parents: 76208
diff changeset
  4884
      by (rule euclidean_relation_polyI)
4111c94657b4 slightly less abusive proof pattern
haftmann
parents: 76208
diff changeset
  4885
        (use False in \<open>simp_all add: dvd_smult_iff degree_mod_less_degree flip: smult_add_right\<close>)
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4886
  qed
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4887
  then show ?Q and ?R
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4888
    by simp_all
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4889
qed
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4890
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4891
lemma poly_div_minus_left [simp]: "(- x) div y = - (x div y)"
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4892
  for x y :: "'a::field poly"
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4893
  using div_smult_left [of "- 1::'a"] by simp
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4894
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4895
lemma poly_mod_minus_left [simp]: "(- x) mod y = - (x mod y)"
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4896
  for x y :: "'a::field poly"
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4897
  using mod_smult_left [of "- 1::'a"] by simp
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4898
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4899
lemma poly_div_add_left: \<open>(x + y) div z = x div z + y div z\<close> (is ?Q)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4900
  and poly_mod_add_left: \<open>(x + y) mod z = x mod z + y mod z\<close> (is ?R)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4901
  for x y z :: \<open>'a::field poly\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4902
proof -
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4903
  have \<open>((x + y) div z, (x + y) mod z) = (x div z + y div z, x mod z + y mod z)\<close>
76245
4111c94657b4 slightly less abusive proof pattern
haftmann
parents: 76208
diff changeset
  4904
  proof (induction rule: euclidean_relation_polyI)
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4905
    case by0
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4906
    then show ?case by simp
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  4907
  next
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4908
    case divides
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4909
    then obtain w where \<open>x + y = z * w\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4910
      by blast
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4911
    then have y: \<open>y = z * w - x\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4912
      by (simp add: algebra_simps)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4913
    from \<open>z \<noteq> 0\<close> show ?case
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4914
      using mod_mult_self4 [of z w \<open>- x\<close>] div_mult_self4 [of z w \<open>- x\<close>]
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4915
      by (simp add: algebra_simps y)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4916
  next
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4917
    case euclidean_relation
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4918
    then have \<open>degree (x mod z + y mod z) < degree z\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4919
      using degree_mod_less_degree [of z x] degree_mod_less_degree [of z y]
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4920
        dvd_add_right_iff [of z x y] dvd_add_left_iff [of z y x]
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4921
      by (cases \<open>z dvd x \<or> z dvd y\<close>) (auto intro: degree_add_less)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4922
    moreover have \<open>x + y = (x div z + y div z) * z + (x mod z + y mod z)\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4923
      by (simp add: algebra_simps)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4924
    ultimately show ?case
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4925
      by simp
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4926
  qed
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4927
  then show ?Q and ?R
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4928
    by simp_all
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4929
qed
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4930
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4931
lemma poly_div_diff_left: "(x - y) div z = x div z - y div z"
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4932
  for x y z :: "'a::field poly"
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4933
  by (simp only: diff_conv_add_uminus poly_div_add_left poly_div_minus_left)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4934
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4935
lemma poly_mod_diff_left: "(x - y) mod z = x mod z - y mod z"
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4936
  for x y z :: "'a::field poly"
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4937
  by (simp only: diff_conv_add_uminus poly_mod_add_left poly_mod_minus_left)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4938
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4939
lemma div_smult_right: \<open>x div smult a y = smult (inverse a) (x div y)\<close> (is ?Q)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4940
  and mod_smult_right: \<open>x mod smult a y = (if a = 0 then x else x mod y)\<close> (is ?R)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4941
proof -
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4942
  have \<open>(x div smult a y, x mod smult a y) = (smult (inverse a) (x div y), (if a = 0 then x else x mod y))\<close>
76245
4111c94657b4 slightly less abusive proof pattern
haftmann
parents: 76208
diff changeset
  4943
  proof (induction rule: euclidean_relation_polyI)
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4944
    case by0
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4945
    then show ?case by auto
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4946
  next
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4947
    case divides
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4948
    moreover define w where \<open>w = x div y\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4949
    ultimately have \<open>x = y * w\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4950
      by (simp add: smult_dvd_iff)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4951
    with divides show ?case
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4952
      by simp
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4953
  next
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4954
    case euclidean_relation
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  4955
    then show ?case
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4956
      by (simp add: smult_dvd_iff degree_mod_less_degree)
72750
96d39c1dd64c More removal of apply
paulson <lp15@cam.ac.uk>
parents: 72610
diff changeset
  4957
  qed
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4958
  then show ?Q and ?R
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4959
    by simp_all
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4960
qed
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4961
76386
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4962
lemma mod_mult_unit_eq:
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4963
  \<open>x mod (z * y) = x mod y\<close>
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4964
  if \<open>is_unit z\<close>
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4965
  for x y z :: \<open>'a::field poly\<close>
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4966
proof (cases \<open>y = 0\<close>)
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4967
  case True
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4968
  then show ?thesis
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4969
    by simp
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4970
next
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4971
  case False
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4972
  moreover have \<open>z \<noteq> 0\<close>
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4973
    using that by auto
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4974
  moreover define a where \<open>a = lead_coeff z\<close>
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4975
  ultimately have \<open>z = [:a:]\<close> \<open>a \<noteq> 0\<close>
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4976
    using that monom_0 [of a] by (simp_all add: is_unit_monom_trivial)
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4977
  then show ?thesis
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4978
    by (simp add: mod_smult_right)
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4979
qed
6bc3bb9d0e3e modulus for polynomials is invariant wrt. units
haftmann
parents: 76245
diff changeset
  4980
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4981
lemma poly_div_minus_right [simp]: "x div (- y) = - (x div y)"
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4982
  for x y :: "'a::field poly"
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4983
  using div_smult_right [of _ "- 1::'a"] by (simp add: nonzero_inverse_minus_eq)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4984
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4985
lemma poly_mod_minus_right [simp]: "x mod (- y) = x mod y"
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4986
  for x y :: "'a::field poly"
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4987
  using mod_smult_right [of _ "- 1::'a"] by simp
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4988
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4989
lemma poly_div_mult_right: \<open>x div (y * z) = (x div y) div z\<close> (is ?Q)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4990
  and poly_mod_mult_right: \<open>x mod (y * z) = y * (x div y mod z) + x mod y\<close> (is ?R)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4991
  for x y z :: \<open>'a::field poly\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4992
proof -
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4993
  have \<open>(x div (y * z), x mod (y * z)) = ((x div y) div z, y * (x div y mod z) + x mod y)\<close>
76245
4111c94657b4 slightly less abusive proof pattern
haftmann
parents: 76208
diff changeset
  4994
  proof (induction rule: euclidean_relation_polyI)
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4995
    case by0
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4996
    then show ?case by auto
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4997
  next
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4998
    case divides
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  4999
    then show ?case by auto
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5000
  next                    
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5001
    case euclidean_relation
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5002
    then have \<open>y \<noteq> 0\<close> \<open>z \<noteq> 0\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5003
      by simp_all
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5004
    with \<open>\<not> y * z dvd x\<close> have \<open>degree (y * (x div y mod z) + x mod y) < degree (y * z)\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5005
      using degree_mod_less_degree [of y x] degree_mod_less_degree [of z \<open>x div y\<close>]
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5006
        degree_add_eq_left [of \<open>x mod y\<close> \<open>y * (x div y mod z)\<close>]
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5007
        by (cases \<open>z dvd x div y\<close>; cases \<open>y dvd x\<close>)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5008
          (auto simp add: degree_mult_eq not_dvd_imp_mod_neq_0 dvd_div_iff_mult)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5009
    moreover have \<open>x = x div y div z * (y * z) + (y * (x div y mod z) + x mod y)\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5010
      by (simp add: field_simps flip: distrib_left)
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5011
    ultimately show ?case
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5012
      by simp
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5013
  qed
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5014
  then show ?Q and ?R
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5015
    by simp_all
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5016
qed
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5017
76208
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5018
lemma dvd_pCons_imp_dvd_pCons_mod:
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5019
  \<open>y dvd pCons a (x mod y)\<close> if \<open>y dvd pCons a x\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5020
proof -
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5021
  have \<open>pCons a x = pCons a (x div y * y + x mod y)\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5022
    by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5023
  also have \<open>\<dots> = pCons 0 (x div y * y) + pCons a (x mod y)\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5024
    by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5025
  also have \<open>pCons 0 (x div y * y) = (x div y * monom 1 (Suc 0)) * y\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5026
    by (simp add: monom_Suc)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5027
  finally show \<open>y dvd pCons a (x mod y)\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5028
    using \<open>y dvd pCons a x\<close> by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5029
qed
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5030
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5031
lemma degree_less_if_less_eqI:
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5032
  \<open>degree x < degree y\<close> if \<open>degree x \<le> degree y\<close> \<open>coeff x (degree y) = 0\<close> \<open>x \<noteq> 0\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5033
proof (cases \<open>degree x = degree y\<close>)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5034
  case True
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5035
  with \<open>coeff x (degree y) = 0\<close> have \<open>lead_coeff x = 0\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5036
    by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5037
  then have \<open>x = 0\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5038
    by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5039
  with \<open>x \<noteq> 0\<close> show ?thesis
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5040
    by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5041
next
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5042
  case False
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5043
  with \<open>degree x \<le> degree y\<close> show ?thesis
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5044
    by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5045
qed
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5046
64811
5477d6b1222f obsolete
haftmann
parents: 64795
diff changeset
  5047
lemma div_pCons_eq:
76208
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5048
    \<open>pCons a p div q = (if q = 0 then 0 else pCons (coeff (pCons a (p mod q)) (degree q) / lead_coeff q) (p div q))\<close> (is ?Q)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5049
  and mod_pCons_eq:
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5050
    \<open>pCons a p mod q = (if q = 0 then pCons a p else pCons a (p mod q) - smult (coeff (pCons a (p mod q)) (degree q) / lead_coeff q) q)\<close> (is ?R)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5051
    for x y :: \<open>'a::field poly\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5052
proof -
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5053
  have \<open>?Q\<close> and \<open>?R\<close> if \<open>q = 0\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5054
    using that by simp_all
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5055
  moreover have \<open>?Q\<close> and \<open>?R\<close> if \<open>q \<noteq> 0\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5056
  proof -
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5057
    define b where \<open>b = coeff (pCons a (p mod q)) (degree q) / lead_coeff q\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5058
    have \<open>(pCons a p div q, pCons a p mod q) =
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5059
      (pCons b (p div q), (pCons a (p mod q) - smult b q))\<close> (is \<open>_ = (?q, ?r)\<close>)
76245
4111c94657b4 slightly less abusive proof pattern
haftmann
parents: 76208
diff changeset
  5060
    proof (induction rule: euclidean_relation_polyI)
76208
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5061
      case by0
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5062
      with \<open>q \<noteq> 0\<close> show ?case by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5063
    next
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5064
      case divides
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5065
      show ?case
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5066
      proof (cases \<open>pCons a (p mod q) = 0\<close>)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5067
        case True
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5068
        then show ?thesis
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5069
          by (auto simp add: b_def)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5070
      next
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5071
        case False
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5072
        have \<open>q dvd pCons a (p mod q)\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5073
          using \<open>q dvd pCons a p\<close> by (rule dvd_pCons_imp_dvd_pCons_mod)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5074
        then obtain s where *: \<open>pCons a (p mod q) = q * s\<close> ..
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5075
        with False have \<open>s \<noteq> 0\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5076
          by auto
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5077
        from \<open>q \<noteq> 0\<close> have \<open>degree (pCons a (p mod q)) \<le> degree q\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5078
          by (auto simp add: Suc_le_eq intro: degree_mod_less_degree)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5079
        moreover from \<open>s \<noteq> 0\<close> have \<open>degree q \<le> degree (pCons a (p mod q))\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5080
          by (simp add: degree_mult_right_le *)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5081
        ultimately have \<open>degree (pCons a (p mod q)) = degree q\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5082
          by (rule order.antisym)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5083
        with \<open>s \<noteq> 0\<close> \<open>q \<noteq> 0\<close> have \<open>degree s = 0\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5084
          by (simp add: * degree_mult_eq)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5085
        then obtain c where \<open>s = [:c:]\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5086
          by (rule degree_eq_zeroE)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5087
        also have \<open>c = b\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5088
          using \<open>q \<noteq> 0\<close> by (simp add: b_def * \<open>s = [:c:]\<close>)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5089
        finally have \<open>smult b q = pCons a (p mod q)\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5090
          by (simp add: *)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5091
        then show ?thesis
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5092
          by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5093
      qed
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5094
    next
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5095
      case euclidean_relation
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5096
      then have \<open>degree q > 0\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5097
        using is_unit_iff_degree by blast
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5098
      from \<open>q \<noteq> 0\<close> have \<open>degree (pCons a (p mod q)) \<le> degree q\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5099
        by (auto simp add: Suc_le_eq intro: degree_mod_less_degree)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5100
      moreover have \<open>degree (smult b q) \<le> degree q\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5101
        by (rule degree_smult_le)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5102
      ultimately have \<open>degree (pCons a (p mod q) - smult b q) \<le> degree q\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5103
        by (rule degree_diff_le)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5104
      moreover have \<open>coeff (pCons a (p mod q) - smult b q) (degree q) = 0\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5105
        using \<open>degree q > 0\<close> by (auto simp add: b_def)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5106
      ultimately have \<open>degree (pCons a (p mod q) - smult b q) < degree q\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5107
        using \<open>degree q > 0\<close>
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5108
        by (cases \<open>pCons a (p mod q) = smult b q\<close>)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5109
          (auto intro: degree_less_if_less_eqI)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5110
      then show ?case
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5111
        by simp
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5112
    qed
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5113
    with \<open>q \<noteq> 0\<close> show ?Q and ?R
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5114
      by (simp_all add: b_def)
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5115
  qed
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5116
  ultimately show ?Q and ?R
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5117
    by simp_all
14dd8b46307f streamlined division on polynomials
haftmann
parents: 76207
diff changeset
  5118
qed
64811
5477d6b1222f obsolete
haftmann
parents: 64795
diff changeset
  5119
5477d6b1222f obsolete
haftmann
parents: 64795
diff changeset
  5120
lemma div_mod_fold_coeffs:
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5121
  "(p div q, p mod q) =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5122
    (if q = 0 then (0, p)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5123
     else
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5124
      fold_coeffs
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5125
        (\<lambda>a (s, r).
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5126
          let b = coeff (pCons a r) (degree q) / coeff q (degree q)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5127
          in (pCons b s, pCons a r - smult b q)) p (0, 0))"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5128
  by (rule sym, induct p) (auto simp: div_pCons_eq mod_pCons_eq Let_def)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5129
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5130
lemma mod_pCons:
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5131
  fixes a :: "'a::field"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5132
    and x y :: "'a::field poly"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5133
  assumes y: "y \<noteq> 0"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5134
  defines "b \<equiv> coeff (pCons a (x mod y)) (degree y) / coeff y (degree y)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5135
  shows "(pCons a x) mod y = pCons a (x mod y) - smult b y"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5136
  unfolding b_def
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5137
  by (simp add: mod_pCons_eq)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5138
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5139
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5140
subsubsection \<open>List-based versions for fast implementation\<close>
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5141
(* Subsection by:
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5142
      Sebastiaan Joosten
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5143
      René Thiemann
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5144
      Akihisa Yamada
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5145
    *)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5146
fun minus_poly_rev_list :: "'a :: group_add list \<Rightarrow> 'a list \<Rightarrow> 'a list"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5147
  where
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5148
    "minus_poly_rev_list (x # xs) (y # ys) = (x - y) # (minus_poly_rev_list xs ys)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5149
  | "minus_poly_rev_list xs [] = xs"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5150
  | "minus_poly_rev_list [] (y # ys) = []"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5151
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5152
fun pseudo_divmod_main_list ::
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5153
  "'a::comm_ring_1 \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> nat \<Rightarrow> 'a list \<times> 'a list"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5154
  where
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5155
    "pseudo_divmod_main_list lc q r d (Suc n) =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5156
      (let
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5157
        rr = map ((*) lc) r;
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5158
        a = hd r;
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5159
        qqq = cCons a (map ((*) lc) q);
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5160
        rrr = tl (if a = 0 then rr else minus_poly_rev_list rr (map ((*) a) d))
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5161
       in pseudo_divmod_main_list lc qqq rrr d n)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5162
  | "pseudo_divmod_main_list lc q r d 0 = (q, r)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5163
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5164
fun pseudo_mod_main_list :: "'a::comm_ring_1 \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> nat \<Rightarrow> 'a list"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5165
  where
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5166
    "pseudo_mod_main_list lc r d (Suc n) =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5167
      (let
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5168
        rr = map ((*) lc) r;
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5169
        a = hd r;
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5170
        rrr = tl (if a = 0 then rr else minus_poly_rev_list rr (map ((*) a) d))
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5171
       in pseudo_mod_main_list lc rrr d n)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5172
  | "pseudo_mod_main_list lc r d 0 = r"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5173
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5174
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5175
fun divmod_poly_one_main_list ::
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5176
    "'a::comm_ring_1 list \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> nat \<Rightarrow> 'a list \<times> 'a list"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5177
  where
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5178
    "divmod_poly_one_main_list q r d (Suc n) =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5179
      (let
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5180
        a = hd r;
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5181
        qqq = cCons a q;
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5182
        rr = tl (if a = 0 then r else minus_poly_rev_list r (map ((*) a) d))
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5183
       in divmod_poly_one_main_list qqq rr d n)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5184
  | "divmod_poly_one_main_list q r d 0 = (q, r)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5185
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5186
fun mod_poly_one_main_list :: "'a::comm_ring_1 list \<Rightarrow> 'a list \<Rightarrow> nat \<Rightarrow> 'a list"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5187
  where
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5188
    "mod_poly_one_main_list r d (Suc n) =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5189
      (let
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5190
        a = hd r;
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5191
        rr = tl (if a = 0 then r else minus_poly_rev_list r (map ((*) a) d))
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5192
       in mod_poly_one_main_list rr d n)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5193
  | "mod_poly_one_main_list r d 0 = r"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5194
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5195
definition pseudo_divmod_list :: "'a::comm_ring_1 list \<Rightarrow> 'a list \<Rightarrow> 'a list \<times> 'a list"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5196
  where "pseudo_divmod_list p q =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5197
    (if q = [] then ([], p)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5198
     else
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5199
      (let rq = rev q;
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5200
        (qu,re) = pseudo_divmod_main_list (hd rq) [] (rev p) rq (1 + length p - length q)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5201
       in (qu, rev re)))"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5202
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5203
definition pseudo_mod_list :: "'a::comm_ring_1 list \<Rightarrow> 'a list \<Rightarrow> 'a list"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5204
  where "pseudo_mod_list p q =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5205
    (if q = [] then p
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5206
     else
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5207
      (let
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5208
        rq = rev q;
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5209
        re = pseudo_mod_main_list (hd rq) (rev p) rq (1 + length p - length q)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5210
       in rev re))"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5211
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5212
lemma minus_zero_does_nothing: "minus_poly_rev_list x (map ((*) 0) y) = x"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5213
  for x :: "'a::ring list"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5214
  by (induct x y rule: minus_poly_rev_list.induct) auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5215
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5216
lemma length_minus_poly_rev_list [simp]: "length (minus_poly_rev_list xs ys) = length xs"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5217
  by (induct xs ys rule: minus_poly_rev_list.induct) auto
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5218
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5219
lemma if_0_minus_poly_rev_list:
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5220
  "(if a = 0 then x else minus_poly_rev_list x (map ((*) a) y)) =
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5221
    minus_poly_rev_list x (map ((*) a) y)"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5222
  for a :: "'a::ring"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5223
  by(cases "a = 0") (simp_all add: minus_zero_does_nothing)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5224
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5225
lemma Poly_append: "Poly (a @ b) = Poly a + monom 1 (length a) * Poly b"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5226
  for a :: "'a::comm_semiring_1 list"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5227
  by (induct a) (auto simp: monom_0 monom_Suc)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5228
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5229
lemma minus_poly_rev_list: "length p \<ge> length q \<Longrightarrow>
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5230
  Poly (rev (minus_poly_rev_list (rev p) (rev q))) =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5231
    Poly p - monom 1 (length p - length q) * Poly q"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5232
  for p q :: "'a :: comm_ring_1 list"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5233
proof (induct "rev p" "rev q" arbitrary: p q rule: minus_poly_rev_list.induct)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5234
  case (1 x xs y ys)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5235
  then have "length (rev q) \<le> length (rev p)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5236
    by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5237
  from this[folded 1(2,3)] have ys_xs: "length ys \<le> length xs"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5238
    by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5239
  then have *: "Poly (rev (minus_poly_rev_list xs ys)) =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5240
      Poly (rev xs) - monom 1 (length xs - length ys) * Poly (rev ys)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5241
    by (subst "1.hyps"(1)[of "rev xs" "rev ys", unfolded rev_rev_ident length_rev]) auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5242
  have "Poly p - monom 1 (length p - length q) * Poly q =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5243
    Poly (rev (rev p)) - monom 1 (length (rev (rev p)) - length (rev (rev q))) * Poly (rev (rev q))"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5244
    by simp
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5245
  also have "\<dots> =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5246
      Poly (rev (x # xs)) - monom 1 (length (x # xs) - length (y # ys)) * Poly (rev (y # ys))"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5247
    unfolding 1(2,3) by simp
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5248
  also from ys_xs have "\<dots> =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5249
    Poly (rev xs) + monom x (length xs) -
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5250
      (monom 1 (length xs - length ys) * Poly (rev ys) + monom y (length xs))"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5251
    by (simp add: Poly_append distrib_left mult_monom smult_monom)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5252
  also have "\<dots> = Poly (rev (minus_poly_rev_list xs ys)) + monom (x - y) (length xs)"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5253
    unfolding * diff_monom[symmetric] by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5254
  finally show ?case
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5255
    by (simp add: 1(2,3)[symmetric] smult_monom Poly_append)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5256
qed auto
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5257
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5258
lemma smult_monom_mult: "smult a (monom b n * f) = monom (a * b) n * f"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5259
  using smult_monom [of a _ n] by (metis mult_smult_left)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5260
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5261
lemma head_minus_poly_rev_list:
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5262
  "length d \<le> length r \<Longrightarrow> d \<noteq> [] \<Longrightarrow>
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5263
    hd (minus_poly_rev_list (map ((*) (last d)) r) (map ((*) (hd r)) (rev d))) = 0"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5264
  for d r :: "'a::comm_ring list"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5265
proof (induct r)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5266
  case Nil
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5267
  then show ?case by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5268
next
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5269
  case (Cons a rs)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5270
  then show ?case by (cases "rev d") (simp_all add: ac_simps)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5271
qed
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5272
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5273
lemma Poly_map: "Poly (map ((*) a) p) = smult a (Poly p)"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5274
proof (induct p)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5275
  case Nil
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5276
  then show ?case by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5277
next
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5278
  case (Cons x xs)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5279
  then show ?case by (cases "Poly xs = 0") auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5280
qed
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5281
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5282
lemma last_coeff_is_hd: "xs \<noteq> [] \<Longrightarrow> coeff (Poly xs) (length xs - 1) = hd (rev xs)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5283
  by (simp_all add: hd_conv_nth rev_nth nth_default_nth nth_append)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5284
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5285
lemma pseudo_divmod_main_list_invar:
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5286
  assumes leading_nonzero: "last d \<noteq> 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5287
    and lc: "last d = lc"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5288
    and "d \<noteq> []"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5289
    and "pseudo_divmod_main_list lc q (rev r) (rev d) n = (q', rev r')"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5290
    and "n = 1 + length r - length d"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5291
  shows "pseudo_divmod_main lc (monom 1 n * Poly q) (Poly r) (Poly d) (length r - 1) n =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5292
    (Poly q', Poly r')"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5293
  using assms(4-)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5294
proof (induct n arbitrary: r q)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5295
  case (Suc n)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5296
  from Suc.prems have *: "\<not> Suc (length r) \<le> length d"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5297
    by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5298
  with \<open>d \<noteq> []\<close> have "r \<noteq> []"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5299
    using Suc_leI length_greater_0_conv list.size(3) by fastforce
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5300
  let ?a = "(hd (rev r))"
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5301
  let ?rr = "map ((*) lc) (rev r)"
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5302
  let ?rrr = "rev (tl (minus_poly_rev_list ?rr (map ((*) ?a) (rev d))))"
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5303
  let ?qq = "cCons ?a (map ((*) lc) q)"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5304
  from * Suc(3) have n: "n = (1 + length r - length d - 1)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5305
    by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5306
  from * have rr_val:"(length ?rrr) = (length r - 1)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5307
    by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5308
  with \<open>r \<noteq> []\<close> * have rr_smaller: "(1 + length r - length d - 1) = (1 + length ?rrr - length d)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5309
    by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5310
  from * have id: "Suc (length r) - length d = Suc (length r - length d)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5311
    by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5312
  from Suc.prems *
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5313
  have "pseudo_divmod_main_list lc ?qq (rev ?rrr) (rev d) (1 + length r - length d - 1) = (q', rev r')"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5314
    by (simp add: Let_def if_0_minus_poly_rev_list id)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5315
  with n have v: "pseudo_divmod_main_list lc ?qq (rev ?rrr) (rev d) n = (q', rev r')"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5316
    by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5317
  from * have sucrr:"Suc (length r) - length d = Suc (length r - length d)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5318
    using Suc_diff_le not_less_eq_eq by blast
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5319
  from Suc(3) \<open>r \<noteq> []\<close> have n_ok : "n = 1 + (length ?rrr) - length d"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5320
    by simp
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5321
  have cong: "\<And>x1 x2 x3 x4 y1 y2 y3 y4. x1 = y1 \<Longrightarrow> x2 = y2 \<Longrightarrow> x3 = y3 \<Longrightarrow> x4 = y4 \<Longrightarrow>
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5322
      pseudo_divmod_main lc x1 x2 x3 x4 n = pseudo_divmod_main lc y1 y2 y3 y4 n"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5323
    by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5324
  have hd_rev: "coeff (Poly r) (length r - Suc 0) = hd (rev r)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5325
    using last_coeff_is_hd[OF \<open>r \<noteq> []\<close>] by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5326
  show ?case
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5327
    unfolding Suc.hyps(1)[OF v n_ok, symmetric] pseudo_divmod_main.simps Let_def
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5328
  proof (rule cong[OF _ _ refl], goal_cases)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5329
    case 1
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5330
    show ?case
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5331
      by (simp add: monom_Suc hd_rev[symmetric] smult_monom Poly_map)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5332
  next
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5333
    case 2
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5334
    show ?case
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5335
    proof (subst Poly_on_rev_starting_with_0, goal_cases)
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5336
      show "hd (minus_poly_rev_list (map ((*) lc) (rev r)) (map ((*) (hd (rev r))) (rev d))) = 0"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5337
        by (fold lc, subst head_minus_poly_rev_list, insert * \<open>d \<noteq> []\<close>, auto)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5338
      from * have "length d \<le> length r"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5339
        by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5340
      then show "smult lc (Poly r) - monom (coeff (Poly r) (length r - 1)) n * Poly d =
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5341
          Poly (rev (minus_poly_rev_list (map ((*) lc) (rev r)) (map ((*) (hd (rev r))) (rev d))))"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5342
        by (fold rev_map) (auto simp add: n smult_monom_mult Poly_map hd_rev [symmetric]
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5343
            minus_poly_rev_list)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5344
    qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5345
  qed simp
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5346
qed simp
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5347
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5348
lemma pseudo_divmod_impl [code]:
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5349
  "pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5350
    for f g :: "'a::comm_ring_1 poly"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5351
proof (cases "g = 0")
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5352
  case False
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5353
  then have "last (coeffs g) \<noteq> 0"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5354
    and "last (coeffs g) = lead_coeff g"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5355
    and "coeffs g \<noteq> []"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5356
    by (simp_all add: last_coeffs_eq_coeff_degree)
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5357
  moreover obtain q r where qr: "pseudo_divmod_main_list
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5358
    (last (coeffs g)) (rev [])
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5359
    (rev (coeffs f)) (rev (coeffs g))
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5360
    (1 + length (coeffs f) -
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5361
    length (coeffs g)) = (q, rev (rev r))"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5362
    by force
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5363
  ultimately have "(Poly q, Poly (rev r)) = pseudo_divmod_main (lead_coeff g) 0 f g
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5364
    (length (coeffs f) - Suc 0) (Suc (length (coeffs f)) - length (coeffs g))"
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5365
    by (subst pseudo_divmod_main_list_invar [symmetric]) auto
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5366
  moreover have "pseudo_divmod_main_list
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5367
    (hd (rev (coeffs g))) []
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5368
    (rev (coeffs f)) (rev (coeffs g))
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5369
    (1 + length (coeffs f) -
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5370
    length (coeffs g)) = (q, r)"
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  5371
    by (metis hd_rev qr rev.simps(1) rev_swap)
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5372
  ultimately show ?thesis
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  5373
    by (simp add: degree_eq_length_coeffs pseudo_divmod_def pseudo_divmod_list_def)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5374
next
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5375
  case True
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5376
  then show ?thesis
65390
83586780598b more concise criterion
haftmann
parents: 65366
diff changeset
  5377
    by (auto simp add: pseudo_divmod_def pseudo_divmod_list_def)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5378
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5379
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5380
lemma pseudo_mod_main_list:
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5381
  "snd (pseudo_divmod_main_list l q xs ys n) = pseudo_mod_main_list l xs ys n"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5382
  by (induct n arbitrary: l q xs ys) (auto simp: Let_def)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5383
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5384
lemma pseudo_mod_impl[code]: "pseudo_mod f g = poly_of_list (pseudo_mod_list (coeffs f) (coeffs g))"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5385
proof -
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5386
  have snd_case: "\<And>f g p. snd ((\<lambda>(x,y). (f x, g y)) p) = g (snd p)"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5387
    by auto
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5388
  show ?thesis
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5389
    unfolding pseudo_mod_def pseudo_divmod_impl pseudo_divmod_list_def
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5390
      pseudo_mod_list_def Let_def
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5391
    by (simp add: snd_case pseudo_mod_main_list)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5392
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5393
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5394
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5395
subsubsection \<open>Improved Code-Equations for Polynomial (Pseudo) Division\<close>
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5396
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5397
lemma pdivmod_via_pseudo_divmod:
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5398
  \<open>(f div g, f mod g) =
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5399
    (if g = 0 then (0, f)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5400
     else
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5401
      let
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5402
        ilc = inverse (lead_coeff g);
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5403
        h = smult ilc g;
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5404
        (q,r) = pseudo_divmod f h
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5405
      in (smult ilc q, r))\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5406
  (is \<open>?l = ?r\<close>)
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5407
proof (cases \<open>g = 0\<close>)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5408
  case True
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5409
  then show ?thesis by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5410
next
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5411
  case False
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5412
  define ilc where \<open>ilc = inverse (lead_coeff g)\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5413
  define h where \<open>h = smult ilc g\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5414
  from False have \<open>lead_coeff h = 1\<close>
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5415
    and \<open>ilc \<noteq> 0\<close>
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5416
    by (auto simp: h_def ilc_def)
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5417
  define q r where \<open>q = f div h\<close> and \<open>r = f mod h\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5418
  with \<open>lead_coeff h = 1\<close> have p: \<open>pseudo_divmod f h = (q, r)\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5419
    by (simp add: pseudo_divmod_eq_div_mod)
76207
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5420
  from \<open>ilc \<noteq> 0\<close> have \<open>(f div g, f mod g) = (smult ilc q, r)\<close>
8fcbce9f317c streamlined division on polynomials
haftmann
parents: 76194
diff changeset
  5421
    by (auto simp: h_def div_smult_right mod_smult_right q_def r_def)
76194
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5422
  also have \<open>(smult ilc q, r) = ?r\<close>
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5423
    using \<open>g \<noteq> 0\<close> by (auto simp: Let_def p simp flip: h_def ilc_def)
d435f7b57212 streamlined division on polynomials
haftmann
parents: 76121
diff changeset
  5424
  finally show ?thesis .
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5425
qed
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5426
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5427
lemma pdivmod_via_pseudo_divmod_list:
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5428
  "(f div g, f mod g) =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5429
    (let cg = coeffs g in
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5430
      if cg = [] then (0, f)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5431
      else
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5432
        let
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5433
          cf = coeffs f;
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5434
          ilc = inverse (last cg);
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5435
          ch = map ((*) ilc) cg;
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5436
          (q, r) = pseudo_divmod_main_list 1 [] (rev cf) (rev ch) (1 + length cf - length cg)
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5437
        in (poly_of_list (map ((*) ilc) q), poly_of_list (rev r)))"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5438
proof -
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5439
  note d = pdivmod_via_pseudo_divmod pseudo_divmod_impl pseudo_divmod_list_def
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5440
  show ?thesis
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5441
  proof (cases "g = 0")
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5442
    case True
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5443
    with d show ?thesis by auto
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5444
  next
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5445
    case False
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5446
    define ilc where "ilc = inverse (coeff g (degree g))"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5447
    from False have ilc: "ilc \<noteq> 0"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5448
      by (auto simp: ilc_def)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5449
    with False have id: "g = 0 \<longleftrightarrow> False" "coeffs g = [] \<longleftrightarrow> False"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5450
      "last (coeffs g) = coeff g (degree g)"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5451
      "coeffs (smult ilc g) = [] \<longleftrightarrow> False"
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5452
      by (auto simp: last_coeffs_eq_coeff_degree)
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5453
    have id2: "hd (rev (coeffs (smult ilc g))) = 1"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5454
      by (subst hd_rev, insert id ilc, auto simp: coeffs_smult, subst last_map, auto simp: id ilc_def)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5455
    have id3: "length (coeffs (smult ilc g)) = length (coeffs g)"
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5456
      "rev (coeffs (smult ilc g)) = rev (map ((*) ilc) (coeffs g))"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5457
      unfolding coeffs_smult using ilc by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5458
    obtain q r where pair:
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5459
      "pseudo_divmod_main_list 1 [] (rev (coeffs f)) (rev (map ((*) ilc) (coeffs g)))
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5460
        (1 + length (coeffs f) - length (coeffs g)) = (q, r)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5461
      by force
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5462
    show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5463
      unfolding d Let_def id if_False ilc_def[symmetric] map_prod_def[symmetric] id2
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5464
      unfolding id3 pair map_prod_def split
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5465
      by (auto simp: Poly_map)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5466
  qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5467
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5468
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5469
lemma pseudo_divmod_main_list_1: "pseudo_divmod_main_list 1 = divmod_poly_one_main_list"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5470
proof (intro ext, goal_cases)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5471
  case (1 q r d n)
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5472
  have *: "map ((*) 1) xs = xs" for xs :: "'a list"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5473
    by (induct xs) auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5474
  show ?case
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5475
    by (induct n arbitrary: q r d) (auto simp: * Let_def)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5476
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5477
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5478
fun divide_poly_main_list :: "'a::idom_divide \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> nat \<Rightarrow> 'a list"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5479
  where
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5480
    "divide_poly_main_list lc q r d (Suc n) =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5481
      (let
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5482
        cr = hd r
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5483
        in if cr = 0 then divide_poly_main_list lc (cCons cr q) (tl r) d n else let
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5484
        a = cr div lc;
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5485
        qq = cCons a q;
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5486
        rr = minus_poly_rev_list r (map ((*) a) d)
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5487
       in if hd rr = 0 then divide_poly_main_list lc qq (tl rr) d n else [])"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5488
  | "divide_poly_main_list lc q r d 0 = q"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5489
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5490
lemma divide_poly_main_list_simp [simp]:
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5491
  "divide_poly_main_list lc q r d (Suc n) =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5492
    (let
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5493
      cr = hd r;
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5494
      a = cr div lc;
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5495
      qq = cCons a q;
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5496
      rr = minus_poly_rev_list r (map ((*) a) d)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5497
     in if hd rr = 0 then divide_poly_main_list lc qq (tl rr) d n else [])"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5498
  by (simp add: Let_def minus_zero_does_nothing)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5499
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5500
declare divide_poly_main_list.simps(1)[simp del]
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5501
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5502
definition divide_poly_list :: "'a::idom_divide poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5503
  where "divide_poly_list f g =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5504
    (let cg = coeffs g in
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5505
      if cg = [] then g
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5506
      else
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5507
        let
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5508
          cf = coeffs f;
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5509
          cgr = rev cg
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5510
        in poly_of_list (divide_poly_main_list (hd cgr) [] (rev cf) cgr (1 + length cf - length cg)))"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5511
64811
5477d6b1222f obsolete
haftmann
parents: 64795
diff changeset
  5512
lemmas pdivmod_via_divmod_list = pdivmod_via_pseudo_divmod_list[unfolded pseudo_divmod_main_list_1]
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5513
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5514
lemma mod_poly_one_main_list: "snd (divmod_poly_one_main_list q r d n) = mod_poly_one_main_list r d n"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5515
  by (induct n arbitrary: q r d) (auto simp: Let_def)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5516
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5517
lemma mod_poly_code [code]:
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5518
  "f mod g =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5519
    (let cg = coeffs g in
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5520
      if cg = [] then f
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5521
      else
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5522
        let
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5523
          cf = coeffs f;
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5524
          ilc = inverse (last cg);
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5525
          ch = map ((*) ilc) cg;
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5526
          r = mod_poly_one_main_list (rev cf) (rev ch) (1 + length cf - length cg)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5527
        in poly_of_list (rev r))"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5528
  (is "_ = ?rhs")
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5529
proof -
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5530
  have "snd (f div g, f mod g) = ?rhs"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5531
    unfolding pdivmod_via_divmod_list Let_def mod_poly_one_main_list [symmetric, of _ _ _ Nil]
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5532
    by (auto split: prod.splits)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5533
  then show ?thesis by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5534
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5535
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5536
definition div_field_poly_impl :: "'a :: field poly \<Rightarrow> 'a poly \<Rightarrow> 'a poly"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5537
  where "div_field_poly_impl f g =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5538
    (let cg = coeffs g in
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5539
      if cg = [] then 0
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5540
      else
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5541
        let
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5542
          cf = coeffs f;
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5543
          ilc = inverse (last cg);
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5544
          ch = map ((*) ilc) cg;
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5545
          q = fst (divmod_poly_one_main_list [] (rev cf) (rev ch) (1 + length cf - length cg))
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5546
        in poly_of_list ((map ((*) ilc) q)))"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5547
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5548
text \<open>We do not declare the following lemma as code equation, since then polynomial division
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5549
  on non-fields will no longer be executable. However, a code-unfold is possible, since
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5550
  \<open>div_field_poly_impl\<close> is a bit more efficient than the generic polynomial division.\<close>
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67369
diff changeset
  5551
lemma div_field_poly_impl[code_unfold]: "(div) = div_field_poly_impl"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5552
proof (intro ext)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5553
  fix f g :: "'a poly"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5554
  have "fst (f div g, f mod g) = div_field_poly_impl f g"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5555
    unfolding div_field_poly_impl_def pdivmod_via_divmod_list Let_def
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5556
    by (auto split: prod.splits)
64811
5477d6b1222f obsolete
haftmann
parents: 64795
diff changeset
  5557
  then show "f div g =  div_field_poly_impl f g"
5477d6b1222f obsolete
haftmann
parents: 64795
diff changeset
  5558
    by simp
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5559
qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5560
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5561
lemma divide_poly_main_list:
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5562
  assumes lc0: "lc \<noteq> 0"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5563
    and lc: "last d = lc"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5564
    and d: "d \<noteq> []"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5565
    and "n = (1 + length r - length d)"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5566
  shows "Poly (divide_poly_main_list lc q (rev r) (rev d) n) =
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5567
    divide_poly_main lc (monom 1 n * Poly q) (Poly r) (Poly d) (length r - 1) n"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5568
  using assms(4-)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5569
proof (induct "n" arbitrary: r q)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5570
  case (Suc n)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5571
  from Suc.prems have ifCond: "\<not> Suc (length r) \<le> length d"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5572
    by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5573
  with d have r: "r \<noteq> []"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5574
    using Suc_leI length_greater_0_conv list.size(3) by fastforce
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5575
  then obtain rr lcr where r: "r = rr @ [lcr]"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5576
    by (cases r rule: rev_cases) auto
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5577
  from d lc obtain dd where d: "d = dd @ [lc]"
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5578
    by (cases d rule: rev_cases) auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5579
  from Suc(2) ifCond have n: "n = 1 + length rr - length d"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5580
    by (auto simp: r)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5581
  from ifCond have len: "length dd \<le> length rr"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5582
    by (simp add: r d)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5583
  show ?case
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5584
  proof (cases "lcr div lc * lc = lcr")
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5585
    case False
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5586
    with r d show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5587
      unfolding Suc(2)[symmetric]
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5588
      by (auto simp add: Let_def nth_default_append)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5589
  next
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5590
    case True
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5591
    with r d have id:
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5592
      "?thesis \<longleftrightarrow>
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5593
        Poly (divide_poly_main_list lc (cCons (lcr div lc) q)
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 69022
diff changeset
  5594
          (rev (rev (minus_poly_rev_list (rev rr) (rev (map ((*) (lcr div lc)) dd))))) (rev d) n) =
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5595
          divide_poly_main lc
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5596
            (monom 1 (Suc n) * Poly q + monom (lcr div lc) n)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5597
            (Poly r - monom (lcr div lc) n * Poly d)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5598
            (Poly d) (length rr - 1) n"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5599
      by (cases r rule: rev_cases; cases "d" rule: rev_cases)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5600
        (auto simp add: Let_def rev_map nth_default_append)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5601
    have cong: "\<And>x1 x2 x3 x4 y1 y2 y3 y4. x1 = y1 \<Longrightarrow> x2 = y2 \<Longrightarrow> x3 = y3 \<Longrightarrow> x4 = y4 \<Longrightarrow>
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5602
        divide_poly_main lc x1 x2 x3 x4 n = divide_poly_main lc y1 y2 y3 y4 n"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5603
      by simp
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5604
    show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5605
      unfolding id
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5606
    proof (subst Suc(1), simp add: n,
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5607
        subst minus_poly_rev_list, force simp: len, rule cong[OF _ _ refl], goal_cases)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5608
      case 2
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5609
      have "monom lcr (length rr) = monom (lcr div lc) (length rr - length dd) * monom lc (length dd)"
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5610
        by (simp add: mult_monom len True)
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5611
      then show ?case unfolding r d Poly_append n ring_distribs
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5612
        by (auto simp: Poly_map smult_monom smult_monom_mult)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5613
    qed (auto simp: len monom_Suc smult_monom)
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5614
  qed
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5615
qed simp
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5616
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5617
lemma divide_poly_list[code]: "f div g = divide_poly_list f g"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5618
proof -
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5619
  note d = divide_poly_def divide_poly_list_def
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5620
  show ?thesis
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5621
  proof (cases "g = 0")
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5622
    case True
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5623
    show ?thesis by (auto simp: d True)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5624
  next
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5625
    case False
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5626
    then obtain cg lcg where cg: "coeffs g = cg @ [lcg]"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5627
      by (cases "coeffs g" rule: rev_cases) auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5628
    with False have id: "(g = 0) = False" "(cg @ [lcg] = []) = False"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5629
      by auto
65346
673a7b3379ec misc tuning and modernization;
wenzelm
parents: 64861
diff changeset
  5630
    from cg False have lcg: "coeff g (degree g) = lcg"
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5631
      using last_coeffs_eq_coeff_degree last_snoc by force
65347
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5632
    with False have "lcg \<noteq> 0" by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5633
    from cg Poly_coeffs [of g] have ltp: "Poly (cg @ [lcg]) = g"
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5634
      by auto
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5635
    show ?thesis
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5636
      unfolding d cg Let_def id if_False poly_of_list_def
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5637
      by (subst divide_poly_main_list, insert False cg \<open>lcg \<noteq> 0\<close>)
d27f9b4e027d misc tuning and modernization;
wenzelm
parents: 65346
diff changeset
  5638
        (auto simp: lcg ltp, simp add: degree_eq_length_coeffs)
64795
8e7db8df16a0 tuned structure
haftmann
parents: 64794
diff changeset
  5639
  qed
63317
ca187a9f66da Various additions to polynomials, FPSs, Gamma function
eberlm
parents: 63145
diff changeset
  5640
qed
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 49962
diff changeset
  5641
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5642
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5643
subsection \<open>Primality and irreducibility in polynomial rings\<close>
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5644
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5645
lemma prod_mset_const_poly: "(\<Prod>x\<in>#A. [:f x:]) = [:prod_mset (image_mset f A):]"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5646
  by (induct A) (simp_all add: ac_simps)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5647
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5648
lemma irreducible_const_poly_iff:
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5649
  fixes c :: "'a :: {comm_semiring_1,semiring_no_zero_divisors}"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5650
  shows "irreducible [:c:] \<longleftrightarrow> irreducible c"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5651
proof
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5652
  assume A: "irreducible c"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5653
  show "irreducible [:c:]"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5654
  proof (rule irreducibleI)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5655
    fix a b assume ab: "[:c:] = a * b"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5656
    hence "degree [:c:] = degree (a * b)" by (simp only: )
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5657
    also from A ab have "a \<noteq> 0" "b \<noteq> 0" by auto
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5658
    hence "degree (a * b) = degree a + degree b" by (simp add: degree_mult_eq)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5659
    finally have "degree a = 0" "degree b = 0" by auto
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5660
    then obtain a' b' where ab': "a = [:a':]" "b = [:b':]" by (auto elim!: degree_eq_zeroE)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5661
    from ab have "coeff [:c:] 0 = coeff (a * b) 0" by (simp only: )
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5662
    hence "c = a' * b'" by (simp add: ab' mult_ac)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5663
    from A and this have "a' dvd 1 \<or> b' dvd 1" by (rule irreducibleD)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5664
    with ab' show "a dvd 1 \<or> b dvd 1"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5665
      by (auto simp add: is_unit_const_poly_iff)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5666
  qed (insert A, auto simp: irreducible_def is_unit_poly_iff)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5667
next
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5668
  assume A: "irreducible [:c:]"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5669
  then have "c \<noteq> 0" and "\<not> c dvd 1"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5670
    by (auto simp add: irreducible_def is_unit_const_poly_iff)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5671
  then show "irreducible c"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5672
  proof (rule irreducibleI)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5673
    fix a b assume ab: "c = a * b"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5674
    hence "[:c:] = [:a:] * [:b:]" by (simp add: mult_ac)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5675
    from A and this have "[:a:] dvd 1 \<or> [:b:] dvd 1" by (rule irreducibleD)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5676
    then show "a dvd 1 \<or> b dvd 1"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5677
      by (auto simp add: is_unit_const_poly_iff)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5678
  qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5679
qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5680
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5681
lemma lift_prime_elem_poly:
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5682
  assumes "prime_elem (c :: 'a :: semidom)"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5683
  shows   "prime_elem [:c:]"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5684
proof (rule prime_elemI)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5685
  fix a b assume *: "[:c:] dvd a * b"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5686
  from * have dvd: "c dvd coeff (a * b) n" for n
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5687
    by (subst (asm) const_poly_dvd_iff) blast
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5688
  {
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5689
    define m where "m = (GREATEST m. \<not>c dvd coeff b m)"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5690
    assume "\<not>[:c:] dvd b"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5691
    hence A: "\<exists>i. \<not>c dvd coeff b i" by (subst (asm) const_poly_dvd_iff) blast
71586
e30dbfa53b0d new-style Greater lemmas
paulson <lp15@cam.ac.uk>
parents: 71398
diff changeset
  5692
    have B: "\<And>i. \<not>c dvd coeff b i \<Longrightarrow> i \<le> degree b"
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5693
      by (auto intro: le_degree)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5694
    have coeff_m: "\<not>c dvd coeff b m" unfolding m_def by (rule GreatestI_ex_nat[OF A B])
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5695
    have "i \<le> m" if "\<not>c dvd coeff b i" for i
71586
e30dbfa53b0d new-style Greater lemmas
paulson <lp15@cam.ac.uk>
parents: 71398
diff changeset
  5696
      unfolding m_def by (metis (mono_tags, lifting) B Greatest_le_nat that)
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5697
    hence dvd_b: "c dvd coeff b i" if "i > m" for i using that by force
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5698
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5699
    have "c dvd coeff a i" for i
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5700
    proof (induction i rule: nat_descend_induct[of "degree a"])
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5701
      case (base i)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5702
      thus ?case by (simp add: coeff_eq_0)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5703
    next
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5704
      case (descend i)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5705
      let ?A = "{..i+m} - {i}"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5706
      have "c dvd coeff (a * b) (i + m)" by (rule dvd)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5707
      also have "coeff (a * b) (i + m) = (\<Sum>k\<le>i + m. coeff a k * coeff b (i + m - k))"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5708
        by (simp add: coeff_mult)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5709
      also have "{..i+m} = insert i ?A" by auto
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5710
      also have "(\<Sum>k\<in>\<dots>. coeff a k * coeff b (i + m - k)) =
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5711
                   coeff a i * coeff b m + (\<Sum>k\<in>?A. coeff a k * coeff b (i + m - k))"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5712
        (is "_ = _ + ?S")
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5713
        by (subst sum.insert) simp_all
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5714
      finally have eq: "c dvd coeff a i * coeff b m + ?S" .
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5715
      moreover have "c dvd ?S"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5716
      proof (rule dvd_sum)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5717
        fix k assume k: "k \<in> {..i+m} - {i}"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5718
        show "c dvd coeff a k * coeff b (i + m - k)"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5719
        proof (cases "k < i")
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5720
          case False
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5721
          with k have "c dvd coeff a k" by (intro descend.IH) simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5722
          thus ?thesis by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5723
        next
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5724
          case True
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5725
          hence "c dvd coeff b (i + m - k)" by (intro dvd_b) simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5726
          thus ?thesis by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5727
        qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5728
      qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5729
      ultimately have "c dvd coeff a i * coeff b m"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5730
        by (simp add: dvd_add_left_iff)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5731
      with assms coeff_m show "c dvd coeff a i"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5732
        by (simp add: prime_elem_dvd_mult_iff)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5733
    qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5734
    hence "[:c:] dvd a" by (subst const_poly_dvd_iff) blast
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5735
  }
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5736
  then show "[:c:] dvd a \<or> [:c:] dvd b" by blast
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5737
next
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5738
  from assms show "[:c:] \<noteq> 0" and "\<not> [:c:] dvd 1"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5739
    by (simp_all add: prime_elem_def is_unit_const_poly_iff)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5740
qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5741
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5742
lemma prime_elem_const_poly_iff:
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5743
  fixes c :: "'a :: semidom"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5744
  shows   "prime_elem [:c:] \<longleftrightarrow> prime_elem c"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5745
proof
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5746
  assume A: "prime_elem [:c:]"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5747
  show "prime_elem c"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5748
  proof (rule prime_elemI)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5749
    fix a b assume "c dvd a * b"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5750
    hence "[:c:] dvd [:a:] * [:b:]" by (simp add: mult_ac)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5751
    from A and this have "[:c:] dvd [:a:] \<or> [:c:] dvd [:b:]" by (rule prime_elem_dvd_multD)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5752
    thus "c dvd a \<or> c dvd b" by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5753
  qed (insert A, auto simp: prime_elem_def is_unit_poly_iff)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5754
qed (auto intro: lift_prime_elem_poly)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5755
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5756
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5757
subsection \<open>Content and primitive part of a polynomial\<close>
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5758
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5759
definition content :: "'a::semiring_gcd poly \<Rightarrow> 'a"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5760
  where "content p = gcd_list (coeffs p)"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5761
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5762
lemma content_eq_fold_coeffs [code]: "content p = fold_coeffs gcd p 0"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5763
  by (simp add: content_def Gcd_fin.set_eq_fold fold_coeffs_def foldr_fold fun_eq_iff ac_simps)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5764
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5765
lemma content_0 [simp]: "content 0 = 0"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5766
  by (simp add: content_def)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5767
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5768
lemma content_1 [simp]: "content 1 = 1"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5769
  by (simp add: content_def)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5770
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5771
lemma content_const [simp]: "content [:c:] = normalize c"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5772
  by (simp add: content_def cCons_def)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5773
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5774
lemma const_poly_dvd_iff_dvd_content: "[:c:] dvd p \<longleftrightarrow> c dvd content p"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5775
  for c :: "'a::semiring_gcd"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5776
proof (cases "p = 0")
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5777
  case True
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5778
  then show ?thesis by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5779
next
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5780
  case False
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5781
  have "[:c:] dvd p \<longleftrightarrow> (\<forall>n. c dvd coeff p n)"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5782
    by (rule const_poly_dvd_iff)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5783
  also have "\<dots> \<longleftrightarrow> (\<forall>a\<in>set (coeffs p). c dvd a)"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5784
  proof safe
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5785
    fix n :: nat
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5786
    assume "\<forall>a\<in>set (coeffs p). c dvd a"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5787
    then show "c dvd coeff p n"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5788
      by (cases "n \<le> degree p") (auto simp: coeff_eq_0 coeffs_def split: if_splits)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5789
  qed (auto simp: coeffs_def simp del: upt_Suc split: if_splits)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5790
  also have "\<dots> \<longleftrightarrow> c dvd content p"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5791
    by (simp add: content_def dvd_Gcd_fin_iff dvd_mult_unit_iff)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5792
  finally show ?thesis .
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5793
qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5794
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5795
lemma content_dvd [simp]: "[:content p:] dvd p"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5796
  by (subst const_poly_dvd_iff_dvd_content) simp_all
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5797
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5798
lemma content_dvd_coeff [simp]: "content p dvd coeff p n"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5799
proof (cases "p = 0")
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5800
  case True
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5801
  then show ?thesis
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5802
    by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5803
next
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5804
  case False
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5805
  then show ?thesis
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5806
    by (cases "n \<le> degree p")
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5807
      (auto simp add: content_def not_le coeff_eq_0 coeff_in_coeffs intro: Gcd_fin_dvd)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5808
qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5809
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5810
lemma content_dvd_coeffs: "c \<in> set (coeffs p) \<Longrightarrow> content p dvd c"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5811
  by (simp add: content_def Gcd_fin_dvd)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5812
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5813
lemma normalize_content [simp]: "normalize (content p) = content p"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5814
  by (simp add: content_def)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5815
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5816
lemma is_unit_content_iff [simp]: "is_unit (content p) \<longleftrightarrow> content p = 1"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5817
proof
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5818
  assume "is_unit (content p)"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5819
  then have "normalize (content p) = 1" by (simp add: is_unit_normalize del: normalize_content)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5820
  then show "content p = 1" by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5821
qed auto
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5822
71398
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  5823
lemma content_smult [simp]:
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  5824
  fixes c :: "'a :: {normalization_semidom_multiplicative, semiring_gcd}"
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  5825
  shows "content (smult c p) = normalize c * content p"
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  5826
  by (simp add: content_def coeffs_smult Gcd_fin_mult normalize_mult)
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5827
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5828
lemma content_eq_zero_iff [simp]: "content p = 0 \<longleftrightarrow> p = 0"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5829
  by (auto simp: content_def simp: poly_eq_iff coeffs_def)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5830
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5831
definition primitive_part :: "'a :: semiring_gcd poly \<Rightarrow> 'a poly"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5832
  where "primitive_part p = map_poly (\<lambda>x. x div content p) p"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5833
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5834
lemma primitive_part_0 [simp]: "primitive_part 0 = 0"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5835
  by (simp add: primitive_part_def)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5836
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5837
lemma content_times_primitive_part [simp]: "smult (content p) (primitive_part p) = p"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5838
  for p :: "'a :: semiring_gcd poly"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5839
proof (cases "p = 0")
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5840
  case True
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5841
  then show ?thesis by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5842
next
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5843
  case False
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5844
  then show ?thesis
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5845
  unfolding primitive_part_def
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5846
  by (auto simp: smult_conv_map_poly map_poly_map_poly o_def content_dvd_coeffs
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5847
      intro: map_poly_idI)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5848
qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5849
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5850
lemma primitive_part_eq_0_iff [simp]: "primitive_part p = 0 \<longleftrightarrow> p = 0"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5851
proof (cases "p = 0")
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5852
  case True
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5853
  then show ?thesis by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5854
next
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5855
  case False
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5856
  then have "primitive_part p = map_poly (\<lambda>x. x div content p) p"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5857
    by (simp add:  primitive_part_def)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5858
  also from False have "\<dots> = 0 \<longleftrightarrow> p = 0"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5859
    by (intro map_poly_eq_0_iff) (auto simp: dvd_div_eq_0_iff content_dvd_coeffs)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5860
  finally show ?thesis
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5861
    using False by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5862
qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5863
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5864
lemma content_primitive_part [simp]:
71398
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  5865
  fixes p :: "'a :: {normalization_semidom_multiplicative, semiring_gcd} poly"
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5866
  assumes "p \<noteq> 0"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5867
  shows "content (primitive_part p) = 1"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5868
proof -
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5869
  have "p = smult (content p) (primitive_part p)"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5870
    by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5871
  also have "content \<dots> = content (primitive_part p) * content p"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5872
    by (simp del: content_times_primitive_part add: ac_simps)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5873
  finally have "1 * content p = content (primitive_part p) * content p"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5874
    by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5875
  then have "1 * content p div content p = content (primitive_part p) * content p div content p"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5876
    by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5877
  with assms show ?thesis
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5878
    by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5879
qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5880
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5881
lemma content_decompose:
71398
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  5882
  obtains p' :: "'a :: {normalization_semidom_multiplicative, semiring_gcd} poly"
68790
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5883
  where "p = smult (content p) p'" "content p' = 1"
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5884
proof (cases "p = 0")
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5885
  case True
68790
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5886
  then have "p = smult (content p) 1" "content 1 = 1"
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5887
    by simp_all
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5888
  then show ?thesis ..
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5889
next
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5890
  case False
68790
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5891
  then have "p = smult (content p) (primitive_part p)" "content (primitive_part p) = 1"
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5892
    by simp_all
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5893
  then show ?thesis ..
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5894
qed
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  5895
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5896
lemma content_dvd_contentI [intro]: "p dvd q \<Longrightarrow> content p dvd content q"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5897
  using const_poly_dvd_iff_dvd_content content_dvd dvd_trans by blast
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5898
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5899
lemma primitive_part_const_poly [simp]: "primitive_part [:x:] = [:unit_factor x:]"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5900
  by (simp add: primitive_part_def map_poly_pCons)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5901
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5902
lemma primitive_part_prim: "content p = 1 \<Longrightarrow> primitive_part p = p"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5903
  by (auto simp: primitive_part_def)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5904
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5905
lemma degree_primitive_part [simp]: "degree (primitive_part p) = degree p"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5906
proof (cases "p = 0")
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5907
  case True
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5908
  then show ?thesis by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5909
next
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5910
  case False
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5911
  have "p = smult (content p) (primitive_part p)"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5912
    by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5913
  also from False have "degree \<dots> = degree (primitive_part p)"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5914
    by (subst degree_smult_eq) simp_all
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5915
  finally show ?thesis ..
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5916
qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5917
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5918
lemma smult_content_normalize_primitive_part [simp]:
71398
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  5919
  fixes p :: "'a :: {normalization_semidom_multiplicative, semiring_gcd, idom_divide} poly"
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  5920
  shows "smult (content p) (normalize (primitive_part p)) = normalize p"
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5921
proof -
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5922
  have "smult (content p) (normalize (primitive_part p)) =
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5923
      normalize ([:content p:] * primitive_part p)"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5924
    by (subst normalize_mult) (simp_all add: normalize_const_poly)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5925
  also have "[:content p:] * primitive_part p = p" by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5926
  finally show ?thesis .
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5927
qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5928
68790
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5929
context
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5930
begin
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5931
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5932
private
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5933
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5934
lemma content_1_mult:
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5935
  fixes f g :: "'a :: {semiring_gcd, factorial_semiring} poly"
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5936
  assumes "content f = 1" "content g = 1"
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5937
  shows   "content (f * g) = 1"
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5938
proof (cases "f * g = 0")
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5939
  case False
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5940
  from assms have "f \<noteq> 0" "g \<noteq> 0" by auto
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5941
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5942
  hence "f * g \<noteq> 0" by auto
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5943
  {
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5944
    assume "\<not>is_unit (content (f * g))"
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5945
    with False have "\<exists>p. p dvd content (f * g) \<and> prime p"
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5946
      by (intro prime_divisor_exists) simp_all
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5947
    then obtain p where "p dvd content (f * g)" "prime p" by blast
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5948
    from \<open>p dvd content (f * g)\<close> have "[:p:] dvd f * g"
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5949
      by (simp add: const_poly_dvd_iff_dvd_content)
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5950
    moreover from \<open>prime p\<close> have "prime_elem [:p:]" by (simp add: lift_prime_elem_poly)
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5951
    ultimately have "[:p:] dvd f \<or> [:p:] dvd g"
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5952
      by (simp add: prime_elem_dvd_mult_iff)
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5953
    with assms have "is_unit p" by (simp add: const_poly_dvd_iff_dvd_content)
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5954
    with \<open>prime p\<close> have False by simp
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5955
  }
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5956
  hence "is_unit (content (f * g))" by blast
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5957
  hence "normalize (content (f * g)) = 1" by (simp add: is_unit_normalize del: normalize_content)
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5958
  thus ?thesis by simp
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5959
qed (insert assms, auto)
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5960
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5961
lemma content_mult:
71398
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  5962
  fixes p q :: "'a :: {factorial_semiring, semiring_gcd, normalization_semidom_multiplicative} poly"
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5963
  shows "content (p * q) = content p * content q"
68790
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5964
proof (cases "p * q = 0")
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5965
  case False
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5966
  then have "p \<noteq> 0" and "q \<noteq> 0"
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5967
    by simp_all
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5968
  then have *: "content (primitive_part p * primitive_part q) = 1"
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5969
    by (auto intro: content_1_mult)
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5970
  have "p * q = smult (content p) (primitive_part p) * smult (content q) (primitive_part q)"
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5971
    by simp
68790
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5972
  also have "\<dots> = smult (content p * content q) (primitive_part p * primitive_part q)"
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5973
    by (metis mult.commute mult_smult_right smult_smult)
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5974
  with * show ?thesis
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5975
  by (simp add: normalize_mult)
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5976
next
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5977
  case True
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5978
  then show ?thesis
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5979
    by auto
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5980
qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5981
68790
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5982
end
851a9d9746c6 prefer constructive primitive_part over implicit content_decompose
haftmann
parents: 68534
diff changeset
  5983
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5984
lemma primitive_part_mult:
71398
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  5985
  fixes p q :: "'a :: {factorial_semiring, semiring_Gcd, ring_gcd, idom_divide,
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  5986
                       normalization_semidom_multiplicative} poly"
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5987
  shows "primitive_part (p * q) = primitive_part p * primitive_part q"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5988
proof -
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5989
  have "primitive_part (p * q) = p * q div [:content (p * q):]"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5990
    by (simp add: primitive_part_def div_const_poly_conv_map_poly)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5991
  also have "\<dots> = (p div [:content p:]) * (q div [:content q:])"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5992
    by (subst div_mult_div_if_dvd) (simp_all add: content_mult mult_ac)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5993
  also have "\<dots> = primitive_part p * primitive_part q"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5994
    by (simp add: primitive_part_def div_const_poly_conv_map_poly)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5995
  finally show ?thesis .
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5996
qed
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5997
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  5998
lemma primitive_part_smult:
71398
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  5999
  fixes p :: "'a :: {factorial_semiring, semiring_Gcd, ring_gcd, idom_divide,
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  6000
                     normalization_semidom_multiplicative} poly"
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6001
  shows "primitive_part (smult a p) = smult (unit_factor a) (primitive_part p)"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6002
proof -
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6003
  have "smult a p = [:a:] * p" by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6004
  also have "primitive_part \<dots> = smult (unit_factor a) (primitive_part p)"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6005
    by (subst primitive_part_mult) simp_all
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6006
  finally show ?thesis .
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  6007
qed
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6008
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6009
lemma primitive_part_dvd_primitive_partI [intro]:
71398
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  6010
  fixes p q :: "'a :: {factorial_semiring, semiring_Gcd, ring_gcd, idom_divide,
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  6011
                       normalization_semidom_multiplicative} poly"
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6012
  shows "p dvd q \<Longrightarrow> primitive_part p dvd primitive_part q"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6013
  by (auto elim!: dvdE simp: primitive_part_mult)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6014
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  6015
lemma content_prod_mset:
71398
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  6016
  fixes A :: "'a :: {factorial_semiring, semiring_Gcd, normalization_semidom_multiplicative}
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  6017
      poly multiset"
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6018
  shows "content (prod_mset A) = prod_mset (image_mset content A)"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6019
  by (induction A) (simp_all add: content_mult mult_ac)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6020
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  6021
lemma content_prod_eq_1_iff:
71398
e0237f2eb49d Removed multiplicativity assumption from normalization_semidom
Manuel Eberl <eberlm@in.tum.de>
parents: 70113
diff changeset
  6022
  fixes p q :: "'a :: {factorial_semiring, semiring_Gcd, normalization_semidom_multiplicative} poly"
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6023
  shows "content (p * q) = 1 \<longleftrightarrow> content p = 1 \<and> content q = 1"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6024
proof safe
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6025
  assume A: "content (p * q) = 1"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6026
  {
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6027
    fix p q :: "'a poly" assume "content p * content q = 1"
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6028
    hence "1 = content p * content q" by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6029
    hence "content p dvd 1" by (rule dvdI)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6030
    hence "content p = 1" by simp
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6031
  } note B = this
73510
c526eb2c7ca0 removal of needless hypothesis in hd_rev and last_rev
paulson <lp15@cam.ac.uk>
parents: 73114
diff changeset
  6032
  from A B[of p q] B [of q p] show "content p = 1" "content q = 1"
66805
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6033
    by (simp_all add: content_mult mult_ac)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6034
qed (auto simp: content_mult)
274b4edca859 Polynomial_Factorial does not depend on Field_as_Ring as such
haftmann
parents: 66799
diff changeset
  6035
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6036
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6037
subsection \<open>A typeclass for algebraically closed fields\<close>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6038
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6039
(* TODO: Move! *)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6040
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6041
text \<open>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6042
  Since the required sort constraints are not available inside the class, we have to resort
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6043
  to a somewhat awkward way of writing the definition of algebraically closed fields:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6044
\<close>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6045
class alg_closed_field = field +
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6046
  assumes alg_closed: "n > 0 \<Longrightarrow> f n \<noteq> 0 \<Longrightarrow> \<exists>x. (\<Sum>k\<le>n. f k * x ^ k) = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6047
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6048
text \<open>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6049
  We can then however easily show the equivalence to the proper definition:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6050
\<close>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6051
lemma alg_closed_imp_poly_has_root:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6052
  assumes "degree (p :: 'a :: alg_closed_field poly) > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6053
  shows   "\<exists>x. poly p x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6054
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6055
  have "\<exists>x. (\<Sum>k\<le>degree p. coeff p k * x ^ k) = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6056
    using assms by (intro alg_closed) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6057
  thus ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6058
    by (simp add: poly_altdef)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6059
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6060
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6061
lemma alg_closedI [Pure.intro]:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6062
  assumes "\<And>p :: 'a poly. degree p > 0 \<Longrightarrow> lead_coeff p = 1 \<Longrightarrow> \<exists>x. poly p x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6063
  shows   "OFCLASS('a :: field, alg_closed_field_class)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6064
proof
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6065
  fix n :: nat and f :: "nat \<Rightarrow> 'a"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6066
  assume n: "n > 0" "f n \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6067
  define p where "p = Abs_poly (\<lambda>k. if k \<le> n then f k else 0)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6068
  have coeff_p: "coeff p k = (if k \<le> n then f k else 0)" for k
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6069
  proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6070
    have "eventually (\<lambda>k. k > n) cofinite"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6071
      by (auto simp: MOST_nat)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6072
    hence "eventually (\<lambda>k. (if k \<le> n then f k else 0) = 0) cofinite"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6073
      by eventually_elim auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6074
    thus ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6075
      unfolding p_def by (subst Abs_poly_inverse) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6076
  qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6077
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6078
  from n have "degree p \<ge> n"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6079
    by (intro le_degree) (auto simp: coeff_p)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6080
  moreover have "degree p \<le> n"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6081
    by (intro degree_le) (auto simp: coeff_p)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6082
  ultimately have deg_p: "degree p = n"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6083
    by linarith
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6084
  from deg_p and n have [simp]: "p \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6085
    by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6086
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6087
  define p' where "p' = smult (inverse (lead_coeff p)) p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6088
  have deg_p': "degree p' = degree p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6089
    by (auto simp: p'_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6090
  have lead_coeff_p' [simp]: "lead_coeff p' = 1"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6091
    by (auto simp: p'_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6092
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6093
  from deg_p and deg_p' and n have "degree p' > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6094
    by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6095
  from assms[OF this] obtain x where "poly p' x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6096
    by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6097
  hence "poly p x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6098
    by (simp add: p'_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6099
  also have "poly p x = (\<Sum>k\<le>n. f k * x ^ k)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6100
    unfolding poly_altdef by (intro sum.cong) (auto simp: deg_p coeff_p)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6101
  finally show "\<exists>x. (\<Sum>k\<le>n. f k * x ^ k) = 0" ..
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6102
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6103
80084
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  6104
lemma (in alg_closed_field) nth_root_exists:
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  6105
  assumes "n > 0"
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  6106
  shows   "\<exists>y. y ^ n = (x :: 'a)"
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  6107
proof -
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  6108
  define f where "f = (\<lambda>i. if i = 0 then -x else if i = n then 1 else 0)"
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  6109
  have "\<exists>x. (\<Sum>k\<le>n. f k * x ^ k) = 0"
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  6110
    by (rule alg_closed) (use assms in \<open>auto simp: f_def\<close>)
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  6111
  also have "(\<lambda>x. \<Sum>k\<le>n. f k * x ^ k) = (\<lambda>x. \<Sum>k\<in>{0,n}. f k * x ^ k)"
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  6112
    by (intro ext sum.mono_neutral_right) (auto simp: f_def)
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  6113
  finally show "\<exists>y. y ^ n = x"
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  6114
    using assms by (simp add: f_def)
173548e4d5d0 moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents: 80061
diff changeset
  6115
qed
80061
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6116
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6117
text \<open>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6118
  We can now prove by induction that every polynomial of degree \<open>n\<close> splits into a product of
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6119
  \<open>n\<close> linear factors:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6120
\<close>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6121
lemma alg_closed_imp_factorization:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6122
  fixes p :: "'a :: alg_closed_field poly"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6123
  assumes "p \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6124
  shows "\<exists>A. size A = degree p \<and> p = smult (lead_coeff p) (\<Prod>x\<in>#A. [:-x, 1:])"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6125
  using assms
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6126
proof (induction "degree p" arbitrary: p rule: less_induct)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6127
  case (less p)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6128
  show ?case
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6129
  proof (cases "degree p = 0")
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6130
    case True
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6131
    thus ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6132
      by (intro exI[of _ "{#}"]) (auto elim!: degree_eq_zeroE)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6133
  next
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6134
    case False
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6135
    then obtain x where x: "poly p x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6136
      using alg_closed_imp_poly_has_root by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6137
    hence "[:-x, 1:] dvd p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6138
      using poly_eq_0_iff_dvd by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6139
    then obtain q where p_eq: "p = [:-x, 1:] * q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6140
      by (elim dvdE)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6141
    have "q \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6142
      using less.prems p_eq by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6143
    moreover from this have deg: "degree p = Suc (degree q)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6144
      unfolding p_eq by (subst degree_mult_eq) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6145
    ultimately obtain A where A: "size A = degree q" "q = smult (lead_coeff q) (\<Prod>x\<in>#A. [:-x, 1:])"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6146
      using less.hyps[of q] by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6147
    have "smult (lead_coeff p) (\<Prod>y\<in>#add_mset x A. [:- y, 1:]) =
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6148
          [:- x, 1:] * smult (lead_coeff q) (\<Prod>y\<in>#A. [:- y, 1:])"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6149
      unfolding p_eq lead_coeff_mult by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6150
    also note A(2) [symmetric]
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6151
    also note p_eq [symmetric]
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6152
    finally show ?thesis using A(1)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6153
      by (intro exI[of _ "add_mset x A"]) (auto simp: deg)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6154
  qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6155
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6156
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6157
text \<open>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6158
  As an alternative characterisation of algebraic closure, one can also say that any
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6159
  polynomial of degree at least 2 splits into non-constant factors:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6160
\<close>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6161
lemma alg_closed_imp_reducible:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6162
  assumes "degree (p :: 'a :: alg_closed_field poly) > 1"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6163
  shows   "\<not>irreducible p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6164
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6165
  have "degree p > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6166
    using assms by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6167
  then obtain z where z: "poly p z = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6168
    using alg_closed_imp_poly_has_root[of p] by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6169
  then have dvd: "[:-z, 1:] dvd p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6170
    by (subst dvd_iff_poly_eq_0) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6171
  then obtain q where q: "p = [:-z, 1:] * q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6172
    by (erule dvdE)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6173
  have [simp]: "q \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6174
    using assms q by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6175
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6176
  show ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6177
  proof (rule reducible_polyI)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6178
    show "p = [:-z, 1:] * q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6179
      by fact
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6180
  next
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6181
    have "degree p = degree ([:-z, 1:] * q)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6182
      by (simp only: q)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6183
    also have "\<dots> = degree q + 1"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6184
      by (subst degree_mult_eq) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6185
    finally show "degree q > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6186
      using assms by linarith
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6187
  qed auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6188
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6189
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6190
text \<open>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6191
  When proving algebraic closure through reducibility, we can assume w.l.o.g. that the polynomial
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6192
  is monic and has a non-zero constant coefficient:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6193
\<close>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6194
lemma alg_closedI_reducible:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6195
  assumes "\<And>p :: 'a poly. degree p > 1 \<Longrightarrow> lead_coeff p = 1 \<Longrightarrow> coeff p 0 \<noteq> 0 \<Longrightarrow>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6196
              \<not>irreducible p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6197
  shows   "OFCLASS('a :: field, alg_closed_field_class)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6198
proof
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6199
  fix p :: "'a poly" assume p: "degree p > 0" "lead_coeff p = 1"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6200
  show "\<exists>x. poly p x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6201
  proof (cases "coeff p 0 = 0")
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6202
    case True
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6203
    hence "poly p 0 = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6204
      by (simp add: poly_0_coeff_0)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6205
    thus ?thesis by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6206
  next
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6207
    case False
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6208
    from p and this show ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6209
    proof (induction "degree p" arbitrary: p rule: less_induct)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6210
      case (less p)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6211
      show ?case
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6212
      proof (cases "degree p = 1")
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6213
        case True
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6214
        then obtain a b where p: "p = [:a, b:]"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6215
          by (cases p) (auto split: if_splits elim!: degree_eq_zeroE)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6216
        from True have [simp]: "b \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6217
          by (auto simp: p)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6218
        have "poly p (-a/b) = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6219
          by (auto simp: p)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6220
        thus ?thesis by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6221
      next
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6222
        case False
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6223
        hence "degree p > 1"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6224
          using less.prems by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6225
        from assms[OF \<open>degree p > 1\<close> \<open>lead_coeff p = 1\<close> \<open>coeff p 0 \<noteq> 0\<close>]
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6226
        have "\<not>irreducible p" by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6227
        then obtain r s where rs: "degree r > 0" "degree s > 0" "p = r * s"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6228
          using less.prems unfolding irreducible_def
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6229
          by (metis is_unit_iff_degree mult_not_zero zero_less_iff_neq_zero)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6230
        hence "coeff r 0 \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6231
          using \<open>coeff p 0 \<noteq> 0\<close> by (auto simp: coeff_mult_0)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6232
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6233
        define r' where "r' = smult (inverse (lead_coeff r)) r"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6234
        have [simp]: "degree r' = degree r"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6235
          by (simp add: r'_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6236
        have lc: "lead_coeff r' = 1"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6237
          using rs by (auto simp: r'_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6238
        have nz: "coeff r' 0 \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6239
          using \<open>coeff r 0 \<noteq> 0\<close> by (auto simp: r'_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6240
  
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6241
        have "degree r < degree r + degree s"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6242
          using rs by linarith
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6243
        also have "\<dots> = degree (r * s)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6244
          using rs(3) less.prems by (subst degree_mult_eq) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6245
        also have "r * s = p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6246
          using rs(3) by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6247
        finally have "\<exists>x. poly r' x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6248
          by (intro less) (use lc rs nz in auto)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6249
        thus ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6250
          using rs(3) by (auto simp: r'_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6251
      qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6252
    qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6253
  qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6254
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6255
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6256
text \<open>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6257
  Using a clever Tschirnhausen transformation mentioned e.g. in the article by
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6258
  Nowak~\<^cite>\<open>"nowak2000"\<close>, we can also assume w.l.o.g. that the coefficient $a_{n-1}$ is zero.
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6259
\<close>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6260
lemma alg_closedI_reducible_coeff_deg_minus_one_eq_0:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6261
  assumes "\<And>p :: 'a poly. degree p > 1 \<Longrightarrow> lead_coeff p = 1 \<Longrightarrow> coeff p (degree p - 1) = 0 \<Longrightarrow>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6262
              coeff p 0 \<noteq> 0 \<Longrightarrow> \<not>irreducible p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6263
  shows   "OFCLASS('a :: field_char_0, alg_closed_field_class)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6264
proof (rule alg_closedI_reducible, goal_cases)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6265
  case (1 p)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6266
  define n where [simp]: "n = degree p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6267
  define a where "a = coeff p (n - 1)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6268
  define r where "r = [: -a / of_nat n, 1 :]"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6269
  define s where "s = [: a / of_nat n, 1 :]"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6270
  define q where "q = pcompose p r"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6271
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6272
  have "n > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6273
    using 1 by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6274
  have r_altdef: "r = monom 1 1 + [:-a / of_nat n:]"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6275
    by (simp add: r_def monom_altdef)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6276
  have deg_q: "degree q = n"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6277
    by (simp add: q_def r_def degree_pcompose)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6278
  have lc_q: "lead_coeff q = 1"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6279
    unfolding q_def using 1 by (subst lead_coeff_comp) (simp_all add: r_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6280
  have "q \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6281
    using 1 deg_q by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6282
  
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6283
  have "coeff q (n - 1) =
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6284
          (\<Sum>i\<le>n. \<Sum>k\<le>i. coeff p i * (of_nat (i choose k) *
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6285
            ((-a / of_nat n) ^ (i - k) * (if k = n - 1 then 1 else 0))))"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6286
    unfolding q_def pcompose_altdef poly_altdef r_altdef
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6287
    by (simp_all add: degree_map_poly coeff_map_poly coeff_sum binomial_ring sum_distrib_left poly_const_pow
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6288
                  sum_distrib_right mult_ac monom_power coeff_monom_mult of_nat_poly cong: if_cong)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6289
  also have "\<dots> = (\<Sum>i\<le>n. \<Sum>k\<in>(if i \<ge> n - 1 then {n-1} else {}).
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6290
                     coeff p i * (of_nat (i choose k) * (-a / of_nat n) ^ (i - k)))"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6291
    by (rule sum.cong [OF refl], rule sum.mono_neutral_cong_right) (auto split: if_splits)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6292
  also have "\<dots> = (\<Sum>i\<in>{n-1,n}. \<Sum>k\<in>(if i \<ge> n - 1 then {n-1} else {}).
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6293
                     coeff p i * (of_nat (i choose k) * (-a / of_nat n) ^ (i - k)))"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6294
    by (rule sum.mono_neutral_right) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6295
  also have "\<dots> = a - of_nat (n choose (n - 1)) * a / of_nat n"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6296
    using 1 by (simp add: a_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6297
  also have "n choose (n - 1) = n"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6298
    using \<open>n > 0\<close> by (subst binomial_symmetric) auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6299
  also have "a - of_nat n * a / of_nat n = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6300
    using \<open>n > 0\<close> by simp
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6301
  finally have "coeff q (n - 1) = 0" .
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6302
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6303
  show ?case
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6304
  proof (cases "coeff q 0 = 0")
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6305
    case True
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6306
    hence "poly p (- (a / of_nat (degree p))) = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6307
      by (auto simp: q_def r_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6308
    thus ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6309
      by (rule root_imp_reducible_poly) (use 1 in auto)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6310
  next
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6311
    case False
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6312
    hence "\<not>irreducible q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6313
      using assms[of q] and lc_q and 1 and \<open>coeff q (n - 1) = 0\<close>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6314
      by (auto simp: deg_q)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6315
    then obtain u v where uv: "degree u > 0" "degree v > 0" "q = u * v"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6316
      using \<open>q \<noteq> 0\<close> 1 deg_q unfolding irreducible_def
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6317
      by (metis degree_mult_eq_0 is_unit_iff_degree n_def neq0_conv not_one_less_zero)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6318
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6319
    have "p = pcompose q s"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6320
      by (simp add: q_def r_def s_def pcompose_pCons flip: pcompose_assoc)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6321
    also have "q = u * v"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6322
      by fact
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6323
    finally have "p = pcompose u s * pcompose v s"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6324
      by (simp add: pcompose_mult)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6325
    moreover have "degree (pcompose u s) > 0" "degree (pcompose v s) > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6326
      using uv by (simp_all add: s_def degree_pcompose)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6327
    ultimately show "\<not>irreducible p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6328
      using 1 by (intro reducible_polyI)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6329
  qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6330
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6331
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6332
text \<open>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6333
  As a consequence of the full factorisation lemma proven above, we can also show that any
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6334
  polynomial with at least two different roots splits into two non-constant coprime factors:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6335
\<close>
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6336
lemma alg_closed_imp_poly_splits_coprime:
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6337
  assumes "degree (p :: 'a :: {alg_closed_field} poly) > 1"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6338
  assumes "poly p x = 0" "poly p y = 0" "x \<noteq> y"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6339
  obtains r s where "degree r > 0" "degree s > 0" "coprime r s" "p = r * s"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6340
proof -
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6341
  define n where "n = order x p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6342
  have "n > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6343
    using assms by (metis degree_0 gr0I n_def not_one_less_zero order_root)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6344
  have "[:-x, 1:] ^ n dvd p"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6345
    unfolding n_def by (simp add: order_1)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6346
  then obtain q where p_eq: "p = [:-x, 1:] ^ n * q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6347
    by (elim dvdE)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6348
  from assms have [simp]: "q \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6349
    by (auto simp: p_eq)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6350
  have "order x p = n + Polynomial.order x q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6351
    unfolding p_eq by (subst order_mult) (auto simp: order_power_n_n)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6352
  hence "Polynomial.order x q = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6353
    by (simp add: n_def)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6354
  hence "poly q x \<noteq> 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6355
    by (simp add: order_root)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6356
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6357
  show ?thesis
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6358
  proof (rule that)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6359
    show "coprime ([:-x, 1:] ^ n) q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6360
    proof (rule coprimeI)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6361
      fix d
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6362
      assume d: "d dvd [:-x, 1:] ^ n" "d dvd q"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6363
      have "degree d = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6364
      proof (rule ccontr)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6365
        assume "\<not>(degree d = 0)"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6366
        then obtain z where z: "poly d z = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6367
          using alg_closed_imp_poly_has_root by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6368
        moreover from this and d(1) have "poly ([:-x, 1:] ^ n) z = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6369
          using dvd_trans poly_eq_0_iff_dvd by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6370
        ultimately have "poly d x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6371
          by auto
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6372
        with d(2) have "poly q x = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6373
          using dvd_trans poly_eq_0_iff_dvd by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6374
        with \<open>poly q x \<noteq> 0\<close> show False by contradiction
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6375
      qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6376
      thus "is_unit d" using d
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6377
        by (metis \<open>q \<noteq> 0\<close> dvd_0_left is_unit_iff_degree)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6378
    qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6379
  next
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6380
    have "poly q y = 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6381
      using \<open>poly p y = 0\<close> \<open>x \<noteq> y\<close> by (auto simp: p_eq)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6382
    with \<open>q \<noteq> 0\<close> show "degree q > 0"
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6383
      using order_degree order_gt_0_iff order_less_le_trans by blast
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6384
  qed (use \<open>n > 0\<close> in \<open>simp_all add: p_eq degree_power_eq\<close>)
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6385
qed
4c1347e172b1 moved over material from AFP; most importantly on algebraic numbers and algebraically closed fields
Manuel Eberl <eberlm@in.tum.de>
parents: 79672
diff changeset
  6386
80914
d97fdabd9e2b standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents: 80786
diff changeset
  6387
no_notation cCons (infixr \<open>##\<close> 65)
31663
5eb82f064630 smult_dvd lemmas; polynomial gcd
huffman
parents: 31021
diff changeset
  6388
29478
4a2482e16934 code generation for polynomials
huffman
parents: 29475
diff changeset
  6389
end