83 assumes bnd: "tmboundslt (length bs) t" and nb: "tmbound n t" and le: "n \<le> length bs" |
83 assumes bnd: "tmboundslt (length bs) t" and nb: "tmbound n t" and le: "n \<le> length bs" |
84 shows "Itm vs (bs[n:=x]) t = Itm vs bs t" |
84 shows "Itm vs (bs[n:=x]) t = Itm vs bs t" |
85 using nb le bnd |
85 using nb le bnd |
86 by (induct t rule: tm.induct , auto) |
86 by (induct t rule: tm.induct , auto) |
87 |
87 |
88 consts |
88 fun decrtm0:: "tm \<Rightarrow> tm" where |
89 incrtm0:: "tm \<Rightarrow> tm" |
|
90 decrtm0:: "tm \<Rightarrow> tm" |
|
91 |
|
92 recdef decrtm0 "measure size" |
|
93 "decrtm0 (Bound n) = Bound (n - 1)" |
89 "decrtm0 (Bound n) = Bound (n - 1)" |
94 "decrtm0 (Neg a) = Neg (decrtm0 a)" |
90 | "decrtm0 (Neg a) = Neg (decrtm0 a)" |
95 "decrtm0 (Add a b) = Add (decrtm0 a) (decrtm0 b)" |
91 | "decrtm0 (Add a b) = Add (decrtm0 a) (decrtm0 b)" |
96 "decrtm0 (Sub a b) = Sub (decrtm0 a) (decrtm0 b)" |
92 | "decrtm0 (Sub a b) = Sub (decrtm0 a) (decrtm0 b)" |
97 "decrtm0 (Mul c a) = Mul c (decrtm0 a)" |
93 | "decrtm0 (Mul c a) = Mul c (decrtm0 a)" |
98 "decrtm0 (CNP n c a) = CNP (n - 1) c (decrtm0 a)" |
94 | "decrtm0 (CNP n c a) = CNP (n - 1) c (decrtm0 a)" |
99 "decrtm0 a = a" |
95 | "decrtm0 a = a" |
100 |
96 |
101 recdef incrtm0 "measure size" |
97 fun incrtm0:: "tm \<Rightarrow> tm" where |
102 "incrtm0 (Bound n) = Bound (n + 1)" |
98 "incrtm0 (Bound n) = Bound (n + 1)" |
103 "incrtm0 (Neg a) = Neg (incrtm0 a)" |
99 | "incrtm0 (Neg a) = Neg (incrtm0 a)" |
104 "incrtm0 (Add a b) = Add (incrtm0 a) (incrtm0 b)" |
100 | "incrtm0 (Add a b) = Add (incrtm0 a) (incrtm0 b)" |
105 "incrtm0 (Sub a b) = Sub (incrtm0 a) (incrtm0 b)" |
101 | "incrtm0 (Sub a b) = Sub (incrtm0 a) (incrtm0 b)" |
106 "incrtm0 (Mul c a) = Mul c (incrtm0 a)" |
102 | "incrtm0 (Mul c a) = Mul c (incrtm0 a)" |
107 "incrtm0 (CNP n c a) = CNP (n + 1) c (incrtm0 a)" |
103 | "incrtm0 (CNP n c a) = CNP (n + 1) c (incrtm0 a)" |
108 "incrtm0 a = a" |
104 | "incrtm0 a = a" |
109 |
105 |
110 lemma decrtm0: assumes nb: "tmbound0 t" |
106 lemma decrtm0: assumes nb: "tmbound0 t" |
111 shows "Itm vs (x#bs) t = Itm vs bs (decrtm0 t)" |
107 shows "Itm vs (x#bs) t = Itm vs bs (decrtm0 t)" |
112 using nb by (induct t rule: decrtm0.induct, simp_all add: nth_pos2) |
108 using nb by (induct t rule: decrtm0.induct, simp_all add: nth_pos2) |
113 |
109 |
211 lemma incrtm0_tmbound: "tmbound n t \<Longrightarrow> tmbound (Suc n) (incrtm0 t)" |
207 lemma incrtm0_tmbound: "tmbound n t \<Longrightarrow> tmbound (Suc n) (incrtm0 t)" |
212 by (induct t, auto) |
208 by (induct t, auto) |
213 (* Simplification *) |
209 (* Simplification *) |
214 |
210 |
215 consts |
211 consts |
216 simptm:: "tm \<Rightarrow> tm" |
|
217 tmadd:: "tm \<times> tm \<Rightarrow> tm" |
212 tmadd:: "tm \<times> tm \<Rightarrow> tm" |
218 tmmul:: "tm \<Rightarrow> poly \<Rightarrow> tm" |
|
219 recdef tmadd "measure (\<lambda> (t,s). size t + size s)" |
213 recdef tmadd "measure (\<lambda> (t,s). size t + size s)" |
220 "tmadd (CNP n1 c1 r1,CNP n2 c2 r2) = |
214 "tmadd (CNP n1 c1 r1,CNP n2 c2 r2) = |
221 (if n1=n2 then |
215 (if n1=n2 then |
222 (let c = c1 +\<^sub>p c2 |
216 (let c = c1 +\<^sub>p c2 |
223 in if c = 0\<^sub>p then tmadd(r1,r2) else CNP n1 c (tmadd (r1,r2))) |
217 in if c = 0\<^sub>p then tmadd(r1,r2) else CNP n1 c (tmadd (r1,r2))) |
243 lemma tmadd_blt[simp]: "\<lbrakk>tmboundslt n t ; tmboundslt n s\<rbrakk> \<Longrightarrow> tmboundslt n (tmadd (t,s))" |
237 lemma tmadd_blt[simp]: "\<lbrakk>tmboundslt n t ; tmboundslt n s\<rbrakk> \<Longrightarrow> tmboundslt n (tmadd (t,s))" |
244 by (induct t s rule: tmadd.induct, auto simp add: Let_def) |
238 by (induct t s rule: tmadd.induct, auto simp add: Let_def) |
245 |
239 |
246 lemma tmadd_allpolys_npoly[simp]: "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly s \<Longrightarrow> allpolys isnpoly (tmadd(t,s))" by (induct t s rule: tmadd.induct, simp_all add: Let_def polyadd_norm) |
240 lemma tmadd_allpolys_npoly[simp]: "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly s \<Longrightarrow> allpolys isnpoly (tmadd(t,s))" by (induct t s rule: tmadd.induct, simp_all add: Let_def polyadd_norm) |
247 |
241 |
248 recdef tmmul "measure size" |
242 fun tmmul:: "tm \<Rightarrow> poly \<Rightarrow> tm" where |
249 "tmmul (CP j) = (\<lambda> i. CP (i *\<^sub>p j))" |
243 "tmmul (CP j) = (\<lambda> i. CP (i *\<^sub>p j))" |
250 "tmmul (CNP n c a) = (\<lambda> i. CNP n (i *\<^sub>p c) (tmmul a i))" |
244 | "tmmul (CNP n c a) = (\<lambda> i. CNP n (i *\<^sub>p c) (tmmul a i))" |
251 "tmmul t = (\<lambda> i. Mul i t)" |
245 | "tmmul t = (\<lambda> i. Mul i t)" |
252 |
246 |
253 lemma tmmul[simp]: "Itm vs bs (tmmul t i) = Itm vs bs (Mul i t)" |
247 lemma tmmul[simp]: "Itm vs bs (tmmul t i) = Itm vs bs (Mul i t)" |
254 by (induct t arbitrary: i rule: tmmul.induct, simp_all add: field_simps) |
248 by (induct t arbitrary: i rule: tmmul.induct, simp_all add: field_simps) |
255 |
249 |
256 lemma tmmul_nb0[simp]: "tmbound0 t \<Longrightarrow> tmbound0 (tmmul t i)" |
250 lemma tmmul_nb0[simp]: "tmbound0 t \<Longrightarrow> tmbound0 (tmmul t i)" |
304 lemma tmsub_allpolys_npoly[simp]: |
298 lemma tmsub_allpolys_npoly[simp]: |
305 assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})" |
299 assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})" |
306 shows "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly s \<Longrightarrow> allpolys isnpoly (tmsub t s)" |
300 shows "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly s \<Longrightarrow> allpolys isnpoly (tmsub t s)" |
307 unfolding tmsub_def by (simp add: isnpoly_def) |
301 unfolding tmsub_def by (simp add: isnpoly_def) |
308 |
302 |
309 recdef simptm "measure size" |
303 fun simptm:: "tm \<Rightarrow> tm" where |
310 "simptm (CP j) = CP (polynate j)" |
304 "simptm (CP j) = CP (polynate j)" |
311 "simptm (Bound n) = CNP n 1\<^sub>p (CP 0\<^sub>p)" |
305 | "simptm (Bound n) = CNP n 1\<^sub>p (CP 0\<^sub>p)" |
312 "simptm (Neg t) = tmneg (simptm t)" |
306 | "simptm (Neg t) = tmneg (simptm t)" |
313 "simptm (Add t s) = tmadd (simptm t,simptm s)" |
307 | "simptm (Add t s) = tmadd (simptm t,simptm s)" |
314 "simptm (Sub t s) = tmsub (simptm t) (simptm s)" |
308 | "simptm (Sub t s) = tmsub (simptm t) (simptm s)" |
315 "simptm (Mul i t) = (let i' = polynate i in if i' = 0\<^sub>p then CP 0\<^sub>p else tmmul (simptm t) i')" |
309 | "simptm (Mul i t) = (let i' = polynate i in if i' = 0\<^sub>p then CP 0\<^sub>p else tmmul (simptm t) i')" |
316 "simptm (CNP n c t) = (let c' = polynate c in if c' = 0\<^sub>p then simptm t else tmadd (CNP n c' (CP 0\<^sub>p ), simptm t))" |
310 | "simptm (CNP n c t) = (let c' = polynate c in if c' = 0\<^sub>p then simptm t else tmadd (CNP n c' (CP 0\<^sub>p ), simptm t))" |
317 |
311 |
318 lemma polynate_stupid: |
312 lemma polynate_stupid: |
319 assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})" |
313 assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})" |
320 shows "polynate t = 0\<^sub>p \<Longrightarrow> Ipoly bs t = (0::'a::{field_char_0, field_inverse_zero})" |
314 shows "polynate t = 0\<^sub>p \<Longrightarrow> Ipoly bs t = (0::'a::{field_char_0, field_inverse_zero})" |
321 apply (subst polynate[symmetric]) |
315 apply (subst polynate[symmetric]) |