src/HOL/Algebra/poly/UnivPoly.thy
author ballarin
Thu, 23 Jan 2003 09:16:53 +0100
changeset 13783 3294f727e20d
parent 13735 7de9342aca7a
permissions -rw-r--r--
Fixed term order for normal form in rings.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7998
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
     1
(*
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
     2
  Title:     Univariate Polynomials
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
     3
  Id:        $Id$
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
     4
  Author:    Clemens Ballarin, started 9 December 1996
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
     5
  Copyright: Clemens Ballarin
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
     6
*)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
     7
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
     8
header {* Univariate Polynomials *}
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
     9
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    10
theory UnivPoly = Abstract:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    11
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    12
(* already proved in Finite_Set.thy
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    13
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    14
lemma setsum_cong:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    15
  "[| A = B; !!i. i : B ==> f i = g i |] ==> setsum f A = setsum g B"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    16
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    17
  assume prems: "A = B" "!!i. i : B ==> f i = g i"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    18
  show ?thesis
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    19
  proof (cases "finite B")
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    20
    case True
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    21
    then have "!!A. [| A = B; !!i. i : B ==> f i = g i |] ==>
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    22
      setsum f A = setsum g B"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    23
    proof induct
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    24
      case empty thus ?case by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    25
    next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    26
      case insert thus ?case by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    27
    qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    28
    with prems show ?thesis by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    29
  next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    30
    case False with prems show ?thesis by (simp add: setsum_def)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    31
  qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    32
qed
7998
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
    33
*)
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
    34
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    35
(* Instruct simplifier to simplify assumptions introduced by congs.
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    36
   This makes setsum_cong more convenient to use, because assumptions
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    37
   like i:{m..n} get simplified (to m <= i & i <= n). *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    38
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    39
ML_setup {* 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    40
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    41
Addcongs [thm "setsum_cong"];
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    42
Context.>> (fn thy => (simpset_ref_of thy :=
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    43
  simpset_of thy setsubgoaler asm_full_simp_tac; thy)) *}
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    44
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    45
section {* Definition of type up *}
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    46
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    47
constdefs
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    48
  bound  :: "[nat, nat => 'a::zero] => bool"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    49
  "bound n f == (ALL i. n < i --> f i = 0)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    50
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    51
lemma boundI [intro!]: "[| !! m. n < m ==> f m = 0 |] ==> bound n f"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    52
proof (unfold bound_def)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    53
qed fast
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    54
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    55
lemma boundE [elim?]: "[| bound n f; (!! m. n < m ==> f m = 0) ==> P |] ==> P"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    56
proof (unfold bound_def)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    57
qed fast
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    58
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    59
lemma boundD [dest]: "[| bound n f; n < m |] ==> f m = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    60
proof (unfold bound_def)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    61
qed fast
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    62
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    63
lemma bound_below:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    64
  assumes bound: "bound m f" and nonzero: "f n ~= 0" shows "n <= m"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    65
proof (rule classical)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    66
  assume "~ ?thesis"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    67
  then have "m < n" by arith
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    68
  with bound have "f n = 0" ..
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    69
  with nonzero show ?thesis by contradiction
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    70
qed
7998
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
    71
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
    72
typedef (UP)
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    73
  ('a) up = "{f :: nat => 'a::zero. EX n. bound n f}"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    74
by (rule+)   (* Question: what does trace_rule show??? *)
7998
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
    75
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    76
section {* Constants *}
7998
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
    77
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
    78
consts
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    79
  coeff  :: "['a up, nat] => ('a::zero)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    80
  monom  :: "['a::zero, nat] => 'a up"              ("(3_*X^/_)" [71, 71] 70)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    81
  "*s"   :: "['a::{zero, times}, 'a up] => 'a up"   (infixl 70)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    82
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    83
defs
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    84
  coeff_def: "coeff p n == Rep_UP p n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    85
  monom_def: "monom a n == Abs_UP (%i. if i=n then a else 0)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    86
  smult_def: "a *s p == Abs_UP (%i. a * Rep_UP p i)"
7998
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
    87
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    88
lemma coeff_bound_ex: "EX n. bound n (coeff p)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    89
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    90
  have "(%n. coeff p n) : UP" by (simp add: coeff_def Rep_UP)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    91
  then obtain n where "bound n (coeff p)" by (unfold UP_def) fast
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    92
  then show ?thesis ..
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    93
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    94
  
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    95
lemma bound_coeff_obtain:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    96
  assumes prem: "(!!n. bound n (coeff p) ==> P)" shows "P"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    97
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    98
  have "(%n. coeff p n) : UP" by (simp add: coeff_def Rep_UP)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
    99
  then obtain n where "bound n (coeff p)" by (unfold UP_def) fast
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   100
  with prem show P .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   101
qed
7998
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
   102
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   103
text {* Ring operations *}
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   104
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   105
instance up :: (zero) zero ..
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   106
instance up :: (one) one ..
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   107
instance up :: (plus) plus ..
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   108
instance up :: (minus) minus ..
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   109
instance up :: (times) times ..
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   110
instance up :: (inverse) inverse ..
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   111
instance up :: (power) power ..
7998
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
   112
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
   113
defs
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   114
  up_add_def:	"p + q == Abs_UP (%n. Rep_UP p n + Rep_UP q n)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   115
  up_mult_def:  "p * q == Abs_UP (%n::nat. setsum
11093
62c2e0af1d30 Changes to HOL/Algebra:
ballarin
parents: 10448
diff changeset
   116
		     (%i. Rep_UP p i * Rep_UP q (n-i)) {..n})"
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   117
  up_zero_def:  "0 == monom 0 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   118
  up_one_def:   "1 == monom 1 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   119
  up_uminus_def:"- p == (- 1) *s p"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   120
                (* easier to use than "Abs_UP (%i. - Rep_UP p i)" *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   121
                (* note: - 1 is different from -1; latter is of class number *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   122
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   123
  up_minus_def:   "(a::'a::{plus, minus} up) - b == a + (-b)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   124
  up_inverse_def: "inverse (a::'a::{zero, one, times, inverse} up) == 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   125
                     (if a dvd 1 then THE x. a*x = 1 else 0)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   126
  up_divide_def:  "(a::'a::{times, inverse} up) / b == a * inverse b"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   127
  up_power_def:   "(a::'a::{one, times, power} up) ^ n ==
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   128
                     nat_rec 1 (%u b. b * a) n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   129
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   130
subsection {* Effect of operations on coefficients *}
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   131
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   132
lemma coeff_monom [simp]: "coeff (monom a m) n = (if m=n then a else 0)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   133
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   134
  have "(%n. if n = m then a else 0) : UP"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   135
    using UP_def by force
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   136
  from this show ?thesis
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   137
    by (simp add: coeff_def monom_def Abs_UP_inverse Rep_UP)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   138
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   139
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   140
lemma coeff_zero [simp]: "coeff 0 n = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   141
proof (unfold up_zero_def)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   142
qed simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   143
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   144
lemma coeff_one [simp]: "coeff 1 n = (if n=0 then 1 else 0)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   145
proof (unfold up_one_def)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   146
qed simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   147
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   148
(* term order
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   149
lemma coeff_smult [simp]: "coeff (a *s p) n = (a::'a::ring) * coeff p n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   150
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   151
  have "!!f. f : UP ==> (%n. a * f n) : UP"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   152
    by (unfold UP_def) (force simp add: ring_simps)
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   153
*)      (* this force step is slow *)
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   154
(*  then show ?thesis
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   155
    apply (simp add: coeff_def smult_def Abs_UP_inverse Rep_UP)
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   156
qed
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   157
*)
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   158
lemma coeff_smult [simp]: "coeff (a *s p) n = (a::'a::ring) * coeff p n"
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   159
proof -
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   160
  have "Rep_UP p : UP ==> (%n. a * Rep_UP p n) : UP"
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   161
    by (unfold UP_def) (force simp add: ring_simps)
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   162
      (* this force step is slow *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   163
  then show ?thesis
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   164
    by (simp add: coeff_def smult_def Abs_UP_inverse Rep_UP)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   165
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   166
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   167
lemma coeff_add [simp]: "coeff (p+q) n = (coeff p n + coeff q n::'a::ring)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   168
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   169
  {
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   170
    fix f g
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   171
    assume fup: "(f::nat=>'a::ring) : UP" and gup: "(g::nat=>'a::ring) : UP"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   172
    have "(%i. f i + g i) : UP"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   173
    proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   174
      from fup obtain n where boundn: "bound n f"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   175
	by (unfold UP_def) fast
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   176
      from gup obtain m where boundm: "bound m g"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   177
	by (unfold UP_def) fast
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   178
      have "bound (max n m) (%i. (f i + g i))"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   179
      proof
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   180
	fix i
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   181
	assume "max n m < i"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   182
	with boundn and boundm show "f i + g i = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   183
          by (fastsimp simp add: ring_simps)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   184
      qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   185
      then show "(%i. (f i + g i)) : UP"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   186
	by (unfold UP_def) fast
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   187
    qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   188
  }
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   189
  then show ?thesis
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   190
    by (simp add: coeff_def up_add_def Abs_UP_inverse Rep_UP)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   191
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   192
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   193
lemma coeff_mult [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   194
  "coeff (p * q) n = (setsum (%i. coeff p i * coeff q (n-i)) {..n}::'a::ring)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   195
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   196
  {
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   197
    fix f g
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   198
    assume fup: "(f::nat=>'a::ring) : UP" and gup: "(g::nat=>'a::ring) : UP"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   199
    have "(%n. setsum (%i. f i * g (n-i)) {..n}) : UP"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   200
    proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   201
      from fup obtain n where "bound n f"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   202
	by (unfold UP_def) fast
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   203
      from gup obtain m where "bound m g"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   204
	by (unfold UP_def) fast
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   205
      have "bound (n + m) (%n. setsum (%i. f i * g (n-i)) {..n})"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   206
      proof
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   207
	fix k
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   208
	assume bound: "n + m < k"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   209
	{
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   210
	  fix i
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   211
	  have "f i * g (k-i) = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   212
	  proof cases
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   213
	    assume "n < i"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   214
	    show ?thesis by (auto! simp add: ring_simps)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   215
	  next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   216
	    assume "~ (n < i)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   217
	    with bound have "m < k-i" by arith
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   218
	    then show ?thesis by (auto! simp add: ring_simps)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   219
	  qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   220
	}
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   221
	then show "setsum (%i. f i * g (k-i)) {..k} = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   222
	  by (simp add: ring_simps)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   223
      qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   224
      then show "(%n. setsum (%i. f i * g (n-i)) {..n}) : UP"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   225
	by (unfold UP_def) fast
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   226
    qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   227
  }
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   228
  then show ?thesis
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   229
    by (simp add: coeff_def up_mult_def Abs_UP_inverse Rep_UP)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   230
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   231
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   232
lemma coeff_uminus [simp]: "coeff (-p) n = (-coeff p n::'a::ring)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   233
by (unfold up_uminus_def) (simp add: ring_simps)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   234
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   235
(* Other lemmas *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   236
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   237
lemma up_eqI: assumes prem: "(!! n. coeff p n = coeff q n)" shows "p = q"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   238
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   239
  have "p = Abs_UP (%u. Rep_UP p u)" by (simp add: Rep_UP_inverse)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   240
  also from prem have "... = Abs_UP (Rep_UP q)" by (simp only: coeff_def)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   241
  also have "... = q" by (simp add: Rep_UP_inverse)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   242
  finally show ?thesis .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   243
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   244
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   245
(* ML_setup {* Addsimprocs [ring_simproc] *} *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   246
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   247
instance up :: (ring) ring
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   248
proof
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   249
  fix p q r :: "'a::ring up"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   250
  fix n
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   251
  show "(p + q) + r = p + (q + r)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   252
    by (rule up_eqI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   253
  show "0 + p = p"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   254
    by (rule up_eqI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   255
  show "(-p) + p = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   256
    by (rule up_eqI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   257
  show "p + q = q + p"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   258
    by (rule up_eqI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   259
  show "(p * q) * r = p * (q * r)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   260
  proof (rule up_eqI)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   261
    fix n 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   262
    {
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   263
      fix k and a b c :: "nat=>'a::ring"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   264
      have "k <= n ==> 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   265
	setsum (%j. setsum (%i. a i * b (j-i)) {..j} * c (n-j)) {..k} = 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   266
	setsum (%j. a j * setsum  (%i. b i * c (n-j-i)) {..k-j}) {..k}"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   267
	(is "_ ==> ?eq k")
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   268
      proof (induct k)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   269
	case 0 show ?case by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   270
      next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   271
	case (Suc k)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   272
	then have "k <= n" by arith
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   273
	then have "?eq k" by (rule Suc)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   274
	then show ?case
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   275
	  by (simp add: Suc_diff_le natsum_ldistr)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   276
      qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   277
    }
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   278
    then show "coeff ((p * q) * r) n = coeff (p * (q * r)) n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   279
      by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   280
  qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   281
  show "1 * p = p"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   282
  proof (rule up_eqI)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   283
    fix n
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   284
    show "coeff (1 * p) n = coeff p n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   285
    proof (cases n)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   286
      case 0 then show ?thesis by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   287
    next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   288
      case Suc then show ?thesis by (simp del: natsum_Suc add: natsum_Suc2)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   289
    qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   290
  qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   291
  show "(p + q) * r = p * r + q * r"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   292
    by (rule up_eqI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   293
  show "p * q = q * p"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   294
  proof (rule up_eqI)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   295
    fix n 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   296
    {
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   297
      fix k
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   298
      fix a b :: "nat=>'a::ring"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   299
      have "k <= n ==> 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   300
	setsum (%i. a i * b (n-i)) {..k} =
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   301
	setsum (%i. a (k-i) * b (i+n-k)) {..k}"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   302
	(is "_ ==> ?eq k")
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   303
      proof (induct k)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   304
	case 0 show ?case by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   305
      next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   306
	case (Suc k) then show ?case by (subst natsum_Suc2) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   307
      qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   308
    }
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   309
    then show "coeff (p * q) n = coeff (q * p) n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   310
      by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   311
  qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   312
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   313
  show "p - q = p + (-q)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   314
    by (simp add: up_minus_def)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   315
  show "inverse p = (if p dvd 1 then THE x. p*x = 1 else 0)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   316
    by (simp add: up_inverse_def)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   317
  show "p / q = p * inverse q"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   318
    by (simp add: up_divide_def)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   319
  show "p ^ n = nat_rec 1 (%u b. b * p) n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   320
    by (simp add: up_power_def)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   321
  qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   322
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   323
(* Further properties of monom *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   324
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   325
lemma monom_zero [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   326
  "monom 0 n = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   327
  by (simp add: monom_def up_zero_def)
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   328
(* term order: application of coeff_mult goes wrong: rule not symmetric
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   329
lemma monom_mult_is_smult:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   330
  "monom (a::'a::ring) 0 * p = a *s p"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   331
proof (rule up_eqI)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   332
  fix k
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   333
  show "coeff (monom a 0 * p) k = coeff (a *s p) k"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   334
  proof (cases k)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   335
    case 0 then show ?thesis by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   336
  next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   337
    case Suc then show ?thesis by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   338
  qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   339
qed
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   340
*)
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   341
ML_setup {* Delsimprocs [ring_simproc] *}
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   342
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   343
lemma monom_mult_is_smult:
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   344
  "monom (a::'a::ring) 0 * p = a *s p"
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   345
proof (rule up_eqI)
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   346
  fix k
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   347
  have "coeff (p * monom a 0) k = coeff (a *s p) k"
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   348
  proof (cases k)
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   349
    case 0 then show ?thesis by simp ring
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   350
  next
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   351
    case Suc then show ?thesis by (simp add: ring_simps) ring
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   352
  qed
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   353
  then show "coeff (monom a 0 * p) k = coeff (a *s p) k" by ring
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   354
qed
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   355
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   356
ML_setup {* Addsimprocs [ring_simproc] *}
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   357
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   358
lemma monom_add [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   359
  "monom (a + b) n = monom (a::'a::ring) n + monom b n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   360
by (rule up_eqI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   361
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   362
lemma monom_mult_smult:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   363
  "monom (a * b) n = a *s monom (b::'a::ring) n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   364
by (rule up_eqI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   365
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   366
lemma monom_uminus [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   367
  "monom (-a) n = - monom (a::'a::ring) n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   368
by (rule up_eqI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   369
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   370
lemma monom_one [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   371
  "monom 1 0 = 1"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   372
by (simp add: up_one_def)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   373
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   374
lemma monom_inj:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   375
  "(monom a n = monom b n) = (a = b)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   376
proof
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   377
  assume "monom a n = monom b n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   378
  then have "coeff (monom a n) n = coeff (monom b n) n" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   379
  then show "a = b" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   380
next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   381
  assume "a = b" then show "monom a n = monom b n" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   382
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   383
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   384
(* Properties of *s:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   385
   Polynomials form a module *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   386
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   387
lemma smult_l_distr:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   388
  "(a + b::'a::ring) *s p = a *s p + b *s p"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   389
by (rule up_eqI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   390
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   391
lemma smult_r_distr:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   392
  "(a::'a::ring) *s (p + q) = a *s p + a *s q"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   393
by (rule up_eqI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   394
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   395
lemma smult_assoc1:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   396
  "(a * b::'a::ring) *s p = a *s (b *s p)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   397
by (rule up_eqI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   398
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   399
lemma smult_one [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   400
  "(1::'a::ring) *s p = p"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   401
by (rule up_eqI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   402
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   403
(* Polynomials form an algebra *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   404
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   405
ML_setup {* Delsimprocs [ring_simproc] *}
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   406
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   407
lemma smult_assoc2:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   408
  "(a *s p) * q = (a::'a::ring) *s (p * q)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   409
by (rule up_eqI) (simp add: natsum_rdistr m_assoc)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   410
(* Simproc fails. *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   411
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   412
ML_setup {* Addsimprocs [ring_simproc] *}
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   413
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   414
(* the following can be derived from the above ones,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   415
   for generality reasons, it is therefore done *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   416
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   417
lemma smult_l_null [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   418
  "(0::'a::ring) *s p = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   419
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   420
  fix a
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   421
  have "0 *s p = (0 *s p + a *s p) + - (a *s p)" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   422
  also have "... = (0 + a) *s p + - (a *s p)" by (simp only: smult_l_distr)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   423
  also have "... = 0" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   424
  finally show ?thesis .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   425
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   426
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   427
lemma smult_r_null [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   428
  "(a::'a::ring) *s 0 = 0";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   429
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   430
  fix p
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   431
  have "a *s 0 = (a *s 0 + a *s p) + - (a *s p)" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   432
  also have "... = a *s (0 + p) + - (a *s p)" by (simp only: smult_r_distr)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   433
  also have "... = 0" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   434
  finally show ?thesis .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   435
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   436
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   437
lemma smult_l_minus:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   438
  "(-a::'a::ring) *s p = - (a *s p)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   439
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   440
  have "(-a) *s p = (-a *s p + a *s p) + -(a *s p)" by simp 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   441
  also have "... = (-a + a) *s p + -(a *s p)" by (simp only: smult_l_distr)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   442
  also have "... = -(a *s p)" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   443
  finally show ?thesis .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   444
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   445
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   446
lemma smult_r_minus:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   447
  "(a::'a::ring) *s (-p) = - (a *s p)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   448
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   449
  have "a *s (-p) = (a *s -p + a *s p) + -(a *s p)" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   450
  also have "... = a *s (-p + p) + -(a *s p)" by (simp only: smult_r_distr)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   451
  also have "... = -(a *s p)" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   452
  finally show ?thesis .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   453
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   454
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   455
section {* The degree function *}
7998
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
   456
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   457
constdefs
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   458
  deg :: "('a::zero) up => nat"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   459
  "deg p == LEAST n. bound n (coeff p)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   460
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   461
lemma deg_aboveI:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   462
  "(!!m. n < m ==> coeff p m = 0) ==> deg p <= n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   463
by (unfold deg_def) (fast intro: Least_le)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   464
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   465
lemma deg_aboveD:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   466
  assumes prem: "deg p < m" shows "coeff p m = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   467
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   468
  obtain n where "bound n (coeff p)" by (rule bound_coeff_obtain)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   469
  then have "bound (deg p) (coeff p)" by (unfold deg_def, rule LeastI)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   470
  then show "coeff p m = 0" by (rule boundD)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   471
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   472
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   473
lemma deg_belowI:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   474
  assumes prem: "n ~= 0 ==> coeff p n ~= 0" shows "n <= deg p"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   475
(* logically, this is a slightly stronger version of deg_aboveD *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   476
proof (cases "n=0")
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   477
  case True then show ?thesis by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   478
next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   479
  case False then have "coeff p n ~= 0" by (rule prem)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   480
  then have "~ deg p < n" by (fast dest: deg_aboveD)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   481
  then show ?thesis by arith
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   482
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   483
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   484
lemma lcoeff_nonzero_deg:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   485
  assumes deg: "deg p ~= 0" shows "coeff p (deg p) ~= 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   486
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   487
  obtain m where "deg p <= m" and m_coeff: "coeff p m ~= 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   488
  proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   489
    have minus: "!!(n::nat) m. n ~= 0 ==> (n - Suc 0 < m) = (n <= m)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   490
      by arith (* make public?, why does proof not work with "1" *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   491
    from deg have "deg p - 1 < (LEAST n. bound n (coeff p))"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   492
      by (unfold deg_def) arith
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   493
    then have "~ bound (deg p - 1) (coeff p)" by (rule not_less_Least)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   494
    then have "EX m. deg p - 1 < m & coeff p m ~= 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   495
      by (unfold bound_def) fast
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   496
    then have "EX m. deg p <= m & coeff p m ~= 0" by (simp add: deg minus)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   497
    then show ?thesis by auto 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   498
  qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   499
  with deg_belowI have "deg p = m" by fastsimp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   500
  with m_coeff show ?thesis by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   501
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   502
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   503
lemma lcoeff_nonzero_nonzero:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   504
  assumes deg: "deg p = 0" and nonzero: "p ~= 0" shows "coeff p 0 ~= 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   505
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   506
  have "EX m. coeff p m ~= 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   507
  proof (rule classical)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   508
    assume "~ ?thesis"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   509
    then have "p = 0" by (auto intro: up_eqI)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   510
    with nonzero show ?thesis by contradiction
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   511
  qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   512
  then obtain m where coeff: "coeff p m ~= 0" ..
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   513
  then have "m <= deg p" by (rule deg_belowI)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   514
  then have "m = 0" by (simp add: deg)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   515
  with coeff show ?thesis by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   516
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   517
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   518
lemma lcoeff_nonzero:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   519
  "p ~= 0 ==> coeff p (deg p) ~= 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   520
proof (cases "deg p = 0")
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   521
  case True
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   522
  assume "p ~= 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   523
  with True show ?thesis by (simp add: lcoeff_nonzero_nonzero)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   524
next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   525
  case False
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   526
  assume "p ~= 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   527
  with False show ?thesis by (simp add: lcoeff_nonzero_deg)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   528
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   529
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   530
lemma deg_eqI:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   531
  "[| !!m. n < m ==> coeff p m = 0;
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   532
      !!n. n ~= 0 ==> coeff p n ~= 0|] ==> deg p = n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   533
by (fast intro: le_anti_sym deg_aboveI deg_belowI)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   534
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   535
(* Degree and polynomial operations *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   536
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   537
lemma deg_add [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   538
  "deg ((p::'a::ring up) + q) <= max (deg p) (deg q)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   539
proof (cases "deg p <= deg q")
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   540
  case True show ?thesis by (rule deg_aboveI) (simp add: True deg_aboveD) 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   541
next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   542
  case False show ?thesis by (rule deg_aboveI) (simp add: False deg_aboveD)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   543
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   544
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   545
lemma deg_monom_ring:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   546
  "deg (monom a n::'a::ring up) <= n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   547
by (rule deg_aboveI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   548
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   549
lemma deg_monom [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   550
  "a ~= 0 ==> deg (monom a n::'a::ring up) = n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   551
by (fastsimp intro: le_anti_sym deg_aboveI deg_belowI)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   552
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   553
lemma deg_const [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   554
  "deg (monom (a::'a::ring) 0) = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   555
proof (rule le_anti_sym)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   556
  show "deg (monom a 0) <= 0" by (rule deg_aboveI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   557
next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   558
  show "0 <= deg (monom a 0)" by (rule deg_belowI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   559
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   560
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   561
lemma deg_zero [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   562
  "deg 0 = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   563
proof (rule le_anti_sym)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   564
  show "deg 0 <= 0" by (rule deg_aboveI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   565
next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   566
  show "0 <= deg 0" by (rule deg_belowI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   567
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   568
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   569
lemma deg_one [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   570
  "deg 1 = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   571
proof (rule le_anti_sym)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   572
  show "deg 1 <= 0" by (rule deg_aboveI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   573
next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   574
  show "0 <= deg 1" by (rule deg_belowI) simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   575
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   576
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   577
lemma uminus_monom:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   578
  "!!a::'a::ring. (-a = 0) = (a = 0)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   579
proof
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   580
  fix a::"'a::ring"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   581
  assume "a = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   582
  then show "-a = 0" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   583
next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   584
  fix a::"'a::ring"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   585
  assume "- a = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   586
  then have "-(- a) = 0" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   587
  then show "a = 0" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   588
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   589
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   590
lemma deg_uminus [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   591
  "deg (-p::('a::ring) up) = deg p"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   592
proof (rule le_anti_sym)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   593
  show "deg (- p) <= deg p" by (simp add: deg_aboveI deg_aboveD)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   594
next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   595
  show "deg p <= deg (- p)" 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   596
  by (simp add: deg_belowI lcoeff_nonzero_deg uminus_monom)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   597
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   598
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   599
lemma deg_smult_ring:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   600
  "deg ((a::'a::ring) *s p) <= (if a = 0 then 0 else deg p)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   601
proof (cases "a = 0")
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   602
qed (simp add: deg_aboveI deg_aboveD)+
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   603
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   604
lemma deg_smult [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   605
  "deg ((a::'a::domain) *s p) = (if a = 0 then 0 else deg p)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   606
proof (rule le_anti_sym)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   607
  show "deg (a *s p) <= (if a = 0 then 0 else deg p)" by (rule deg_smult_ring)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   608
next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   609
  show "(if a = 0 then 0 else deg p) <= deg (a *s p)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   610
  proof (cases "a = 0")
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   611
  qed (simp, simp add: deg_belowI lcoeff_nonzero_deg integral_iff)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   612
qed
7998
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
   613
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   614
lemma deg_mult_ring:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   615
  "deg (p * q::'a::ring up) <= deg p + deg q"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   616
proof (rule deg_aboveI)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   617
  fix m
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   618
  assume boundm: "deg p + deg q < m"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   619
  {
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   620
    fix k i
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   621
    assume boundk: "deg p + deg q < k"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   622
    then have "coeff p i * coeff q (k - i) = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   623
    proof (cases "deg p < i")
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   624
      case True then show ?thesis by (simp add: deg_aboveD)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   625
    next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   626
      case False with boundk have "deg q < k - i" by arith
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   627
      then show ?thesis by (simp add: deg_aboveD)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   628
    qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   629
  }
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   630
      (* This is similar to bound_mult_zero and deg_above_mult_zero in the old
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   631
         proofs. *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   632
  with boundm show "coeff (p * q) m = 0" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   633
qed
7998
3d0c34795831 Algebra and Polynomial theories, by Clemens Ballarin
paulson
parents:
diff changeset
   634
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   635
lemma deg_mult [simp]:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   636
  "[| (p::'a::domain up) ~= 0; q ~= 0|] ==> deg (p * q) = deg p + deg q"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   637
proof (rule le_anti_sym)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   638
  show "deg (p * q) <= deg p + deg q" by (rule deg_mult_ring)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   639
next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   640
  let ?s = "(%i. coeff p i * coeff q (deg p + deg q - i))"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   641
  assume nz: "p ~= 0" "q ~= 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   642
  have less_add_diff: "!!(k::nat) n m. k < n ==> m < n + m - k" by arith
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   643
  show "deg p + deg q <= deg (p * q)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   644
  proof (rule deg_belowI, simp)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   645
    have "setsum ?s {.. deg p + deg q}
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   646
      = setsum ?s ({.. deg p(} Un {deg p .. deg p + deg q})"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   647
      by (simp only: ivl_disj_un_one)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   648
    also have "... = setsum ?s {deg p .. deg p + deg q}"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   649
      by (simp add: setsum_Un_disjoint ivl_disj_int_one
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   650
        setsum_0 deg_aboveD less_add_diff)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   651
    also have "... = setsum ?s ({deg p} Un {)deg p .. deg p + deg q})"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   652
      by (simp only: ivl_disj_un_singleton)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   653
    also have "... = coeff p (deg p) * coeff q (deg q)" 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   654
      by (simp add: setsum_Un_disjoint ivl_disj_int_singleton 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   655
        setsum_0 deg_aboveD)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   656
    finally have "setsum ?s {.. deg p + deg q} 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   657
      = coeff p (deg p) * coeff q (deg q)" .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   658
    with nz show "setsum ?s {.. deg p + deg q} ~= 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   659
      by (simp add: integral_iff lcoeff_nonzero)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   660
    qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   661
  qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   662
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   663
lemma coeff_natsum:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   664
  "((coeff (setsum p A) k)::'a::ring) = 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   665
   setsum (%i. coeff (p i) k) A"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   666
proof (cases "finite A")
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   667
  case True then show ?thesis by induct auto
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   668
next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   669
  case False then show ?thesis by (simp add: setsum_def)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   670
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   671
(* Instance of a more general result!!! *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   672
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   673
(*
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   674
lemma coeff_natsum:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   675
  "((coeff (setsum p {..n::nat}) k)::'a::ring) = 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   676
   setsum (%i. coeff (p i) k) {..n}"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   677
by (induct n) auto
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   678
*)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   679
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   680
lemma up_repr:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   681
  "setsum (%i. monom (coeff p i) i) {..deg (p::'a::ring up)} = p"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   682
proof (rule up_eqI)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   683
  let ?s = "(%i. monom (coeff p i) i)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   684
  fix k
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   685
  show "coeff (setsum ?s {..deg p}) k = coeff p k"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   686
  proof (cases "k <= deg p")
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   687
    case True
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   688
    hence "coeff (setsum ?s {..deg p}) k = 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   689
          coeff (setsum ?s ({..k} Un {)k..deg p})) k"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   690
      by (simp only: ivl_disj_un_one)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   691
    also from True
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   692
    have "... = coeff (setsum ?s {..k}) k"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   693
      by (simp add: setsum_Un_disjoint ivl_disj_int_one order_less_imp_not_eq2
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   694
        setsum_0 coeff_natsum )
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   695
    also
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   696
    have "... = coeff (setsum ?s ({..k(} Un {k})) k"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   697
      by (simp only: ivl_disj_un_singleton)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   698
    also have "... = coeff p k"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   699
      by (simp add: setsum_Un_disjoint ivl_disj_int_singleton 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   700
        setsum_0 coeff_natsum deg_aboveD)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   701
    finally show ?thesis .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   702
  next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   703
    case False
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   704
    hence "coeff (setsum ?s {..deg p}) k = 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   705
          coeff (setsum ?s ({..deg p(} Un {deg p})) k"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   706
      by (simp only: ivl_disj_un_singleton)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   707
    also from False have "... = coeff p k"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   708
      by (simp add: setsum_Un_disjoint ivl_disj_int_singleton 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   709
        setsum_0 coeff_natsum deg_aboveD)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   710
    finally show ?thesis .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   711
  qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   712
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   713
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   714
lemma up_repr_le:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   715
  "deg (p::'a::ring up) <= n ==> setsum (%i. monom (coeff p i) i) {..n} = p"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   716
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   717
  let ?s = "(%i. monom (coeff p i) i)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   718
  assume "deg p <= n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   719
  then have "setsum ?s {..n} = setsum ?s ({..deg p} Un {)deg p..n})"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   720
    by (simp only: ivl_disj_un_one)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   721
  also have "... = setsum ?s {..deg p}"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   722
    by (simp add: setsum_Un_disjoint ivl_disj_int_one
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   723
      setsum_0 deg_aboveD)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   724
  also have "... = p" by (rule up_repr)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   725
  finally show ?thesis .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   726
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   727
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   728
instance up :: ("domain") "domain"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   729
proof
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   730
  show "1 ~= (0::'a up)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   731
  proof (* notI is applied here *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   732
    assume "1 = (0::'a up)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   733
    hence "coeff 1 0 = (coeff 0 0::'a)" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   734
    hence "1 = (0::'a)" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   735
    with one_not_zero show "False" by contradiction
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   736
  qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   737
next
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   738
  fix p q :: "'a::domain up"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   739
  assume pq: "p * q = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   740
  show "p = 0 | q = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   741
  proof (rule classical)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   742
    assume c: "~ (p = 0 | q = 0)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   743
    then have "deg p + deg q = deg (p * q)" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   744
    also from pq have "... = 0" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   745
    finally have "deg p + deg q = 0" .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   746
    then have f1: "deg p = 0 & deg q = 0" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   747
    from f1 have "p = setsum (%i. (monom (coeff p i) i)) {..0}"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   748
      by (simp only: up_repr_le)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   749
    also have "... = monom (coeff p 0) 0" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   750
    finally have p: "p = monom (coeff p 0) 0" .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   751
    from f1 have "q = setsum (%i. (monom (coeff q i) i)) {..0}"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   752
      by (simp only: up_repr_le)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   753
    also have "... = monom (coeff q 0) 0" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   754
    finally have q: "q = monom (coeff q 0) 0" .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   755
    have "coeff p 0 * coeff q 0 = coeff (p * q) 0" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   756
    also from pq have "... = 0" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   757
    finally have "coeff p 0 * coeff q 0 = 0" .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   758
    then have "coeff p 0 = 0 | coeff q 0 = 0" by (simp only: integral_iff)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   759
    with p q show "p = 0 | q = 0" by fastsimp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   760
  qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   761
qed
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   762
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   763
lemma monom_inj_zero:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   764
  "(monom a n = 0) = (a = 0)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   765
proof -
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   766
  have "(monom a n = 0) = (monom a n = monom 0 n)" by simp
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   767
  also have "... = (a = 0)" by (simp add: monom_inj del: monom_zero)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   768
  finally show ?thesis .
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   769
qed
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   770
(* term order: makes this simpler!!!
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   771
lemma smult_integral:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   772
  "(a::'a::domain) *s p = 0 ==> a = 0 | p = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   773
by (simp add: monom_mult_is_smult [THEN sym] integral_iff monom_inj_zero) fast
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   774
*)
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   775
lemma smult_integral:
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   776
  "(a::'a::domain) *s p = 0 ==> a = 0 | p = 0"
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13735
diff changeset
   777
by (simp add: monom_mult_is_smult [THEN sym] integral_iff monom_inj_zero)
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   778
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents: 11093
diff changeset
   779
end