# HG changeset patch # User krauss # Date 1298326476 -3600 # Node ID 9f436d00248f20937290edf217b762a1e2c593d6 # Parent 173e1b50d5c5b54317dd7872aad4b9f2951a38d3 recdef -> function diff -r 173e1b50d5c5 -r 9f436d00248f src/HOL/Decision_Procs/Reflected_Multivariate_Polynomial.thy --- a/src/HOL/Decision_Procs/Reflected_Multivariate_Polynomial.thy Mon Feb 21 18:29:47 2011 +0100 +++ b/src/HOL/Decision_Procs/Reflected_Multivariate_Polynomial.thy Mon Feb 21 23:14:36 2011 +0100 @@ -50,75 +50,72 @@ | "polysubst0 t (CN c n p) = (if n=0 then Add (polysubst0 t c) (Mul t (polysubst0 t p)) else CN (polysubst0 t c) n (polysubst0 t p))" -consts - decrpoly:: "poly \ poly" -recdef decrpoly "measure polysize" +fun decrpoly:: "poly \ poly" +where "decrpoly (Bound n) = Bound (n - 1)" - "decrpoly (Neg a) = Neg (decrpoly a)" - "decrpoly (Add a b) = Add (decrpoly a) (decrpoly b)" - "decrpoly (Sub a b) = Sub (decrpoly a) (decrpoly b)" - "decrpoly (Mul a b) = Mul (decrpoly a) (decrpoly b)" - "decrpoly (Pw p n) = Pw (decrpoly p) n" - "decrpoly (CN c n p) = CN (decrpoly c) (n - 1) (decrpoly p)" - "decrpoly a = a" +| "decrpoly (Neg a) = Neg (decrpoly a)" +| "decrpoly (Add a b) = Add (decrpoly a) (decrpoly b)" +| "decrpoly (Sub a b) = Sub (decrpoly a) (decrpoly b)" +| "decrpoly (Mul a b) = Mul (decrpoly a) (decrpoly b)" +| "decrpoly (Pw p n) = Pw (decrpoly p) n" +| "decrpoly (CN c n p) = CN (decrpoly c) (n - 1) (decrpoly p)" +| "decrpoly a = a" subsection{* Degrees and heads and coefficients *} -consts degree:: "poly \ nat" -recdef degree "measure size" +fun degree:: "poly \ nat" +where "degree (CN c 0 p) = 1 + degree p" - "degree p = 0" -consts head:: "poly \ poly" +| "degree p = 0" -recdef head "measure size" +fun head:: "poly \ poly" +where "head (CN c 0 p) = head p" - "head p = p" - (* More general notions of degree and head *) -consts degreen:: "poly \ nat \ nat" -recdef degreen "measure size" +| "head p = p" + +(* More general notions of degree and head *) +fun degreen:: "poly \ nat \ nat" +where "degreen (CN c n p) = (\m. if n=m then 1 + degreen p n else 0)" - "degreen p = (\m. 0)" - -consts headn:: "poly \ nat \ poly" -recdef headn "measure size" - "headn (CN c n p) = (\m. if n \ m then headn p m else CN c n p)" - "headn p = (\m. p)" + |"degreen p = (\m. 0)" -consts coefficients:: "poly \ poly list" -recdef coefficients "measure size" - "coefficients (CN c 0 p) = c#(coefficients p)" - "coefficients p = [p]" +fun headn:: "poly \ nat \ poly" +where + "headn (CN c n p) = (\m. if n \ m then headn p m else CN c n p)" +| "headn p = (\m. p)" -consts isconstant:: "poly \ bool" -recdef isconstant "measure size" - "isconstant (CN c 0 p) = False" - "isconstant p = True" +fun coefficients:: "poly \ poly list" +where + "coefficients (CN c 0 p) = c#(coefficients p)" +| "coefficients p = [p]" -consts behead:: "poly \ poly" -recdef behead "measure size" - "behead (CN c 0 p) = (let p' = behead p in if p' = 0\<^sub>p then c else CN c 0 p')" - "behead p = 0\<^sub>p" +fun isconstant:: "poly \ bool" +where + "isconstant (CN c 0 p) = False" +| "isconstant p = True" -consts headconst:: "poly \ Num" -recdef headconst "measure size" +fun behead:: "poly \ poly" +where + "behead (CN c 0 p) = (let p' = behead p in if p' = 0\<^sub>p then c else CN c 0 p')" +| "behead p = 0\<^sub>p" + +fun headconst:: "poly \ Num" +where "headconst (CN c n p) = headconst p" - "headconst (C n) = n" +| "headconst (C n) = n" subsection{* Operations for normalization *} consts polyadd :: "poly\poly \ poly" - polyneg :: "poly \ poly" ("~\<^sub>p") polysub :: "poly\poly \ poly" polymul :: "poly\poly \ poly" - polypow :: "nat \ poly \ poly" + abbreviation poly_add :: "poly \ poly \ poly" (infixl "+\<^sub>p" 60) where "a +\<^sub>p b \ polyadd (a,b)" abbreviation poly_mul :: "poly \ poly \ poly" (infixl "*\<^sub>p" 60) where "a *\<^sub>p b \ polymul (a,b)" abbreviation poly_sub :: "poly \ poly \ poly" (infixl "-\<^sub>p" 60) where "a -\<^sub>p b \ polysub (a,b)" -abbreviation poly_pow :: "poly \ nat \ poly" (infixl "^\<^sub>p" 60) - where "a ^\<^sub>p k \ polypow k a" recdef polyadd "measure (\ (a,b). polysize a + polysize b)" "polyadd (C c, C c') = C (c+\<^sub>Nc')" @@ -133,10 +130,11 @@ "polyadd (a, b) = Add a b" (hints recdef_simp add: Let_def measure_def split_def inv_image_def recdef_cong del: if_cong) -recdef polyneg "measure size" +fun polyneg :: "poly \ poly" ("~\<^sub>p") +where "polyneg (C c) = C (~\<^sub>N c)" - "polyneg (CN c n p) = CN (polyneg c) n (polyneg p)" - "polyneg a = Neg a" +| "polyneg (CN c n p) = CN (polyneg c) n (polyneg p)" +| "polyneg a = Neg a" defs polysub_def[code]: "polysub \ \ (p,q). polyadd (p,polyneg q)" @@ -152,21 +150,28 @@ then CN (polymul(CN c n p,c')) n' (polymul(CN c n p,p')) else polyadd(polymul(CN c n p, c'),CN 0\<^sub>p n' (polymul(CN c n p, p'))))" "polymul (a,b) = Mul a b" -recdef polypow "measure id" + +fun polypow :: "nat \ poly \ poly" +where "polypow 0 = (\p. 1\<^sub>p)" - "polypow n = (\p. let q = polypow (n div 2) p ; d = polymul(q,q) in +| "polypow n = (\p. let q = polypow (n div 2) p ; d = polymul(q,q) in if even n then d else polymul(p,d))" -consts polynate :: "poly \ poly" -recdef polynate "measure polysize" +abbreviation poly_pow :: "poly \ nat \ poly" (infixl "^\<^sub>p" 60) + where "a ^\<^sub>p k \ polypow k a" + +function polynate :: "poly \ poly" +where "polynate (Bound n) = CN 0\<^sub>p n 1\<^sub>p" - "polynate (Add p q) = (polynate p +\<^sub>p polynate q)" - "polynate (Sub p q) = (polynate p -\<^sub>p polynate q)" - "polynate (Mul p q) = (polynate p *\<^sub>p polynate q)" - "polynate (Neg p) = (~\<^sub>p (polynate p))" - "polynate (Pw p n) = ((polynate p) ^\<^sub>p n)" - "polynate (CN c n p) = polynate (Add c (Mul (Bound n) p))" - "polynate (C c) = C (normNum c)" +| "polynate (Add p q) = (polynate p +\<^sub>p polynate q)" +| "polynate (Sub p q) = (polynate p -\<^sub>p polynate q)" +| "polynate (Mul p q) = (polynate p *\<^sub>p polynate q)" +| "polynate (Neg p) = (~\<^sub>p (polynate p))" +| "polynate (Pw p n) = ((polynate p) ^\<^sub>p n)" +| "polynate (CN c n p) = polynate (Add c (Mul (Bound n) p))" +| "polynate (C c) = C (normNum c)" +by pat_completeness auto +termination by (relation "measure polysize") auto fun poly_cmul :: "Num \ poly \ poly" where "poly_cmul y (C x) = C (y *\<^sub>N x)" @@ -235,11 +240,11 @@ subsection {* Normal form and normalization *} -consts isnpolyh:: "poly \ nat \ bool" -recdef isnpolyh "measure size" +fun isnpolyh:: "poly \ nat \ bool" +where "isnpolyh (C c) = (\k. isnormNum c)" - "isnpolyh (CN c n p) = (\k. n\ k \ (isnpolyh c (Suc n)) \ (isnpolyh p n) \ (p \ 0\<^sub>p))" - "isnpolyh p = (\k. False)" +| "isnpolyh (CN c n p) = (\k. n \ k \ (isnpolyh c (Suc n)) \ (isnpolyh p n) \ (p \ 0\<^sub>p))" +| "isnpolyh p = (\k. False)" lemma isnpolyh_mono: "\n' \ n ; isnpolyh p n\ \ isnpolyh p n'" by (induct p rule: isnpolyh.induct, auto) @@ -1618,11 +1623,11 @@ lemma swap_nz [simp]: " (swap n m p = 0\<^sub>p) = (p = 0\<^sub>p)" by (induct p, simp_all) -consts isweaknpoly :: "poly \ bool" -recdef isweaknpoly "measure size" +fun isweaknpoly :: "poly \ bool" +where "isweaknpoly (C c) = True" - "isweaknpoly (CN c n p) \ isweaknpoly c \ isweaknpoly p" - "isweaknpoly p = False" +| "isweaknpoly (CN c n p) \ isweaknpoly c \ isweaknpoly p" +| "isweaknpoly p = False" lemma isnpolyh_isweaknpoly: "isnpolyh p n0 \ isweaknpoly p" by (induct p arbitrary: n0, auto)