src/HOL/Algebra/UnivPoly.thy
author ballarin
Tue Jul 15 16:50:09 2008 +0200 (2008-07-15)
changeset 27611 2c01c0bdb385
parent 26934 c1ae80a58341
child 27714 27b4d7c01f8b
permissions -rw-r--r--
Removed uses of context element includes.
ballarin@13940
     1
(*
wenzelm@14706
     2
  Title:     HOL/Algebra/UnivPoly.thy
ballarin@13940
     3
  Id:        $Id$
ballarin@13940
     4
  Author:    Clemens Ballarin, started 9 December 1996
ballarin@13940
     5
  Copyright: Clemens Ballarin
ballarin@13940
     6
*)
ballarin@13940
     7
ballarin@20318
     8
theory UnivPoly imports Module begin
ballarin@13940
     9
ballarin@20318
    10
ballarin@20318
    11
section {* Univariate Polynomials *}
ballarin@13940
    12
ballarin@14553
    13
text {*
wenzelm@14666
    14
  Polynomials are formalised as modules with additional operations for
wenzelm@14666
    15
  extracting coefficients from polynomials and for obtaining monomials
wenzelm@14666
    16
  from coefficients and exponents (record @{text "up_ring"}).  The
wenzelm@14666
    17
  carrier set is a set of bounded functions from Nat to the
wenzelm@14666
    18
  coefficient domain.  Bounded means that these functions return zero
wenzelm@14666
    19
  above a certain bound (the degree).  There is a chapter on the
wenzelm@14706
    20
  formalisation of polynomials in the PhD thesis \cite{Ballarin:1999},
wenzelm@14706
    21
  which was implemented with axiomatic type classes.  This was later
wenzelm@14706
    22
  ported to Locales.
ballarin@14553
    23
*}
ballarin@14553
    24
wenzelm@14666
    25
ballarin@13949
    26
subsection {* The Constructor for Univariate Polynomials *}
ballarin@13940
    27
ballarin@15095
    28
text {*
ballarin@15095
    29
  Functions with finite support.
ballarin@15095
    30
*}
ballarin@15095
    31
wenzelm@14666
    32
locale bound =
wenzelm@14666
    33
  fixes z :: 'a
wenzelm@14666
    34
    and n :: nat
wenzelm@14666
    35
    and f :: "nat => 'a"
wenzelm@14666
    36
  assumes bound: "!!m. n < m \<Longrightarrow> f m = z"
ballarin@13940
    37
wenzelm@14666
    38
declare bound.intro [intro!]
wenzelm@14666
    39
  and bound.bound [dest]
ballarin@13940
    40
ballarin@13940
    41
lemma bound_below:
wenzelm@14666
    42
  assumes bound: "bound z m f" and nonzero: "f n \<noteq> z" shows "n \<le> m"
ballarin@13940
    43
proof (rule classical)
ballarin@13940
    44
  assume "~ ?thesis"
ballarin@13940
    45
  then have "m < n" by arith
ballarin@13940
    46
  with bound have "f n = z" ..
ballarin@13940
    47
  with nonzero show ?thesis by contradiction
ballarin@13940
    48
qed
ballarin@13940
    49
ballarin@13940
    50
record ('a, 'p) up_ring = "('a, 'p) module" +
ballarin@13940
    51
  monom :: "['a, nat] => 'p"
ballarin@13940
    52
  coeff :: "['p, nat] => 'a"
ballarin@13940
    53
wenzelm@14651
    54
constdefs (structure R)
ballarin@15095
    55
  up :: "('a, 'm) ring_scheme => (nat => 'a) set"
wenzelm@14651
    56
  "up R == {f. f \<in> UNIV -> carrier R & (EX n. bound \<zero> n f)}"
ballarin@15095
    57
  UP :: "('a, 'm) ring_scheme => ('a, nat => 'a) up_ring"
ballarin@13940
    58
  "UP R == (|
ballarin@13940
    59
    carrier = up R,
wenzelm@14651
    60
    mult = (%p:up R. %q:up R. %n. \<Oplus>i \<in> {..n}. p i \<otimes> q (n-i)),
wenzelm@14651
    61
    one = (%i. if i=0 then \<one> else \<zero>),
wenzelm@14651
    62
    zero = (%i. \<zero>),
wenzelm@14651
    63
    add = (%p:up R. %q:up R. %i. p i \<oplus> q i),
wenzelm@14651
    64
    smult = (%a:carrier R. %p:up R. %i. a \<otimes> p i),
wenzelm@14651
    65
    monom = (%a:carrier R. %n i. if i=n then a else \<zero>),
ballarin@13940
    66
    coeff = (%p:up R. %n. p n) |)"
ballarin@13940
    67
ballarin@13940
    68
text {*
ballarin@13940
    69
  Properties of the set of polynomials @{term up}.
ballarin@13940
    70
*}
ballarin@13940
    71
ballarin@13940
    72
lemma mem_upI [intro]:
ballarin@13940
    73
  "[| !!n. f n \<in> carrier R; EX n. bound (zero R) n f |] ==> f \<in> up R"
ballarin@13940
    74
  by (simp add: up_def Pi_def)
ballarin@13940
    75
ballarin@13940
    76
lemma mem_upD [dest]:
ballarin@13940
    77
  "f \<in> up R ==> f n \<in> carrier R"
ballarin@13940
    78
  by (simp add: up_def Pi_def)
ballarin@13940
    79
ballarin@13940
    80
lemma (in cring) bound_upD [dest]:
ballarin@13940
    81
  "f \<in> up R ==> EX n. bound \<zero> n f"
ballarin@13940
    82
  by (simp add: up_def)
ballarin@13940
    83
ballarin@13940
    84
lemma (in cring) up_one_closed:
ballarin@13940
    85
   "(%n. if n = 0 then \<one> else \<zero>) \<in> up R"
ballarin@13940
    86
  using up_def by force
ballarin@13940
    87
ballarin@13940
    88
lemma (in cring) up_smult_closed:
ballarin@13940
    89
  "[| a \<in> carrier R; p \<in> up R |] ==> (%i. a \<otimes> p i) \<in> up R"
ballarin@13940
    90
  by force
ballarin@13940
    91
ballarin@13940
    92
lemma (in cring) up_add_closed:
ballarin@13940
    93
  "[| p \<in> up R; q \<in> up R |] ==> (%i. p i \<oplus> q i) \<in> up R"
ballarin@13940
    94
proof
ballarin@13940
    95
  fix n
ballarin@13940
    96
  assume "p \<in> up R" and "q \<in> up R"
ballarin@13940
    97
  then show "p n \<oplus> q n \<in> carrier R"
ballarin@13940
    98
    by auto
ballarin@13940
    99
next
ballarin@13940
   100
  assume UP: "p \<in> up R" "q \<in> up R"
ballarin@13940
   101
  show "EX n. bound \<zero> n (%i. p i \<oplus> q i)"
ballarin@13940
   102
  proof -
ballarin@13940
   103
    from UP obtain n where boundn: "bound \<zero> n p" by fast
ballarin@13940
   104
    from UP obtain m where boundm: "bound \<zero> m q" by fast
ballarin@13940
   105
    have "bound \<zero> (max n m) (%i. p i \<oplus> q i)"
ballarin@13940
   106
    proof
ballarin@13940
   107
      fix i
ballarin@13940
   108
      assume "max n m < i"
ballarin@13940
   109
      with boundn and boundm and UP show "p i \<oplus> q i = \<zero>" by fastsimp
ballarin@13940
   110
    qed
ballarin@13940
   111
    then show ?thesis ..
ballarin@13940
   112
  qed
ballarin@13940
   113
qed
ballarin@13940
   114
ballarin@13940
   115
lemma (in cring) up_a_inv_closed:
ballarin@13940
   116
  "p \<in> up R ==> (%i. \<ominus> (p i)) \<in> up R"
ballarin@13940
   117
proof
ballarin@13940
   118
  assume R: "p \<in> up R"
ballarin@13940
   119
  then obtain n where "bound \<zero> n p" by auto
ballarin@13940
   120
  then have "bound \<zero> n (%i. \<ominus> p i)" by auto
ballarin@13940
   121
  then show "EX n. bound \<zero> n (%i. \<ominus> p i)" by auto
ballarin@13940
   122
qed auto
ballarin@13940
   123
ballarin@13940
   124
lemma (in cring) up_mult_closed:
ballarin@13940
   125
  "[| p \<in> up R; q \<in> up R |] ==>
wenzelm@14666
   126
  (%n. \<Oplus>i \<in> {..n}. p i \<otimes> q (n-i)) \<in> up R"
ballarin@13940
   127
proof
ballarin@13940
   128
  fix n
ballarin@13940
   129
  assume "p \<in> up R" "q \<in> up R"
wenzelm@14666
   130
  then show "(\<Oplus>i \<in> {..n}. p i \<otimes> q (n-i)) \<in> carrier R"
ballarin@13940
   131
    by (simp add: mem_upD  funcsetI)
ballarin@13940
   132
next
ballarin@13940
   133
  assume UP: "p \<in> up R" "q \<in> up R"
wenzelm@14666
   134
  show "EX n. bound \<zero> n (%n. \<Oplus>i \<in> {..n}. p i \<otimes> q (n-i))"
ballarin@13940
   135
  proof -
ballarin@13940
   136
    from UP obtain n where boundn: "bound \<zero> n p" by fast
ballarin@13940
   137
    from UP obtain m where boundm: "bound \<zero> m q" by fast
wenzelm@14666
   138
    have "bound \<zero> (n + m) (%n. \<Oplus>i \<in> {..n}. p i \<otimes> q (n - i))"
ballarin@13940
   139
    proof
wenzelm@14666
   140
      fix k assume bound: "n + m < k"
ballarin@13940
   141
      {
wenzelm@14666
   142
        fix i
wenzelm@14666
   143
        have "p i \<otimes> q (k-i) = \<zero>"
wenzelm@14666
   144
        proof (cases "n < i")
wenzelm@14666
   145
          case True
wenzelm@14666
   146
          with boundn have "p i = \<zero>" by auto
ballarin@13940
   147
          moreover from UP have "q (k-i) \<in> carrier R" by auto
wenzelm@14666
   148
          ultimately show ?thesis by simp
wenzelm@14666
   149
        next
wenzelm@14666
   150
          case False
wenzelm@14666
   151
          with bound have "m < k-i" by arith
wenzelm@14666
   152
          with boundm have "q (k-i) = \<zero>" by auto
wenzelm@14666
   153
          moreover from UP have "p i \<in> carrier R" by auto
wenzelm@14666
   154
          ultimately show ?thesis by simp
wenzelm@14666
   155
        qed
ballarin@13940
   156
      }
wenzelm@14666
   157
      then show "(\<Oplus>i \<in> {..k}. p i \<otimes> q (k-i)) = \<zero>"
wenzelm@14666
   158
        by (simp add: Pi_def)
ballarin@13940
   159
    qed
ballarin@13940
   160
    then show ?thesis by fast
ballarin@13940
   161
  qed
ballarin@13940
   162
qed
ballarin@13940
   163
wenzelm@14666
   164
ballarin@20318
   165
subsection {* Effect of Operations on Coefficients *}
ballarin@13940
   166
ballarin@19783
   167
locale UP =
ballarin@19783
   168
  fixes R (structure) and P (structure)
ballarin@13940
   169
  defines P_def: "P == UP R"
ballarin@13940
   170
ballarin@13940
   171
locale UP_cring = UP + cring R
ballarin@13940
   172
ballarin@13940
   173
locale UP_domain = UP_cring + "domain" R
ballarin@13940
   174
ballarin@13940
   175
text {*
ballarin@15095
   176
  Temporarily declare @{thm [locale=UP] P_def} as simp rule.
ballarin@15095
   177
*}
ballarin@13940
   178
ballarin@13940
   179
declare (in UP) P_def [simp]
ballarin@13940
   180
ballarin@13940
   181
lemma (in UP_cring) coeff_monom [simp]:
ballarin@13940
   182
  "a \<in> carrier R ==>
ballarin@13940
   183
  coeff P (monom P a m) n = (if m=n then a else \<zero>)"
ballarin@13940
   184
proof -
ballarin@13940
   185
  assume R: "a \<in> carrier R"
ballarin@13940
   186
  then have "(%n. if n = m then a else \<zero>) \<in> up R"
ballarin@13940
   187
    using up_def by force
ballarin@13940
   188
  with R show ?thesis by (simp add: UP_def)
ballarin@13940
   189
qed
ballarin@13940
   190
ballarin@13940
   191
lemma (in UP_cring) coeff_zero [simp]:
ballarin@15095
   192
  "coeff P \<zero>\<^bsub>P\<^esub> n = \<zero>"
ballarin@13940
   193
  by (auto simp add: UP_def)
ballarin@13940
   194
ballarin@13940
   195
lemma (in UP_cring) coeff_one [simp]:
ballarin@15095
   196
  "coeff P \<one>\<^bsub>P\<^esub> n = (if n=0 then \<one> else \<zero>)"
ballarin@13940
   197
  using up_one_closed by (simp add: UP_def)
ballarin@13940
   198
ballarin@13940
   199
lemma (in UP_cring) coeff_smult [simp]:
ballarin@13940
   200
  "[| a \<in> carrier R; p \<in> carrier P |] ==>
ballarin@15095
   201
  coeff P (a \<odot>\<^bsub>P\<^esub> p) n = a \<otimes> coeff P p n"
ballarin@13940
   202
  by (simp add: UP_def up_smult_closed)
ballarin@13940
   203
ballarin@13940
   204
lemma (in UP_cring) coeff_add [simp]:
ballarin@13940
   205
  "[| p \<in> carrier P; q \<in> carrier P |] ==>
ballarin@15095
   206
  coeff P (p \<oplus>\<^bsub>P\<^esub> q) n = coeff P p n \<oplus> coeff P q n"
ballarin@13940
   207
  by (simp add: UP_def up_add_closed)
ballarin@13940
   208
ballarin@13940
   209
lemma (in UP_cring) coeff_mult [simp]:
ballarin@13940
   210
  "[| p \<in> carrier P; q \<in> carrier P |] ==>
ballarin@15095
   211
  coeff P (p \<otimes>\<^bsub>P\<^esub> q) n = (\<Oplus>i \<in> {..n}. coeff P p i \<otimes> coeff P q (n-i))"
ballarin@13940
   212
  by (simp add: UP_def up_mult_closed)
ballarin@13940
   213
ballarin@13940
   214
lemma (in UP) up_eqI:
ballarin@13940
   215
  assumes prem: "!!n. coeff P p n = coeff P q n"
ballarin@13940
   216
    and R: "p \<in> carrier P" "q \<in> carrier P"
ballarin@13940
   217
  shows "p = q"
ballarin@13940
   218
proof
ballarin@13940
   219
  fix x
ballarin@13940
   220
  from prem and R show "p x = q x" by (simp add: UP_def)
ballarin@13940
   221
qed
wenzelm@14666
   222
ballarin@20318
   223
ballarin@20318
   224
subsection {* Polynomials Form a Commutative Ring. *}
ballarin@13940
   225
wenzelm@14666
   226
text {* Operations are closed over @{term P}. *}
ballarin@13940
   227
ballarin@13940
   228
lemma (in UP_cring) UP_mult_closed [simp]:
ballarin@15095
   229
  "[| p \<in> carrier P; q \<in> carrier P |] ==> p \<otimes>\<^bsub>P\<^esub> q \<in> carrier P"
ballarin@13940
   230
  by (simp add: UP_def up_mult_closed)
ballarin@13940
   231
ballarin@13940
   232
lemma (in UP_cring) UP_one_closed [simp]:
ballarin@15095
   233
  "\<one>\<^bsub>P\<^esub> \<in> carrier P"
ballarin@13940
   234
  by (simp add: UP_def up_one_closed)
ballarin@13940
   235
ballarin@13940
   236
lemma (in UP_cring) UP_zero_closed [intro, simp]:
ballarin@15095
   237
  "\<zero>\<^bsub>P\<^esub> \<in> carrier P"
ballarin@13940
   238
  by (auto simp add: UP_def)
ballarin@13940
   239
ballarin@13940
   240
lemma (in UP_cring) UP_a_closed [intro, simp]:
ballarin@15095
   241
  "[| p \<in> carrier P; q \<in> carrier P |] ==> p \<oplus>\<^bsub>P\<^esub> q \<in> carrier P"
ballarin@13940
   242
  by (simp add: UP_def up_add_closed)
ballarin@13940
   243
ballarin@13940
   244
lemma (in UP_cring) monom_closed [simp]:
ballarin@13940
   245
  "a \<in> carrier R ==> monom P a n \<in> carrier P"
ballarin@13940
   246
  by (auto simp add: UP_def up_def Pi_def)
ballarin@13940
   247
ballarin@13940
   248
lemma (in UP_cring) UP_smult_closed [simp]:
ballarin@15095
   249
  "[| a \<in> carrier R; p \<in> carrier P |] ==> a \<odot>\<^bsub>P\<^esub> p \<in> carrier P"
ballarin@13940
   250
  by (simp add: UP_def up_smult_closed)
ballarin@13940
   251
ballarin@13940
   252
lemma (in UP) coeff_closed [simp]:
ballarin@13940
   253
  "p \<in> carrier P ==> coeff P p n \<in> carrier R"
ballarin@13940
   254
  by (auto simp add: UP_def)
ballarin@13940
   255
ballarin@13940
   256
declare (in UP) P_def [simp del]
ballarin@13940
   257
ballarin@13940
   258
text {* Algebraic ring properties *}
ballarin@13940
   259
ballarin@13940
   260
lemma (in UP_cring) UP_a_assoc:
ballarin@13940
   261
  assumes R: "p \<in> carrier P" "q \<in> carrier P" "r \<in> carrier P"
ballarin@15095
   262
  shows "(p \<oplus>\<^bsub>P\<^esub> q) \<oplus>\<^bsub>P\<^esub> r = p \<oplus>\<^bsub>P\<^esub> (q \<oplus>\<^bsub>P\<^esub> r)"
ballarin@13940
   263
  by (rule up_eqI, simp add: a_assoc R, simp_all add: R)
ballarin@13940
   264
ballarin@13940
   265
lemma (in UP_cring) UP_l_zero [simp]:
ballarin@13940
   266
  assumes R: "p \<in> carrier P"
ballarin@15095
   267
  shows "\<zero>\<^bsub>P\<^esub> \<oplus>\<^bsub>P\<^esub> p = p"
ballarin@13940
   268
  by (rule up_eqI, simp_all add: R)
ballarin@13940
   269
ballarin@13940
   270
lemma (in UP_cring) UP_l_neg_ex:
ballarin@13940
   271
  assumes R: "p \<in> carrier P"
ballarin@15095
   272
  shows "EX q : carrier P. q \<oplus>\<^bsub>P\<^esub> p = \<zero>\<^bsub>P\<^esub>"
ballarin@13940
   273
proof -
ballarin@13940
   274
  let ?q = "%i. \<ominus> (p i)"
ballarin@13940
   275
  from R have closed: "?q \<in> carrier P"
ballarin@13940
   276
    by (simp add: UP_def P_def up_a_inv_closed)
ballarin@13940
   277
  from R have coeff: "!!n. coeff P ?q n = \<ominus> (coeff P p n)"
ballarin@13940
   278
    by (simp add: UP_def P_def up_a_inv_closed)
ballarin@13940
   279
  show ?thesis
ballarin@13940
   280
  proof
ballarin@15095
   281
    show "?q \<oplus>\<^bsub>P\<^esub> p = \<zero>\<^bsub>P\<^esub>"
ballarin@13940
   282
      by (auto intro!: up_eqI simp add: R closed coeff R.l_neg)
ballarin@13940
   283
  qed (rule closed)
ballarin@13940
   284
qed
ballarin@13940
   285
ballarin@13940
   286
lemma (in UP_cring) UP_a_comm:
ballarin@13940
   287
  assumes R: "p \<in> carrier P" "q \<in> carrier P"
ballarin@15095
   288
  shows "p \<oplus>\<^bsub>P\<^esub> q = q \<oplus>\<^bsub>P\<^esub> p"
ballarin@13940
   289
  by (rule up_eqI, simp add: a_comm R, simp_all add: R)
ballarin@13940
   290
ballarin@13940
   291
lemma (in UP_cring) UP_m_assoc:
ballarin@13940
   292
  assumes R: "p \<in> carrier P" "q \<in> carrier P" "r \<in> carrier P"
ballarin@15095
   293
  shows "(p \<otimes>\<^bsub>P\<^esub> q) \<otimes>\<^bsub>P\<^esub> r = p \<otimes>\<^bsub>P\<^esub> (q \<otimes>\<^bsub>P\<^esub> r)"
ballarin@13940
   294
proof (rule up_eqI)
ballarin@13940
   295
  fix n
ballarin@13940
   296
  {
ballarin@13940
   297
    fix k and a b c :: "nat=>'a"
ballarin@13940
   298
    assume R: "a \<in> UNIV -> carrier R" "b \<in> UNIV -> carrier R"
ballarin@13940
   299
      "c \<in> UNIV -> carrier R"
ballarin@13940
   300
    then have "k <= n ==>
wenzelm@14666
   301
      (\<Oplus>j \<in> {..k}. (\<Oplus>i \<in> {..j}. a i \<otimes> b (j-i)) \<otimes> c (n-j)) =
wenzelm@14666
   302
      (\<Oplus>j \<in> {..k}. a j \<otimes> (\<Oplus>i \<in> {..k-j}. b i \<otimes> c (n-j-i)))"
wenzelm@19582
   303
      (is "_ \<Longrightarrow> ?eq k")
ballarin@13940
   304
    proof (induct k)
ballarin@13940
   305
      case 0 then show ?case by (simp add: Pi_def m_assoc)
ballarin@13940
   306
    next
ballarin@13940
   307
      case (Suc k)
ballarin@13940
   308
      then have "k <= n" by arith
wenzelm@23350
   309
      from this R have "?eq k" by (rule Suc)
ballarin@13940
   310
      with R show ?case
wenzelm@14666
   311
        by (simp cong: finsum_cong
ballarin@13940
   312
             add: Suc_diff_le Pi_def l_distr r_distr m_assoc)
ballarin@13940
   313
          (simp cong: finsum_cong add: Pi_def a_ac finsum_ldistr m_assoc)
ballarin@13940
   314
    qed
ballarin@13940
   315
  }
ballarin@15095
   316
  with R show "coeff P ((p \<otimes>\<^bsub>P\<^esub> q) \<otimes>\<^bsub>P\<^esub> r) n = coeff P (p \<otimes>\<^bsub>P\<^esub> (q \<otimes>\<^bsub>P\<^esub> r)) n"
ballarin@13940
   317
    by (simp add: Pi_def)
ballarin@13940
   318
qed (simp_all add: R)
ballarin@13940
   319
ballarin@13940
   320
lemma (in UP_cring) UP_l_one [simp]:
ballarin@13940
   321
  assumes R: "p \<in> carrier P"
ballarin@15095
   322
  shows "\<one>\<^bsub>P\<^esub> \<otimes>\<^bsub>P\<^esub> p = p"
ballarin@13940
   323
proof (rule up_eqI)
ballarin@13940
   324
  fix n
ballarin@15095
   325
  show "coeff P (\<one>\<^bsub>P\<^esub> \<otimes>\<^bsub>P\<^esub> p) n = coeff P p n"
ballarin@13940
   326
  proof (cases n)
ballarin@13940
   327
    case 0 with R show ?thesis by simp
ballarin@13940
   328
  next
ballarin@13940
   329
    case Suc with R show ?thesis
ballarin@13940
   330
      by (simp del: finsum_Suc add: finsum_Suc2 Pi_def)
ballarin@13940
   331
  qed
ballarin@13940
   332
qed (simp_all add: R)
ballarin@13940
   333
ballarin@13940
   334
lemma (in UP_cring) UP_l_distr:
ballarin@13940
   335
  assumes R: "p \<in> carrier P" "q \<in> carrier P" "r \<in> carrier P"
ballarin@15095
   336
  shows "(p \<oplus>\<^bsub>P\<^esub> q) \<otimes>\<^bsub>P\<^esub> r = (p \<otimes>\<^bsub>P\<^esub> r) \<oplus>\<^bsub>P\<^esub> (q \<otimes>\<^bsub>P\<^esub> r)"
ballarin@13940
   337
  by (rule up_eqI) (simp add: l_distr R Pi_def, simp_all add: R)
ballarin@13940
   338
ballarin@13940
   339
lemma (in UP_cring) UP_m_comm:
ballarin@13940
   340
  assumes R: "p \<in> carrier P" "q \<in> carrier P"
ballarin@15095
   341
  shows "p \<otimes>\<^bsub>P\<^esub> q = q \<otimes>\<^bsub>P\<^esub> p"
ballarin@13940
   342
proof (rule up_eqI)
wenzelm@14666
   343
  fix n
ballarin@13940
   344
  {
ballarin@13940
   345
    fix k and a b :: "nat=>'a"
ballarin@13940
   346
    assume R: "a \<in> UNIV -> carrier R" "b \<in> UNIV -> carrier R"
wenzelm@14666
   347
    then have "k <= n ==>
wenzelm@14666
   348
      (\<Oplus>i \<in> {..k}. a i \<otimes> b (n-i)) =
wenzelm@14666
   349
      (\<Oplus>i \<in> {..k}. a (k-i) \<otimes> b (i+n-k))"
wenzelm@19582
   350
      (is "_ \<Longrightarrow> ?eq k")
ballarin@13940
   351
    proof (induct k)
ballarin@13940
   352
      case 0 then show ?case by (simp add: Pi_def)
ballarin@13940
   353
    next
ballarin@13940
   354
      case (Suc k) then show ?case
paulson@15944
   355
        by (subst (2) finsum_Suc2) (simp add: Pi_def a_comm)+
ballarin@13940
   356
    qed
ballarin@13940
   357
  }
ballarin@13940
   358
  note l = this
ballarin@15095
   359
  from R show "coeff P (p \<otimes>\<^bsub>P\<^esub> q) n =  coeff P (q \<otimes>\<^bsub>P\<^esub> p) n"
ballarin@13940
   360
    apply (simp add: Pi_def)
ballarin@13940
   361
    apply (subst l)
ballarin@13940
   362
    apply (auto simp add: Pi_def)
ballarin@13940
   363
    apply (simp add: m_comm)
ballarin@13940
   364
    done
ballarin@13940
   365
qed (simp_all add: R)
ballarin@13940
   366
ballarin@13940
   367
theorem (in UP_cring) UP_cring:
ballarin@13940
   368
  "cring P"
ballarin@13940
   369
  by (auto intro!: cringI abelian_groupI comm_monoidI UP_a_assoc UP_l_zero
ballarin@13940
   370
    UP_l_neg_ex UP_a_comm UP_m_assoc UP_l_one UP_m_comm UP_l_distr)
ballarin@13940
   371
ballarin@17094
   372
lemma (in UP_cring) UP_ring:
ballarin@17094
   373
  (* preliminary,
ballarin@17094
   374
     we want "UP_ring R P ==> ring P", not "UP_cring R P ==> ring P" *)
ballarin@14399
   375
  "ring P"
ballarin@14399
   376
  by (auto intro: ring.intro cring.axioms UP_cring)
ballarin@14399
   377
ballarin@13940
   378
lemma (in UP_cring) UP_a_inv_closed [intro, simp]:
ballarin@15095
   379
  "p \<in> carrier P ==> \<ominus>\<^bsub>P\<^esub> p \<in> carrier P"
ballarin@13940
   380
  by (rule abelian_group.a_inv_closed
ballarin@14399
   381
    [OF ring.is_abelian_group [OF UP_ring]])
ballarin@13940
   382
ballarin@13940
   383
lemma (in UP_cring) coeff_a_inv [simp]:
ballarin@13940
   384
  assumes R: "p \<in> carrier P"
ballarin@15095
   385
  shows "coeff P (\<ominus>\<^bsub>P\<^esub> p) n = \<ominus> (coeff P p n)"
ballarin@13940
   386
proof -
ballarin@13940
   387
  from R coeff_closed UP_a_inv_closed have
ballarin@15095
   388
    "coeff P (\<ominus>\<^bsub>P\<^esub> p) n = \<ominus> coeff P p n \<oplus> (coeff P p n \<oplus> coeff P (\<ominus>\<^bsub>P\<^esub> p) n)"
ballarin@13940
   389
    by algebra
ballarin@13940
   390
  also from R have "... =  \<ominus> (coeff P p n)"
ballarin@13940
   391
    by (simp del: coeff_add add: coeff_add [THEN sym]
ballarin@14399
   392
      abelian_group.r_neg [OF ring.is_abelian_group [OF UP_ring]])
ballarin@13940
   393
  finally show ?thesis .
ballarin@13940
   394
qed
ballarin@13940
   395
ballarin@13940
   396
text {*
ballarin@17094
   397
  Interpretation of lemmas from @{term cring}.  Saves lifting 43
ballarin@17094
   398
  lemmas manually.
ballarin@13940
   399
*}
ballarin@13940
   400
ballarin@17094
   401
interpretation UP_cring < cring P
ballarin@19984
   402
  by intro_locales
ballarin@19931
   403
    (rule cring.axioms ring.axioms abelian_group.axioms comm_monoid.axioms UP_cring)+
ballarin@13940
   404
wenzelm@14666
   405
ballarin@20318
   406
subsection {* Polynomials Form an Algebra *}
ballarin@13940
   407
ballarin@13940
   408
lemma (in UP_cring) UP_smult_l_distr:
ballarin@13940
   409
  "[| a \<in> carrier R; b \<in> carrier R; p \<in> carrier P |] ==>
ballarin@15095
   410
  (a \<oplus> b) \<odot>\<^bsub>P\<^esub> p = a \<odot>\<^bsub>P\<^esub> p \<oplus>\<^bsub>P\<^esub> b \<odot>\<^bsub>P\<^esub> p"
ballarin@13940
   411
  by (rule up_eqI) (simp_all add: R.l_distr)
ballarin@13940
   412
ballarin@13940
   413
lemma (in UP_cring) UP_smult_r_distr:
ballarin@13940
   414
  "[| a \<in> carrier R; p \<in> carrier P; q \<in> carrier P |] ==>
ballarin@15095
   415
  a \<odot>\<^bsub>P\<^esub> (p \<oplus>\<^bsub>P\<^esub> q) = a \<odot>\<^bsub>P\<^esub> p \<oplus>\<^bsub>P\<^esub> a \<odot>\<^bsub>P\<^esub> q"
ballarin@13940
   416
  by (rule up_eqI) (simp_all add: R.r_distr)
ballarin@13940
   417
ballarin@13940
   418
lemma (in UP_cring) UP_smult_assoc1:
ballarin@13940
   419
      "[| a \<in> carrier R; b \<in> carrier R; p \<in> carrier P |] ==>
ballarin@15095
   420
      (a \<otimes> b) \<odot>\<^bsub>P\<^esub> p = a \<odot>\<^bsub>P\<^esub> (b \<odot>\<^bsub>P\<^esub> p)"
ballarin@13940
   421
  by (rule up_eqI) (simp_all add: R.m_assoc)
ballarin@13940
   422
ballarin@13940
   423
lemma (in UP_cring) UP_smult_one [simp]:
ballarin@15095
   424
      "p \<in> carrier P ==> \<one> \<odot>\<^bsub>P\<^esub> p = p"
ballarin@13940
   425
  by (rule up_eqI) simp_all
ballarin@13940
   426
ballarin@13940
   427
lemma (in UP_cring) UP_smult_assoc2:
ballarin@13940
   428
  "[| a \<in> carrier R; p \<in> carrier P; q \<in> carrier P |] ==>
ballarin@15095
   429
  (a \<odot>\<^bsub>P\<^esub> p) \<otimes>\<^bsub>P\<^esub> q = a \<odot>\<^bsub>P\<^esub> (p \<otimes>\<^bsub>P\<^esub> q)"
ballarin@13940
   430
  by (rule up_eqI) (simp_all add: R.finsum_rdistr R.m_assoc Pi_def)
ballarin@13940
   431
ballarin@13940
   432
text {*
ballarin@17094
   433
  Interpretation of lemmas from @{term algebra}.
ballarin@13940
   434
*}
ballarin@13940
   435
ballarin@13940
   436
lemma (in cring) cring:
ballarin@13940
   437
  "cring R"
ballarin@13940
   438
  by (fast intro: cring.intro prems)
ballarin@13940
   439
ballarin@13940
   440
lemma (in UP_cring) UP_algebra:
ballarin@13940
   441
  "algebra R P"
ballarin@17094
   442
  by (auto intro: algebraI R.cring UP_cring UP_smult_l_distr UP_smult_r_distr
ballarin@13940
   443
    UP_smult_assoc1 UP_smult_assoc2)
ballarin@13940
   444
ballarin@17094
   445
interpretation UP_cring < algebra R P
ballarin@19984
   446
  by intro_locales
ballarin@19931
   447
    (rule module.axioms algebra.axioms UP_algebra)+
ballarin@13940
   448
ballarin@13940
   449
ballarin@20318
   450
subsection {* Further Lemmas Involving Monomials *}
ballarin@13940
   451
ballarin@13940
   452
lemma (in UP_cring) monom_zero [simp]:
ballarin@15095
   453
  "monom P \<zero> n = \<zero>\<^bsub>P\<^esub>"
ballarin@13940
   454
  by (simp add: UP_def P_def)
ballarin@13940
   455
ballarin@13940
   456
lemma (in UP_cring) monom_mult_is_smult:
ballarin@13940
   457
  assumes R: "a \<in> carrier R" "p \<in> carrier P"
ballarin@15095
   458
  shows "monom P a 0 \<otimes>\<^bsub>P\<^esub> p = a \<odot>\<^bsub>P\<^esub> p"
ballarin@13940
   459
proof (rule up_eqI)
ballarin@13940
   460
  fix n
ballarin@15095
   461
  have "coeff P (p \<otimes>\<^bsub>P\<^esub> monom P a 0) n = coeff P (a \<odot>\<^bsub>P\<^esub> p) n"
ballarin@13940
   462
  proof (cases n)
ballarin@13940
   463
    case 0 with R show ?thesis by (simp add: R.m_comm)
ballarin@13940
   464
  next
ballarin@13940
   465
    case Suc with R show ?thesis
ballarin@17094
   466
      by (simp cong: R.finsum_cong add: R.r_null Pi_def)
ballarin@17094
   467
        (simp add: R.m_comm)
ballarin@13940
   468
  qed
ballarin@15095
   469
  with R show "coeff P (monom P a 0 \<otimes>\<^bsub>P\<^esub> p) n = coeff P (a \<odot>\<^bsub>P\<^esub> p) n"
ballarin@13940
   470
    by (simp add: UP_m_comm)
ballarin@13940
   471
qed (simp_all add: R)
ballarin@13940
   472
ballarin@13940
   473
lemma (in UP_cring) monom_add [simp]:
ballarin@13940
   474
  "[| a \<in> carrier R; b \<in> carrier R |] ==>
ballarin@15095
   475
  monom P (a \<oplus> b) n = monom P a n \<oplus>\<^bsub>P\<^esub> monom P b n"
ballarin@13940
   476
  by (rule up_eqI) simp_all
ballarin@13940
   477
ballarin@13940
   478
lemma (in UP_cring) monom_one_Suc:
ballarin@15095
   479
  "monom P \<one> (Suc n) = monom P \<one> n \<otimes>\<^bsub>P\<^esub> monom P \<one> 1"
ballarin@13940
   480
proof (rule up_eqI)
ballarin@13940
   481
  fix k
ballarin@15095
   482
  show "coeff P (monom P \<one> (Suc n)) k = coeff P (monom P \<one> n \<otimes>\<^bsub>P\<^esub> monom P \<one> 1) k"
ballarin@13940
   483
  proof (cases "k = Suc n")
ballarin@13940
   484
    case True show ?thesis
ballarin@13940
   485
    proof -
wenzelm@26934
   486
      fix m
wenzelm@14666
   487
      from True have less_add_diff:
wenzelm@14666
   488
        "!!i. [| n < i; i <= n + m |] ==> n + m - i < m" by arith
ballarin@13940
   489
      from True have "coeff P (monom P \<one> (Suc n)) k = \<one>" by simp
ballarin@13940
   490
      also from True
nipkow@15045
   491
      have "... = (\<Oplus>i \<in> {..<n} \<union> {n}. coeff P (monom P \<one> n) i \<otimes>
wenzelm@14666
   492
        coeff P (monom P \<one> 1) (k - i))"
ballarin@17094
   493
        by (simp cong: R.finsum_cong add: Pi_def)
wenzelm@14666
   494
      also have "... = (\<Oplus>i \<in>  {..n}. coeff P (monom P \<one> n) i \<otimes>
wenzelm@14666
   495
        coeff P (monom P \<one> 1) (k - i))"
wenzelm@14666
   496
        by (simp only: ivl_disj_un_singleton)
ballarin@15095
   497
      also from True
ballarin@15095
   498
      have "... = (\<Oplus>i \<in> {..n} \<union> {n<..k}. coeff P (monom P \<one> n) i \<otimes>
wenzelm@14666
   499
        coeff P (monom P \<one> 1) (k - i))"
ballarin@17094
   500
        by (simp cong: R.finsum_cong add: R.finsum_Un_disjoint ivl_disj_int_one
wenzelm@14666
   501
          order_less_imp_not_eq Pi_def)
ballarin@15095
   502
      also from True have "... = coeff P (monom P \<one> n \<otimes>\<^bsub>P\<^esub> monom P \<one> 1) k"
wenzelm@14666
   503
        by (simp add: ivl_disj_un_one)
ballarin@13940
   504
      finally show ?thesis .
ballarin@13940
   505
    qed
ballarin@13940
   506
  next
ballarin@13940
   507
    case False
ballarin@13940
   508
    note neq = False
ballarin@13940
   509
    let ?s =
wenzelm@14666
   510
      "\<lambda>i. (if n = i then \<one> else \<zero>) \<otimes> (if Suc 0 = k - i then \<one> else \<zero>)"
ballarin@13940
   511
    from neq have "coeff P (monom P \<one> (Suc n)) k = \<zero>" by simp
wenzelm@14666
   512
    also have "... = (\<Oplus>i \<in> {..k}. ?s i)"
ballarin@13940
   513
    proof -
ballarin@15095
   514
      have f1: "(\<Oplus>i \<in> {..<n}. ?s i) = \<zero>"
ballarin@17094
   515
        by (simp cong: R.finsum_cong add: Pi_def)
wenzelm@14666
   516
      from neq have f2: "(\<Oplus>i \<in> {n}. ?s i) = \<zero>"
webertj@20432
   517
        by (simp cong: R.finsum_cong add: Pi_def) arith
nipkow@15045
   518
      have f3: "n < k ==> (\<Oplus>i \<in> {n<..k}. ?s i) = \<zero>"
ballarin@17094
   519
        by (simp cong: R.finsum_cong add: order_less_imp_not_eq Pi_def)
ballarin@13940
   520
      show ?thesis
ballarin@13940
   521
      proof (cases "k < n")
ballarin@17094
   522
        case True then show ?thesis by (simp cong: R.finsum_cong add: Pi_def)
ballarin@13940
   523
      next
wenzelm@14666
   524
        case False then have n_le_k: "n <= k" by arith
wenzelm@14666
   525
        show ?thesis
wenzelm@14666
   526
        proof (cases "n = k")
wenzelm@14666
   527
          case True
nipkow@15045
   528
          then have "\<zero> = (\<Oplus>i \<in> {..<n} \<union> {n}. ?s i)"
ballarin@17094
   529
            by (simp cong: R.finsum_cong add: ivl_disj_int_singleton Pi_def)
wenzelm@14666
   530
          also from True have "... = (\<Oplus>i \<in> {..k}. ?s i)"
wenzelm@14666
   531
            by (simp only: ivl_disj_un_singleton)
wenzelm@14666
   532
          finally show ?thesis .
wenzelm@14666
   533
        next
wenzelm@14666
   534
          case False with n_le_k have n_less_k: "n < k" by arith
nipkow@15045
   535
          with neq have "\<zero> = (\<Oplus>i \<in> {..<n} \<union> {n}. ?s i)"
ballarin@17094
   536
            by (simp add: R.finsum_Un_disjoint f1 f2
wenzelm@14666
   537
              ivl_disj_int_singleton Pi_def del: Un_insert_right)
wenzelm@14666
   538
          also have "... = (\<Oplus>i \<in> {..n}. ?s i)"
wenzelm@14666
   539
            by (simp only: ivl_disj_un_singleton)
nipkow@15045
   540
          also from n_less_k neq have "... = (\<Oplus>i \<in> {..n} \<union> {n<..k}. ?s i)"
ballarin@17094
   541
            by (simp add: R.finsum_Un_disjoint f3 ivl_disj_int_one Pi_def)
wenzelm@14666
   542
          also from n_less_k have "... = (\<Oplus>i \<in> {..k}. ?s i)"
wenzelm@14666
   543
            by (simp only: ivl_disj_un_one)
wenzelm@14666
   544
          finally show ?thesis .
wenzelm@14666
   545
        qed
ballarin@13940
   546
      qed
ballarin@13940
   547
    qed
ballarin@15095
   548
    also have "... = coeff P (monom P \<one> n \<otimes>\<^bsub>P\<^esub> monom P \<one> 1) k" by simp
ballarin@13940
   549
    finally show ?thesis .
ballarin@13940
   550
  qed
ballarin@13940
   551
qed (simp_all)
ballarin@13940
   552
ballarin@13940
   553
lemma (in UP_cring) monom_mult_smult:
ballarin@15095
   554
  "[| a \<in> carrier R; b \<in> carrier R |] ==> monom P (a \<otimes> b) n = a \<odot>\<^bsub>P\<^esub> monom P b n"
ballarin@13940
   555
  by (rule up_eqI) simp_all
ballarin@13940
   556
ballarin@13940
   557
lemma (in UP_cring) monom_one [simp]:
ballarin@15095
   558
  "monom P \<one> 0 = \<one>\<^bsub>P\<^esub>"
ballarin@13940
   559
  by (rule up_eqI) simp_all
ballarin@13940
   560
ballarin@13940
   561
lemma (in UP_cring) monom_one_mult:
ballarin@15095
   562
  "monom P \<one> (n + m) = monom P \<one> n \<otimes>\<^bsub>P\<^esub> monom P \<one> m"
ballarin@13940
   563
proof (induct n)
ballarin@13940
   564
  case 0 show ?case by simp
ballarin@13940
   565
next
ballarin@13940
   566
  case Suc then show ?case
ballarin@17094
   567
    by (simp only: add_Suc monom_one_Suc) (simp add: P.m_ac)
ballarin@13940
   568
qed
ballarin@13940
   569
ballarin@13940
   570
lemma (in UP_cring) monom_mult [simp]:
ballarin@13940
   571
  assumes R: "a \<in> carrier R" "b \<in> carrier R"
ballarin@15095
   572
  shows "monom P (a \<otimes> b) (n + m) = monom P a n \<otimes>\<^bsub>P\<^esub> monom P b m"
ballarin@13940
   573
proof -
ballarin@13940
   574
  from R have "monom P (a \<otimes> b) (n + m) = monom P (a \<otimes> b \<otimes> \<one>) (n + m)" by simp
ballarin@15095
   575
  also from R have "... = a \<otimes> b \<odot>\<^bsub>P\<^esub> monom P \<one> (n + m)"
ballarin@17094
   576
    by (simp add: monom_mult_smult del: R.r_one)
ballarin@15095
   577
  also have "... = a \<otimes> b \<odot>\<^bsub>P\<^esub> (monom P \<one> n \<otimes>\<^bsub>P\<^esub> monom P \<one> m)"
ballarin@13940
   578
    by (simp only: monom_one_mult)
ballarin@15095
   579
  also from R have "... = a \<odot>\<^bsub>P\<^esub> (b \<odot>\<^bsub>P\<^esub> (monom P \<one> n \<otimes>\<^bsub>P\<^esub> monom P \<one> m))"
ballarin@13940
   580
    by (simp add: UP_smult_assoc1)
ballarin@15095
   581
  also from R have "... = a \<odot>\<^bsub>P\<^esub> (b \<odot>\<^bsub>P\<^esub> (monom P \<one> m \<otimes>\<^bsub>P\<^esub> monom P \<one> n))"
ballarin@17094
   582
    by (simp add: P.m_comm)
ballarin@15095
   583
  also from R have "... = a \<odot>\<^bsub>P\<^esub> ((b \<odot>\<^bsub>P\<^esub> monom P \<one> m) \<otimes>\<^bsub>P\<^esub> monom P \<one> n)"
ballarin@13940
   584
    by (simp add: UP_smult_assoc2)
ballarin@15095
   585
  also from R have "... = a \<odot>\<^bsub>P\<^esub> (monom P \<one> n \<otimes>\<^bsub>P\<^esub> (b \<odot>\<^bsub>P\<^esub> monom P \<one> m))"
ballarin@17094
   586
    by (simp add: P.m_comm)
ballarin@15095
   587
  also from R have "... = (a \<odot>\<^bsub>P\<^esub> monom P \<one> n) \<otimes>\<^bsub>P\<^esub> (b \<odot>\<^bsub>P\<^esub> monom P \<one> m)"
ballarin@13940
   588
    by (simp add: UP_smult_assoc2)
ballarin@15095
   589
  also from R have "... = monom P (a \<otimes> \<one>) n \<otimes>\<^bsub>P\<^esub> monom P (b \<otimes> \<one>) m"
ballarin@17094
   590
    by (simp add: monom_mult_smult del: R.r_one)
ballarin@15095
   591
  also from R have "... = monom P a n \<otimes>\<^bsub>P\<^esub> monom P b m" by simp
ballarin@13940
   592
  finally show ?thesis .
ballarin@13940
   593
qed
ballarin@13940
   594
ballarin@13940
   595
lemma (in UP_cring) monom_a_inv [simp]:
ballarin@15095
   596
  "a \<in> carrier R ==> monom P (\<ominus> a) n = \<ominus>\<^bsub>P\<^esub> monom P a n"
ballarin@13940
   597
  by (rule up_eqI) simp_all
ballarin@13940
   598
ballarin@13940
   599
lemma (in UP_cring) monom_inj:
ballarin@13940
   600
  "inj_on (%a. monom P a n) (carrier R)"
ballarin@13940
   601
proof (rule inj_onI)
ballarin@13940
   602
  fix x y
ballarin@13940
   603
  assume R: "x \<in> carrier R" "y \<in> carrier R" and eq: "monom P x n = monom P y n"
ballarin@13940
   604
  then have "coeff P (monom P x n) n = coeff P (monom P y n) n" by simp
ballarin@13940
   605
  with R show "x = y" by simp
ballarin@13940
   606
qed
ballarin@13940
   607
ballarin@17094
   608
ballarin@20318
   609
subsection {* The Degree Function *}
ballarin@13940
   610
wenzelm@14651
   611
constdefs (structure R)
ballarin@15095
   612
  deg :: "[('a, 'm) ring_scheme, nat => 'a] => nat"
wenzelm@14651
   613
  "deg R p == LEAST n. bound \<zero> n (coeff (UP R) p)"
ballarin@13940
   614
ballarin@13940
   615
lemma (in UP_cring) deg_aboveI:
wenzelm@14666
   616
  "[| (!!m. n < m ==> coeff P p m = \<zero>); p \<in> carrier P |] ==> deg R p <= n"
ballarin@13940
   617
  by (unfold deg_def P_def) (fast intro: Least_le)
ballarin@15095
   618
ballarin@13940
   619
(*
ballarin@13940
   620
lemma coeff_bound_ex: "EX n. bound n (coeff p)"
ballarin@13940
   621
proof -
ballarin@13940
   622
  have "(%n. coeff p n) : UP" by (simp add: coeff_def Rep_UP)
ballarin@13940
   623
  then obtain n where "bound n (coeff p)" by (unfold UP_def) fast
ballarin@13940
   624
  then show ?thesis ..
ballarin@13940
   625
qed
wenzelm@14666
   626
ballarin@13940
   627
lemma bound_coeff_obtain:
ballarin@13940
   628
  assumes prem: "(!!n. bound n (coeff p) ==> P)" shows "P"
ballarin@13940
   629
proof -
ballarin@13940
   630
  have "(%n. coeff p n) : UP" by (simp add: coeff_def Rep_UP)
ballarin@13940
   631
  then obtain n where "bound n (coeff p)" by (unfold UP_def) fast
ballarin@13940
   632
  with prem show P .
ballarin@13940
   633
qed
ballarin@13940
   634
*)
ballarin@15095
   635
ballarin@13940
   636
lemma (in UP_cring) deg_aboveD:
wenzelm@23350
   637
  assumes "deg R p < m" and "p \<in> carrier P"
wenzelm@23350
   638
  shows "coeff P p m = \<zero>"
ballarin@13940
   639
proof -
wenzelm@23350
   640
  from `p \<in> carrier P` obtain n where "bound \<zero> n (coeff P p)"
ballarin@13940
   641
    by (auto simp add: UP_def P_def)
ballarin@13940
   642
  then have "bound \<zero> (deg R p) (coeff P p)"
ballarin@13940
   643
    by (auto simp: deg_def P_def dest: LeastI)
wenzelm@23350
   644
  from this and `deg R p < m` show ?thesis ..
ballarin@13940
   645
qed
ballarin@13940
   646
ballarin@13940
   647
lemma (in UP_cring) deg_belowI:
ballarin@13940
   648
  assumes non_zero: "n ~= 0 ==> coeff P p n ~= \<zero>"
ballarin@13940
   649
    and R: "p \<in> carrier P"
ballarin@13940
   650
  shows "n <= deg R p"
wenzelm@14666
   651
-- {* Logically, this is a slightly stronger version of
ballarin@15095
   652
   @{thm [source] deg_aboveD} *}
ballarin@13940
   653
proof (cases "n=0")
ballarin@13940
   654
  case True then show ?thesis by simp
ballarin@13940
   655
next
ballarin@13940
   656
  case False then have "coeff P p n ~= \<zero>" by (rule non_zero)
ballarin@13940
   657
  then have "~ deg R p < n" by (fast dest: deg_aboveD intro: R)
ballarin@13940
   658
  then show ?thesis by arith
ballarin@13940
   659
qed
ballarin@13940
   660
ballarin@13940
   661
lemma (in UP_cring) lcoeff_nonzero_deg:
ballarin@13940
   662
  assumes deg: "deg R p ~= 0" and R: "p \<in> carrier P"
ballarin@13940
   663
  shows "coeff P p (deg R p) ~= \<zero>"
ballarin@13940
   664
proof -
ballarin@13940
   665
  from R obtain m where "deg R p <= m" and m_coeff: "coeff P p m ~= \<zero>"
ballarin@13940
   666
  proof -
ballarin@13940
   667
    have minus: "!!(n::nat) m. n ~= 0 ==> (n - Suc 0 < m) = (n <= m)"
ballarin@13940
   668
      by arith
ballarin@15095
   669
(* TODO: why does simplification below not work with "1" *)
ballarin@13940
   670
    from deg have "deg R p - 1 < (LEAST n. bound \<zero> n (coeff P p))"
ballarin@13940
   671
      by (unfold deg_def P_def) arith
ballarin@13940
   672
    then have "~ bound \<zero> (deg R p - 1) (coeff P p)" by (rule not_less_Least)
ballarin@13940
   673
    then have "EX m. deg R p - 1 < m & coeff P p m ~= \<zero>"
ballarin@13940
   674
      by (unfold bound_def) fast
ballarin@13940
   675
    then have "EX m. deg R p <= m & coeff P p m ~= \<zero>" by (simp add: deg minus)
wenzelm@23350
   676
    then show ?thesis by (auto intro: that)
ballarin@13940
   677
  qed
ballarin@13940
   678
  with deg_belowI R have "deg R p = m" by fastsimp
ballarin@13940
   679
  with m_coeff show ?thesis by simp
ballarin@13940
   680
qed
ballarin@13940
   681
ballarin@13940
   682
lemma (in UP_cring) lcoeff_nonzero_nonzero:
ballarin@15095
   683
  assumes deg: "deg R p = 0" and nonzero: "p ~= \<zero>\<^bsub>P\<^esub>" and R: "p \<in> carrier P"
ballarin@13940
   684
  shows "coeff P p 0 ~= \<zero>"
ballarin@13940
   685
proof -
ballarin@13940
   686
  have "EX m. coeff P p m ~= \<zero>"
ballarin@13940
   687
  proof (rule classical)
ballarin@13940
   688
    assume "~ ?thesis"
ballarin@15095
   689
    with R have "p = \<zero>\<^bsub>P\<^esub>" by (auto intro: up_eqI)
ballarin@13940
   690
    with nonzero show ?thesis by contradiction
ballarin@13940
   691
  qed
ballarin@13940
   692
  then obtain m where coeff: "coeff P p m ~= \<zero>" ..
wenzelm@23350
   693
  from this and R have "m <= deg R p" by (rule deg_belowI)
ballarin@13940
   694
  then have "m = 0" by (simp add: deg)
ballarin@13940
   695
  with coeff show ?thesis by simp
ballarin@13940
   696
qed
ballarin@13940
   697
ballarin@13940
   698
lemma (in UP_cring) lcoeff_nonzero:
ballarin@15095
   699
  assumes neq: "p ~= \<zero>\<^bsub>P\<^esub>" and R: "p \<in> carrier P"
ballarin@13940
   700
  shows "coeff P p (deg R p) ~= \<zero>"
ballarin@13940
   701
proof (cases "deg R p = 0")
ballarin@13940
   702
  case True with neq R show ?thesis by (simp add: lcoeff_nonzero_nonzero)
ballarin@13940
   703
next
ballarin@13940
   704
  case False with neq R show ?thesis by (simp add: lcoeff_nonzero_deg)
ballarin@13940
   705
qed
ballarin@13940
   706
ballarin@13940
   707
lemma (in UP_cring) deg_eqI:
ballarin@13940
   708
  "[| !!m. n < m ==> coeff P p m = \<zero>;
ballarin@13940
   709
      !!n. n ~= 0 ==> coeff P p n ~= \<zero>; p \<in> carrier P |] ==> deg R p = n"
ballarin@13940
   710
by (fast intro: le_anti_sym deg_aboveI deg_belowI)
ballarin@13940
   711
ballarin@17094
   712
text {* Degree and polynomial operations *}
ballarin@13940
   713
ballarin@13940
   714
lemma (in UP_cring) deg_add [simp]:
ballarin@13940
   715
  assumes R: "p \<in> carrier P" "q \<in> carrier P"
ballarin@15095
   716
  shows "deg R (p \<oplus>\<^bsub>P\<^esub> q) <= max (deg R p) (deg R q)"
ballarin@13940
   717
proof (cases "deg R p <= deg R q")
ballarin@13940
   718
  case True show ?thesis
wenzelm@14666
   719
    by (rule deg_aboveI) (simp_all add: True R deg_aboveD)
ballarin@13940
   720
next
ballarin@13940
   721
  case False show ?thesis
ballarin@13940
   722
    by (rule deg_aboveI) (simp_all add: False R deg_aboveD)
ballarin@13940
   723
qed
ballarin@13940
   724
ballarin@13940
   725
lemma (in UP_cring) deg_monom_le:
ballarin@13940
   726
  "a \<in> carrier R ==> deg R (monom P a n) <= n"
ballarin@13940
   727
  by (intro deg_aboveI) simp_all
ballarin@13940
   728
ballarin@13940
   729
lemma (in UP_cring) deg_monom [simp]:
ballarin@13940
   730
  "[| a ~= \<zero>; a \<in> carrier R |] ==> deg R (monom P a n) = n"
ballarin@13940
   731
  by (fastsimp intro: le_anti_sym deg_aboveI deg_belowI)
ballarin@13940
   732
ballarin@13940
   733
lemma (in UP_cring) deg_const [simp]:
ballarin@13940
   734
  assumes R: "a \<in> carrier R" shows "deg R (monom P a 0) = 0"
ballarin@13940
   735
proof (rule le_anti_sym)
ballarin@13940
   736
  show "deg R (monom P a 0) <= 0" by (rule deg_aboveI) (simp_all add: R)
ballarin@13940
   737
next
ballarin@13940
   738
  show "0 <= deg R (monom P a 0)" by (rule deg_belowI) (simp_all add: R)
ballarin@13940
   739
qed
ballarin@13940
   740
ballarin@13940
   741
lemma (in UP_cring) deg_zero [simp]:
ballarin@15095
   742
  "deg R \<zero>\<^bsub>P\<^esub> = 0"
ballarin@13940
   743
proof (rule le_anti_sym)
ballarin@15095
   744
  show "deg R \<zero>\<^bsub>P\<^esub> <= 0" by (rule deg_aboveI) simp_all
ballarin@13940
   745
next
ballarin@15095
   746
  show "0 <= deg R \<zero>\<^bsub>P\<^esub>" by (rule deg_belowI) simp_all
ballarin@13940
   747
qed
ballarin@13940
   748
ballarin@13940
   749
lemma (in UP_cring) deg_one [simp]:
ballarin@15095
   750
  "deg R \<one>\<^bsub>P\<^esub> = 0"
ballarin@13940
   751
proof (rule le_anti_sym)
ballarin@15095
   752
  show "deg R \<one>\<^bsub>P\<^esub> <= 0" by (rule deg_aboveI) simp_all
ballarin@13940
   753
next
ballarin@15095
   754
  show "0 <= deg R \<one>\<^bsub>P\<^esub>" by (rule deg_belowI) simp_all
ballarin@13940
   755
qed
ballarin@13940
   756
ballarin@13940
   757
lemma (in UP_cring) deg_uminus [simp]:
ballarin@15095
   758
  assumes R: "p \<in> carrier P" shows "deg R (\<ominus>\<^bsub>P\<^esub> p) = deg R p"
ballarin@13940
   759
proof (rule le_anti_sym)
ballarin@15095
   760
  show "deg R (\<ominus>\<^bsub>P\<^esub> p) <= deg R p" by (simp add: deg_aboveI deg_aboveD R)
ballarin@13940
   761
next
ballarin@15095
   762
  show "deg R p <= deg R (\<ominus>\<^bsub>P\<^esub> p)"
ballarin@13940
   763
    by (simp add: deg_belowI lcoeff_nonzero_deg
ballarin@17094
   764
      inj_on_iff [OF R.a_inv_inj, of _ "\<zero>", simplified] R)
ballarin@13940
   765
qed
ballarin@13940
   766
ballarin@13940
   767
lemma (in UP_domain) deg_smult_ring:
ballarin@13940
   768
  "[| a \<in> carrier R; p \<in> carrier P |] ==>
ballarin@15095
   769
  deg R (a \<odot>\<^bsub>P\<^esub> p) <= (if a = \<zero> then 0 else deg R p)"
ballarin@13940
   770
  by (cases "a = \<zero>") (simp add: deg_aboveI deg_aboveD)+
ballarin@13940
   771
ballarin@13940
   772
lemma (in UP_domain) deg_smult [simp]:
ballarin@13940
   773
  assumes R: "a \<in> carrier R" "p \<in> carrier P"
ballarin@15095
   774
  shows "deg R (a \<odot>\<^bsub>P\<^esub> p) = (if a = \<zero> then 0 else deg R p)"
ballarin@13940
   775
proof (rule le_anti_sym)
ballarin@15095
   776
  show "deg R (a \<odot>\<^bsub>P\<^esub> p) <= (if a = \<zero> then 0 else deg R p)"
wenzelm@23350
   777
    using R by (rule deg_smult_ring)
ballarin@13940
   778
next
ballarin@15095
   779
  show "(if a = \<zero> then 0 else deg R p) <= deg R (a \<odot>\<^bsub>P\<^esub> p)"
ballarin@13940
   780
  proof (cases "a = \<zero>")
ballarin@13940
   781
  qed (simp, simp add: deg_belowI lcoeff_nonzero_deg integral_iff R)
ballarin@13940
   782
qed
ballarin@13940
   783
ballarin@13940
   784
lemma (in UP_cring) deg_mult_cring:
ballarin@13940
   785
  assumes R: "p \<in> carrier P" "q \<in> carrier P"
ballarin@15095
   786
  shows "deg R (p \<otimes>\<^bsub>P\<^esub> q) <= deg R p + deg R q"
ballarin@13940
   787
proof (rule deg_aboveI)
ballarin@13940
   788
  fix m
ballarin@13940
   789
  assume boundm: "deg R p + deg R q < m"
ballarin@13940
   790
  {
ballarin@13940
   791
    fix k i
ballarin@13940
   792
    assume boundk: "deg R p + deg R q < k"
ballarin@13940
   793
    then have "coeff P p i \<otimes> coeff P q (k - i) = \<zero>"
ballarin@13940
   794
    proof (cases "deg R p < i")
ballarin@13940
   795
      case True then show ?thesis by (simp add: deg_aboveD R)
ballarin@13940
   796
    next
ballarin@13940
   797
      case False with boundk have "deg R q < k - i" by arith
ballarin@13940
   798
      then show ?thesis by (simp add: deg_aboveD R)
ballarin@13940
   799
    qed
ballarin@13940
   800
  }
ballarin@15095
   801
  with boundm R show "coeff P (p \<otimes>\<^bsub>P\<^esub> q) m = \<zero>" by simp
ballarin@13940
   802
qed (simp add: R)
ballarin@13940
   803
ballarin@13940
   804
lemma (in UP_domain) deg_mult [simp]:
ballarin@15095
   805
  "[| p ~= \<zero>\<^bsub>P\<^esub>; q ~= \<zero>\<^bsub>P\<^esub>; p \<in> carrier P; q \<in> carrier P |] ==>
ballarin@15095
   806
  deg R (p \<otimes>\<^bsub>P\<^esub> q) = deg R p + deg R q"
ballarin@13940
   807
proof (rule le_anti_sym)
ballarin@13940
   808
  assume "p \<in> carrier P" " q \<in> carrier P"
wenzelm@23350
   809
  then show "deg R (p \<otimes>\<^bsub>P\<^esub> q) <= deg R p + deg R q" by (rule deg_mult_cring)
ballarin@13940
   810
next
ballarin@13940
   811
  let ?s = "(%i. coeff P p i \<otimes> coeff P q (deg R p + deg R q - i))"
ballarin@15095
   812
  assume R: "p \<in> carrier P" "q \<in> carrier P" and nz: "p ~= \<zero>\<^bsub>P\<^esub>" "q ~= \<zero>\<^bsub>P\<^esub>"
ballarin@13940
   813
  have less_add_diff: "!!(k::nat) n m. k < n ==> m < n + m - k" by arith
ballarin@15095
   814
  show "deg R p + deg R q <= deg R (p \<otimes>\<^bsub>P\<^esub> q)"
ballarin@13940
   815
  proof (rule deg_belowI, simp add: R)
ballarin@15095
   816
    have "(\<Oplus>i \<in> {.. deg R p + deg R q}. ?s i)
ballarin@15095
   817
      = (\<Oplus>i \<in> {..< deg R p} \<union> {deg R p .. deg R p + deg R q}. ?s i)"
ballarin@13940
   818
      by (simp only: ivl_disj_un_one)
ballarin@15095
   819
    also have "... = (\<Oplus>i \<in> {deg R p .. deg R p + deg R q}. ?s i)"
ballarin@17094
   820
      by (simp cong: R.finsum_cong add: R.finsum_Un_disjoint ivl_disj_int_one
ballarin@13940
   821
        deg_aboveD less_add_diff R Pi_def)
ballarin@15095
   822
    also have "...= (\<Oplus>i \<in> {deg R p} \<union> {deg R p <.. deg R p + deg R q}. ?s i)"
ballarin@13940
   823
      by (simp only: ivl_disj_un_singleton)
wenzelm@14666
   824
    also have "... = coeff P p (deg R p) \<otimes> coeff P q (deg R q)"
ballarin@17094
   825
      by (simp cong: R.finsum_cong
ballarin@17094
   826
	add: ivl_disj_int_singleton deg_aboveD R Pi_def)
ballarin@15095
   827
    finally have "(\<Oplus>i \<in> {.. deg R p + deg R q}. ?s i)
ballarin@13940
   828
      = coeff P p (deg R p) \<otimes> coeff P q (deg R q)" .
ballarin@15095
   829
    with nz show "(\<Oplus>i \<in> {.. deg R p + deg R q}. ?s i) ~= \<zero>"
ballarin@13940
   830
      by (simp add: integral_iff lcoeff_nonzero R)
ballarin@13940
   831
    qed (simp add: R)
ballarin@13940
   832
  qed
ballarin@13940
   833
ballarin@13940
   834
lemma (in UP_cring) coeff_finsum:
ballarin@13940
   835
  assumes fin: "finite A"
ballarin@13940
   836
  shows "p \<in> A -> carrier P ==>
ballarin@15095
   837
    coeff P (finsum P p A) k = (\<Oplus>i \<in> A. coeff P (p i) k)"
ballarin@13940
   838
  using fin by induct (auto simp: Pi_def)
ballarin@13940
   839
ballarin@13940
   840
lemma (in UP_cring) up_repr:
ballarin@13940
   841
  assumes R: "p \<in> carrier P"
ballarin@15095
   842
  shows "(\<Oplus>\<^bsub>P\<^esub> i \<in> {..deg R p}. monom P (coeff P p i) i) = p"
ballarin@13940
   843
proof (rule up_eqI)
ballarin@13940
   844
  let ?s = "(%i. monom P (coeff P p i) i)"
ballarin@13940
   845
  fix k
ballarin@13940
   846
  from R have RR: "!!i. (if i = k then coeff P p i else \<zero>) \<in> carrier R"
ballarin@13940
   847
    by simp
ballarin@15095
   848
  show "coeff P (\<Oplus>\<^bsub>P\<^esub> i \<in> {..deg R p}. ?s i) k = coeff P p k"
ballarin@13940
   849
  proof (cases "k <= deg R p")
ballarin@13940
   850
    case True
ballarin@15095
   851
    hence "coeff P (\<Oplus>\<^bsub>P\<^esub> i \<in> {..deg R p}. ?s i) k =
ballarin@15095
   852
          coeff P (\<Oplus>\<^bsub>P\<^esub> i \<in> {..k} \<union> {k<..deg R p}. ?s i) k"
ballarin@13940
   853
      by (simp only: ivl_disj_un_one)
ballarin@13940
   854
    also from True
ballarin@15095
   855
    have "... = coeff P (\<Oplus>\<^bsub>P\<^esub> i \<in> {..k}. ?s i) k"
ballarin@17094
   856
      by (simp cong: R.finsum_cong add: R.finsum_Un_disjoint
wenzelm@14666
   857
        ivl_disj_int_one order_less_imp_not_eq2 coeff_finsum R RR Pi_def)
ballarin@13940
   858
    also
ballarin@15095
   859
    have "... = coeff P (\<Oplus>\<^bsub>P\<^esub> i \<in> {..<k} \<union> {k}. ?s i) k"
ballarin@13940
   860
      by (simp only: ivl_disj_un_singleton)
ballarin@13940
   861
    also have "... = coeff P p k"
ballarin@17094
   862
      by (simp cong: R.finsum_cong
ballarin@17094
   863
	add: ivl_disj_int_singleton coeff_finsum deg_aboveD R RR Pi_def)
ballarin@13940
   864
    finally show ?thesis .
ballarin@13940
   865
  next
ballarin@13940
   866
    case False
ballarin@15095
   867
    hence "coeff P (\<Oplus>\<^bsub>P\<^esub> i \<in> {..deg R p}. ?s i) k =
ballarin@15095
   868
          coeff P (\<Oplus>\<^bsub>P\<^esub> i \<in> {..<deg R p} \<union> {deg R p}. ?s i) k"
ballarin@13940
   869
      by (simp only: ivl_disj_un_singleton)
ballarin@13940
   870
    also from False have "... = coeff P p k"
ballarin@17094
   871
      by (simp cong: R.finsum_cong
ballarin@17094
   872
	add: ivl_disj_int_singleton coeff_finsum deg_aboveD R Pi_def)
ballarin@13940
   873
    finally show ?thesis .
ballarin@13940
   874
  qed
ballarin@13940
   875
qed (simp_all add: R Pi_def)
ballarin@13940
   876
ballarin@13940
   877
lemma (in UP_cring) up_repr_le:
ballarin@13940
   878
  "[| deg R p <= n; p \<in> carrier P |] ==>
ballarin@15095
   879
  (\<Oplus>\<^bsub>P\<^esub> i \<in> {..n}. monom P (coeff P p i) i) = p"
ballarin@13940
   880
proof -
ballarin@13940
   881
  let ?s = "(%i. monom P (coeff P p i) i)"
ballarin@13940
   882
  assume R: "p \<in> carrier P" and "deg R p <= n"
ballarin@15095
   883
  then have "finsum P ?s {..n} = finsum P ?s ({..deg R p} \<union> {deg R p<..n})"
ballarin@13940
   884
    by (simp only: ivl_disj_un_one)
ballarin@13940
   885
  also have "... = finsum P ?s {..deg R p}"
ballarin@17094
   886
    by (simp cong: P.finsum_cong add: P.finsum_Un_disjoint ivl_disj_int_one
ballarin@13940
   887
      deg_aboveD R Pi_def)
wenzelm@23350
   888
  also have "... = p" using R by (rule up_repr)
ballarin@13940
   889
  finally show ?thesis .
ballarin@13940
   890
qed
ballarin@13940
   891
ballarin@17094
   892
ballarin@20318
   893
subsection {* Polynomials over Integral Domains *}
ballarin@13940
   894
ballarin@13940
   895
lemma domainI:
ballarin@13940
   896
  assumes cring: "cring R"
ballarin@13940
   897
    and one_not_zero: "one R ~= zero R"
ballarin@13940
   898
    and integral: "!!a b. [| mult R a b = zero R; a \<in> carrier R;
ballarin@13940
   899
      b \<in> carrier R |] ==> a = zero R | b = zero R"
ballarin@13940
   900
  shows "domain R"
ballarin@13940
   901
  by (auto intro!: domain.intro domain_axioms.intro cring.axioms prems
ballarin@13940
   902
    del: disjCI)
ballarin@13940
   903
ballarin@13940
   904
lemma (in UP_domain) UP_one_not_zero:
ballarin@15095
   905
  "\<one>\<^bsub>P\<^esub> ~= \<zero>\<^bsub>P\<^esub>"
ballarin@13940
   906
proof
ballarin@15095
   907
  assume "\<one>\<^bsub>P\<^esub> = \<zero>\<^bsub>P\<^esub>"
ballarin@15095
   908
  hence "coeff P \<one>\<^bsub>P\<^esub> 0 = (coeff P \<zero>\<^bsub>P\<^esub> 0)" by simp
ballarin@13940
   909
  hence "\<one> = \<zero>" by simp
ballarin@13940
   910
  with one_not_zero show "False" by contradiction
ballarin@13940
   911
qed
ballarin@13940
   912
ballarin@13940
   913
lemma (in UP_domain) UP_integral:
ballarin@15095
   914
  "[| p \<otimes>\<^bsub>P\<^esub> q = \<zero>\<^bsub>P\<^esub>; p \<in> carrier P; q \<in> carrier P |] ==> p = \<zero>\<^bsub>P\<^esub> | q = \<zero>\<^bsub>P\<^esub>"
ballarin@13940
   915
proof -
ballarin@13940
   916
  fix p q
ballarin@15095
   917
  assume pq: "p \<otimes>\<^bsub>P\<^esub> q = \<zero>\<^bsub>P\<^esub>" and R: "p \<in> carrier P" "q \<in> carrier P"
ballarin@15095
   918
  show "p = \<zero>\<^bsub>P\<^esub> | q = \<zero>\<^bsub>P\<^esub>"
ballarin@13940
   919
  proof (rule classical)
ballarin@15095
   920
    assume c: "~ (p = \<zero>\<^bsub>P\<^esub> | q = \<zero>\<^bsub>P\<^esub>)"
ballarin@15095
   921
    with R have "deg R p + deg R q = deg R (p \<otimes>\<^bsub>P\<^esub> q)" by simp
ballarin@13940
   922
    also from pq have "... = 0" by simp
ballarin@13940
   923
    finally have "deg R p + deg R q = 0" .
ballarin@13940
   924
    then have f1: "deg R p = 0 & deg R q = 0" by simp
ballarin@15095
   925
    from f1 R have "p = (\<Oplus>\<^bsub>P\<^esub> i \<in> {..0}. monom P (coeff P p i) i)"
ballarin@13940
   926
      by (simp only: up_repr_le)
ballarin@13940
   927
    also from R have "... = monom P (coeff P p 0) 0" by simp
ballarin@13940
   928
    finally have p: "p = monom P (coeff P p 0) 0" .
ballarin@15095
   929
    from f1 R have "q = (\<Oplus>\<^bsub>P\<^esub> i \<in> {..0}. monom P (coeff P q i) i)"
ballarin@13940
   930
      by (simp only: up_repr_le)
ballarin@13940
   931
    also from R have "... = monom P (coeff P q 0) 0" by simp
ballarin@13940
   932
    finally have q: "q = monom P (coeff P q 0) 0" .
ballarin@15095
   933
    from R have "coeff P p 0 \<otimes> coeff P q 0 = coeff P (p \<otimes>\<^bsub>P\<^esub> q) 0" by simp
ballarin@13940
   934
    also from pq have "... = \<zero>" by simp
ballarin@13940
   935
    finally have "coeff P p 0 \<otimes> coeff P q 0 = \<zero>" .
ballarin@13940
   936
    with R have "coeff P p 0 = \<zero> | coeff P q 0 = \<zero>"
ballarin@13940
   937
      by (simp add: R.integral_iff)
ballarin@15095
   938
    with p q show "p = \<zero>\<^bsub>P\<^esub> | q = \<zero>\<^bsub>P\<^esub>" by fastsimp
ballarin@13940
   939
  qed
ballarin@13940
   940
qed
ballarin@13940
   941
ballarin@13940
   942
theorem (in UP_domain) UP_domain:
ballarin@13940
   943
  "domain P"
ballarin@13940
   944
  by (auto intro!: domainI UP_cring UP_one_not_zero UP_integral del: disjCI)
ballarin@13940
   945
ballarin@13940
   946
text {*
ballarin@17094
   947
  Interpretation of theorems from @{term domain}.
ballarin@13940
   948
*}
ballarin@13940
   949
ballarin@17094
   950
interpretation UP_domain < "domain" P
ballarin@19984
   951
  by intro_locales (rule domain.axioms UP_domain)+
ballarin@13940
   952
wenzelm@14666
   953
ballarin@20318
   954
subsection {* The Evaluation Homomorphism and Universal Property*}
ballarin@13940
   955
wenzelm@14666
   956
(* alternative congruence rule (possibly more efficient)
wenzelm@14666
   957
lemma (in abelian_monoid) finsum_cong2:
wenzelm@14666
   958
  "[| !!i. i \<in> A ==> f i \<in> carrier G = True; A = B;
wenzelm@14666
   959
  !!i. i \<in> B ==> f i = g i |] ==> finsum G f A = finsum G g B"
wenzelm@14666
   960
  sorry*)
wenzelm@14666
   961
ballarin@13940
   962
theorem (in cring) diagonal_sum:
ballarin@13940
   963
  "[| f \<in> {..n + m::nat} -> carrier R; g \<in> {..n + m} -> carrier R |] ==>
wenzelm@14666
   964
  (\<Oplus>k \<in> {..n + m}. \<Oplus>i \<in> {..k}. f i \<otimes> g (k - i)) =
wenzelm@14666
   965
  (\<Oplus>k \<in> {..n + m}. \<Oplus>i \<in> {..n + m - k}. f k \<otimes> g i)"
ballarin@13940
   966
proof -
ballarin@13940
   967
  assume Rf: "f \<in> {..n + m} -> carrier R" and Rg: "g \<in> {..n + m} -> carrier R"
ballarin@13940
   968
  {
ballarin@13940
   969
    fix j
ballarin@13940
   970
    have "j <= n + m ==>
wenzelm@14666
   971
      (\<Oplus>k \<in> {..j}. \<Oplus>i \<in> {..k}. f i \<otimes> g (k - i)) =
wenzelm@14666
   972
      (\<Oplus>k \<in> {..j}. \<Oplus>i \<in> {..j - k}. f k \<otimes> g i)"
ballarin@13940
   973
    proof (induct j)
ballarin@13940
   974
      case 0 from Rf Rg show ?case by (simp add: Pi_def)
ballarin@13940
   975
    next
wenzelm@14666
   976
      case (Suc j)
ballarin@13940
   977
      have R6: "!!i k. [| k <= j; i <= Suc j - k |] ==> g i \<in> carrier R"
webertj@20217
   978
        using Suc by (auto intro!: funcset_mem [OF Rg])
ballarin@13940
   979
      have R8: "!!i k. [| k <= Suc j; i <= k |] ==> g (k - i) \<in> carrier R"
webertj@20217
   980
        using Suc by (auto intro!: funcset_mem [OF Rg])
ballarin@13940
   981
      have R9: "!!i k. [| k <= Suc j |] ==> f k \<in> carrier R"
wenzelm@14666
   982
        using Suc by (auto intro!: funcset_mem [OF Rf])
ballarin@13940
   983
      have R10: "!!i k. [| k <= Suc j; i <= Suc j - k |] ==> g i \<in> carrier R"
webertj@20217
   984
        using Suc by (auto intro!: funcset_mem [OF Rg])
ballarin@13940
   985
      have R11: "g 0 \<in> carrier R"
wenzelm@14666
   986
        using Suc by (auto intro!: funcset_mem [OF Rg])
ballarin@13940
   987
      from Suc show ?case
wenzelm@14666
   988
        by (simp cong: finsum_cong add: Suc_diff_le a_ac
wenzelm@14666
   989
          Pi_def R6 R8 R9 R10 R11)
ballarin@13940
   990
    qed
ballarin@13940
   991
  }
ballarin@13940
   992
  then show ?thesis by fast
ballarin@13940
   993
qed
ballarin@13940
   994
ballarin@13940
   995
lemma (in abelian_monoid) boundD_carrier:
ballarin@13940
   996
  "[| bound \<zero> n f; n < m |] ==> f m \<in> carrier G"
ballarin@13940
   997
  by auto
ballarin@13940
   998
ballarin@13940
   999
theorem (in cring) cauchy_product:
ballarin@13940
  1000
  assumes bf: "bound \<zero> n f" and bg: "bound \<zero> m g"
ballarin@13940
  1001
    and Rf: "f \<in> {..n} -> carrier R" and Rg: "g \<in> {..m} -> carrier R"
wenzelm@14666
  1002
  shows "(\<Oplus>k \<in> {..n + m}. \<Oplus>i \<in> {..k}. f i \<otimes> g (k - i)) =
ballarin@17094
  1003
    (\<Oplus>i \<in> {..n}. f i) \<otimes> (\<Oplus>i \<in> {..m}. g i)"      (* State reverse direction? *)
ballarin@13940
  1004
proof -
ballarin@13940
  1005
  have f: "!!x. f x \<in> carrier R"
ballarin@13940
  1006
  proof -
ballarin@13940
  1007
    fix x
ballarin@13940
  1008
    show "f x \<in> carrier R"
ballarin@13940
  1009
      using Rf bf boundD_carrier by (cases "x <= n") (auto simp: Pi_def)
ballarin@13940
  1010
  qed
ballarin@13940
  1011
  have g: "!!x. g x \<in> carrier R"
ballarin@13940
  1012
  proof -
ballarin@13940
  1013
    fix x
ballarin@13940
  1014
    show "g x \<in> carrier R"
ballarin@13940
  1015
      using Rg bg boundD_carrier by (cases "x <= m") (auto simp: Pi_def)
ballarin@13940
  1016
  qed
wenzelm@14666
  1017
  from f g have "(\<Oplus>k \<in> {..n + m}. \<Oplus>i \<in> {..k}. f i \<otimes> g (k - i)) =
wenzelm@14666
  1018
      (\<Oplus>k \<in> {..n + m}. \<Oplus>i \<in> {..n + m - k}. f k \<otimes> g i)"
ballarin@13940
  1019
    by (simp add: diagonal_sum Pi_def)
nipkow@15045
  1020
  also have "... = (\<Oplus>k \<in> {..n} \<union> {n<..n + m}. \<Oplus>i \<in> {..n + m - k}. f k \<otimes> g i)"
ballarin@13940
  1021
    by (simp only: ivl_disj_un_one)
wenzelm@14666
  1022
  also from f g have "... = (\<Oplus>k \<in> {..n}. \<Oplus>i \<in> {..n + m - k}. f k \<otimes> g i)"
ballarin@13940
  1023
    by (simp cong: finsum_cong
wenzelm@14666
  1024
      add: bound.bound [OF bf] finsum_Un_disjoint ivl_disj_int_one Pi_def)
ballarin@15095
  1025
  also from f g
ballarin@15095
  1026
  have "... = (\<Oplus>k \<in> {..n}. \<Oplus>i \<in> {..m} \<union> {m<..n + m - k}. f k \<otimes> g i)"
ballarin@13940
  1027
    by (simp cong: finsum_cong add: ivl_disj_un_one le_add_diff Pi_def)
wenzelm@14666
  1028
  also from f g have "... = (\<Oplus>k \<in> {..n}. \<Oplus>i \<in> {..m}. f k \<otimes> g i)"
ballarin@13940
  1029
    by (simp cong: finsum_cong
wenzelm@14666
  1030
      add: bound.bound [OF bg] finsum_Un_disjoint ivl_disj_int_one Pi_def)
wenzelm@14666
  1031
  also from f g have "... = (\<Oplus>i \<in> {..n}. f i) \<otimes> (\<Oplus>i \<in> {..m}. g i)"
ballarin@13940
  1032
    by (simp add: finsum_ldistr diagonal_sum Pi_def,
ballarin@13940
  1033
      simp cong: finsum_cong add: finsum_rdistr Pi_def)
ballarin@13940
  1034
  finally show ?thesis .
ballarin@13940
  1035
qed
ballarin@13940
  1036
ballarin@13940
  1037
lemma (in UP_cring) const_ring_hom:
ballarin@13940
  1038
  "(%a. monom P a 0) \<in> ring_hom R P"
ballarin@13940
  1039
  by (auto intro!: ring_hom_memI intro: up_eqI simp: monom_mult_is_smult)
ballarin@13940
  1040
wenzelm@14651
  1041
constdefs (structure S)
ballarin@15095
  1042
  eval :: "[('a, 'm) ring_scheme, ('b, 'n) ring_scheme,
ballarin@15095
  1043
           'a => 'b, 'b, nat => 'a] => 'b"
wenzelm@14651
  1044
  "eval R S phi s == \<lambda>p \<in> carrier (UP R).
ballarin@15095
  1045
    \<Oplus>i \<in> {..deg R p}. phi (coeff (UP R) p i) \<otimes> s (^) i"
ballarin@15095
  1046
wenzelm@14666
  1047
ballarin@15095
  1048
lemma (in UP) eval_on_carrier:
ballarin@19783
  1049
  fixes S (structure)
ballarin@17094
  1050
  shows "p \<in> carrier P ==>
ballarin@17094
  1051
  eval R S phi s p = (\<Oplus>\<^bsub>S\<^esub> i \<in> {..deg R p}. phi (coeff P p i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i)"
ballarin@13940
  1052
  by (unfold eval_def, fold P_def) simp
ballarin@13940
  1053
ballarin@15095
  1054
lemma (in UP) eval_extensional:
ballarin@17094
  1055
  "eval R S phi p \<in> extensional (carrier P)"
ballarin@13940
  1056
  by (unfold eval_def, fold P_def) simp
ballarin@13940
  1057
ballarin@17094
  1058
ballarin@17094
  1059
text {* The universal property of the polynomial ring *}
ballarin@17094
  1060
ballarin@17094
  1061
locale UP_pre_univ_prop = ring_hom_cring R S h + UP_cring R P
ballarin@17094
  1062
ballarin@19783
  1063
locale UP_univ_prop = UP_pre_univ_prop +
ballarin@19783
  1064
  fixes s and Eval
ballarin@17094
  1065
  assumes indet_img_carrier [simp, intro]: "s \<in> carrier S"
ballarin@17094
  1066
  defines Eval_def: "Eval == eval R S h s"
ballarin@17094
  1067
ballarin@17094
  1068
theorem (in UP_pre_univ_prop) eval_ring_hom:
ballarin@17094
  1069
  assumes S: "s \<in> carrier S"
ballarin@17094
  1070
  shows "eval R S h s \<in> ring_hom P S"
ballarin@13940
  1071
proof (rule ring_hom_memI)
ballarin@13940
  1072
  fix p
ballarin@17094
  1073
  assume R: "p \<in> carrier P"
ballarin@13940
  1074
  then show "eval R S h s p \<in> carrier S"
ballarin@17094
  1075
    by (simp only: eval_on_carrier) (simp add: S Pi_def)
ballarin@13940
  1076
next
ballarin@13940
  1077
  fix p q
ballarin@17094
  1078
  assume R: "p \<in> carrier P" "q \<in> carrier P"
ballarin@15095
  1079
  then show "eval R S h s (p \<otimes>\<^bsub>P\<^esub> q) = eval R S h s p \<otimes>\<^bsub>S\<^esub> eval R S h s q"
ballarin@13940
  1080
  proof (simp only: eval_on_carrier UP_mult_closed)
ballarin@17094
  1081
    from R S have
ballarin@15095
  1082
      "(\<Oplus>\<^bsub>S\<^esub> i \<in> {..deg R (p \<otimes>\<^bsub>P\<^esub> q)}. h (coeff P (p \<otimes>\<^bsub>P\<^esub> q) i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i) =
ballarin@15095
  1083
      (\<Oplus>\<^bsub>S\<^esub> i \<in> {..deg R (p \<otimes>\<^bsub>P\<^esub> q)} \<union> {deg R (p \<otimes>\<^bsub>P\<^esub> q)<..deg R p + deg R q}.
ballarin@15095
  1084
        h (coeff P (p \<otimes>\<^bsub>P\<^esub> q) i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i)"
ballarin@17094
  1085
      by (simp cong: S.finsum_cong
ballarin@17094
  1086
        add: deg_aboveD S.finsum_Un_disjoint ivl_disj_int_one Pi_def
wenzelm@14666
  1087
        del: coeff_mult)
ballarin@17094
  1088
    also from R have "... =
ballarin@15095
  1089
      (\<Oplus>\<^bsub>S\<^esub> i \<in> {..deg R p + deg R q}. h (coeff P (p \<otimes>\<^bsub>P\<^esub> q) i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i)"
ballarin@13940
  1090
      by (simp only: ivl_disj_un_one deg_mult_cring)
ballarin@17094
  1091
    also from R S have "... =
ballarin@15095
  1092
      (\<Oplus>\<^bsub>S\<^esub> i \<in> {..deg R p + deg R q}.
ballarin@15095
  1093
         \<Oplus>\<^bsub>S\<^esub> k \<in> {..i}.
ballarin@15095
  1094
           h (coeff P p k) \<otimes>\<^bsub>S\<^esub> h (coeff P q (i - k)) \<otimes>\<^bsub>S\<^esub>
ballarin@15095
  1095
           (s (^)\<^bsub>S\<^esub> k \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> (i - k)))"
ballarin@17094
  1096
      by (simp cong: S.finsum_cong add: S.nat_pow_mult Pi_def
wenzelm@14666
  1097
        S.m_ac S.finsum_rdistr)
ballarin@17094
  1098
    also from R S have "... =
ballarin@15095
  1099
      (\<Oplus>\<^bsub>S\<^esub> i\<in>{..deg R p}. h (coeff P p i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i) \<otimes>\<^bsub>S\<^esub>
ballarin@15095
  1100
      (\<Oplus>\<^bsub>S\<^esub> i\<in>{..deg R q}. h (coeff P q i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i)"
wenzelm@14666
  1101
      by (simp add: S.cauchy_product [THEN sym] bound.intro deg_aboveD S.m_ac
wenzelm@14666
  1102
        Pi_def)
ballarin@13940
  1103
    finally show
ballarin@15095
  1104
      "(\<Oplus>\<^bsub>S\<^esub> i \<in> {..deg R (p \<otimes>\<^bsub>P\<^esub> q)}. h (coeff P (p \<otimes>\<^bsub>P\<^esub> q) i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i) =
ballarin@15095
  1105
      (\<Oplus>\<^bsub>S\<^esub> i \<in> {..deg R p}. h (coeff P p i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i) \<otimes>\<^bsub>S\<^esub>
ballarin@15095
  1106
      (\<Oplus>\<^bsub>S\<^esub> i \<in> {..deg R q}. h (coeff P q i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i)" .
ballarin@13940
  1107
  qed
ballarin@13940
  1108
next
ballarin@13940
  1109
  fix p q
ballarin@17094
  1110
  assume R: "p \<in> carrier P" "q \<in> carrier P"
ballarin@15095
  1111
  then show "eval R S h s (p \<oplus>\<^bsub>P\<^esub> q) = eval R S h s p \<oplus>\<^bsub>S\<^esub> eval R S h s q"
ballarin@17094
  1112
  proof (simp only: eval_on_carrier P.a_closed)
ballarin@17094
  1113
    from S R have
ballarin@15095
  1114
      "(\<Oplus>\<^bsub>S \<^esub>i\<in>{..deg R (p \<oplus>\<^bsub>P\<^esub> q)}. h (coeff P (p \<oplus>\<^bsub>P\<^esub> q) i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i) =
ballarin@15095
  1115
      (\<Oplus>\<^bsub>S \<^esub>i\<in>{..deg R (p \<oplus>\<^bsub>P\<^esub> q)} \<union> {deg R (p \<oplus>\<^bsub>P\<^esub> q)<..max (deg R p) (deg R q)}.
ballarin@15095
  1116
        h (coeff P (p \<oplus>\<^bsub>P\<^esub> q) i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i)"
ballarin@17094
  1117
      by (simp cong: S.finsum_cong
ballarin@17094
  1118
        add: deg_aboveD S.finsum_Un_disjoint ivl_disj_int_one Pi_def
wenzelm@14666
  1119
        del: coeff_add)
ballarin@17094
  1120
    also from R have "... =
ballarin@15095
  1121
        (\<Oplus>\<^bsub>S\<^esub> i \<in> {..max (deg R p) (deg R q)}.
ballarin@15095
  1122
          h (coeff P (p \<oplus>\<^bsub>P\<^esub> q) i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i)"
ballarin@13940
  1123
      by (simp add: ivl_disj_un_one)
ballarin@17094
  1124
    also from R S have "... =
ballarin@15095
  1125
      (\<Oplus>\<^bsub>S\<^esub>i\<in>{..max (deg R p) (deg R q)}. h (coeff P p i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i) \<oplus>\<^bsub>S\<^esub>
ballarin@15095
  1126
      (\<Oplus>\<^bsub>S\<^esub>i\<in>{..max (deg R p) (deg R q)}. h (coeff P q i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i)"
ballarin@17094
  1127
      by (simp cong: S.finsum_cong
ballarin@17094
  1128
        add: S.l_distr deg_aboveD ivl_disj_int_one Pi_def)
ballarin@13940
  1129
    also have "... =
ballarin@15095
  1130
        (\<Oplus>\<^bsub>S\<^esub> i \<in> {..deg R p} \<union> {deg R p<..max (deg R p) (deg R q)}.
ballarin@15095
  1131
          h (coeff P p i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i) \<oplus>\<^bsub>S\<^esub>
ballarin@15095
  1132
        (\<Oplus>\<^bsub>S\<^esub> i \<in> {..deg R q} \<union> {deg R q<..max (deg R p) (deg R q)}.
ballarin@15095
  1133
          h (coeff P q i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i)"
ballarin@13940
  1134
      by (simp only: ivl_disj_un_one le_maxI1 le_maxI2)
ballarin@17094
  1135
    also from R S have "... =
ballarin@15095
  1136
      (\<Oplus>\<^bsub>S\<^esub> i \<in> {..deg R p}. h (coeff P p i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i) \<oplus>\<^bsub>S\<^esub>
ballarin@15095
  1137
      (\<Oplus>\<^bsub>S\<^esub> i \<in> {..deg R q}. h (coeff P q i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i)"
ballarin@17094
  1138
      by (simp cong: S.finsum_cong
ballarin@17094
  1139
        add: deg_aboveD S.finsum_Un_disjoint ivl_disj_int_one Pi_def)
ballarin@13940
  1140
    finally show
ballarin@15095
  1141
      "(\<Oplus>\<^bsub>S\<^esub>i \<in> {..deg R (p \<oplus>\<^bsub>P\<^esub> q)}. h (coeff P (p \<oplus>\<^bsub>P\<^esub> q) i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i) =
ballarin@15095
  1142
      (\<Oplus>\<^bsub>S\<^esub>i \<in> {..deg R p}. h (coeff P p i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i) \<oplus>\<^bsub>S\<^esub>
ballarin@15095
  1143
      (\<Oplus>\<^bsub>S\<^esub>i \<in> {..deg R q}. h (coeff P q i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i)" .
ballarin@13940
  1144
  qed
ballarin@13940
  1145
next
ballarin@17094
  1146
  show "eval R S h s \<one>\<^bsub>P\<^esub> = \<one>\<^bsub>S\<^esub>"
ballarin@13940
  1147
    by (simp only: eval_on_carrier UP_one_closed) simp
ballarin@13940
  1148
qed
ballarin@13940
  1149
ballarin@17094
  1150
text {* Interpretation of ring homomorphism lemmas. *}
ballarin@13940
  1151
ballarin@17094
  1152
interpretation UP_univ_prop < ring_hom_cring P S Eval
ballarin@19931
  1153
  apply (unfold Eval_def)
ballarin@19984
  1154
  apply intro_locales
ballarin@19931
  1155
  apply (rule ring_hom_cring.axioms)
ballarin@19931
  1156
  apply (rule ring_hom_cring.intro)
ballarin@19984
  1157
  apply unfold_locales
ballarin@19931
  1158
  apply (rule eval_ring_hom)
ballarin@19931
  1159
  apply rule
ballarin@19931
  1160
  done
ballarin@19931
  1161
ballarin@13940
  1162
ballarin@13940
  1163
text {* Further properties of the evaluation homomorphism. *}
ballarin@13940
  1164
wenzelm@21502
  1165
text {*
wenzelm@21502
  1166
  The following lemma could be proved in @{text UP_cring} with the additional
wenzelm@21502
  1167
  assumption that @{text h} is closed. *}
ballarin@13940
  1168
ballarin@17094
  1169
lemma (in UP_pre_univ_prop) eval_const:
ballarin@13940
  1170
  "[| s \<in> carrier S; r \<in> carrier R |] ==> eval R S h s (monom P r 0) = h r"
ballarin@13940
  1171
  by (simp only: eval_on_carrier monom_closed) simp
ballarin@13940
  1172
ballarin@13940
  1173
text {* The following proof is complicated by the fact that in arbitrary
ballarin@13940
  1174
  rings one might have @{term "one R = zero R"}. *}
ballarin@13940
  1175
ballarin@13940
  1176
(* TODO: simplify by cases "one R = zero R" *)
ballarin@13940
  1177
ballarin@17094
  1178
lemma (in UP_pre_univ_prop) eval_monom1:
ballarin@17094
  1179
  assumes S: "s \<in> carrier S"
ballarin@17094
  1180
  shows "eval R S h s (monom P \<one> 1) = s"
ballarin@13940
  1181
proof (simp only: eval_on_carrier monom_closed R.one_closed)
ballarin@17094
  1182
   from S have
ballarin@15095
  1183
    "(\<Oplus>\<^bsub>S\<^esub> i\<in>{..deg R (monom P \<one> 1)}. h (coeff P (monom P \<one> 1) i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i) =
ballarin@15095
  1184
    (\<Oplus>\<^bsub>S\<^esub> i\<in>{..deg R (monom P \<one> 1)} \<union> {deg R (monom P \<one> 1)<..1}.
ballarin@15095
  1185
      h (coeff P (monom P \<one> 1) i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i)"
ballarin@17094
  1186
    by (simp cong: S.finsum_cong del: coeff_monom
ballarin@17094
  1187
      add: deg_aboveD S.finsum_Un_disjoint ivl_disj_int_one Pi_def)
wenzelm@14666
  1188
  also have "... =
ballarin@15095
  1189
    (\<Oplus>\<^bsub>S\<^esub> i \<in> {..1}. h (coeff P (monom P \<one> 1) i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i)"
ballarin@13940
  1190
    by (simp only: ivl_disj_un_one deg_monom_le R.one_closed)
ballarin@13940
  1191
  also have "... = s"
ballarin@15095
  1192
  proof (cases "s = \<zero>\<^bsub>S\<^esub>")
ballarin@13940
  1193
    case True then show ?thesis by (simp add: Pi_def)
ballarin@13940
  1194
  next
ballarin@17094
  1195
    case False then show ?thesis by (simp add: S Pi_def)
ballarin@13940
  1196
  qed
ballarin@15095
  1197
  finally show "(\<Oplus>\<^bsub>S\<^esub> i \<in> {..deg R (monom P \<one> 1)}.
ballarin@15095
  1198
    h (coeff P (monom P \<one> 1) i) \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> i) = s" .
ballarin@13940
  1199
qed
ballarin@13940
  1200
ballarin@13940
  1201
lemma (in UP_cring) monom_pow:
ballarin@13940
  1202
  assumes R: "a \<in> carrier R"
ballarin@15095
  1203
  shows "(monom P a n) (^)\<^bsub>P\<^esub> m = monom P (a (^) m) (n * m)"
ballarin@13940
  1204
proof (induct m)
ballarin@13940
  1205
  case 0 from R show ?case by simp
ballarin@13940
  1206
next
ballarin@13940
  1207
  case Suc with R show ?case
ballarin@13940
  1208
    by (simp del: monom_mult add: monom_mult [THEN sym] add_commute)
ballarin@13940
  1209
qed
ballarin@13940
  1210
ballarin@13940
  1211
lemma (in ring_hom_cring) hom_pow [simp]:
ballarin@15095
  1212
  "x \<in> carrier R ==> h (x (^) n) = h x (^)\<^bsub>S\<^esub> (n::nat)"
ballarin@13940
  1213
  by (induct n) simp_all
ballarin@13940
  1214
ballarin@17094
  1215
lemma (in UP_univ_prop) Eval_monom:
ballarin@17094
  1216
  "r \<in> carrier R ==> Eval (monom P r n) = h r \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> n"
ballarin@13940
  1217
proof -
ballarin@17094
  1218
  assume R: "r \<in> carrier R"
ballarin@17094
  1219
  from R have "Eval (monom P r n) = Eval (monom P r 0 \<otimes>\<^bsub>P\<^esub> (monom P \<one> 1) (^)\<^bsub>P\<^esub> n)"
ballarin@17094
  1220
    by (simp del: monom_mult add: monom_mult [THEN sym] monom_pow)
ballarin@15095
  1221
  also
ballarin@17094
  1222
  from R eval_monom1 [where s = s, folded Eval_def]
ballarin@17094
  1223
  have "... = h r \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> n"
ballarin@17094
  1224
    by (simp add: eval_const [where s = s, folded Eval_def])
ballarin@13940
  1225
  finally show ?thesis .
ballarin@13940
  1226
qed
ballarin@13940
  1227
ballarin@17094
  1228
lemma (in UP_pre_univ_prop) eval_monom:
ballarin@17094
  1229
  assumes R: "r \<in> carrier R" and S: "s \<in> carrier S"
ballarin@17094
  1230
  shows "eval R S h s (monom P r n) = h r \<otimes>\<^bsub>S\<^esub> s (^)\<^bsub>S\<^esub> n"
ballarin@15095
  1231
proof -
ballarin@19931
  1232
  interpret UP_univ_prop [R S h P s _]
wenzelm@26202
  1233
    using UP_pre_univ_prop_axioms P_def R S
wenzelm@22931
  1234
    by (auto intro: UP_univ_prop.intro UP_univ_prop_axioms.intro)
ballarin@17094
  1235
  from R
ballarin@17094
  1236
  show ?thesis by (rule Eval_monom)
ballarin@17094
  1237
qed
ballarin@17094
  1238
ballarin@17094
  1239
lemma (in UP_univ_prop) Eval_smult:
ballarin@17094
  1240
  "[| r \<in> carrier R; p \<in> carrier P |] ==> Eval (r \<odot>\<^bsub>P\<^esub> p) = h r \<otimes>\<^bsub>S\<^esub> Eval p"
ballarin@17094
  1241
proof -
ballarin@17094
  1242
  assume R: "r \<in> carrier R" and P: "p \<in> carrier P"
ballarin@17094
  1243
  then show ?thesis
ballarin@17094
  1244
    by (simp add: monom_mult_is_smult [THEN sym]
ballarin@17094
  1245
      eval_const [where s = s, folded Eval_def])
ballarin@15095
  1246
qed
ballarin@13940
  1247
ballarin@13940
  1248
lemma ring_hom_cringI:
ballarin@13940
  1249
  assumes "cring R"
ballarin@13940
  1250
    and "cring S"
ballarin@13940
  1251
    and "h \<in> ring_hom R S"
ballarin@13940
  1252
  shows "ring_hom_cring R S h"
ballarin@13940
  1253
  by (fast intro: ring_hom_cring.intro ring_hom_cring_axioms.intro
ballarin@13940
  1254
    cring.axioms prems)
ballarin@13940
  1255
ballarin@17094
  1256
lemma (in UP_pre_univ_prop) UP_hom_unique:
ballarin@27611
  1257
  assumes "ring_hom_cring P S Phi"
ballarin@17094
  1258
  assumes Phi: "Phi (monom P \<one> (Suc 0)) = s"
ballarin@13940
  1259
      "!!r. r \<in> carrier R ==> Phi (monom P r 0) = h r"
ballarin@27611
  1260
  assumes "ring_hom_cring P S Psi"
ballarin@17094
  1261
  assumes Psi: "Psi (monom P \<one> (Suc 0)) = s"
ballarin@13940
  1262
      "!!r. r \<in> carrier R ==> Psi (monom P r 0) = h r"
ballarin@17094
  1263
    and P: "p \<in> carrier P" and S: "s \<in> carrier S"
ballarin@13940
  1264
  shows "Phi p = Psi p"
ballarin@13940
  1265
proof -
ballarin@27611
  1266
  interpret ring_hom_cring [P S Phi] by fact
ballarin@27611
  1267
  interpret ring_hom_cring [P S Psi] by fact
ballarin@15095
  1268
  have "Phi p =
ballarin@15095
  1269
      Phi (\<Oplus>\<^bsub>P \<^esub>i \<in> {..deg R p}. monom P (coeff P p i) 0 \<otimes>\<^bsub>P\<^esub> monom P \<one> 1 (^)\<^bsub>P\<^esub> i)"
ballarin@17094
  1270
    by (simp add: up_repr P monom_mult [THEN sym] monom_pow del: monom_mult)
ballarin@15696
  1271
  also
ballarin@15696
  1272
  have "... =
ballarin@15095
  1273
      Psi (\<Oplus>\<^bsub>P \<^esub>i\<in>{..deg R p}. monom P (coeff P p i) 0 \<otimes>\<^bsub>P\<^esub> monom P \<one> 1 (^)\<^bsub>P\<^esub> i)"
ballarin@17094
  1274
    by (simp add: Phi Psi P Pi_def comp_def)
ballarin@13940
  1275
  also have "... = Psi p"
ballarin@17094
  1276
    by (simp add: up_repr P monom_mult [THEN sym] monom_pow del: monom_mult)
ballarin@13940
  1277
  finally show ?thesis .
ballarin@13940
  1278
qed
ballarin@13940
  1279
ballarin@17094
  1280
lemma (in UP_pre_univ_prop) ring_homD:
ballarin@17094
  1281
  assumes Phi: "Phi \<in> ring_hom P S"
ballarin@17094
  1282
  shows "ring_hom_cring P S Phi"
ballarin@17094
  1283
proof (rule ring_hom_cring.intro)
ballarin@17094
  1284
  show "ring_hom_cring_axioms P S Phi"
ballarin@17094
  1285
  by (rule ring_hom_cring_axioms.intro) (rule Phi)
ballarin@19984
  1286
qed unfold_locales
ballarin@17094
  1287
ballarin@17094
  1288
theorem (in UP_pre_univ_prop) UP_universal_property:
ballarin@17094
  1289
  assumes S: "s \<in> carrier S"
ballarin@17094
  1290
  shows "EX! Phi. Phi \<in> ring_hom P S \<inter> extensional (carrier P) &
wenzelm@14666
  1291
    Phi (monom P \<one> 1) = s &
ballarin@13940
  1292
    (ALL r : carrier R. Phi (monom P r 0) = h r)"
ballarin@17094
  1293
  using S eval_monom1
ballarin@13940
  1294
  apply (auto intro: eval_ring_hom eval_const eval_extensional)
wenzelm@14666
  1295
  apply (rule extensionalityI)
ballarin@17094
  1296
  apply (auto intro: UP_hom_unique ring_homD)
wenzelm@14666
  1297
  done
ballarin@13940
  1298
ballarin@17094
  1299
ballarin@20318
  1300
subsection {* Sample Application of Evaluation Homomorphism *}
ballarin@13940
  1301
ballarin@17094
  1302
lemma UP_pre_univ_propI:
ballarin@13940
  1303
  assumes "cring R"
ballarin@13940
  1304
    and "cring S"
ballarin@13940
  1305
    and "h \<in> ring_hom R S"
ballarin@19931
  1306
  shows "UP_pre_univ_prop R S h"
wenzelm@23350
  1307
  using assms
ballarin@19931
  1308
  by (auto intro!: UP_pre_univ_prop.intro ring_hom_cring.intro
ballarin@19931
  1309
    ring_hom_cring_axioms.intro UP_cring.intro)
ballarin@13940
  1310
ballarin@13975
  1311
constdefs
ballarin@13975
  1312
  INTEG :: "int ring"
ballarin@13975
  1313
  "INTEG == (| carrier = UNIV, mult = op *, one = 1, zero = 0, add = op + |)"
ballarin@13975
  1314
ballarin@15095
  1315
lemma INTEG_cring:
ballarin@13975
  1316
  "cring INTEG"
ballarin@13975
  1317
  by (unfold INTEG_def) (auto intro!: cringI abelian_groupI comm_monoidI
ballarin@13975
  1318
    zadd_zminus_inverse2 zadd_zmult_distrib)
ballarin@13975
  1319
ballarin@15095
  1320
lemma INTEG_id_eval:
ballarin@17094
  1321
  "UP_pre_univ_prop INTEG INTEG id"
ballarin@17094
  1322
  by (fast intro: UP_pre_univ_propI INTEG_cring id_ring_hom)
ballarin@13940
  1323
ballarin@13940
  1324
text {*
ballarin@17094
  1325
  Interpretation now enables to import all theorems and lemmas
ballarin@13940
  1326
  valid in the context of homomorphisms between @{term INTEG} and @{term
ballarin@15095
  1327
  "UP INTEG"} globally.
wenzelm@14666
  1328
*}
ballarin@13940
  1329
ballarin@17094
  1330
interpretation INTEG: UP_pre_univ_prop [INTEG INTEG id]
ballarin@19931
  1331
  apply simp
ballarin@15763
  1332
  using INTEG_id_eval
ballarin@19931
  1333
  apply simp
ballarin@19931
  1334
  done
ballarin@15763
  1335
ballarin@13940
  1336
lemma INTEG_closed [intro, simp]:
ballarin@13940
  1337
  "z \<in> carrier INTEG"
ballarin@13940
  1338
  by (unfold INTEG_def) simp
ballarin@13940
  1339
ballarin@13940
  1340
lemma INTEG_mult [simp]:
ballarin@13940
  1341
  "mult INTEG z w = z * w"
ballarin@13940
  1342
  by (unfold INTEG_def) simp
ballarin@13940
  1343
ballarin@13940
  1344
lemma INTEG_pow [simp]:
ballarin@13940
  1345
  "pow INTEG z n = z ^ n"
ballarin@13940
  1346
  by (induct n) (simp_all add: INTEG_def nat_pow_def)
ballarin@13940
  1347
ballarin@13940
  1348
lemma "eval INTEG INTEG id 10 (monom (UP INTEG) 5 2) = 500"
ballarin@15763
  1349
  by (simp add: INTEG.eval_monom)
ballarin@13940
  1350
wenzelm@14590
  1351
end