src/HOL/ex/Commutative_Ring_Complete.thy
author chaieb
Wed Sep 14 17:25:52 2005 +0200 (2005-09-14)
changeset 17378 105519771c67
child 17388 495c799df31d
permissions -rw-r--r--
The oracle for Presburger has been changer: It is automatically generated form a verified formaliztion of Cooper's Algorithm ex/Reflected_Presburger.thy
comm_ring : a reflected Method for proving equalities in a commutative ring
chaieb@17378
     1
(*  ID:         $Id$
chaieb@17378
     2
    Author:     Bernhard Haeupler
chaieb@17378
     3
chaieb@17378
     4
  This theory is about the relative completeness of the tactic 
chaieb@17378
     5
  As long as the reified atomic polynomials of type 'a pol 
chaieb@17378
     6
  are in normal form, the cring method is complete *)	
chaieb@17378
     7
chaieb@17378
     8
theory Commutative_Ring_Complete
chaieb@17378
     9
imports Main
chaieb@17378
    10
begin
chaieb@17378
    11
	
chaieb@17378
    12
  (* Fromalization of normal form *)
chaieb@17378
    13
consts isnorm :: "('a::{comm_ring,recpower}) pol \<Rightarrow> bool"
chaieb@17378
    14
recdef isnorm "measure size"
chaieb@17378
    15
  "isnorm (Pc c) = True"
chaieb@17378
    16
  "isnorm (Pinj i (Pc c)) = False"
chaieb@17378
    17
  "isnorm (Pinj i (Pinj j Q)) = False"
chaieb@17378
    18
  "isnorm (Pinj 0 P) = False"
chaieb@17378
    19
  "isnorm (Pinj i (PX Q1 j Q2)) = isnorm (PX Q1 j Q2)"
chaieb@17378
    20
  "isnorm (PX P 0 Q) = False"
chaieb@17378
    21
  "isnorm (PX (Pc c) i Q) = (c \<noteq> 0 & isnorm Q)"
chaieb@17378
    22
  "isnorm (PX (PX P1 j (Pc c)) i Q) = (c\<noteq>0 \<and> isnorm(PX P1 j (Pc c))\<and>isnorm Q)"
chaieb@17378
    23
  "isnorm (PX P i Q) = (isnorm P \<and> isnorm Q)"
chaieb@17378
    24
chaieb@17378
    25
(* Some helpful lemmas *)
chaieb@17378
    26
lemma norm_Pinj_0_False:"isnorm (Pinj 0 P) = False"
chaieb@17378
    27
by(cases P, auto)
chaieb@17378
    28
chaieb@17378
    29
lemma norm_PX_0_False:"isnorm (PX (Pc 0) i Q) = False"
chaieb@17378
    30
by(cases i, auto)
chaieb@17378
    31
chaieb@17378
    32
lemma norm_Pinj:"isnorm (Pinj i Q) \<Longrightarrow> isnorm Q"
chaieb@17378
    33
by(cases i,simp add: norm_Pinj_0_False norm_PX_0_False,cases Q) auto
chaieb@17378
    34
chaieb@17378
    35
lemma norm_PX2:"isnorm (PX P i Q) \<Longrightarrow> isnorm Q"
chaieb@17378
    36
by(cases i, auto, cases P, auto, case_tac pol2, auto)
chaieb@17378
    37
chaieb@17378
    38
lemma norm_PX1:"isnorm (PX P i Q) \<Longrightarrow> isnorm P"
chaieb@17378
    39
by(cases i, auto, cases P, auto, case_tac pol2, auto)
chaieb@17378
    40
chaieb@17378
    41
lemma mkPinj_cn:"\<lbrakk>y~=0; isnorm Q\<rbrakk> \<Longrightarrow> isnorm (mkPinj y Q)" 
chaieb@17378
    42
apply(auto simp add: mkPinj_def norm_Pinj_0_False split: pol.split)
chaieb@17378
    43
apply(case_tac nat, auto simp add: norm_Pinj_0_False)
chaieb@17378
    44
by(case_tac pol, auto) (case_tac y, auto)
chaieb@17378
    45
chaieb@17378
    46
lemma norm_PXtrans: 
chaieb@17378
    47
  assumes A:"isnorm (PX P x Q)" and "isnorm Q2" 
chaieb@17378
    48
  shows "isnorm (PX P x Q2)"
chaieb@17378
    49
proof(cases P)
chaieb@17378
    50
  case (PX p1 y p2) from prems show ?thesis by(cases x, auto, cases p2, auto)
chaieb@17378
    51
next
chaieb@17378
    52
  case Pc from prems show ?thesis by(cases x, auto)
chaieb@17378
    53
next
chaieb@17378
    54
  case Pinj from prems show ?thesis by(cases x, auto)
chaieb@17378
    55
qed
chaieb@17378
    56
 
chaieb@17378
    57
chaieb@17378
    58
lemma norm_PXtrans2: assumes A:"isnorm (PX P x Q)" and "isnorm Q2" shows "isnorm (PX P (Suc (n+x)) Q2)"
chaieb@17378
    59
proof(cases P)
chaieb@17378
    60
  case (PX p1 y p2)
chaieb@17378
    61
  from prems show ?thesis by(cases x, auto, cases p2, auto)
chaieb@17378
    62
next
chaieb@17378
    63
  case Pc
chaieb@17378
    64
  from prems show ?thesis by(cases x, auto)
chaieb@17378
    65
next
chaieb@17378
    66
  case Pinj
chaieb@17378
    67
  from prems show ?thesis by(cases x, auto)
chaieb@17378
    68
qed
chaieb@17378
    69
chaieb@17378
    70
    (* mkPX conserves normalizedness (_cn)*)
chaieb@17378
    71
lemma mkPX_cn: 
chaieb@17378
    72
  assumes "x \<noteq> 0" and "isnorm P" and "isnorm Q" 
chaieb@17378
    73
  shows "isnorm (mkPX P x Q)"
chaieb@17378
    74
proof(cases P)
chaieb@17378
    75
  case (Pc c)
chaieb@17378
    76
  from prems show ?thesis by (cases x) (auto simp add: mkPinj_cn mkPX_def)
chaieb@17378
    77
next
chaieb@17378
    78
  case (Pinj i Q)
chaieb@17378
    79
  from prems show ?thesis by (cases x) (auto simp add: mkPinj_cn mkPX_def)
chaieb@17378
    80
next
chaieb@17378
    81
  case (PX P1 y P2)
chaieb@17378
    82
  from prems have Y0:"y>0" by(cases y, auto)
chaieb@17378
    83
  from prems have "isnorm P1" "isnorm P2" by (auto simp add: norm_PX1[of P1 y P2] norm_PX2[of P1 y P2])
chaieb@17378
    84
  with prems Y0 show ?thesis by (cases x, auto simp add: mkPX_def norm_PXtrans2[of P1 y _ Q _], cases P2, auto)
chaieb@17378
    85
qed
chaieb@17378
    86
chaieb@17378
    87
    (* add conserves normalizedness *)
chaieb@17378
    88
lemma add_cn:"\<lbrakk>isnorm P; (isnorm Q)\<rbrakk> \<Longrightarrow> isnorm (add (P, Q))"
chaieb@17378
    89
proof(induct P Q rule: add.induct)
chaieb@17378
    90
  case (2 c i P2) thus ?case by (cases P2, simp_all, cases i, simp_all)
chaieb@17378
    91
next
chaieb@17378
    92
  case (3 i P2 c) thus ?case by (cases P2, simp_all, cases i, simp_all)
chaieb@17378
    93
next
chaieb@17378
    94
  case (4 c P2 i Q2)
chaieb@17378
    95
  from prems have "isnorm P2" "isnorm Q2" by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
chaieb@17378
    96
  with prems show ?case by(cases i, simp, cases P2, auto, case_tac pol2, auto)
chaieb@17378
    97
next
chaieb@17378
    98
  case (5 P2 i Q2 c)
chaieb@17378
    99
  from prems have "isnorm P2" "isnorm Q2" by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
chaieb@17378
   100
  with prems show ?case by(cases i, simp, cases P2, auto, case_tac pol2, auto)
chaieb@17378
   101
next
chaieb@17378
   102
  case (6 x P2 y Q2)
chaieb@17378
   103
  from prems have Y0:"y>0" by (cases y, auto simp add: norm_Pinj_0_False) 
chaieb@17378
   104
  from prems have X0:"x>0" by (cases x, auto simp add: norm_Pinj_0_False) 
chaieb@17378
   105
  have "x < y \<or> x = y \<or> x > y" by arith
chaieb@17378
   106
  moreover
chaieb@17378
   107
  { assume "x<y" hence "EX d. y=d+x" by arith
chaieb@17378
   108
    then obtain d where "y=d+x"..
chaieb@17378
   109
    moreover
chaieb@17378
   110
    note prems X0
chaieb@17378
   111
    moreover
chaieb@17378
   112
    from prems have "isnorm P2" "isnorm Q2" by (auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
chaieb@17378
   113
    moreover
chaieb@17378
   114
    with prems have "isnorm (Pinj d Q2)" by (cases d, simp, cases Q2, auto)
chaieb@17378
   115
    ultimately have ?case by (simp add: mkPinj_cn)}
chaieb@17378
   116
  moreover
chaieb@17378
   117
  { assume "x=y"
chaieb@17378
   118
    moreover
chaieb@17378
   119
    from prems have "isnorm P2" "isnorm Q2" by(auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
chaieb@17378
   120
    moreover
chaieb@17378
   121
    note prems Y0
chaieb@17378
   122
    moreover
chaieb@17378
   123
    ultimately have ?case by (simp add: mkPinj_cn) }
chaieb@17378
   124
  moreover
chaieb@17378
   125
  { assume "x>y" hence "EX d. x=d+y" by arith
chaieb@17378
   126
    then obtain d where "x=d+y"..
chaieb@17378
   127
    moreover
chaieb@17378
   128
    note prems Y0
chaieb@17378
   129
    moreover
chaieb@17378
   130
    from prems have "isnorm P2" "isnorm Q2" by (auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
chaieb@17378
   131
    moreover
chaieb@17378
   132
    with prems have "isnorm (Pinj d P2)" by (cases d, simp, cases P2, auto)
chaieb@17378
   133
    ultimately have ?case by (simp add: mkPinj_cn)}
chaieb@17378
   134
  ultimately show ?case by blast
chaieb@17378
   135
next
chaieb@17378
   136
  case (7 x P2 Q2 y R)
chaieb@17378
   137
  have "x=0 \<or> (x = 1) \<or> (x > 1)" by arith
chaieb@17378
   138
  moreover
chaieb@17378
   139
  { assume "x=0" with prems have ?case by (auto simp add: norm_Pinj_0_False)}
chaieb@17378
   140
  moreover
chaieb@17378
   141
  { assume "x=1"
chaieb@17378
   142
    from prems have "isnorm R" "isnorm P2" by (auto simp add: norm_Pinj[of _ P2] norm_PX2[of Q2 y R])
chaieb@17378
   143
    with prems have "isnorm (add (R, P2))" by simp
chaieb@17378
   144
    with prems have ?case by (simp add: norm_PXtrans[of Q2 y _]) }
chaieb@17378
   145
  moreover
chaieb@17378
   146
  { assume "x > 1" hence "EX d. x=Suc (Suc d)" by arith
chaieb@17378
   147
    then obtain d where X:"x=Suc (Suc d)" ..
chaieb@17378
   148
    from prems have NR:"isnorm R" "isnorm P2" by (auto simp add: norm_Pinj[of _ P2] norm_PX2[of Q2 y R])
chaieb@17378
   149
    with prems have "isnorm (Pinj (x - 1) P2)" by(cases P2, auto)
chaieb@17378
   150
    with prems NR have "isnorm( add (R, Pinj (x - 1) P2))" "isnorm(PX Q2 y R)" by simp
chaieb@17378
   151
    with X have ?case by (simp add: norm_PXtrans[of Q2 y _]) }
chaieb@17378
   152
  ultimately show ?case by blast
chaieb@17378
   153
next
chaieb@17378
   154
  case (8 Q2 y R x P2)
chaieb@17378
   155
  have "x=0 \<or> (x = 1) \<or> (x > 1)" by arith
chaieb@17378
   156
  moreover
chaieb@17378
   157
  { assume "x=0" with prems have ?case by (auto simp add: norm_Pinj_0_False)}
chaieb@17378
   158
  moreover
chaieb@17378
   159
  { assume "x=1"
chaieb@17378
   160
    from prems have "isnorm R" "isnorm P2" by (auto simp add: norm_Pinj[of _ P2] norm_PX2[of Q2 y R])
chaieb@17378
   161
    with prems have "isnorm (add (R, P2))" by simp
chaieb@17378
   162
    with prems have ?case by (simp add: norm_PXtrans[of Q2 y _]) }
chaieb@17378
   163
  moreover
chaieb@17378
   164
  { assume "x > 1" hence "EX d. x=Suc (Suc d)" by arith
chaieb@17378
   165
    then obtain d where X:"x=Suc (Suc d)" ..
chaieb@17378
   166
    from prems have NR:"isnorm R" "isnorm P2" by (auto simp add: norm_Pinj[of _ P2] norm_PX2[of Q2 y R])
chaieb@17378
   167
    with prems have "isnorm (Pinj (x - 1) P2)" by(cases P2, auto)
chaieb@17378
   168
    with prems NR have "isnorm( add (R, Pinj (x - 1) P2))" "isnorm(PX Q2 y R)" by simp
chaieb@17378
   169
    with X have ?case by (simp add: norm_PXtrans[of Q2 y _]) }
chaieb@17378
   170
  ultimately show ?case by blast
chaieb@17378
   171
next
chaieb@17378
   172
  case (9 P1 x P2 Q1 y Q2)
chaieb@17378
   173
  from prems have Y0:"y>0" by(cases y, auto)
chaieb@17378
   174
  from prems have X0:"x>0" by(cases x, auto)
chaieb@17378
   175
  from prems have NP1:"isnorm P1" and NP2:"isnorm P2" by (auto simp add: norm_PX1[of P1 _ P2] norm_PX2[of P1 _ P2])
chaieb@17378
   176
  from prems have NQ1:"isnorm Q1" and NQ2:"isnorm Q2" by (auto simp add: norm_PX1[of Q1 _ Q2] norm_PX2[of Q1 _ Q2])
chaieb@17378
   177
  have "y < x \<or> x = y \<or> x < y" by arith
chaieb@17378
   178
  moreover
chaieb@17378
   179
  {assume sm1:"y < x" hence "EX d. x=d+y" by arith
chaieb@17378
   180
    then obtain d where sm2:"x=d+y"..
chaieb@17378
   181
    note prems NQ1 NP1 NP2 NQ2 sm1 sm2
chaieb@17378
   182
    moreover
chaieb@17378
   183
    have "isnorm (PX P1 d (Pc 0))" 
chaieb@17378
   184
    proof(cases P1)
chaieb@17378
   185
      case (PX p1 y p2)
chaieb@17378
   186
      with prems show ?thesis by(cases d, simp,cases p2, auto)
chaieb@17378
   187
    next case Pc   from prems show ?thesis by(cases d, auto)
chaieb@17378
   188
    next case Pinj from prems show ?thesis by(cases d, auto)
chaieb@17378
   189
    qed
chaieb@17378
   190
    ultimately have "isnorm (add (P2, Q2))" "isnorm (add (PX P1 (x - y) (Pc 0), Q1))" by auto
chaieb@17378
   191
    with Y0 sm1 sm2 have ?case by (simp add: mkPX_cn)}
chaieb@17378
   192
  moreover
chaieb@17378
   193
  {assume "x=y"
chaieb@17378
   194
    from prems NP1 NP2 NQ1 NQ2 have "isnorm (add (P2, Q2))" "isnorm (add (P1, Q1))" by auto
chaieb@17378
   195
    with Y0 prems have ?case by (simp add: mkPX_cn) }
chaieb@17378
   196
  moreover
chaieb@17378
   197
  {assume sm1:"x<y" hence "EX d. y=d+x" by arith
chaieb@17378
   198
    then obtain d where sm2:"y=d+x"..
chaieb@17378
   199
    note prems NQ1 NP1 NP2 NQ2 sm1 sm2
chaieb@17378
   200
    moreover
chaieb@17378
   201
    have "isnorm (PX Q1 d (Pc 0))" 
chaieb@17378
   202
    proof(cases Q1)
chaieb@17378
   203
      case (PX p1 y p2)
chaieb@17378
   204
      with prems show ?thesis by(cases d, simp,cases p2, auto)
chaieb@17378
   205
    next case Pc   from prems show ?thesis by(cases d, auto)
chaieb@17378
   206
    next case Pinj from prems show ?thesis by(cases d, auto)
chaieb@17378
   207
    qed
chaieb@17378
   208
    ultimately have "isnorm (add (P2, Q2))" "isnorm (add (PX Q1 (y - x) (Pc 0), P1))" by auto
chaieb@17378
   209
    with X0 sm1 sm2 have ?case by (simp add: mkPX_cn)}
chaieb@17378
   210
  ultimately show ?case by blast
chaieb@17378
   211
qed(simp)
chaieb@17378
   212
chaieb@17378
   213
    (* mul concerves normalizedness *)
chaieb@17378
   214
lemma mul_cn :"\<lbrakk>isnorm P; (isnorm Q)\<rbrakk> \<Longrightarrow> isnorm (mul (P, Q))"
chaieb@17378
   215
proof(induct P Q rule: mul.induct)
chaieb@17378
   216
  case (2 c i P2) thus ?case 
chaieb@17378
   217
    by (cases P2, simp_all) (cases "i",simp_all add: mkPinj_cn)
chaieb@17378
   218
next
chaieb@17378
   219
  case (3 i P2 c) thus ?case 
chaieb@17378
   220
    by (cases P2, simp_all) (cases "i",simp_all add: mkPinj_cn)
chaieb@17378
   221
next
chaieb@17378
   222
  case (4 c P2 i Q2)
chaieb@17378
   223
  from prems have "isnorm P2" "isnorm Q2" by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
chaieb@17378
   224
  with prems show ?case 
chaieb@17378
   225
    by - (case_tac "c=0",simp_all,case_tac "i=0",simp_all add: mkPX_cn)
chaieb@17378
   226
next
chaieb@17378
   227
  case (5 P2 i Q2 c)
chaieb@17378
   228
  from prems have "isnorm P2" "isnorm Q2" by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
chaieb@17378
   229
  with prems show ?case
chaieb@17378
   230
    by - (case_tac "c=0",simp_all,case_tac "i=0",simp_all add: mkPX_cn)
chaieb@17378
   231
next
chaieb@17378
   232
  case (6 x P2 y Q2)
chaieb@17378
   233
  have "x < y \<or> x = y \<or> x > y" by arith
chaieb@17378
   234
  moreover
chaieb@17378
   235
  { assume "x<y" hence "EX d. y=d+x" by arith
chaieb@17378
   236
    then obtain d where "y=d+x"..
chaieb@17378
   237
    moreover
chaieb@17378
   238
    note prems
chaieb@17378
   239
    moreover
chaieb@17378
   240
    from prems have "x>0" by (cases x, auto simp add: norm_Pinj_0_False) 
chaieb@17378
   241
    moreover
chaieb@17378
   242
    from prems have "isnorm P2" "isnorm Q2" by (auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
chaieb@17378
   243
    moreover
chaieb@17378
   244
    with prems have "isnorm (Pinj d Q2)" by (cases d, simp, cases Q2, auto) 
chaieb@17378
   245
    ultimately have ?case by (simp add: mkPinj_cn)}
chaieb@17378
   246
  moreover
chaieb@17378
   247
  { assume "x=y"
chaieb@17378
   248
    moreover
chaieb@17378
   249
    from prems have "isnorm P2" "isnorm Q2" by(auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
chaieb@17378
   250
    moreover
chaieb@17378
   251
    with prems have "y>0" by (cases y, auto simp add: norm_Pinj_0_False)
chaieb@17378
   252
    moreover
chaieb@17378
   253
    note prems
chaieb@17378
   254
    moreover
chaieb@17378
   255
    ultimately have ?case by (simp add: mkPinj_cn) }
chaieb@17378
   256
  moreover
chaieb@17378
   257
  { assume "x>y" hence "EX d. x=d+y" by arith
chaieb@17378
   258
    then obtain d where "x=d+y"..
chaieb@17378
   259
    moreover
chaieb@17378
   260
    note prems
chaieb@17378
   261
    moreover
chaieb@17378
   262
    from prems have "y>0" by (cases y, auto simp add: norm_Pinj_0_False) 
chaieb@17378
   263
    moreover
chaieb@17378
   264
    from prems have "isnorm P2" "isnorm Q2" by (auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
chaieb@17378
   265
    moreover
chaieb@17378
   266
    with prems have "isnorm (Pinj d P2)"  by (cases d, simp, cases P2, auto)
chaieb@17378
   267
    ultimately have ?case by (simp add: mkPinj_cn) }
chaieb@17378
   268
  ultimately show ?case by blast
chaieb@17378
   269
next
chaieb@17378
   270
  case (7 x P2 Q2 y R)
chaieb@17378
   271
  from prems have Y0:"y>0" by(cases y, auto)
chaieb@17378
   272
  have "x=0 \<or> (x = 1) \<or> (x > 1)" by arith
chaieb@17378
   273
  moreover
chaieb@17378
   274
  { assume "x=0" with prems have ?case by (auto simp add: norm_Pinj_0_False)}
chaieb@17378
   275
  moreover
chaieb@17378
   276
  { assume "x=1"
chaieb@17378
   277
    from prems have "isnorm R" "isnorm P2" by (auto simp add: norm_Pinj[of _ P2] norm_PX2[of Q2 y R])
chaieb@17378
   278
    with prems have "isnorm (mul (R, P2))" "isnorm Q2" by (auto simp add: norm_PX1[of Q2 y R])
chaieb@17378
   279
    with Y0 prems have ?case by (simp add: mkPX_cn)}
chaieb@17378
   280
  moreover
chaieb@17378
   281
  { assume "x > 1" hence "EX d. x=Suc (Suc d)" by arith
chaieb@17378
   282
    then obtain d where X:"x=Suc (Suc d)" ..
chaieb@17378
   283
    from prems have NR:"isnorm R" "isnorm Q2" by (auto simp add: norm_PX2[of Q2 y R] norm_PX1[of Q2 y R])
chaieb@17378
   284
    moreover
chaieb@17378
   285
    from prems have "isnorm (Pinj (x - 1) P2)" by(cases P2, auto)
chaieb@17378
   286
    moreover
chaieb@17378
   287
    from prems have "isnorm (Pinj x P2)" by(cases P2, auto)
chaieb@17378
   288
    moreover
chaieb@17378
   289
    note prems
chaieb@17378
   290
    ultimately have "isnorm (mul (R, Pinj (x - 1) P2))" "isnorm (mul (Pinj x P2, Q2))" by auto
chaieb@17378
   291
    with Y0 X have ?case by (simp add: mkPX_cn)}
chaieb@17378
   292
  ultimately show ?case by blast
chaieb@17378
   293
next
chaieb@17378
   294
  case (8 Q2 y R x P2)
chaieb@17378
   295
  from prems have Y0:"y>0" by(cases y, auto)
chaieb@17378
   296
  have "x=0 \<or> (x = 1) \<or> (x > 1)" by arith
chaieb@17378
   297
  moreover
chaieb@17378
   298
  { assume "x=0" with prems have ?case by (auto simp add: norm_Pinj_0_False)}
chaieb@17378
   299
  moreover
chaieb@17378
   300
  { assume "x=1"
chaieb@17378
   301
    from prems have "isnorm R" "isnorm P2" by (auto simp add: norm_Pinj[of _ P2] norm_PX2[of Q2 y R])
chaieb@17378
   302
    with prems have "isnorm (mul (R, P2))" "isnorm Q2" by (auto simp add: norm_PX1[of Q2 y R])
chaieb@17378
   303
    with Y0 prems have ?case by (simp add: mkPX_cn) }
chaieb@17378
   304
  moreover
chaieb@17378
   305
  { assume "x > 1" hence "EX d. x=Suc (Suc d)" by arith
chaieb@17378
   306
    then obtain d where X:"x=Suc (Suc d)" ..
chaieb@17378
   307
    from prems have NR:"isnorm R" "isnorm Q2" by (auto simp add: norm_PX2[of Q2 y R] norm_PX1[of Q2 y R])
chaieb@17378
   308
    moreover
chaieb@17378
   309
    from prems have "isnorm (Pinj (x - 1) P2)" by(cases P2, auto)
chaieb@17378
   310
    moreover
chaieb@17378
   311
    from prems have "isnorm (Pinj x P2)" by(cases P2, auto)
chaieb@17378
   312
    moreover
chaieb@17378
   313
    note prems
chaieb@17378
   314
    ultimately have "isnorm (mul (R, Pinj (x - 1) P2))" "isnorm (mul (Pinj x P2, Q2))" by auto
chaieb@17378
   315
    with Y0 X have ?case by (simp add: mkPX_cn) }
chaieb@17378
   316
  ultimately show ?case by blast
chaieb@17378
   317
next
chaieb@17378
   318
  case (9 P1 x P2 Q1 y Q2)
chaieb@17378
   319
  from prems have X0:"x>0" by(cases x, auto)
chaieb@17378
   320
  from prems have Y0:"y>0" by(cases y, auto)
chaieb@17378
   321
  note prems
chaieb@17378
   322
  moreover
chaieb@17378
   323
  from prems have "isnorm P1" "isnorm P2" by (auto simp add: norm_PX1[of P1 x P2] norm_PX2[of P1 x P2])
chaieb@17378
   324
  moreover 
chaieb@17378
   325
  from prems have "isnorm Q1" "isnorm Q2" by (auto simp add: norm_PX1[of Q1 y Q2] norm_PX2[of Q1 y Q2])
chaieb@17378
   326
  ultimately have "isnorm (mul (P1, Q1))" "isnorm (mul (P2, Q2))" "isnorm (mul (P1, mkPinj 1 Q2))" "isnorm (mul (Q1, mkPinj 1 P2))" 
chaieb@17378
   327
    by (auto simp add: mkPinj_cn)
chaieb@17378
   328
  with prems X0 Y0 have "isnorm (mkPX (mul (P1, Q1)) (x + y) (mul (P2, Q2)))" "isnorm (mkPX (mul (P1, mkPinj (Suc 0) Q2)) x (Pc 0))"  
chaieb@17378
   329
    "isnorm (mkPX (mul (Q1, mkPinj (Suc 0) P2)) y (Pc 0))" 
chaieb@17378
   330
    by (auto simp add: mkPX_cn)
chaieb@17378
   331
  thus ?case by (simp add: add_cn)
chaieb@17378
   332
qed(simp)
chaieb@17378
   333
chaieb@17378
   334
    (* neg conserves normalizedness *)
chaieb@17378
   335
lemma neg_cn: "isnorm P \<Longrightarrow> isnorm (neg P)"
chaieb@17378
   336
proof(induct P rule: neg.induct)
chaieb@17378
   337
  case (Pinj i P2)
chaieb@17378
   338
  from prems have "isnorm P2" by (simp add: norm_Pinj[of i P2])
chaieb@17378
   339
  with prems show ?case by(cases P2, auto, cases i, auto)
chaieb@17378
   340
next
chaieb@17378
   341
  case (PX P1 x P2)
chaieb@17378
   342
  from prems have "isnorm P2" "isnorm P1" by (auto simp add: norm_PX1[of P1 x P2] norm_PX2[of P1 x P2])
chaieb@17378
   343
  with prems show ?case
chaieb@17378
   344
  proof(cases P1)
chaieb@17378
   345
    case (PX p1 y p2)
chaieb@17378
   346
    with prems show ?thesis by(cases x, auto, cases p2, auto)
chaieb@17378
   347
  next
chaieb@17378
   348
    case Pinj
chaieb@17378
   349
    with prems show ?thesis by(cases x, auto)
chaieb@17378
   350
  qed(cases x, auto)
chaieb@17378
   351
qed(simp)
chaieb@17378
   352
chaieb@17378
   353
    (* sub conserves normalizedness *)
chaieb@17378
   354
lemma sub_cn:"\<lbrakk>isnorm p; isnorm q\<rbrakk> \<Longrightarrow> isnorm (sub p q)"
chaieb@17378
   355
by (simp add: sub_def add_cn neg_cn)
chaieb@17378
   356
chaieb@17378
   357
  (* sqr conserves normalizizedness *)
chaieb@17378
   358
lemma sqr_cn:"isnorm P \<Longrightarrow> isnorm (sqr P)"
chaieb@17378
   359
proof(induct P)
chaieb@17378
   360
  case (Pinj i Q)
chaieb@17378
   361
  from prems show ?case by(cases Q, auto simp add: mkPX_cn mkPinj_cn, cases i, auto simp add: mkPX_cn mkPinj_cn)
chaieb@17378
   362
next 
chaieb@17378
   363
  case (PX P1 x P2)
chaieb@17378
   364
  from prems have "x+x~=0" "isnorm P2" "isnorm P1" by (cases x,  auto simp add: norm_PX1[of P1 x P2] norm_PX2[of P1 x P2])
chaieb@17378
   365
  with prems have "isnorm (mkPX (mul (mul (Pc ((1\<Colon>'a) + (1\<Colon>'a)), P1), mkPinj (Suc 0) P2)) x (Pc (0\<Colon>'a)))"
chaieb@17378
   366
              and "isnorm (mkPX (sqr P1) (x + x) (sqr P2))" by( auto simp add: add_cn mkPX_cn mkPinj_cn mul_cn)
chaieb@17378
   367
  thus ?case by( auto simp add: add_cn mkPX_cn mkPinj_cn mul_cn)
chaieb@17378
   368
qed(simp)
chaieb@17378
   369
chaieb@17378
   370
chaieb@17378
   371
    (* pow conserves normalizedness  *)
chaieb@17378
   372
lemma pow_cn:"!! P. \<lbrakk>isnorm P\<rbrakk> \<Longrightarrow> isnorm (pow (P, n))"
chaieb@17378
   373
proof(induct n rule: nat_less_induct)
chaieb@17378
   374
  case (1 k)
chaieb@17378
   375
  show ?case 
chaieb@17378
   376
  proof(cases "k=0")
chaieb@17378
   377
    case False
chaieb@17378
   378
    hence K2:"k div 2 < k" by (cases k, auto)
chaieb@17378
   379
    from prems have "isnorm (sqr P)" by (simp add: sqr_cn)
chaieb@17378
   380
    with prems K2 show ?thesis by(simp add: allE[of _ "(k div 2)" _] allE[of _ "(sqr P)" _], cases k, auto simp add: mul_cn)
chaieb@17378
   381
  qed(simp)
chaieb@17378
   382
qed
chaieb@17378
   383
chaieb@17378
   384
end