made repository layout more coherent with logical distribution structure; stripped some $Id$s
authorhaftmann
Wed Dec 03 15:58:44 2008 +0100 (2008-12-03)
changeset 2895215a4b2cf8c34
parent 28948 1860f016886d
child 28953 48cd567f6940
made repository layout more coherent with logical distribution structure; stripped some $Id$s
NEWS
doc-src/TutorialI/Types/Numbers.thy
src/HOL/Arith_Tools.thy
src/HOL/Code_Eval.thy
src/HOL/Code_Message.thy
src/HOL/Complex.thy
src/HOL/Complex/Complex.thy
src/HOL/Complex/Complex_Main.thy
src/HOL/Complex/Fundamental_Theorem_Algebra.thy
src/HOL/Complex/ex/Arithmetic_Series_Complex.thy
src/HOL/Complex/ex/BigO_Complex.thy
src/HOL/Complex/ex/BinEx.thy
src/HOL/Complex/ex/HarmonicSeries.thy
src/HOL/Complex/ex/MIR.thy
src/HOL/Complex/ex/ReflectedFerrack.thy
src/HOL/Complex/ex/Sqrt.thy
src/HOL/Complex/ex/Sqrt_Script.thy
src/HOL/Complex/ex/document/root.tex
src/HOL/Complex/ex/linrtac.ML
src/HOL/Complex/ex/mirtac.ML
src/HOL/Complex_Main.thy
src/HOL/ContNotDenum.thy
src/HOL/Deriv.thy
src/HOL/Fact.thy
src/HOL/FrechetDeriv.thy
src/HOL/GCD.thy
src/HOL/HOL.thy
src/HOL/Hyperreal/Deriv.thy
src/HOL/Hyperreal/Fact.thy
src/HOL/Hyperreal/FrechetDeriv.thy
src/HOL/Hyperreal/Integration.thy
src/HOL/Hyperreal/Lim.thy
src/HOL/Hyperreal/Ln.thy
src/HOL/Hyperreal/Log.thy
src/HOL/Hyperreal/MacLaurin.thy
src/HOL/Hyperreal/NthRoot.thy
src/HOL/Hyperreal/SEQ.thy
src/HOL/Hyperreal/Series.thy
src/HOL/Hyperreal/Taylor.thy
src/HOL/Hyperreal/Transcendental.thy
src/HOL/Int.thy
src/HOL/Integration.thy
src/HOL/IsaMakefile
src/HOL/Library/Code_Message.thy
src/HOL/Library/Commutative_Ring.thy
src/HOL/Library/Float.thy
src/HOL/Library/GCD.thy
src/HOL/Library/Heap.thy
src/HOL/Library/Library.thy
src/HOL/Library/Order_Relation.thy
src/HOL/Library/Parity.thy
src/HOL/Library/Primes.thy
src/HOL/Library/RType.thy
src/HOL/Library/Univ_Poly.thy
src/HOL/Library/Zorn.thy
src/HOL/Lim.thy
src/HOL/Ln.thy
src/HOL/Log.thy
src/HOL/Lubs.thy
src/HOL/MacLaurin.thy
src/HOL/NSA/HyperDef.thy
src/HOL/NSA/Hyperreal.thy
src/HOL/NSA/NSA.thy
src/HOL/NSA/NSCA.thy
src/HOL/Nat.thy
src/HOL/NthRoot.thy
src/HOL/NumberTheory/EvenOdd.thy
src/HOL/Order_Relation.thy
src/HOL/PReal.thy
src/HOL/Parity.thy
src/HOL/RComplete.thy
src/HOL/ROOT.ML
src/HOL/Rational.thy
src/HOL/Real.thy
src/HOL/Real/ContNotDenum.thy
src/HOL/Real/Float.thy
src/HOL/Real/Lubs.thy
src/HOL/Real/PReal.thy
src/HOL/Real/RComplete.thy
src/HOL/Real/Rational.thy
src/HOL/Real/Real.thy
src/HOL/Real/RealDef.thy
src/HOL/Real/RealPow.thy
src/HOL/Real/RealVector.thy
src/HOL/Real/float_arith.ML
src/HOL/Real/float_syntax.ML
src/HOL/Real/rat_arith.ML
src/HOL/Real/real_arith.ML
src/HOL/RealDef.thy
src/HOL/RealPow.thy
src/HOL/Series.thy
src/HOL/Taylor.thy
src/HOL/Tools/arith_data.ML
src/HOL/Tools/float_arith.ML
src/HOL/Tools/float_syntax.ML
src/HOL/Tools/hologic.ML
src/HOL/Tools/int_arith.ML
src/HOL/Tools/int_factor_simprocs.ML
src/HOL/Tools/nat_simprocs.ML
src/HOL/Tools/rat_arith.ML
src/HOL/Tools/real_arith.ML
src/HOL/Tools/simpdata.ML
src/HOL/Transcendental.thy
src/HOL/Typerep.thy
src/HOL/Univ_Poly.thy
src/HOL/Word/Num_Lemmas.thy
src/HOL/Word/ROOT.ML
src/HOL/arith_data.ML
src/HOL/ex/Arithmetic_Series_Complex.thy
src/HOL/ex/BigO_Complex.thy
src/HOL/ex/BinEx.thy
src/HOL/ex/Eval_Examples.thy
src/HOL/ex/ExecutableContent.thy
src/HOL/ex/HarmonicSeries.thy
src/HOL/ex/MIR.thy
src/HOL/ex/NatSum.thy
src/HOL/ex/NormalForm.thy
src/HOL/ex/ROOT.ML
src/HOL/ex/ReflectedFerrack.thy
src/HOL/ex/Sqrt.thy
src/HOL/ex/Sqrt_Script.thy
src/HOL/ex/linrtac.ML
src/HOL/ex/mirtac.ML
src/HOL/hologic.ML
src/HOL/int_arith1.ML
src/HOL/int_factor_simprocs.ML
src/HOL/nat_simprocs.ML
src/HOL/simpdata.ML
src/HOLCF/FOCUS/Buffer.thy
src/HOLCF/NatIso.thy
src/Pure/IsaMakefile
src/Pure/ROOT.ML
src/Pure/Tools/ROOT.ML
src/Pure/Tools/quickcheck.ML
src/Pure/Tools/value.ML
src/Sequents/LK.thy
src/Tools/quickcheck.ML
src/Tools/value.ML
src/ZF/ex/Ring.thy
src/ZF/pair.thy
     1.1 --- a/NEWS	Wed Dec 03 09:53:58 2008 +0100
     1.2 +++ b/NEWS	Wed Dec 03 15:58:44 2008 +0100
     1.3 @@ -58,6 +58,10 @@
     1.4  
     1.5  *** Pure ***
     1.6  
     1.7 +* Module moves in repository:
     1.8 +    src/Pure/Tools/value.ML ~> src/Tools/
     1.9 +    src/Pure/Tools/quickcheck.ML ~> src/Tools/
    1.10 +
    1.11  * Slightly more coherent Pure syntax, with updated documentation in
    1.12  isar-ref manual.  Removed locales meta_term_syntax and
    1.13  meta_conjunction_syntax: TERM and &&& (formerly &&) are now permanent,
    1.14 @@ -133,6 +137,50 @@
    1.15  
    1.16  *** HOL ***
    1.17  
    1.18 +* Made repository layout more coherent with logical
    1.19 +distribution structure:
    1.20 +
    1.21 +    src/HOL/Library/RType.thy ~> src/HOL/Typerep.thy
    1.22 +    src/HOL/Library/Code_Message.thy ~> src/HOL/
    1.23 +    src/HOL/Library/GCD.thy ~> src/HOL/
    1.24 +    src/HOL/Library/Order_Relation.thy ~> src/HOL/
    1.25 +    src/HOL/Library/Parity.thy ~> src/HOL/
    1.26 +    src/HOL/Library/Univ_Poly.thy ~> src/HOL/
    1.27 +    src/HOL/Real/ContNotDenum.thy ~> src/HOL/
    1.28 +    src/HOL/Real/Lubs.thy ~> src/HOL/
    1.29 +    src/HOL/Real/PReal.thy ~> src/HOL/
    1.30 +    src/HOL/Real/Rational.thy ~> src/HOL/
    1.31 +    src/HOL/Real/RComplete.thy ~> src/HOL/
    1.32 +    src/HOL/Real/RealDef.thy ~> src/HOL/
    1.33 +    src/HOL/Real/RealPow.thy ~> src/HOL/
    1.34 +    src/HOL/Real/Real.thy ~> src/HOL/
    1.35 +    src/HOL/Complex/Complex_Main.thy ~> src/HOL/
    1.36 +    src/HOL/Complex/Complex.thy ~> src/HOL/
    1.37 +    src/HOL/Complex/FrechetDeriv.thy ~> src/HOL/
    1.38 +    src/HOL/Hyperreal/Deriv.thy ~> src/HOL/
    1.39 +    src/HOL/Hyperreal/Fact.thy ~> src/HOL/
    1.40 +    src/HOL/Hyperreal/Integration.thy ~> src/HOL/
    1.41 +    src/HOL/Hyperreal/Lim.thy ~> src/HOL/
    1.42 +    src/HOL/Hyperreal/Ln.thy ~> src/HOL/
    1.43 +    src/HOL/Hyperreal/Log.thy ~> src/HOL/
    1.44 +    src/HOL/Hyperreal/MacLaurin.thy ~> src/HOL/
    1.45 +    src/HOL/Hyperreal/NthRoot.thy ~> src/HOL/
    1.46 +    src/HOL/Hyperreal/Series.thy ~> src/HOL/
    1.47 +    src/HOL/Hyperreal/Taylor.thy ~> src/HOL/
    1.48 +    src/HOL/Hyperreal/Transcendental.thy ~> src/HOL/
    1.49 +    src/HOL/Real/Float ~> src/HOL/Library/
    1.50 +
    1.51 +    src/HOL/arith_data.ML ~> src/HOL/Tools
    1.52 +    src/HOL/hologic.ML ~> src/HOL/Tools
    1.53 +    src/HOL/simpdata.ML ~> src/HOL/Tools
    1.54 +    src/HOL/int_arith1.ML ~> src/HOL/Tools/int_arith.ML
    1.55 +    src/HOL/int_factor_simprocs.ML ~> src/HOL/Tools
    1.56 +    src/HOL/nat_simprocs.ML ~> src/HOL/Tools
    1.57 +    src/HOL/Real/float_arith.ML ~> src/HOL/Tools
    1.58 +    src/HOL/Real/float_syntax.ML ~> src/HOL/Tools
    1.59 +    src/HOL/Real/rat_arith.ML ~> src/HOL/Tools
    1.60 +    src/HOL/Real/real_arith.ML ~> src/HOL/Tools
    1.61 +
    1.62  * If methods "eval" and "evaluation" encounter a structured proof state
    1.63  with !!/==>, only the conclusion is evaluated to True (if possible),
    1.64  avoiding strange error messages.
     2.1 --- a/doc-src/TutorialI/Types/Numbers.thy	Wed Dec 03 09:53:58 2008 +0100
     2.2 +++ b/doc-src/TutorialI/Types/Numbers.thy	Wed Dec 03 15:58:44 2008 +0100
     2.3 @@ -1,4 +1,3 @@
     2.4 -(* ID:         $Id$ *)
     2.5  theory Numbers
     2.6  imports Complex_Main
     2.7  begin
     3.1 --- a/src/HOL/Arith_Tools.thy	Wed Dec 03 09:53:58 2008 +0100
     3.2 +++ b/src/HOL/Arith_Tools.thy	Wed Dec 03 15:58:44 2008 +0100
     3.3 @@ -11,8 +11,8 @@
     3.4  uses
     3.5    "~~/src/Provers/Arith/cancel_numeral_factor.ML"
     3.6    "~~/src/Provers/Arith/extract_common_term.ML"
     3.7 -  "int_factor_simprocs.ML"
     3.8 -  "nat_simprocs.ML"
     3.9 +  "Tools/int_factor_simprocs.ML"
    3.10 +  "Tools/nat_simprocs.ML"
    3.11    "Tools/Qelim/qelim.ML"
    3.12  begin
    3.13  
     4.1 --- a/src/HOL/Code_Eval.thy	Wed Dec 03 09:53:58 2008 +0100
     4.2 +++ b/src/HOL/Code_Eval.thy	Wed Dec 03 15:58:44 2008 +0100
     4.3 @@ -6,7 +6,7 @@
     4.4  header {* Term evaluation using the generic code generator *}
     4.5  
     4.6  theory Code_Eval
     4.7 -imports Plain "~~/src/HOL/Library/RType"
     4.8 +imports Plain Typerep
     4.9  begin
    4.10  
    4.11  subsection {* Term representation *}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/HOL/Code_Message.thy	Wed Dec 03 15:58:44 2008 +0100
     5.3 @@ -0,0 +1,58 @@
     5.4 +(*  ID:         $Id$
     5.5 +    Author:     Florian Haftmann, TU Muenchen
     5.6 +*)
     5.7 +
     5.8 +header {* Monolithic strings (message strings) for code generation *}
     5.9 +
    5.10 +theory Code_Message
    5.11 +imports Plain "~~/src/HOL/List"
    5.12 +begin
    5.13 +
    5.14 +subsection {* Datatype of messages *}
    5.15 +
    5.16 +datatype message_string = STR string
    5.17 +
    5.18 +lemmas [code del] = message_string.recs message_string.cases
    5.19 +
    5.20 +lemma [code]: "size (s\<Colon>message_string) = 0"
    5.21 +  by (cases s) simp_all
    5.22 +
    5.23 +lemma [code]: "message_string_size (s\<Colon>message_string) = 0"
    5.24 +  by (cases s) simp_all
    5.25 +
    5.26 +subsection {* ML interface *}
    5.27 +
    5.28 +ML {*
    5.29 +structure Message_String =
    5.30 +struct
    5.31 +
    5.32 +fun mk s = @{term STR} $ HOLogic.mk_string s;
    5.33 +
    5.34 +end;
    5.35 +*}
    5.36 +
    5.37 +
    5.38 +subsection {* Code serialization *}
    5.39 +
    5.40 +code_type message_string
    5.41 +  (SML "string")
    5.42 +  (OCaml "string")
    5.43 +  (Haskell "String")
    5.44 +
    5.45 +setup {*
    5.46 +  fold (fn target => add_literal_message @{const_name STR} target)
    5.47 +    ["SML", "OCaml", "Haskell"]
    5.48 +*}
    5.49 +
    5.50 +code_reserved SML string
    5.51 +code_reserved OCaml string
    5.52 +
    5.53 +code_instance message_string :: eq
    5.54 +  (Haskell -)
    5.55 +
    5.56 +code_const "eq_class.eq \<Colon> message_string \<Rightarrow> message_string \<Rightarrow> bool"
    5.57 +  (SML "!((_ : string) = _)")
    5.58 +  (OCaml "!((_ : string) = _)")
    5.59 +  (Haskell infixl 4 "==")
    5.60 +
    5.61 +end
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/HOL/Complex.thy	Wed Dec 03 15:58:44 2008 +0100
     6.3 @@ -0,0 +1,718 @@
     6.4 +(*  Title:       Complex.thy
     6.5 +    Author:      Jacques D. Fleuriot
     6.6 +    Copyright:   2001 University of Edinburgh
     6.7 +    Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4
     6.8 +*)
     6.9 +
    6.10 +header {* Complex Numbers: Rectangular and Polar Representations *}
    6.11 +
    6.12 +theory Complex
    6.13 +imports Transcendental
    6.14 +begin
    6.15 +
    6.16 +datatype complex = Complex real real
    6.17 +
    6.18 +primrec
    6.19 +  Re :: "complex \<Rightarrow> real"
    6.20 +where
    6.21 +  Re: "Re (Complex x y) = x"
    6.22 +
    6.23 +primrec
    6.24 +  Im :: "complex \<Rightarrow> real"
    6.25 +where
    6.26 +  Im: "Im (Complex x y) = y"
    6.27 +
    6.28 +lemma complex_surj [simp]: "Complex (Re z) (Im z) = z"
    6.29 +  by (induct z) simp
    6.30 +
    6.31 +lemma complex_equality [intro?]: "\<lbrakk>Re x = Re y; Im x = Im y\<rbrakk> \<Longrightarrow> x = y"
    6.32 +  by (induct x, induct y) simp
    6.33 +
    6.34 +lemma expand_complex_eq: "x = y \<longleftrightarrow> Re x = Re y \<and> Im x = Im y"
    6.35 +  by (induct x, induct y) simp
    6.36 +
    6.37 +lemmas complex_Re_Im_cancel_iff = expand_complex_eq
    6.38 +
    6.39 +
    6.40 +subsection {* Addition and Subtraction *}
    6.41 +
    6.42 +instantiation complex :: ab_group_add
    6.43 +begin
    6.44 +
    6.45 +definition
    6.46 +  complex_zero_def: "0 = Complex 0 0"
    6.47 +
    6.48 +definition
    6.49 +  complex_add_def: "x + y = Complex (Re x + Re y) (Im x + Im y)"
    6.50 +
    6.51 +definition
    6.52 +  complex_minus_def: "- x = Complex (- Re x) (- Im x)"
    6.53 +
    6.54 +definition
    6.55 +  complex_diff_def: "x - (y\<Colon>complex) = x + - y"
    6.56 +
    6.57 +lemma Complex_eq_0 [simp]: "Complex a b = 0 \<longleftrightarrow> a = 0 \<and> b = 0"
    6.58 +  by (simp add: complex_zero_def)
    6.59 +
    6.60 +lemma complex_Re_zero [simp]: "Re 0 = 0"
    6.61 +  by (simp add: complex_zero_def)
    6.62 +
    6.63 +lemma complex_Im_zero [simp]: "Im 0 = 0"
    6.64 +  by (simp add: complex_zero_def)
    6.65 +
    6.66 +lemma complex_add [simp]:
    6.67 +  "Complex a b + Complex c d = Complex (a + c) (b + d)"
    6.68 +  by (simp add: complex_add_def)
    6.69 +
    6.70 +lemma complex_Re_add [simp]: "Re (x + y) = Re x + Re y"
    6.71 +  by (simp add: complex_add_def)
    6.72 +
    6.73 +lemma complex_Im_add [simp]: "Im (x + y) = Im x + Im y"
    6.74 +  by (simp add: complex_add_def)
    6.75 +
    6.76 +lemma complex_minus [simp]:
    6.77 +  "- (Complex a b) = Complex (- a) (- b)"
    6.78 +  by (simp add: complex_minus_def)
    6.79 +
    6.80 +lemma complex_Re_minus [simp]: "Re (- x) = - Re x"
    6.81 +  by (simp add: complex_minus_def)
    6.82 +
    6.83 +lemma complex_Im_minus [simp]: "Im (- x) = - Im x"
    6.84 +  by (simp add: complex_minus_def)
    6.85 +
    6.86 +lemma complex_diff [simp]:
    6.87 +  "Complex a b - Complex c d = Complex (a - c) (b - d)"
    6.88 +  by (simp add: complex_diff_def)
    6.89 +
    6.90 +lemma complex_Re_diff [simp]: "Re (x - y) = Re x - Re y"
    6.91 +  by (simp add: complex_diff_def)
    6.92 +
    6.93 +lemma complex_Im_diff [simp]: "Im (x - y) = Im x - Im y"
    6.94 +  by (simp add: complex_diff_def)
    6.95 +
    6.96 +instance
    6.97 +  by intro_classes (simp_all add: complex_add_def complex_diff_def)
    6.98 +
    6.99 +end
   6.100 +
   6.101 +
   6.102 +
   6.103 +subsection {* Multiplication and Division *}
   6.104 +
   6.105 +instantiation complex :: "{field, division_by_zero}"
   6.106 +begin
   6.107 +
   6.108 +definition
   6.109 +  complex_one_def: "1 = Complex 1 0"
   6.110 +
   6.111 +definition
   6.112 +  complex_mult_def: "x * y =
   6.113 +    Complex (Re x * Re y - Im x * Im y) (Re x * Im y + Im x * Re y)"
   6.114 +
   6.115 +definition
   6.116 +  complex_inverse_def: "inverse x =
   6.117 +    Complex (Re x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)) (- Im x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>))"
   6.118 +
   6.119 +definition
   6.120 +  complex_divide_def: "x / (y\<Colon>complex) = x * inverse y"
   6.121 +
   6.122 +lemma Complex_eq_1 [simp]: "(Complex a b = 1) = (a = 1 \<and> b = 0)"
   6.123 +  by (simp add: complex_one_def)
   6.124 +
   6.125 +lemma complex_Re_one [simp]: "Re 1 = 1"
   6.126 +  by (simp add: complex_one_def)
   6.127 +
   6.128 +lemma complex_Im_one [simp]: "Im 1 = 0"
   6.129 +  by (simp add: complex_one_def)
   6.130 +
   6.131 +lemma complex_mult [simp]:
   6.132 +  "Complex a b * Complex c d = Complex (a * c - b * d) (a * d + b * c)"
   6.133 +  by (simp add: complex_mult_def)
   6.134 +
   6.135 +lemma complex_Re_mult [simp]: "Re (x * y) = Re x * Re y - Im x * Im y"
   6.136 +  by (simp add: complex_mult_def)
   6.137 +
   6.138 +lemma complex_Im_mult [simp]: "Im (x * y) = Re x * Im y + Im x * Re y"
   6.139 +  by (simp add: complex_mult_def)
   6.140 +
   6.141 +lemma complex_inverse [simp]:
   6.142 +  "inverse (Complex a b) = Complex (a / (a\<twosuperior> + b\<twosuperior>)) (- b / (a\<twosuperior> + b\<twosuperior>))"
   6.143 +  by (simp add: complex_inverse_def)
   6.144 +
   6.145 +lemma complex_Re_inverse:
   6.146 +  "Re (inverse x) = Re x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)"
   6.147 +  by (simp add: complex_inverse_def)
   6.148 +
   6.149 +lemma complex_Im_inverse:
   6.150 +  "Im (inverse x) = - Im x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)"
   6.151 +  by (simp add: complex_inverse_def)
   6.152 +
   6.153 +instance
   6.154 +  by intro_classes (simp_all add: complex_mult_def
   6.155 +  right_distrib left_distrib right_diff_distrib left_diff_distrib
   6.156 +  complex_inverse_def complex_divide_def
   6.157 +  power2_eq_square add_divide_distrib [symmetric]
   6.158 +  expand_complex_eq)
   6.159 +
   6.160 +end
   6.161 +
   6.162 +
   6.163 +subsection {* Exponentiation *}
   6.164 +
   6.165 +instantiation complex :: recpower
   6.166 +begin
   6.167 +
   6.168 +primrec power_complex where
   6.169 +  complexpow_0:     "z ^ 0     = (1\<Colon>complex)"
   6.170 +  | complexpow_Suc: "z ^ Suc n = (z\<Colon>complex) * z ^ n"
   6.171 +
   6.172 +instance by intro_classes simp_all
   6.173 +
   6.174 +end
   6.175 +
   6.176 +
   6.177 +subsection {* Numerals and Arithmetic *}
   6.178 +
   6.179 +instantiation complex :: number_ring
   6.180 +begin
   6.181 +
   6.182 +definition number_of_complex where
   6.183 +  complex_number_of_def: "number_of w = (of_int w \<Colon> complex)"
   6.184 +
   6.185 +instance
   6.186 +  by intro_classes (simp only: complex_number_of_def)
   6.187 +
   6.188 +end
   6.189 +
   6.190 +lemma complex_Re_of_nat [simp]: "Re (of_nat n) = of_nat n"
   6.191 +by (induct n) simp_all
   6.192 +
   6.193 +lemma complex_Im_of_nat [simp]: "Im (of_nat n) = 0"
   6.194 +by (induct n) simp_all
   6.195 +
   6.196 +lemma complex_Re_of_int [simp]: "Re (of_int z) = of_int z"
   6.197 +by (cases z rule: int_diff_cases) simp
   6.198 +
   6.199 +lemma complex_Im_of_int [simp]: "Im (of_int z) = 0"
   6.200 +by (cases z rule: int_diff_cases) simp
   6.201 +
   6.202 +lemma complex_Re_number_of [simp]: "Re (number_of v) = number_of v"
   6.203 +unfolding number_of_eq by (rule complex_Re_of_int)
   6.204 +
   6.205 +lemma complex_Im_number_of [simp]: "Im (number_of v) = 0"
   6.206 +unfolding number_of_eq by (rule complex_Im_of_int)
   6.207 +
   6.208 +lemma Complex_eq_number_of [simp]:
   6.209 +  "(Complex a b = number_of w) = (a = number_of w \<and> b = 0)"
   6.210 +by (simp add: expand_complex_eq)
   6.211 +
   6.212 +
   6.213 +subsection {* Scalar Multiplication *}
   6.214 +
   6.215 +instantiation complex :: real_field
   6.216 +begin
   6.217 +
   6.218 +definition
   6.219 +  complex_scaleR_def: "scaleR r x = Complex (r * Re x) (r * Im x)"
   6.220 +
   6.221 +lemma complex_scaleR [simp]:
   6.222 +  "scaleR r (Complex a b) = Complex (r * a) (r * b)"
   6.223 +  unfolding complex_scaleR_def by simp
   6.224 +
   6.225 +lemma complex_Re_scaleR [simp]: "Re (scaleR r x) = r * Re x"
   6.226 +  unfolding complex_scaleR_def by simp
   6.227 +
   6.228 +lemma complex_Im_scaleR [simp]: "Im (scaleR r x) = r * Im x"
   6.229 +  unfolding complex_scaleR_def by simp
   6.230 +
   6.231 +instance
   6.232 +proof
   6.233 +  fix a b :: real and x y :: complex
   6.234 +  show "scaleR a (x + y) = scaleR a x + scaleR a y"
   6.235 +    by (simp add: expand_complex_eq right_distrib)
   6.236 +  show "scaleR (a + b) x = scaleR a x + scaleR b x"
   6.237 +    by (simp add: expand_complex_eq left_distrib)
   6.238 +  show "scaleR a (scaleR b x) = scaleR (a * b) x"
   6.239 +    by (simp add: expand_complex_eq mult_assoc)
   6.240 +  show "scaleR 1 x = x"
   6.241 +    by (simp add: expand_complex_eq)
   6.242 +  show "scaleR a x * y = scaleR a (x * y)"
   6.243 +    by (simp add: expand_complex_eq ring_simps)
   6.244 +  show "x * scaleR a y = scaleR a (x * y)"
   6.245 +    by (simp add: expand_complex_eq ring_simps)
   6.246 +qed
   6.247 +
   6.248 +end
   6.249 +
   6.250 +
   6.251 +subsection{* Properties of Embedding from Reals *}
   6.252 +
   6.253 +abbreviation
   6.254 +  complex_of_real :: "real \<Rightarrow> complex" where
   6.255 +    "complex_of_real \<equiv> of_real"
   6.256 +
   6.257 +lemma complex_of_real_def: "complex_of_real r = Complex r 0"
   6.258 +by (simp add: of_real_def complex_scaleR_def)
   6.259 +
   6.260 +lemma Re_complex_of_real [simp]: "Re (complex_of_real z) = z"
   6.261 +by (simp add: complex_of_real_def)
   6.262 +
   6.263 +lemma Im_complex_of_real [simp]: "Im (complex_of_real z) = 0"
   6.264 +by (simp add: complex_of_real_def)
   6.265 +
   6.266 +lemma Complex_add_complex_of_real [simp]:
   6.267 +     "Complex x y + complex_of_real r = Complex (x+r) y"
   6.268 +by (simp add: complex_of_real_def)
   6.269 +
   6.270 +lemma complex_of_real_add_Complex [simp]:
   6.271 +     "complex_of_real r + Complex x y = Complex (r+x) y"
   6.272 +by (simp add: complex_of_real_def)
   6.273 +
   6.274 +lemma Complex_mult_complex_of_real:
   6.275 +     "Complex x y * complex_of_real r = Complex (x*r) (y*r)"
   6.276 +by (simp add: complex_of_real_def)
   6.277 +
   6.278 +lemma complex_of_real_mult_Complex:
   6.279 +     "complex_of_real r * Complex x y = Complex (r*x) (r*y)"
   6.280 +by (simp add: complex_of_real_def)
   6.281 +
   6.282 +
   6.283 +subsection {* Vector Norm *}
   6.284 +
   6.285 +instantiation complex :: real_normed_field
   6.286 +begin
   6.287 +
   6.288 +definition
   6.289 +  complex_norm_def: "norm z = sqrt ((Re z)\<twosuperior> + (Im z)\<twosuperior>)"
   6.290 +
   6.291 +abbreviation
   6.292 +  cmod :: "complex \<Rightarrow> real" where
   6.293 +  "cmod \<equiv> norm"
   6.294 +
   6.295 +definition
   6.296 +  complex_sgn_def: "sgn x = x /\<^sub>R cmod x"
   6.297 +
   6.298 +lemmas cmod_def = complex_norm_def
   6.299 +
   6.300 +lemma complex_norm [simp]: "cmod (Complex x y) = sqrt (x\<twosuperior> + y\<twosuperior>)"
   6.301 +  by (simp add: complex_norm_def)
   6.302 +
   6.303 +instance
   6.304 +proof
   6.305 +  fix r :: real and x y :: complex
   6.306 +  show "0 \<le> norm x"
   6.307 +    by (induct x) simp
   6.308 +  show "(norm x = 0) = (x = 0)"
   6.309 +    by (induct x) simp
   6.310 +  show "norm (x + y) \<le> norm x + norm y"
   6.311 +    by (induct x, induct y)
   6.312 +       (simp add: real_sqrt_sum_squares_triangle_ineq)
   6.313 +  show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
   6.314 +    by (induct x)
   6.315 +       (simp add: power_mult_distrib right_distrib [symmetric] real_sqrt_mult)
   6.316 +  show "norm (x * y) = norm x * norm y"
   6.317 +    by (induct x, induct y)
   6.318 +       (simp add: real_sqrt_mult [symmetric] power2_eq_square ring_simps)
   6.319 +  show "sgn x = x /\<^sub>R cmod x" by(simp add: complex_sgn_def)
   6.320 +qed
   6.321 +
   6.322 +end
   6.323 +
   6.324 +lemma cmod_unit_one [simp]: "cmod (Complex (cos a) (sin a)) = 1"
   6.325 +by simp
   6.326 +
   6.327 +lemma cmod_complex_polar [simp]:
   6.328 +     "cmod (complex_of_real r * Complex (cos a) (sin a)) = abs r"
   6.329 +by (simp add: norm_mult)
   6.330 +
   6.331 +lemma complex_Re_le_cmod: "Re x \<le> cmod x"
   6.332 +unfolding complex_norm_def
   6.333 +by (rule real_sqrt_sum_squares_ge1)
   6.334 +
   6.335 +lemma complex_mod_minus_le_complex_mod [simp]: "- cmod x \<le> cmod x"
   6.336 +by (rule order_trans [OF _ norm_ge_zero], simp)
   6.337 +
   6.338 +lemma complex_mod_triangle_ineq2 [simp]: "cmod(b + a) - cmod b \<le> cmod a"
   6.339 +by (rule ord_le_eq_trans [OF norm_triangle_ineq2], simp)
   6.340 +
   6.341 +lemmas real_sum_squared_expand = power2_sum [where 'a=real]
   6.342 +
   6.343 +lemma abs_Re_le_cmod: "\<bar>Re x\<bar> \<le> cmod x"
   6.344 +by (cases x) simp
   6.345 +
   6.346 +lemma abs_Im_le_cmod: "\<bar>Im x\<bar> \<le> cmod x"
   6.347 +by (cases x) simp
   6.348 +
   6.349 +subsection {* Completeness of the Complexes *}
   6.350 +
   6.351 +interpretation Re: bounded_linear ["Re"]
   6.352 +apply (unfold_locales, simp, simp)
   6.353 +apply (rule_tac x=1 in exI)
   6.354 +apply (simp add: complex_norm_def)
   6.355 +done
   6.356 +
   6.357 +interpretation Im: bounded_linear ["Im"]
   6.358 +apply (unfold_locales, simp, simp)
   6.359 +apply (rule_tac x=1 in exI)
   6.360 +apply (simp add: complex_norm_def)
   6.361 +done
   6.362 +
   6.363 +lemma LIMSEQ_Complex:
   6.364 +  "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. Complex (X n) (Y n)) ----> Complex a b"
   6.365 +apply (rule LIMSEQ_I)
   6.366 +apply (subgoal_tac "0 < r / sqrt 2")
   6.367 +apply (drule_tac r="r / sqrt 2" in LIMSEQ_D, safe)
   6.368 +apply (drule_tac r="r / sqrt 2" in LIMSEQ_D, safe)
   6.369 +apply (rename_tac M N, rule_tac x="max M N" in exI, safe)
   6.370 +apply (simp add: real_sqrt_sum_squares_less)
   6.371 +apply (simp add: divide_pos_pos)
   6.372 +done
   6.373 +
   6.374 +instance complex :: banach
   6.375 +proof
   6.376 +  fix X :: "nat \<Rightarrow> complex"
   6.377 +  assume X: "Cauchy X"
   6.378 +  from Re.Cauchy [OF X] have 1: "(\<lambda>n. Re (X n)) ----> lim (\<lambda>n. Re (X n))"
   6.379 +    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
   6.380 +  from Im.Cauchy [OF X] have 2: "(\<lambda>n. Im (X n)) ----> lim (\<lambda>n. Im (X n))"
   6.381 +    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
   6.382 +  have "X ----> Complex (lim (\<lambda>n. Re (X n))) (lim (\<lambda>n. Im (X n)))"
   6.383 +    using LIMSEQ_Complex [OF 1 2] by simp
   6.384 +  thus "convergent X"
   6.385 +    by (rule convergentI)
   6.386 +qed
   6.387 +
   6.388 +
   6.389 +subsection {* The Complex Number @{term "\<i>"} *}
   6.390 +
   6.391 +definition
   6.392 +  "ii" :: complex  ("\<i>") where
   6.393 +  i_def: "ii \<equiv> Complex 0 1"
   6.394 +
   6.395 +lemma complex_Re_i [simp]: "Re ii = 0"
   6.396 +by (simp add: i_def)
   6.397 +
   6.398 +lemma complex_Im_i [simp]: "Im ii = 1"
   6.399 +by (simp add: i_def)
   6.400 +
   6.401 +lemma Complex_eq_i [simp]: "(Complex x y = ii) = (x = 0 \<and> y = 1)"
   6.402 +by (simp add: i_def)
   6.403 +
   6.404 +lemma complex_i_not_zero [simp]: "ii \<noteq> 0"
   6.405 +by (simp add: expand_complex_eq)
   6.406 +
   6.407 +lemma complex_i_not_one [simp]: "ii \<noteq> 1"
   6.408 +by (simp add: expand_complex_eq)
   6.409 +
   6.410 +lemma complex_i_not_number_of [simp]: "ii \<noteq> number_of w"
   6.411 +by (simp add: expand_complex_eq)
   6.412 +
   6.413 +lemma i_mult_Complex [simp]: "ii * Complex a b = Complex (- b) a"
   6.414 +by (simp add: expand_complex_eq)
   6.415 +
   6.416 +lemma Complex_mult_i [simp]: "Complex a b * ii = Complex (- b) a"
   6.417 +by (simp add: expand_complex_eq)
   6.418 +
   6.419 +lemma i_complex_of_real [simp]: "ii * complex_of_real r = Complex 0 r"
   6.420 +by (simp add: i_def complex_of_real_def)
   6.421 +
   6.422 +lemma complex_of_real_i [simp]: "complex_of_real r * ii = Complex 0 r"
   6.423 +by (simp add: i_def complex_of_real_def)
   6.424 +
   6.425 +lemma i_squared [simp]: "ii * ii = -1"
   6.426 +by (simp add: i_def)
   6.427 +
   6.428 +lemma power2_i [simp]: "ii\<twosuperior> = -1"
   6.429 +by (simp add: power2_eq_square)
   6.430 +
   6.431 +lemma inverse_i [simp]: "inverse ii = - ii"
   6.432 +by (rule inverse_unique, simp)
   6.433 +
   6.434 +
   6.435 +subsection {* Complex Conjugation *}
   6.436 +
   6.437 +definition
   6.438 +  cnj :: "complex \<Rightarrow> complex" where
   6.439 +  "cnj z = Complex (Re z) (- Im z)"
   6.440 +
   6.441 +lemma complex_cnj [simp]: "cnj (Complex a b) = Complex a (- b)"
   6.442 +by (simp add: cnj_def)
   6.443 +
   6.444 +lemma complex_Re_cnj [simp]: "Re (cnj x) = Re x"
   6.445 +by (simp add: cnj_def)
   6.446 +
   6.447 +lemma complex_Im_cnj [simp]: "Im (cnj x) = - Im x"
   6.448 +by (simp add: cnj_def)
   6.449 +
   6.450 +lemma complex_cnj_cancel_iff [simp]: "(cnj x = cnj y) = (x = y)"
   6.451 +by (simp add: expand_complex_eq)
   6.452 +
   6.453 +lemma complex_cnj_cnj [simp]: "cnj (cnj z) = z"
   6.454 +by (simp add: cnj_def)
   6.455 +
   6.456 +lemma complex_cnj_zero [simp]: "cnj 0 = 0"
   6.457 +by (simp add: expand_complex_eq)
   6.458 +
   6.459 +lemma complex_cnj_zero_iff [iff]: "(cnj z = 0) = (z = 0)"
   6.460 +by (simp add: expand_complex_eq)
   6.461 +
   6.462 +lemma complex_cnj_add: "cnj (x + y) = cnj x + cnj y"
   6.463 +by (simp add: expand_complex_eq)
   6.464 +
   6.465 +lemma complex_cnj_diff: "cnj (x - y) = cnj x - cnj y"
   6.466 +by (simp add: expand_complex_eq)
   6.467 +
   6.468 +lemma complex_cnj_minus: "cnj (- x) = - cnj x"
   6.469 +by (simp add: expand_complex_eq)
   6.470 +
   6.471 +lemma complex_cnj_one [simp]: "cnj 1 = 1"
   6.472 +by (simp add: expand_complex_eq)
   6.473 +
   6.474 +lemma complex_cnj_mult: "cnj (x * y) = cnj x * cnj y"
   6.475 +by (simp add: expand_complex_eq)
   6.476 +
   6.477 +lemma complex_cnj_inverse: "cnj (inverse x) = inverse (cnj x)"
   6.478 +by (simp add: complex_inverse_def)
   6.479 +
   6.480 +lemma complex_cnj_divide: "cnj (x / y) = cnj x / cnj y"
   6.481 +by (simp add: complex_divide_def complex_cnj_mult complex_cnj_inverse)
   6.482 +
   6.483 +lemma complex_cnj_power: "cnj (x ^ n) = cnj x ^ n"
   6.484 +by (induct n, simp_all add: complex_cnj_mult)
   6.485 +
   6.486 +lemma complex_cnj_of_nat [simp]: "cnj (of_nat n) = of_nat n"
   6.487 +by (simp add: expand_complex_eq)
   6.488 +
   6.489 +lemma complex_cnj_of_int [simp]: "cnj (of_int z) = of_int z"
   6.490 +by (simp add: expand_complex_eq)
   6.491 +
   6.492 +lemma complex_cnj_number_of [simp]: "cnj (number_of w) = number_of w"
   6.493 +by (simp add: expand_complex_eq)
   6.494 +
   6.495 +lemma complex_cnj_scaleR: "cnj (scaleR r x) = scaleR r (cnj x)"
   6.496 +by (simp add: expand_complex_eq)
   6.497 +
   6.498 +lemma complex_mod_cnj [simp]: "cmod (cnj z) = cmod z"
   6.499 +by (simp add: complex_norm_def)
   6.500 +
   6.501 +lemma complex_cnj_complex_of_real [simp]: "cnj (of_real x) = of_real x"
   6.502 +by (simp add: expand_complex_eq)
   6.503 +
   6.504 +lemma complex_cnj_i [simp]: "cnj ii = - ii"
   6.505 +by (simp add: expand_complex_eq)
   6.506 +
   6.507 +lemma complex_add_cnj: "z + cnj z = complex_of_real (2 * Re z)"
   6.508 +by (simp add: expand_complex_eq)
   6.509 +
   6.510 +lemma complex_diff_cnj: "z - cnj z = complex_of_real (2 * Im z) * ii"
   6.511 +by (simp add: expand_complex_eq)
   6.512 +
   6.513 +lemma complex_mult_cnj: "z * cnj z = complex_of_real ((Re z)\<twosuperior> + (Im z)\<twosuperior>)"
   6.514 +by (simp add: expand_complex_eq power2_eq_square)
   6.515 +
   6.516 +lemma complex_mod_mult_cnj: "cmod (z * cnj z) = (cmod z)\<twosuperior>"
   6.517 +by (simp add: norm_mult power2_eq_square)
   6.518 +
   6.519 +interpretation cnj: bounded_linear ["cnj"]
   6.520 +apply (unfold_locales)
   6.521 +apply (rule complex_cnj_add)
   6.522 +apply (rule complex_cnj_scaleR)
   6.523 +apply (rule_tac x=1 in exI, simp)
   6.524 +done
   6.525 +
   6.526 +
   6.527 +subsection{*The Functions @{term sgn} and @{term arg}*}
   6.528 +
   6.529 +text {*------------ Argand -------------*}
   6.530 +
   6.531 +definition
   6.532 +  arg :: "complex => real" where
   6.533 +  "arg z = (SOME a. Re(sgn z) = cos a & Im(sgn z) = sin a & -pi < a & a \<le> pi)"
   6.534 +
   6.535 +lemma sgn_eq: "sgn z = z / complex_of_real (cmod z)"
   6.536 +by (simp add: complex_sgn_def divide_inverse scaleR_conv_of_real mult_commute)
   6.537 +
   6.538 +lemma i_mult_eq: "ii * ii = complex_of_real (-1)"
   6.539 +by (simp add: i_def complex_of_real_def)
   6.540 +
   6.541 +lemma i_mult_eq2 [simp]: "ii * ii = -(1::complex)"
   6.542 +by (simp add: i_def complex_one_def)
   6.543 +
   6.544 +lemma complex_eq_cancel_iff2 [simp]:
   6.545 +     "(Complex x y = complex_of_real xa) = (x = xa & y = 0)"
   6.546 +by (simp add: complex_of_real_def)
   6.547 +
   6.548 +lemma Re_sgn [simp]: "Re(sgn z) = Re(z)/cmod z"
   6.549 +by (simp add: complex_sgn_def divide_inverse)
   6.550 +
   6.551 +lemma Im_sgn [simp]: "Im(sgn z) = Im(z)/cmod z"
   6.552 +by (simp add: complex_sgn_def divide_inverse)
   6.553 +
   6.554 +lemma complex_inverse_complex_split:
   6.555 +     "inverse(complex_of_real x + ii * complex_of_real y) =
   6.556 +      complex_of_real(x/(x ^ 2 + y ^ 2)) -
   6.557 +      ii * complex_of_real(y/(x ^ 2 + y ^ 2))"
   6.558 +by (simp add: complex_of_real_def i_def diff_minus divide_inverse)
   6.559 +
   6.560 +(*----------------------------------------------------------------------------*)
   6.561 +(* Many of the theorems below need to be moved elsewhere e.g. Transc. Also *)
   6.562 +(* many of the theorems are not used - so should they be kept?                *)
   6.563 +(*----------------------------------------------------------------------------*)
   6.564 +
   6.565 +lemma cos_arg_i_mult_zero_pos:
   6.566 +   "0 < y ==> cos (arg(Complex 0 y)) = 0"
   6.567 +apply (simp add: arg_def abs_if)
   6.568 +apply (rule_tac a = "pi/2" in someI2, auto)
   6.569 +apply (rule order_less_trans [of _ 0], auto)
   6.570 +done
   6.571 +
   6.572 +lemma cos_arg_i_mult_zero_neg:
   6.573 +   "y < 0 ==> cos (arg(Complex 0 y)) = 0"
   6.574 +apply (simp add: arg_def abs_if)
   6.575 +apply (rule_tac a = "- pi/2" in someI2, auto)
   6.576 +apply (rule order_trans [of _ 0], auto)
   6.577 +done
   6.578 +
   6.579 +lemma cos_arg_i_mult_zero [simp]:
   6.580 +     "y \<noteq> 0 ==> cos (arg(Complex 0 y)) = 0"
   6.581 +by (auto simp add: linorder_neq_iff cos_arg_i_mult_zero_pos cos_arg_i_mult_zero_neg)
   6.582 +
   6.583 +
   6.584 +subsection{*Finally! Polar Form for Complex Numbers*}
   6.585 +
   6.586 +definition
   6.587 +
   6.588 +  (* abbreviation for (cos a + i sin a) *)
   6.589 +  cis :: "real => complex" where
   6.590 +  "cis a = Complex (cos a) (sin a)"
   6.591 +
   6.592 +definition
   6.593 +  (* abbreviation for r*(cos a + i sin a) *)
   6.594 +  rcis :: "[real, real] => complex" where
   6.595 +  "rcis r a = complex_of_real r * cis a"
   6.596 +
   6.597 +definition
   6.598 +  (* e ^ (x + iy) *)
   6.599 +  expi :: "complex => complex" where
   6.600 +  "expi z = complex_of_real(exp (Re z)) * cis (Im z)"
   6.601 +
   6.602 +lemma complex_split_polar:
   6.603 +     "\<exists>r a. z = complex_of_real r * (Complex (cos a) (sin a))"
   6.604 +apply (induct z)
   6.605 +apply (auto simp add: polar_Ex complex_of_real_mult_Complex)
   6.606 +done
   6.607 +
   6.608 +lemma rcis_Ex: "\<exists>r a. z = rcis r a"
   6.609 +apply (induct z)
   6.610 +apply (simp add: rcis_def cis_def polar_Ex complex_of_real_mult_Complex)
   6.611 +done
   6.612 +
   6.613 +lemma Re_rcis [simp]: "Re(rcis r a) = r * cos a"
   6.614 +by (simp add: rcis_def cis_def)
   6.615 +
   6.616 +lemma Im_rcis [simp]: "Im(rcis r a) = r * sin a"
   6.617 +by (simp add: rcis_def cis_def)
   6.618 +
   6.619 +lemma sin_cos_squared_add2_mult: "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior>"
   6.620 +proof -
   6.621 +  have "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior> * ((cos a)\<twosuperior> + (sin a)\<twosuperior>)"
   6.622 +    by (simp only: power_mult_distrib right_distrib)
   6.623 +  thus ?thesis by simp
   6.624 +qed
   6.625 +
   6.626 +lemma complex_mod_rcis [simp]: "cmod(rcis r a) = abs r"
   6.627 +by (simp add: rcis_def cis_def sin_cos_squared_add2_mult)
   6.628 +
   6.629 +lemma complex_mod_sqrt_Re_mult_cnj: "cmod z = sqrt (Re (z * cnj z))"
   6.630 +by (simp add: cmod_def power2_eq_square)
   6.631 +
   6.632 +lemma complex_In_mult_cnj_zero [simp]: "Im (z * cnj z) = 0"
   6.633 +by simp
   6.634 +
   6.635 +
   6.636 +(*---------------------------------------------------------------------------*)
   6.637 +(*  (r1 * cis a) * (r2 * cis b) = r1 * r2 * cis (a + b)                      *)
   6.638 +(*---------------------------------------------------------------------------*)
   6.639 +
   6.640 +lemma cis_rcis_eq: "cis a = rcis 1 a"
   6.641 +by (simp add: rcis_def)
   6.642 +
   6.643 +lemma rcis_mult: "rcis r1 a * rcis r2 b = rcis (r1*r2) (a + b)"
   6.644 +by (simp add: rcis_def cis_def cos_add sin_add right_distrib right_diff_distrib
   6.645 +              complex_of_real_def)
   6.646 +
   6.647 +lemma cis_mult: "cis a * cis b = cis (a + b)"
   6.648 +by (simp add: cis_rcis_eq rcis_mult)
   6.649 +
   6.650 +lemma cis_zero [simp]: "cis 0 = 1"
   6.651 +by (simp add: cis_def complex_one_def)
   6.652 +
   6.653 +lemma rcis_zero_mod [simp]: "rcis 0 a = 0"
   6.654 +by (simp add: rcis_def)
   6.655 +
   6.656 +lemma rcis_zero_arg [simp]: "rcis r 0 = complex_of_real r"
   6.657 +by (simp add: rcis_def)
   6.658 +
   6.659 +lemma complex_of_real_minus_one:
   6.660 +   "complex_of_real (-(1::real)) = -(1::complex)"
   6.661 +by (simp add: complex_of_real_def complex_one_def)
   6.662 +
   6.663 +lemma complex_i_mult_minus [simp]: "ii * (ii * x) = - x"
   6.664 +by (simp add: mult_assoc [symmetric])
   6.665 +
   6.666 +
   6.667 +lemma cis_real_of_nat_Suc_mult:
   6.668 +   "cis (real (Suc n) * a) = cis a * cis (real n * a)"
   6.669 +by (simp add: cis_def real_of_nat_Suc left_distrib cos_add sin_add right_distrib)
   6.670 +
   6.671 +lemma DeMoivre: "(cis a) ^ n = cis (real n * a)"
   6.672 +apply (induct_tac "n")
   6.673 +apply (auto simp add: cis_real_of_nat_Suc_mult)
   6.674 +done
   6.675 +
   6.676 +lemma DeMoivre2: "(rcis r a) ^ n = rcis (r ^ n) (real n * a)"
   6.677 +by (simp add: rcis_def power_mult_distrib DeMoivre)
   6.678 +
   6.679 +lemma cis_inverse [simp]: "inverse(cis a) = cis (-a)"
   6.680 +by (simp add: cis_def complex_inverse_complex_split diff_minus)
   6.681 +
   6.682 +lemma rcis_inverse: "inverse(rcis r a) = rcis (1/r) (-a)"
   6.683 +by (simp add: divide_inverse rcis_def)
   6.684 +
   6.685 +lemma cis_divide: "cis a / cis b = cis (a - b)"
   6.686 +by (simp add: complex_divide_def cis_mult real_diff_def)
   6.687 +
   6.688 +lemma rcis_divide: "rcis r1 a / rcis r2 b = rcis (r1/r2) (a - b)"
   6.689 +apply (simp add: complex_divide_def)
   6.690 +apply (case_tac "r2=0", simp)
   6.691 +apply (simp add: rcis_inverse rcis_mult real_diff_def)
   6.692 +done
   6.693 +
   6.694 +lemma Re_cis [simp]: "Re(cis a) = cos a"
   6.695 +by (simp add: cis_def)
   6.696 +
   6.697 +lemma Im_cis [simp]: "Im(cis a) = sin a"
   6.698 +by (simp add: cis_def)
   6.699 +
   6.700 +lemma cos_n_Re_cis_pow_n: "cos (real n * a) = Re(cis a ^ n)"
   6.701 +by (auto simp add: DeMoivre)
   6.702 +
   6.703 +lemma sin_n_Im_cis_pow_n: "sin (real n * a) = Im(cis a ^ n)"
   6.704 +by (auto simp add: DeMoivre)
   6.705 +
   6.706 +lemma expi_add: "expi(a + b) = expi(a) * expi(b)"
   6.707 +by (simp add: expi_def exp_add cis_mult [symmetric] mult_ac)
   6.708 +
   6.709 +lemma expi_zero [simp]: "expi (0::complex) = 1"
   6.710 +by (simp add: expi_def)
   6.711 +
   6.712 +lemma complex_expi_Ex: "\<exists>a r. z = complex_of_real r * expi a"
   6.713 +apply (insert rcis_Ex [of z])
   6.714 +apply (auto simp add: expi_def rcis_def mult_assoc [symmetric])
   6.715 +apply (rule_tac x = "ii * complex_of_real a" in exI, auto)
   6.716 +done
   6.717 +
   6.718 +lemma expi_two_pi_i [simp]: "expi((2::complex) * complex_of_real pi * ii) = 1"
   6.719 +by (simp add: expi_def cis_def)
   6.720 +
   6.721 +end
     7.1 --- a/src/HOL/Complex/Complex.thy	Wed Dec 03 09:53:58 2008 +0100
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,719 +0,0 @@
     7.4 -(*  Title:       Complex.thy
     7.5 -    ID:      $Id$
     7.6 -    Author:      Jacques D. Fleuriot
     7.7 -    Copyright:   2001 University of Edinburgh
     7.8 -    Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4
     7.9 -*)
    7.10 -
    7.11 -header {* Complex Numbers: Rectangular and Polar Representations *}
    7.12 -
    7.13 -theory Complex
    7.14 -imports "../Hyperreal/Transcendental"
    7.15 -begin
    7.16 -
    7.17 -datatype complex = Complex real real
    7.18 -
    7.19 -primrec
    7.20 -  Re :: "complex \<Rightarrow> real"
    7.21 -where
    7.22 -  Re: "Re (Complex x y) = x"
    7.23 -
    7.24 -primrec
    7.25 -  Im :: "complex \<Rightarrow> real"
    7.26 -where
    7.27 -  Im: "Im (Complex x y) = y"
    7.28 -
    7.29 -lemma complex_surj [simp]: "Complex (Re z) (Im z) = z"
    7.30 -  by (induct z) simp
    7.31 -
    7.32 -lemma complex_equality [intro?]: "\<lbrakk>Re x = Re y; Im x = Im y\<rbrakk> \<Longrightarrow> x = y"
    7.33 -  by (induct x, induct y) simp
    7.34 -
    7.35 -lemma expand_complex_eq: "x = y \<longleftrightarrow> Re x = Re y \<and> Im x = Im y"
    7.36 -  by (induct x, induct y) simp
    7.37 -
    7.38 -lemmas complex_Re_Im_cancel_iff = expand_complex_eq
    7.39 -
    7.40 -
    7.41 -subsection {* Addition and Subtraction *}
    7.42 -
    7.43 -instantiation complex :: ab_group_add
    7.44 -begin
    7.45 -
    7.46 -definition
    7.47 -  complex_zero_def: "0 = Complex 0 0"
    7.48 -
    7.49 -definition
    7.50 -  complex_add_def: "x + y = Complex (Re x + Re y) (Im x + Im y)"
    7.51 -
    7.52 -definition
    7.53 -  complex_minus_def: "- x = Complex (- Re x) (- Im x)"
    7.54 -
    7.55 -definition
    7.56 -  complex_diff_def: "x - (y\<Colon>complex) = x + - y"
    7.57 -
    7.58 -lemma Complex_eq_0 [simp]: "Complex a b = 0 \<longleftrightarrow> a = 0 \<and> b = 0"
    7.59 -  by (simp add: complex_zero_def)
    7.60 -
    7.61 -lemma complex_Re_zero [simp]: "Re 0 = 0"
    7.62 -  by (simp add: complex_zero_def)
    7.63 -
    7.64 -lemma complex_Im_zero [simp]: "Im 0 = 0"
    7.65 -  by (simp add: complex_zero_def)
    7.66 -
    7.67 -lemma complex_add [simp]:
    7.68 -  "Complex a b + Complex c d = Complex (a + c) (b + d)"
    7.69 -  by (simp add: complex_add_def)
    7.70 -
    7.71 -lemma complex_Re_add [simp]: "Re (x + y) = Re x + Re y"
    7.72 -  by (simp add: complex_add_def)
    7.73 -
    7.74 -lemma complex_Im_add [simp]: "Im (x + y) = Im x + Im y"
    7.75 -  by (simp add: complex_add_def)
    7.76 -
    7.77 -lemma complex_minus [simp]:
    7.78 -  "- (Complex a b) = Complex (- a) (- b)"
    7.79 -  by (simp add: complex_minus_def)
    7.80 -
    7.81 -lemma complex_Re_minus [simp]: "Re (- x) = - Re x"
    7.82 -  by (simp add: complex_minus_def)
    7.83 -
    7.84 -lemma complex_Im_minus [simp]: "Im (- x) = - Im x"
    7.85 -  by (simp add: complex_minus_def)
    7.86 -
    7.87 -lemma complex_diff [simp]:
    7.88 -  "Complex a b - Complex c d = Complex (a - c) (b - d)"
    7.89 -  by (simp add: complex_diff_def)
    7.90 -
    7.91 -lemma complex_Re_diff [simp]: "Re (x - y) = Re x - Re y"
    7.92 -  by (simp add: complex_diff_def)
    7.93 -
    7.94 -lemma complex_Im_diff [simp]: "Im (x - y) = Im x - Im y"
    7.95 -  by (simp add: complex_diff_def)
    7.96 -
    7.97 -instance
    7.98 -  by intro_classes (simp_all add: complex_add_def complex_diff_def)
    7.99 -
   7.100 -end
   7.101 -
   7.102 -
   7.103 -
   7.104 -subsection {* Multiplication and Division *}
   7.105 -
   7.106 -instantiation complex :: "{field, division_by_zero}"
   7.107 -begin
   7.108 -
   7.109 -definition
   7.110 -  complex_one_def: "1 = Complex 1 0"
   7.111 -
   7.112 -definition
   7.113 -  complex_mult_def: "x * y =
   7.114 -    Complex (Re x * Re y - Im x * Im y) (Re x * Im y + Im x * Re y)"
   7.115 -
   7.116 -definition
   7.117 -  complex_inverse_def: "inverse x =
   7.118 -    Complex (Re x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)) (- Im x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>))"
   7.119 -
   7.120 -definition
   7.121 -  complex_divide_def: "x / (y\<Colon>complex) = x * inverse y"
   7.122 -
   7.123 -lemma Complex_eq_1 [simp]: "(Complex a b = 1) = (a = 1 \<and> b = 0)"
   7.124 -  by (simp add: complex_one_def)
   7.125 -
   7.126 -lemma complex_Re_one [simp]: "Re 1 = 1"
   7.127 -  by (simp add: complex_one_def)
   7.128 -
   7.129 -lemma complex_Im_one [simp]: "Im 1 = 0"
   7.130 -  by (simp add: complex_one_def)
   7.131 -
   7.132 -lemma complex_mult [simp]:
   7.133 -  "Complex a b * Complex c d = Complex (a * c - b * d) (a * d + b * c)"
   7.134 -  by (simp add: complex_mult_def)
   7.135 -
   7.136 -lemma complex_Re_mult [simp]: "Re (x * y) = Re x * Re y - Im x * Im y"
   7.137 -  by (simp add: complex_mult_def)
   7.138 -
   7.139 -lemma complex_Im_mult [simp]: "Im (x * y) = Re x * Im y + Im x * Re y"
   7.140 -  by (simp add: complex_mult_def)
   7.141 -
   7.142 -lemma complex_inverse [simp]:
   7.143 -  "inverse (Complex a b) = Complex (a / (a\<twosuperior> + b\<twosuperior>)) (- b / (a\<twosuperior> + b\<twosuperior>))"
   7.144 -  by (simp add: complex_inverse_def)
   7.145 -
   7.146 -lemma complex_Re_inverse:
   7.147 -  "Re (inverse x) = Re x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)"
   7.148 -  by (simp add: complex_inverse_def)
   7.149 -
   7.150 -lemma complex_Im_inverse:
   7.151 -  "Im (inverse x) = - Im x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)"
   7.152 -  by (simp add: complex_inverse_def)
   7.153 -
   7.154 -instance
   7.155 -  by intro_classes (simp_all add: complex_mult_def
   7.156 -  right_distrib left_distrib right_diff_distrib left_diff_distrib
   7.157 -  complex_inverse_def complex_divide_def
   7.158 -  power2_eq_square add_divide_distrib [symmetric]
   7.159 -  expand_complex_eq)
   7.160 -
   7.161 -end
   7.162 -
   7.163 -
   7.164 -subsection {* Exponentiation *}
   7.165 -
   7.166 -instantiation complex :: recpower
   7.167 -begin
   7.168 -
   7.169 -primrec power_complex where
   7.170 -  complexpow_0:     "z ^ 0     = (1\<Colon>complex)"
   7.171 -  | complexpow_Suc: "z ^ Suc n = (z\<Colon>complex) * z ^ n"
   7.172 -
   7.173 -instance by intro_classes simp_all
   7.174 -
   7.175 -end
   7.176 -
   7.177 -
   7.178 -subsection {* Numerals and Arithmetic *}
   7.179 -
   7.180 -instantiation complex :: number_ring
   7.181 -begin
   7.182 -
   7.183 -definition number_of_complex where
   7.184 -  complex_number_of_def: "number_of w = (of_int w \<Colon> complex)"
   7.185 -
   7.186 -instance
   7.187 -  by intro_classes (simp only: complex_number_of_def)
   7.188 -
   7.189 -end
   7.190 -
   7.191 -lemma complex_Re_of_nat [simp]: "Re (of_nat n) = of_nat n"
   7.192 -by (induct n) simp_all
   7.193 -
   7.194 -lemma complex_Im_of_nat [simp]: "Im (of_nat n) = 0"
   7.195 -by (induct n) simp_all
   7.196 -
   7.197 -lemma complex_Re_of_int [simp]: "Re (of_int z) = of_int z"
   7.198 -by (cases z rule: int_diff_cases) simp
   7.199 -
   7.200 -lemma complex_Im_of_int [simp]: "Im (of_int z) = 0"
   7.201 -by (cases z rule: int_diff_cases) simp
   7.202 -
   7.203 -lemma complex_Re_number_of [simp]: "Re (number_of v) = number_of v"
   7.204 -unfolding number_of_eq by (rule complex_Re_of_int)
   7.205 -
   7.206 -lemma complex_Im_number_of [simp]: "Im (number_of v) = 0"
   7.207 -unfolding number_of_eq by (rule complex_Im_of_int)
   7.208 -
   7.209 -lemma Complex_eq_number_of [simp]:
   7.210 -  "(Complex a b = number_of w) = (a = number_of w \<and> b = 0)"
   7.211 -by (simp add: expand_complex_eq)
   7.212 -
   7.213 -
   7.214 -subsection {* Scalar Multiplication *}
   7.215 -
   7.216 -instantiation complex :: real_field
   7.217 -begin
   7.218 -
   7.219 -definition
   7.220 -  complex_scaleR_def: "scaleR r x = Complex (r * Re x) (r * Im x)"
   7.221 -
   7.222 -lemma complex_scaleR [simp]:
   7.223 -  "scaleR r (Complex a b) = Complex (r * a) (r * b)"
   7.224 -  unfolding complex_scaleR_def by simp
   7.225 -
   7.226 -lemma complex_Re_scaleR [simp]: "Re (scaleR r x) = r * Re x"
   7.227 -  unfolding complex_scaleR_def by simp
   7.228 -
   7.229 -lemma complex_Im_scaleR [simp]: "Im (scaleR r x) = r * Im x"
   7.230 -  unfolding complex_scaleR_def by simp
   7.231 -
   7.232 -instance
   7.233 -proof
   7.234 -  fix a b :: real and x y :: complex
   7.235 -  show "scaleR a (x + y) = scaleR a x + scaleR a y"
   7.236 -    by (simp add: expand_complex_eq right_distrib)
   7.237 -  show "scaleR (a + b) x = scaleR a x + scaleR b x"
   7.238 -    by (simp add: expand_complex_eq left_distrib)
   7.239 -  show "scaleR a (scaleR b x) = scaleR (a * b) x"
   7.240 -    by (simp add: expand_complex_eq mult_assoc)
   7.241 -  show "scaleR 1 x = x"
   7.242 -    by (simp add: expand_complex_eq)
   7.243 -  show "scaleR a x * y = scaleR a (x * y)"
   7.244 -    by (simp add: expand_complex_eq ring_simps)
   7.245 -  show "x * scaleR a y = scaleR a (x * y)"
   7.246 -    by (simp add: expand_complex_eq ring_simps)
   7.247 -qed
   7.248 -
   7.249 -end
   7.250 -
   7.251 -
   7.252 -subsection{* Properties of Embedding from Reals *}
   7.253 -
   7.254 -abbreviation
   7.255 -  complex_of_real :: "real \<Rightarrow> complex" where
   7.256 -    "complex_of_real \<equiv> of_real"
   7.257 -
   7.258 -lemma complex_of_real_def: "complex_of_real r = Complex r 0"
   7.259 -by (simp add: of_real_def complex_scaleR_def)
   7.260 -
   7.261 -lemma Re_complex_of_real [simp]: "Re (complex_of_real z) = z"
   7.262 -by (simp add: complex_of_real_def)
   7.263 -
   7.264 -lemma Im_complex_of_real [simp]: "Im (complex_of_real z) = 0"
   7.265 -by (simp add: complex_of_real_def)
   7.266 -
   7.267 -lemma Complex_add_complex_of_real [simp]:
   7.268 -     "Complex x y + complex_of_real r = Complex (x+r) y"
   7.269 -by (simp add: complex_of_real_def)
   7.270 -
   7.271 -lemma complex_of_real_add_Complex [simp]:
   7.272 -     "complex_of_real r + Complex x y = Complex (r+x) y"
   7.273 -by (simp add: complex_of_real_def)
   7.274 -
   7.275 -lemma Complex_mult_complex_of_real:
   7.276 -     "Complex x y * complex_of_real r = Complex (x*r) (y*r)"
   7.277 -by (simp add: complex_of_real_def)
   7.278 -
   7.279 -lemma complex_of_real_mult_Complex:
   7.280 -     "complex_of_real r * Complex x y = Complex (r*x) (r*y)"
   7.281 -by (simp add: complex_of_real_def)
   7.282 -
   7.283 -
   7.284 -subsection {* Vector Norm *}
   7.285 -
   7.286 -instantiation complex :: real_normed_field
   7.287 -begin
   7.288 -
   7.289 -definition
   7.290 -  complex_norm_def: "norm z = sqrt ((Re z)\<twosuperior> + (Im z)\<twosuperior>)"
   7.291 -
   7.292 -abbreviation
   7.293 -  cmod :: "complex \<Rightarrow> real" where
   7.294 -  "cmod \<equiv> norm"
   7.295 -
   7.296 -definition
   7.297 -  complex_sgn_def: "sgn x = x /\<^sub>R cmod x"
   7.298 -
   7.299 -lemmas cmod_def = complex_norm_def
   7.300 -
   7.301 -lemma complex_norm [simp]: "cmod (Complex x y) = sqrt (x\<twosuperior> + y\<twosuperior>)"
   7.302 -  by (simp add: complex_norm_def)
   7.303 -
   7.304 -instance
   7.305 -proof
   7.306 -  fix r :: real and x y :: complex
   7.307 -  show "0 \<le> norm x"
   7.308 -    by (induct x) simp
   7.309 -  show "(norm x = 0) = (x = 0)"
   7.310 -    by (induct x) simp
   7.311 -  show "norm (x + y) \<le> norm x + norm y"
   7.312 -    by (induct x, induct y)
   7.313 -       (simp add: real_sqrt_sum_squares_triangle_ineq)
   7.314 -  show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
   7.315 -    by (induct x)
   7.316 -       (simp add: power_mult_distrib right_distrib [symmetric] real_sqrt_mult)
   7.317 -  show "norm (x * y) = norm x * norm y"
   7.318 -    by (induct x, induct y)
   7.319 -       (simp add: real_sqrt_mult [symmetric] power2_eq_square ring_simps)
   7.320 -  show "sgn x = x /\<^sub>R cmod x" by(simp add: complex_sgn_def)
   7.321 -qed
   7.322 -
   7.323 -end
   7.324 -
   7.325 -lemma cmod_unit_one [simp]: "cmod (Complex (cos a) (sin a)) = 1"
   7.326 -by simp
   7.327 -
   7.328 -lemma cmod_complex_polar [simp]:
   7.329 -     "cmod (complex_of_real r * Complex (cos a) (sin a)) = abs r"
   7.330 -by (simp add: norm_mult)
   7.331 -
   7.332 -lemma complex_Re_le_cmod: "Re x \<le> cmod x"
   7.333 -unfolding complex_norm_def
   7.334 -by (rule real_sqrt_sum_squares_ge1)
   7.335 -
   7.336 -lemma complex_mod_minus_le_complex_mod [simp]: "- cmod x \<le> cmod x"
   7.337 -by (rule order_trans [OF _ norm_ge_zero], simp)
   7.338 -
   7.339 -lemma complex_mod_triangle_ineq2 [simp]: "cmod(b + a) - cmod b \<le> cmod a"
   7.340 -by (rule ord_le_eq_trans [OF norm_triangle_ineq2], simp)
   7.341 -
   7.342 -lemmas real_sum_squared_expand = power2_sum [where 'a=real]
   7.343 -
   7.344 -lemma abs_Re_le_cmod: "\<bar>Re x\<bar> \<le> cmod x"
   7.345 -by (cases x) simp
   7.346 -
   7.347 -lemma abs_Im_le_cmod: "\<bar>Im x\<bar> \<le> cmod x"
   7.348 -by (cases x) simp
   7.349 -
   7.350 -subsection {* Completeness of the Complexes *}
   7.351 -
   7.352 -interpretation Re: bounded_linear ["Re"]
   7.353 -apply (unfold_locales, simp, simp)
   7.354 -apply (rule_tac x=1 in exI)
   7.355 -apply (simp add: complex_norm_def)
   7.356 -done
   7.357 -
   7.358 -interpretation Im: bounded_linear ["Im"]
   7.359 -apply (unfold_locales, simp, simp)
   7.360 -apply (rule_tac x=1 in exI)
   7.361 -apply (simp add: complex_norm_def)
   7.362 -done
   7.363 -
   7.364 -lemma LIMSEQ_Complex:
   7.365 -  "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. Complex (X n) (Y n)) ----> Complex a b"
   7.366 -apply (rule LIMSEQ_I)
   7.367 -apply (subgoal_tac "0 < r / sqrt 2")
   7.368 -apply (drule_tac r="r / sqrt 2" in LIMSEQ_D, safe)
   7.369 -apply (drule_tac r="r / sqrt 2" in LIMSEQ_D, safe)
   7.370 -apply (rename_tac M N, rule_tac x="max M N" in exI, safe)
   7.371 -apply (simp add: real_sqrt_sum_squares_less)
   7.372 -apply (simp add: divide_pos_pos)
   7.373 -done
   7.374 -
   7.375 -instance complex :: banach
   7.376 -proof
   7.377 -  fix X :: "nat \<Rightarrow> complex"
   7.378 -  assume X: "Cauchy X"
   7.379 -  from Re.Cauchy [OF X] have 1: "(\<lambda>n. Re (X n)) ----> lim (\<lambda>n. Re (X n))"
   7.380 -    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
   7.381 -  from Im.Cauchy [OF X] have 2: "(\<lambda>n. Im (X n)) ----> lim (\<lambda>n. Im (X n))"
   7.382 -    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
   7.383 -  have "X ----> Complex (lim (\<lambda>n. Re (X n))) (lim (\<lambda>n. Im (X n)))"
   7.384 -    using LIMSEQ_Complex [OF 1 2] by simp
   7.385 -  thus "convergent X"
   7.386 -    by (rule convergentI)
   7.387 -qed
   7.388 -
   7.389 -
   7.390 -subsection {* The Complex Number @{term "\<i>"} *}
   7.391 -
   7.392 -definition
   7.393 -  "ii" :: complex  ("\<i>") where
   7.394 -  i_def: "ii \<equiv> Complex 0 1"
   7.395 -
   7.396 -lemma complex_Re_i [simp]: "Re ii = 0"
   7.397 -by (simp add: i_def)
   7.398 -
   7.399 -lemma complex_Im_i [simp]: "Im ii = 1"
   7.400 -by (simp add: i_def)
   7.401 -
   7.402 -lemma Complex_eq_i [simp]: "(Complex x y = ii) = (x = 0 \<and> y = 1)"
   7.403 -by (simp add: i_def)
   7.404 -
   7.405 -lemma complex_i_not_zero [simp]: "ii \<noteq> 0"
   7.406 -by (simp add: expand_complex_eq)
   7.407 -
   7.408 -lemma complex_i_not_one [simp]: "ii \<noteq> 1"
   7.409 -by (simp add: expand_complex_eq)
   7.410 -
   7.411 -lemma complex_i_not_number_of [simp]: "ii \<noteq> number_of w"
   7.412 -by (simp add: expand_complex_eq)
   7.413 -
   7.414 -lemma i_mult_Complex [simp]: "ii * Complex a b = Complex (- b) a"
   7.415 -by (simp add: expand_complex_eq)
   7.416 -
   7.417 -lemma Complex_mult_i [simp]: "Complex a b * ii = Complex (- b) a"
   7.418 -by (simp add: expand_complex_eq)
   7.419 -
   7.420 -lemma i_complex_of_real [simp]: "ii * complex_of_real r = Complex 0 r"
   7.421 -by (simp add: i_def complex_of_real_def)
   7.422 -
   7.423 -lemma complex_of_real_i [simp]: "complex_of_real r * ii = Complex 0 r"
   7.424 -by (simp add: i_def complex_of_real_def)
   7.425 -
   7.426 -lemma i_squared [simp]: "ii * ii = -1"
   7.427 -by (simp add: i_def)
   7.428 -
   7.429 -lemma power2_i [simp]: "ii\<twosuperior> = -1"
   7.430 -by (simp add: power2_eq_square)
   7.431 -
   7.432 -lemma inverse_i [simp]: "inverse ii = - ii"
   7.433 -by (rule inverse_unique, simp)
   7.434 -
   7.435 -
   7.436 -subsection {* Complex Conjugation *}
   7.437 -
   7.438 -definition
   7.439 -  cnj :: "complex \<Rightarrow> complex" where
   7.440 -  "cnj z = Complex (Re z) (- Im z)"
   7.441 -
   7.442 -lemma complex_cnj [simp]: "cnj (Complex a b) = Complex a (- b)"
   7.443 -by (simp add: cnj_def)
   7.444 -
   7.445 -lemma complex_Re_cnj [simp]: "Re (cnj x) = Re x"
   7.446 -by (simp add: cnj_def)
   7.447 -
   7.448 -lemma complex_Im_cnj [simp]: "Im (cnj x) = - Im x"
   7.449 -by (simp add: cnj_def)
   7.450 -
   7.451 -lemma complex_cnj_cancel_iff [simp]: "(cnj x = cnj y) = (x = y)"
   7.452 -by (simp add: expand_complex_eq)
   7.453 -
   7.454 -lemma complex_cnj_cnj [simp]: "cnj (cnj z) = z"
   7.455 -by (simp add: cnj_def)
   7.456 -
   7.457 -lemma complex_cnj_zero [simp]: "cnj 0 = 0"
   7.458 -by (simp add: expand_complex_eq)
   7.459 -
   7.460 -lemma complex_cnj_zero_iff [iff]: "(cnj z = 0) = (z = 0)"
   7.461 -by (simp add: expand_complex_eq)
   7.462 -
   7.463 -lemma complex_cnj_add: "cnj (x + y) = cnj x + cnj y"
   7.464 -by (simp add: expand_complex_eq)
   7.465 -
   7.466 -lemma complex_cnj_diff: "cnj (x - y) = cnj x - cnj y"
   7.467 -by (simp add: expand_complex_eq)
   7.468 -
   7.469 -lemma complex_cnj_minus: "cnj (- x) = - cnj x"
   7.470 -by (simp add: expand_complex_eq)
   7.471 -
   7.472 -lemma complex_cnj_one [simp]: "cnj 1 = 1"
   7.473 -by (simp add: expand_complex_eq)
   7.474 -
   7.475 -lemma complex_cnj_mult: "cnj (x * y) = cnj x * cnj y"
   7.476 -by (simp add: expand_complex_eq)
   7.477 -
   7.478 -lemma complex_cnj_inverse: "cnj (inverse x) = inverse (cnj x)"
   7.479 -by (simp add: complex_inverse_def)
   7.480 -
   7.481 -lemma complex_cnj_divide: "cnj (x / y) = cnj x / cnj y"
   7.482 -by (simp add: complex_divide_def complex_cnj_mult complex_cnj_inverse)
   7.483 -
   7.484 -lemma complex_cnj_power: "cnj (x ^ n) = cnj x ^ n"
   7.485 -by (induct n, simp_all add: complex_cnj_mult)
   7.486 -
   7.487 -lemma complex_cnj_of_nat [simp]: "cnj (of_nat n) = of_nat n"
   7.488 -by (simp add: expand_complex_eq)
   7.489 -
   7.490 -lemma complex_cnj_of_int [simp]: "cnj (of_int z) = of_int z"
   7.491 -by (simp add: expand_complex_eq)
   7.492 -
   7.493 -lemma complex_cnj_number_of [simp]: "cnj (number_of w) = number_of w"
   7.494 -by (simp add: expand_complex_eq)
   7.495 -
   7.496 -lemma complex_cnj_scaleR: "cnj (scaleR r x) = scaleR r (cnj x)"
   7.497 -by (simp add: expand_complex_eq)
   7.498 -
   7.499 -lemma complex_mod_cnj [simp]: "cmod (cnj z) = cmod z"
   7.500 -by (simp add: complex_norm_def)
   7.501 -
   7.502 -lemma complex_cnj_complex_of_real [simp]: "cnj (of_real x) = of_real x"
   7.503 -by (simp add: expand_complex_eq)
   7.504 -
   7.505 -lemma complex_cnj_i [simp]: "cnj ii = - ii"
   7.506 -by (simp add: expand_complex_eq)
   7.507 -
   7.508 -lemma complex_add_cnj: "z + cnj z = complex_of_real (2 * Re z)"
   7.509 -by (simp add: expand_complex_eq)
   7.510 -
   7.511 -lemma complex_diff_cnj: "z - cnj z = complex_of_real (2 * Im z) * ii"
   7.512 -by (simp add: expand_complex_eq)
   7.513 -
   7.514 -lemma complex_mult_cnj: "z * cnj z = complex_of_real ((Re z)\<twosuperior> + (Im z)\<twosuperior>)"
   7.515 -by (simp add: expand_complex_eq power2_eq_square)
   7.516 -
   7.517 -lemma complex_mod_mult_cnj: "cmod (z * cnj z) = (cmod z)\<twosuperior>"
   7.518 -by (simp add: norm_mult power2_eq_square)
   7.519 -
   7.520 -interpretation cnj: bounded_linear ["cnj"]
   7.521 -apply (unfold_locales)
   7.522 -apply (rule complex_cnj_add)
   7.523 -apply (rule complex_cnj_scaleR)
   7.524 -apply (rule_tac x=1 in exI, simp)
   7.525 -done
   7.526 -
   7.527 -
   7.528 -subsection{*The Functions @{term sgn} and @{term arg}*}
   7.529 -
   7.530 -text {*------------ Argand -------------*}
   7.531 -
   7.532 -definition
   7.533 -  arg :: "complex => real" where
   7.534 -  "arg z = (SOME a. Re(sgn z) = cos a & Im(sgn z) = sin a & -pi < a & a \<le> pi)"
   7.535 -
   7.536 -lemma sgn_eq: "sgn z = z / complex_of_real (cmod z)"
   7.537 -by (simp add: complex_sgn_def divide_inverse scaleR_conv_of_real mult_commute)
   7.538 -
   7.539 -lemma i_mult_eq: "ii * ii = complex_of_real (-1)"
   7.540 -by (simp add: i_def complex_of_real_def)
   7.541 -
   7.542 -lemma i_mult_eq2 [simp]: "ii * ii = -(1::complex)"
   7.543 -by (simp add: i_def complex_one_def)
   7.544 -
   7.545 -lemma complex_eq_cancel_iff2 [simp]:
   7.546 -     "(Complex x y = complex_of_real xa) = (x = xa & y = 0)"
   7.547 -by (simp add: complex_of_real_def)
   7.548 -
   7.549 -lemma Re_sgn [simp]: "Re(sgn z) = Re(z)/cmod z"
   7.550 -by (simp add: complex_sgn_def divide_inverse)
   7.551 -
   7.552 -lemma Im_sgn [simp]: "Im(sgn z) = Im(z)/cmod z"
   7.553 -by (simp add: complex_sgn_def divide_inverse)
   7.554 -
   7.555 -lemma complex_inverse_complex_split:
   7.556 -     "inverse(complex_of_real x + ii * complex_of_real y) =
   7.557 -      complex_of_real(x/(x ^ 2 + y ^ 2)) -
   7.558 -      ii * complex_of_real(y/(x ^ 2 + y ^ 2))"
   7.559 -by (simp add: complex_of_real_def i_def diff_minus divide_inverse)
   7.560 -
   7.561 -(*----------------------------------------------------------------------------*)
   7.562 -(* Many of the theorems below need to be moved elsewhere e.g. Transc. Also *)
   7.563 -(* many of the theorems are not used - so should they be kept?                *)
   7.564 -(*----------------------------------------------------------------------------*)
   7.565 -
   7.566 -lemma cos_arg_i_mult_zero_pos:
   7.567 -   "0 < y ==> cos (arg(Complex 0 y)) = 0"
   7.568 -apply (simp add: arg_def abs_if)
   7.569 -apply (rule_tac a = "pi/2" in someI2, auto)
   7.570 -apply (rule order_less_trans [of _ 0], auto)
   7.571 -done
   7.572 -
   7.573 -lemma cos_arg_i_mult_zero_neg:
   7.574 -   "y < 0 ==> cos (arg(Complex 0 y)) = 0"
   7.575 -apply (simp add: arg_def abs_if)
   7.576 -apply (rule_tac a = "- pi/2" in someI2, auto)
   7.577 -apply (rule order_trans [of _ 0], auto)
   7.578 -done
   7.579 -
   7.580 -lemma cos_arg_i_mult_zero [simp]:
   7.581 -     "y \<noteq> 0 ==> cos (arg(Complex 0 y)) = 0"
   7.582 -by (auto simp add: linorder_neq_iff cos_arg_i_mult_zero_pos cos_arg_i_mult_zero_neg)
   7.583 -
   7.584 -
   7.585 -subsection{*Finally! Polar Form for Complex Numbers*}
   7.586 -
   7.587 -definition
   7.588 -
   7.589 -  (* abbreviation for (cos a + i sin a) *)
   7.590 -  cis :: "real => complex" where
   7.591 -  "cis a = Complex (cos a) (sin a)"
   7.592 -
   7.593 -definition
   7.594 -  (* abbreviation for r*(cos a + i sin a) *)
   7.595 -  rcis :: "[real, real] => complex" where
   7.596 -  "rcis r a = complex_of_real r * cis a"
   7.597 -
   7.598 -definition
   7.599 -  (* e ^ (x + iy) *)
   7.600 -  expi :: "complex => complex" where
   7.601 -  "expi z = complex_of_real(exp (Re z)) * cis (Im z)"
   7.602 -
   7.603 -lemma complex_split_polar:
   7.604 -     "\<exists>r a. z = complex_of_real r * (Complex (cos a) (sin a))"
   7.605 -apply (induct z)
   7.606 -apply (auto simp add: polar_Ex complex_of_real_mult_Complex)
   7.607 -done
   7.608 -
   7.609 -lemma rcis_Ex: "\<exists>r a. z = rcis r a"
   7.610 -apply (induct z)
   7.611 -apply (simp add: rcis_def cis_def polar_Ex complex_of_real_mult_Complex)
   7.612 -done
   7.613 -
   7.614 -lemma Re_rcis [simp]: "Re(rcis r a) = r * cos a"
   7.615 -by (simp add: rcis_def cis_def)
   7.616 -
   7.617 -lemma Im_rcis [simp]: "Im(rcis r a) = r * sin a"
   7.618 -by (simp add: rcis_def cis_def)
   7.619 -
   7.620 -lemma sin_cos_squared_add2_mult: "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior>"
   7.621 -proof -
   7.622 -  have "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior> * ((cos a)\<twosuperior> + (sin a)\<twosuperior>)"
   7.623 -    by (simp only: power_mult_distrib right_distrib)
   7.624 -  thus ?thesis by simp
   7.625 -qed
   7.626 -
   7.627 -lemma complex_mod_rcis [simp]: "cmod(rcis r a) = abs r"
   7.628 -by (simp add: rcis_def cis_def sin_cos_squared_add2_mult)
   7.629 -
   7.630 -lemma complex_mod_sqrt_Re_mult_cnj: "cmod z = sqrt (Re (z * cnj z))"
   7.631 -by (simp add: cmod_def power2_eq_square)
   7.632 -
   7.633 -lemma complex_In_mult_cnj_zero [simp]: "Im (z * cnj z) = 0"
   7.634 -by simp
   7.635 -
   7.636 -
   7.637 -(*---------------------------------------------------------------------------*)
   7.638 -(*  (r1 * cis a) * (r2 * cis b) = r1 * r2 * cis (a + b)                      *)
   7.639 -(*---------------------------------------------------------------------------*)
   7.640 -
   7.641 -lemma cis_rcis_eq: "cis a = rcis 1 a"
   7.642 -by (simp add: rcis_def)
   7.643 -
   7.644 -lemma rcis_mult: "rcis r1 a * rcis r2 b = rcis (r1*r2) (a + b)"
   7.645 -by (simp add: rcis_def cis_def cos_add sin_add right_distrib right_diff_distrib
   7.646 -              complex_of_real_def)
   7.647 -
   7.648 -lemma cis_mult: "cis a * cis b = cis (a + b)"
   7.649 -by (simp add: cis_rcis_eq rcis_mult)
   7.650 -
   7.651 -lemma cis_zero [simp]: "cis 0 = 1"
   7.652 -by (simp add: cis_def complex_one_def)
   7.653 -
   7.654 -lemma rcis_zero_mod [simp]: "rcis 0 a = 0"
   7.655 -by (simp add: rcis_def)
   7.656 -
   7.657 -lemma rcis_zero_arg [simp]: "rcis r 0 = complex_of_real r"
   7.658 -by (simp add: rcis_def)
   7.659 -
   7.660 -lemma complex_of_real_minus_one:
   7.661 -   "complex_of_real (-(1::real)) = -(1::complex)"
   7.662 -by (simp add: complex_of_real_def complex_one_def)
   7.663 -
   7.664 -lemma complex_i_mult_minus [simp]: "ii * (ii * x) = - x"
   7.665 -by (simp add: mult_assoc [symmetric])
   7.666 -
   7.667 -
   7.668 -lemma cis_real_of_nat_Suc_mult:
   7.669 -   "cis (real (Suc n) * a) = cis a * cis (real n * a)"
   7.670 -by (simp add: cis_def real_of_nat_Suc left_distrib cos_add sin_add right_distrib)
   7.671 -
   7.672 -lemma DeMoivre: "(cis a) ^ n = cis (real n * a)"
   7.673 -apply (induct_tac "n")
   7.674 -apply (auto simp add: cis_real_of_nat_Suc_mult)
   7.675 -done
   7.676 -
   7.677 -lemma DeMoivre2: "(rcis r a) ^ n = rcis (r ^ n) (real n * a)"
   7.678 -by (simp add: rcis_def power_mult_distrib DeMoivre)
   7.679 -
   7.680 -lemma cis_inverse [simp]: "inverse(cis a) = cis (-a)"
   7.681 -by (simp add: cis_def complex_inverse_complex_split diff_minus)
   7.682 -
   7.683 -lemma rcis_inverse: "inverse(rcis r a) = rcis (1/r) (-a)"
   7.684 -by (simp add: divide_inverse rcis_def)
   7.685 -
   7.686 -lemma cis_divide: "cis a / cis b = cis (a - b)"
   7.687 -by (simp add: complex_divide_def cis_mult real_diff_def)
   7.688 -
   7.689 -lemma rcis_divide: "rcis r1 a / rcis r2 b = rcis (r1/r2) (a - b)"
   7.690 -apply (simp add: complex_divide_def)
   7.691 -apply (case_tac "r2=0", simp)
   7.692 -apply (simp add: rcis_inverse rcis_mult real_diff_def)
   7.693 -done
   7.694 -
   7.695 -lemma Re_cis [simp]: "Re(cis a) = cos a"
   7.696 -by (simp add: cis_def)
   7.697 -
   7.698 -lemma Im_cis [simp]: "Im(cis a) = sin a"
   7.699 -by (simp add: cis_def)
   7.700 -
   7.701 -lemma cos_n_Re_cis_pow_n: "cos (real n * a) = Re(cis a ^ n)"
   7.702 -by (auto simp add: DeMoivre)
   7.703 -
   7.704 -lemma sin_n_Im_cis_pow_n: "sin (real n * a) = Im(cis a ^ n)"
   7.705 -by (auto simp add: DeMoivre)
   7.706 -
   7.707 -lemma expi_add: "expi(a + b) = expi(a) * expi(b)"
   7.708 -by (simp add: expi_def exp_add cis_mult [symmetric] mult_ac)
   7.709 -
   7.710 -lemma expi_zero [simp]: "expi (0::complex) = 1"
   7.711 -by (simp add: expi_def)
   7.712 -
   7.713 -lemma complex_expi_Ex: "\<exists>a r. z = complex_of_real r * expi a"
   7.714 -apply (insert rcis_Ex [of z])
   7.715 -apply (auto simp add: expi_def rcis_def mult_assoc [symmetric])
   7.716 -apply (rule_tac x = "ii * complex_of_real a" in exI, auto)
   7.717 -done
   7.718 -
   7.719 -lemma expi_two_pi_i [simp]: "expi((2::complex) * complex_of_real pi * ii) = 1"
   7.720 -by (simp add: expi_def cis_def)
   7.721 -
   7.722 -end
     8.1 --- a/src/HOL/Complex/Complex_Main.thy	Wed Dec 03 09:53:58 2008 +0100
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,22 +0,0 @@
     8.4 -(*  Title:      HOL/Complex/Complex_Main.thy
     8.5 -    ID:         $Id$
     8.6 -    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     8.7 -    Copyright   2003  University of Cambridge
     8.8 -*)
     8.9 -
    8.10 -header{*Comprehensive Complex Theory*}
    8.11 -
    8.12 -theory Complex_Main
    8.13 -imports
    8.14 -  "../Main"
    8.15 -  "../Real/ContNotDenum"
    8.16 -  "../Real/Real"
    8.17 -  Fundamental_Theorem_Algebra
    8.18 -  "../Hyperreal/Log"
    8.19 -  "../Hyperreal/Ln"
    8.20 -  "../Hyperreal/Taylor"
    8.21 -  "../Hyperreal/Integration"
    8.22 -  "../Hyperreal/FrechetDeriv"
    8.23 -begin
    8.24 -
    8.25 -end
     9.1 --- a/src/HOL/Complex/Fundamental_Theorem_Algebra.thy	Wed Dec 03 09:53:58 2008 +0100
     9.2 +++ b/src/HOL/Complex/Fundamental_Theorem_Algebra.thy	Wed Dec 03 15:58:44 2008 +0100
     9.3 @@ -1,12 +1,11 @@
     9.4  (*  Title:       Fundamental_Theorem_Algebra.thy
     9.5 -    ID:          $Id$
     9.6      Author:      Amine Chaieb
     9.7  *)
     9.8  
     9.9  header{*Fundamental Theorem of Algebra*}
    9.10  
    9.11  theory Fundamental_Theorem_Algebra
    9.12 -imports "~~/src/HOL/Library/Univ_Poly" "~~/src/HOL/Library/Dense_Linear_Order" Complex
    9.13 +imports "~~/src/HOL/Univ_Poly" "~~/src/HOL/Library/Dense_Linear_Order" "~~/src/HOL/Complex"
    9.14  begin
    9.15  
    9.16  subsection {* Square root of complex numbers *}
    10.1 --- a/src/HOL/Complex/ex/Arithmetic_Series_Complex.thy	Wed Dec 03 09:53:58 2008 +0100
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,24 +0,0 @@
    10.4 -(*  Title:      HOL/Complex/ex/Arithmetic_Series_Complex
    10.5 -    ID:         $Id$
    10.6 -    Author:     Benjamin Porter, 2006
    10.7 -*)
    10.8 -
    10.9 -
   10.10 -header {* Arithmetic Series for Reals *}
   10.11 -
   10.12 -theory Arithmetic_Series_Complex
   10.13 -imports Complex_Main 
   10.14 -begin
   10.15 -
   10.16 -lemma arith_series_real:
   10.17 -  "(2::real) * (\<Sum>i\<in>{..<n}. a + of_nat i * d) =
   10.18 -  of_nat n * (a + (a + of_nat(n - 1)*d))"
   10.19 -proof -
   10.20 -  have
   10.21 -    "((1::real) + 1) * (\<Sum>i\<in>{..<n}. a + of_nat(i)*d) =
   10.22 -    of_nat(n) * (a + (a + of_nat(n - 1)*d))"
   10.23 -    by (rule arith_series_general)
   10.24 -  thus ?thesis by simp
   10.25 -qed
   10.26 -
   10.27 -end
    11.1 --- a/src/HOL/Complex/ex/BigO_Complex.thy	Wed Dec 03 09:53:58 2008 +0100
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,50 +0,0 @@
    11.4 -(*  Title:      HOL/Complex/ex/BigO_Complex.thy
    11.5 -    ID:		$Id$
    11.6 -    Authors:    Jeremy Avigad and Kevin Donnelly
    11.7 -*)
    11.8 -
    11.9 -header {* Big O notation -- continued *}
   11.10 -
   11.11 -theory BigO_Complex
   11.12 -imports BigO Complex
   11.13 -begin
   11.14 -
   11.15 -text {*
   11.16 -  Additional lemmas that require the \texttt{HOL-Complex} logic image.
   11.17 -*}
   11.18 -
   11.19 -lemma bigo_LIMSEQ1: "f =o O(g) ==> g ----> 0 ==> f ----> (0::real)"
   11.20 -  apply (simp add: LIMSEQ_def bigo_alt_def)
   11.21 -  apply clarify
   11.22 -  apply (drule_tac x = "r / c" in spec)
   11.23 -  apply (drule mp)
   11.24 -  apply (erule divide_pos_pos)
   11.25 -  apply assumption
   11.26 -  apply clarify
   11.27 -  apply (rule_tac x = no in exI)
   11.28 -  apply (rule allI)
   11.29 -  apply (drule_tac x = n in spec)+
   11.30 -  apply (rule impI)
   11.31 -  apply (drule mp)
   11.32 -  apply assumption
   11.33 -  apply (rule order_le_less_trans)
   11.34 -  apply assumption
   11.35 -  apply (rule order_less_le_trans)
   11.36 -  apply (subgoal_tac "c * abs(g n) < c * (r / c)")
   11.37 -  apply assumption
   11.38 -  apply (erule mult_strict_left_mono)
   11.39 -  apply assumption
   11.40 -  apply simp
   11.41 -done
   11.42 -
   11.43 -lemma bigo_LIMSEQ2: "f =o g +o O(h) ==> h ----> 0 ==> f ----> a 
   11.44 -    ==> g ----> (a::real)"
   11.45 -  apply (drule set_plus_imp_minus)
   11.46 -  apply (drule bigo_LIMSEQ1)
   11.47 -  apply assumption
   11.48 -  apply (simp only: fun_diff_def)
   11.49 -  apply (erule LIMSEQ_diff_approach_zero2)
   11.50 -  apply assumption
   11.51 -done
   11.52 -
   11.53 -end
    12.1 --- a/src/HOL/Complex/ex/BinEx.thy	Wed Dec 03 09:53:58 2008 +0100
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,399 +0,0 @@
    12.4 -(*  Title:      HOL/Complex/ex/BinEx.thy
    12.5 -    ID:         $Id$
    12.6 -    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
    12.7 -    Copyright   1999  University of Cambridge
    12.8 -*)
    12.9 -
   12.10 -header {* Binary arithmetic examples *}
   12.11 -
   12.12 -theory BinEx
   12.13 -imports Complex_Main
   12.14 -begin
   12.15 -
   12.16 -text {*
   12.17 -  Examples of performing binary arithmetic by simplification.  This time
   12.18 -  we use the reals, though the representation is just of integers.
   12.19 -*}
   12.20 -
   12.21 -subsection{*Real Arithmetic*}
   12.22 -
   12.23 -subsubsection {*Addition *}
   12.24 -
   12.25 -lemma "(1359::real) + -2468 = -1109"
   12.26 -by simp
   12.27 -
   12.28 -lemma "(93746::real) + -46375 = 47371"
   12.29 -by simp
   12.30 -
   12.31 -
   12.32 -subsubsection {*Negation *}
   12.33 -
   12.34 -lemma "- (65745::real) = -65745"
   12.35 -by simp
   12.36 -
   12.37 -lemma "- (-54321::real) = 54321"
   12.38 -by simp
   12.39 -
   12.40 -
   12.41 -subsubsection {*Multiplication *}
   12.42 -
   12.43 -lemma "(-84::real) * 51 = -4284"
   12.44 -by simp
   12.45 -
   12.46 -lemma "(255::real) * 255 = 65025"
   12.47 -by simp
   12.48 -
   12.49 -lemma "(1359::real) * -2468 = -3354012"
   12.50 -by simp
   12.51 -
   12.52 -
   12.53 -subsubsection {*Inequalities *}
   12.54 -
   12.55 -lemma "(89::real) * 10 \<noteq> 889"
   12.56 -by simp
   12.57 -
   12.58 -lemma "(13::real) < 18 - 4"
   12.59 -by simp
   12.60 -
   12.61 -lemma "(-345::real) < -242 + -100"
   12.62 -by simp
   12.63 -
   12.64 -lemma "(13557456::real) < 18678654"
   12.65 -by simp
   12.66 -
   12.67 -lemma "(999999::real) \<le> (1000001 + 1) - 2"
   12.68 -by simp
   12.69 -
   12.70 -lemma "(1234567::real) \<le> 1234567"
   12.71 -by simp
   12.72 -
   12.73 -
   12.74 -subsubsection {*Powers *}
   12.75 -
   12.76 -lemma "2 ^ 15 = (32768::real)"
   12.77 -by simp
   12.78 -
   12.79 -lemma "-3 ^ 7 = (-2187::real)"
   12.80 -by simp
   12.81 -
   12.82 -lemma "13 ^ 7 = (62748517::real)"
   12.83 -by simp
   12.84 -
   12.85 -lemma "3 ^ 15 = (14348907::real)"
   12.86 -by simp
   12.87 -
   12.88 -lemma "-5 ^ 11 = (-48828125::real)"
   12.89 -by simp
   12.90 -
   12.91 -
   12.92 -subsubsection {*Tests *}
   12.93 -
   12.94 -lemma "(x + y = x) = (y = (0::real))"
   12.95 -by arith
   12.96 -
   12.97 -lemma "(x + y = y) = (x = (0::real))"
   12.98 -by arith
   12.99 -
  12.100 -lemma "(x + y = (0::real)) = (x = -y)"
  12.101 -by arith
  12.102 -
  12.103 -lemma "(x + y = (0::real)) = (y = -x)"
  12.104 -by arith
  12.105 -
  12.106 -lemma "((x + y) < (x + z)) = (y < (z::real))"
  12.107 -by arith
  12.108 -
  12.109 -lemma "((x + z) < (y + z)) = (x < (y::real))"
  12.110 -by arith
  12.111 -
  12.112 -lemma "(\<not> x < y) = (y \<le> (x::real))"
  12.113 -by arith
  12.114 -
  12.115 -lemma "\<not> (x < y \<and> y < (x::real))"
  12.116 -by arith
  12.117 -
  12.118 -lemma "(x::real) < y ==> \<not> y < x"
  12.119 -by arith
  12.120 -
  12.121 -lemma "((x::real) \<noteq> y) = (x < y \<or> y < x)"
  12.122 -by arith
  12.123 -
  12.124 -lemma "(\<not> x \<le> y) = (y < (x::real))"
  12.125 -by arith
  12.126 -
  12.127 -lemma "x \<le> y \<or> y \<le> (x::real)"
  12.128 -by arith
  12.129 -
  12.130 -lemma "x \<le> y \<or> y < (x::real)"
  12.131 -by arith
  12.132 -
  12.133 -lemma "x < y \<or> y \<le> (x::real)"
  12.134 -by arith
  12.135 -
  12.136 -lemma "x \<le> (x::real)"
  12.137 -by arith
  12.138 -
  12.139 -lemma "((x::real) \<le> y) = (x < y \<or> x = y)"
  12.140 -by arith
  12.141 -
  12.142 -lemma "((x::real) \<le> y \<and> y \<le> x) = (x = y)"
  12.143 -by arith
  12.144 -
  12.145 -lemma "\<not>(x < y \<and> y \<le> (x::real))"
  12.146 -by arith
  12.147 -
  12.148 -lemma "\<not>(x \<le> y \<and> y < (x::real))"
  12.149 -by arith
  12.150 -
  12.151 -lemma "(-x < (0::real)) = (0 < x)"
  12.152 -by arith
  12.153 -
  12.154 -lemma "((0::real) < -x) = (x < 0)"
  12.155 -by arith
  12.156 -
  12.157 -lemma "(-x \<le> (0::real)) = (0 \<le> x)"
  12.158 -by arith
  12.159 -
  12.160 -lemma "((0::real) \<le> -x) = (x \<le> 0)"
  12.161 -by arith
  12.162 -
  12.163 -lemma "(x::real) = y \<or> x < y \<or> y < x"
  12.164 -by arith
  12.165 -
  12.166 -lemma "(x::real) = 0 \<or> 0 < x \<or> 0 < -x"
  12.167 -by arith
  12.168 -
  12.169 -lemma "(0::real) \<le> x \<or> 0 \<le> -x"
  12.170 -by arith
  12.171 -
  12.172 -lemma "((x::real) + y \<le> x + z) = (y \<le> z)"
  12.173 -by arith
  12.174 -
  12.175 -lemma "((x::real) + z \<le> y + z) = (x \<le> y)"
  12.176 -by arith
  12.177 -
  12.178 -lemma "(w::real) < x \<and> y < z ==> w + y < x + z"
  12.179 -by arith
  12.180 -
  12.181 -lemma "(w::real) \<le> x \<and> y \<le> z ==> w + y \<le> x + z"
  12.182 -by arith
  12.183 -
  12.184 -lemma "(0::real) \<le> x \<and> 0 \<le> y ==> 0 \<le> x + y"
  12.185 -by arith
  12.186 -
  12.187 -lemma "(0::real) < x \<and> 0 < y ==> 0 < x + y"
  12.188 -by arith
  12.189 -
  12.190 -lemma "(-x < y) = (0 < x + (y::real))"
  12.191 -by arith
  12.192 -
  12.193 -lemma "(x < -y) = (x + y < (0::real))"
  12.194 -by arith
  12.195 -
  12.196 -lemma "(y < x + -z) = (y + z < (x::real))"
  12.197 -by arith
  12.198 -
  12.199 -lemma "(x + -y < z) = (x < z + (y::real))"
  12.200 -by arith
  12.201 -
  12.202 -lemma "x \<le> y ==> x < y + (1::real)"
  12.203 -by arith
  12.204 -
  12.205 -lemma "(x - y) + y = (x::real)"
  12.206 -by arith
  12.207 -
  12.208 -lemma "y + (x - y) = (x::real)"
  12.209 -by arith
  12.210 -
  12.211 -lemma "x - x = (0::real)"
  12.212 -by arith
  12.213 -
  12.214 -lemma "(x - y = 0) = (x = (y::real))"
  12.215 -by arith
  12.216 -
  12.217 -lemma "((0::real) \<le> x + x) = (0 \<le> x)"
  12.218 -by arith
  12.219 -
  12.220 -lemma "(-x \<le> x) = ((0::real) \<le> x)"
  12.221 -by arith
  12.222 -
  12.223 -lemma "(x \<le> -x) = (x \<le> (0::real))"
  12.224 -by arith
  12.225 -
  12.226 -lemma "(-x = (0::real)) = (x = 0)"
  12.227 -by arith
  12.228 -
  12.229 -lemma "-(x - y) = y - (x::real)"
  12.230 -by arith
  12.231 -
  12.232 -lemma "((0::real) < x - y) = (y < x)"
  12.233 -by arith
  12.234 -
  12.235 -lemma "((0::real) \<le> x - y) = (y \<le> x)"
  12.236 -by arith
  12.237 -
  12.238 -lemma "(x + y) - x = (y::real)"
  12.239 -by arith
  12.240 -
  12.241 -lemma "(-x = y) = (x = (-y::real))"
  12.242 -by arith
  12.243 -
  12.244 -lemma "x < (y::real) ==> \<not>(x = y)"
  12.245 -by arith
  12.246 -
  12.247 -lemma "(x \<le> x + y) = ((0::real) \<le> y)"
  12.248 -by arith
  12.249 -
  12.250 -lemma "(y \<le> x + y) = ((0::real) \<le> x)"
  12.251 -by arith
  12.252 -
  12.253 -lemma "(x < x + y) = ((0::real) < y)"
  12.254 -by arith
  12.255 -
  12.256 -lemma "(y < x + y) = ((0::real) < x)"
  12.257 -by arith
  12.258 -
  12.259 -lemma "(x - y) - x = (-y::real)"
  12.260 -by arith
  12.261 -
  12.262 -lemma "(x + y < z) = (x < z - (y::real))"
  12.263 -by arith
  12.264 -
  12.265 -lemma "(x - y < z) = (x < z + (y::real))"
  12.266 -by arith
  12.267 -
  12.268 -lemma "(x < y - z) = (x + z < (y::real))"
  12.269 -by arith
  12.270 -
  12.271 -lemma "(x \<le> y - z) = (x + z \<le> (y::real))"
  12.272 -by arith
  12.273 -
  12.274 -lemma "(x - y \<le> z) = (x \<le> z + (y::real))"
  12.275 -by arith
  12.276 -
  12.277 -lemma "(-x < -y) = (y < (x::real))"
  12.278 -by arith
  12.279 -
  12.280 -lemma "(-x \<le> -y) = (y \<le> (x::real))"
  12.281 -by arith
  12.282 -
  12.283 -lemma "(a + b) - (c + d) = (a - c) + (b - (d::real))"
  12.284 -by arith
  12.285 -
  12.286 -lemma "(0::real) - x = -x"
  12.287 -by arith
  12.288 -
  12.289 -lemma "x - (0::real) = x"
  12.290 -by arith
  12.291 -
  12.292 -lemma "w \<le> x \<and> y < z ==> w + y < x + (z::real)"
  12.293 -by arith
  12.294 -
  12.295 -lemma "w < x \<and> y \<le> z ==> w + y < x + (z::real)"
  12.296 -by arith
  12.297 -
  12.298 -lemma "(0::real) \<le> x \<and> 0 < y ==> 0 < x + (y::real)"
  12.299 -by arith
  12.300 -
  12.301 -lemma "(0::real) < x \<and> 0 \<le> y ==> 0 < x + y"
  12.302 -by arith
  12.303 -
  12.304 -lemma "-x - y = -(x + (y::real))"
  12.305 -by arith
  12.306 -
  12.307 -lemma "x - (-y) = x + (y::real)"
  12.308 -by arith
  12.309 -
  12.310 -lemma "-x - -y = y - (x::real)"
  12.311 -by arith
  12.312 -
  12.313 -lemma "(a - b) + (b - c) = a - (c::real)"
  12.314 -by arith
  12.315 -
  12.316 -lemma "(x = y - z) = (x + z = (y::real))"
  12.317 -by arith
  12.318 -
  12.319 -lemma "(x - y = z) = (x = z + (y::real))"
  12.320 -by arith
  12.321 -
  12.322 -lemma "x - (x - y) = (y::real)"
  12.323 -by arith
  12.324 -
  12.325 -lemma "x - (x + y) = -(y::real)"
  12.326 -by arith
  12.327 -
  12.328 -lemma "x = y ==> x \<le> (y::real)"
  12.329 -by arith
  12.330 -
  12.331 -lemma "(0::real) < x ==> \<not>(x = 0)"
  12.332 -by arith
  12.333 -
  12.334 -lemma "(x + y) * (x - y) = (x * x) - (y * y)"
  12.335 -  oops
  12.336 -
  12.337 -lemma "(-x = -y) = (x = (y::real))"
  12.338 -by arith
  12.339 -
  12.340 -lemma "(-x < -y) = (y < (x::real))"
  12.341 -by arith
  12.342 -
  12.343 -lemma "!!a::real. a \<le> b ==> c \<le> d ==> x + y < z ==> a + c \<le> b + d"
  12.344 -by (tactic "fast_arith_tac @{context} 1")
  12.345 -
  12.346 -lemma "!!a::real. a < b ==> c < d ==> a - d \<le> b + (-c)"
  12.347 -by (tactic "fast_arith_tac @{context} 1")
  12.348 -
  12.349 -lemma "!!a::real. a \<le> b ==> b + b \<le> c ==> a + a \<le> c"
  12.350 -by (tactic "fast_arith_tac @{context} 1")
  12.351 -
  12.352 -lemma "!!a::real. a + b \<le> i + j ==> a \<le> b ==> i \<le> j ==> a + a \<le> j + j"
  12.353 -by (tactic "fast_arith_tac @{context} 1")
  12.354 -
  12.355 -lemma "!!a::real. a + b < i + j ==> a < b ==> i < j ==> a + a < j + j"
  12.356 -by (tactic "fast_arith_tac @{context} 1")
  12.357 -
  12.358 -lemma "!!a::real. a + b + c \<le> i + j + k \<and> a \<le> b \<and> b \<le> c \<and> i \<le> j \<and> j \<le> k --> a + a + a \<le> k + k + k"
  12.359 -by arith
  12.360 -
  12.361 -lemma "!!a::real. a + b + c + d \<le> i + j + k + l ==> a \<le> b ==> b \<le> c
  12.362 -    ==> c \<le> d ==> i \<le> j ==> j \<le> k ==> k \<le> l ==> a \<le> l"
  12.363 -by (tactic "fast_arith_tac @{context} 1")
  12.364 -
  12.365 -lemma "!!a::real. a + b + c + d \<le> i + j + k + l ==> a \<le> b ==> b \<le> c
  12.366 -    ==> c \<le> d ==> i \<le> j ==> j \<le> k ==> k \<le> l ==> a + a + a + a \<le> l + l + l + l"
  12.367 -by (tactic "fast_arith_tac @{context} 1")
  12.368 -
  12.369 -lemma "!!a::real. a + b + c + d \<le> i + j + k + l ==> a \<le> b ==> b \<le> c
  12.370 -    ==> c \<le> d ==> i \<le> j ==> j \<le> k ==> k \<le> l ==> a + a + a + a + a \<le> l + l + l + l + i"
  12.371 -by (tactic "fast_arith_tac @{context} 1")
  12.372 -
  12.373 -lemma "!!a::real. a + b + c + d \<le> i + j + k + l ==> a \<le> b ==> b \<le> c
  12.374 -    ==> c \<le> d ==> i \<le> j ==> j \<le> k ==> k \<le> l ==> a + a + a + a + a + a \<le> l + l + l + l + i + l"
  12.375 -by (tactic "fast_arith_tac @{context} 1")
  12.376 -
  12.377 -
  12.378 -subsection{*Complex Arithmetic*}
  12.379 -
  12.380 -lemma "(1359 + 93746*ii) - (2468 + 46375*ii) = -1109 + 47371*ii"
  12.381 -by simp
  12.382 -
  12.383 -lemma "- (65745 + -47371*ii) = -65745 + 47371*ii"
  12.384 -by simp
  12.385 -
  12.386 -text{*Multiplication requires distributive laws.  Perhaps versions instantiated
  12.387 -to literal constants should be added to the simpset.*}
  12.388 -
  12.389 -lemma "(1 + ii) * (1 - ii) = 2"
  12.390 -by (simp add: ring_distribs)
  12.391 -
  12.392 -lemma "(1 + 2*ii) * (1 + 3*ii) = -5 + 5*ii"
  12.393 -by (simp add: ring_distribs)
  12.394 -
  12.395 -lemma "(-84 + 255*ii) + (51 * 255*ii) = -84 + 13260 * ii"
  12.396 -by (simp add: ring_distribs)
  12.397 -
  12.398 -text{*No inequalities or linear arithmetic: the complex numbers are unordered!*}
  12.399 -
  12.400 -text{*No powers (not supported yet)*}
  12.401 -
  12.402 -end
    13.1 --- a/src/HOL/Complex/ex/HarmonicSeries.thy	Wed Dec 03 09:53:58 2008 +0100
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,323 +0,0 @@
    13.4 -(*  Title:      HOL/Library/HarmonicSeries.thy
    13.5 -    ID:         $Id$
    13.6 -    Author:     Benjamin Porter, 2006
    13.7 -*)
    13.8 -
    13.9 -header {* Divergence of the Harmonic Series *}
   13.10 -
   13.11 -theory HarmonicSeries
   13.12 -imports Complex_Main
   13.13 -begin
   13.14 -
   13.15 -section {* Abstract *}
   13.16 -
   13.17 -text {* The following document presents a proof of the Divergence of
   13.18 -Harmonic Series theorem formalised in the Isabelle/Isar theorem
   13.19 -proving system.
   13.20 -
   13.21 -{\em Theorem:} The series $\sum_{n=1}^{\infty} \frac{1}{n}$ does not
   13.22 -converge to any number.
   13.23 -
   13.24 -{\em Informal Proof:}
   13.25 -  The informal proof is based on the following auxillary lemmas:
   13.26 -  \begin{itemize}
   13.27 -  \item{aux: $\sum_{n=2^m-1}^{2^m} \frac{1}{n} \geq \frac{1}{2}$}
   13.28 -  \item{aux2: $\sum_{n=1}^{2^M} \frac{1}{n} = 1 + \sum_{m=1}^{M} \sum_{n=2^m-1}^{2^m} \frac{1}{n}$}
   13.29 -  \end{itemize}
   13.30 -
   13.31 -  From {\em aux} and {\em aux2} we can deduce that $\sum_{n=1}^{2^M}
   13.32 -  \frac{1}{n} \geq 1 + \frac{M}{2}$ for all $M$.
   13.33 -  Now for contradiction, assume that $\sum_{n=1}^{\infty} \frac{1}{n}
   13.34 -  = s$ for some $s$. Because $\forall n. \frac{1}{n} > 0$ all the
   13.35 -  partial sums in the series must be less than $s$. However with our
   13.36 -  deduction above we can choose $N > 2*s - 2$ and thus
   13.37 -  $\sum_{n=1}^{2^N} \frac{1}{n} > s$. This leads to a contradiction
   13.38 -  and hence $\sum_{n=1}^{\infty} \frac{1}{n}$ is not summable.
   13.39 -  QED.
   13.40 -*}
   13.41 -
   13.42 -section {* Formal Proof *}
   13.43 -
   13.44 -lemma two_pow_sub:
   13.45 -  "0 < m \<Longrightarrow> (2::nat)^m - 2^(m - 1) = 2^(m - 1)"
   13.46 -  by (induct m) auto
   13.47 -
   13.48 -text {* We first prove the following auxillary lemma. This lemma
   13.49 -simply states that the finite sums: $\frac{1}{2}$, $\frac{1}{3} +
   13.50 -\frac{1}{4}$, $\frac{1}{5} + \frac{1}{6} + \frac{1}{7} + \frac{1}{8}$
   13.51 -etc. are all greater than or equal to $\frac{1}{2}$. We do this by
   13.52 -observing that each term in the sum is greater than or equal to the
   13.53 -last term, e.g. $\frac{1}{3} > \frac{1}{4}$ and thus $\frac{1}{3} +
   13.54 -\frac{1}{4} > \frac{1}{4} + \frac{1}{4} = \frac{1}{2}$. *}
   13.55 -
   13.56 -lemma harmonic_aux:
   13.57 -  "\<forall>m>0. (\<Sum>n\<in>{(2::nat)^(m - 1)+1..2^m}. 1/real n) \<ge> 1/2"
   13.58 -  (is "\<forall>m>0. (\<Sum>n\<in>(?S m). 1/real n) \<ge> 1/2")
   13.59 -proof
   13.60 -  fix m::nat
   13.61 -  obtain tm where tmdef: "tm = (2::nat)^m" by simp
   13.62 -  {
   13.63 -    assume mgt0: "0 < m"
   13.64 -    have "\<And>x. x\<in>(?S m) \<Longrightarrow> 1/(real x) \<ge> 1/(real tm)"
   13.65 -    proof -
   13.66 -      fix x::nat
   13.67 -      assume xs: "x\<in>(?S m)"
   13.68 -      have xgt0: "x>0"
   13.69 -      proof -
   13.70 -        from xs have
   13.71 -          "x \<ge> 2^(m - 1) + 1" by auto
   13.72 -        moreover with mgt0 have
   13.73 -          "2^(m - 1) + 1 \<ge> (1::nat)" by auto
   13.74 -        ultimately have
   13.75 -          "x \<ge> 1" by (rule xtrans)
   13.76 -        thus ?thesis by simp
   13.77 -      qed
   13.78 -      moreover from xs have "x \<le> 2^m" by auto
   13.79 -      ultimately have
   13.80 -        "inverse (real x) \<ge> inverse (real ((2::nat)^m))" by simp
   13.81 -      moreover
   13.82 -      from xgt0 have "real x \<noteq> 0" by simp
   13.83 -      then have
   13.84 -        "inverse (real x) = 1 / (real x)"
   13.85 -        by (rule nonzero_inverse_eq_divide)
   13.86 -      moreover from mgt0 have "real tm \<noteq> 0" by (simp add: tmdef)
   13.87 -      then have
   13.88 -        "inverse (real tm) = 1 / (real tm)"
   13.89 -        by (rule nonzero_inverse_eq_divide)
   13.90 -      ultimately show
   13.91 -        "1/(real x) \<ge> 1/(real tm)" by (auto simp add: tmdef)
   13.92 -    qed
   13.93 -    then have
   13.94 -      "(\<Sum>n\<in>(?S m). 1 / real n) \<ge> (\<Sum>n\<in>(?S m). 1/(real tm))"
   13.95 -      by (rule setsum_mono)
   13.96 -    moreover have
   13.97 -      "(\<Sum>n\<in>(?S m). 1/(real tm)) = 1/2"
   13.98 -    proof -
   13.99 -      have
  13.100 -        "(\<Sum>n\<in>(?S m). 1/(real tm)) =
  13.101 -         (1/(real tm))*(\<Sum>n\<in>(?S m). 1)"
  13.102 -        by simp
  13.103 -      also have
  13.104 -        "\<dots> = ((1/(real tm)) * real (card (?S m)))"
  13.105 -        by (simp add: real_of_card real_of_nat_def)
  13.106 -      also have
  13.107 -        "\<dots> = ((1/(real tm)) * real (tm - (2^(m - 1))))"
  13.108 -        by (simp add: tmdef)
  13.109 -      also from mgt0 have
  13.110 -        "\<dots> = ((1/(real tm)) * real ((2::nat)^(m - 1)))"
  13.111 -        by (auto simp: tmdef dest: two_pow_sub)
  13.112 -      also have
  13.113 -        "\<dots> = (real (2::nat))^(m - 1) / (real (2::nat))^m"
  13.114 -        by (simp add: tmdef realpow_real_of_nat [symmetric])
  13.115 -      also from mgt0 have
  13.116 -        "\<dots> = (real (2::nat))^(m - 1) / (real (2::nat))^((m - 1) + 1)"
  13.117 -        by auto
  13.118 -      also have "\<dots> = 1/2" by simp
  13.119 -      finally show ?thesis .
  13.120 -    qed
  13.121 -    ultimately have
  13.122 -      "(\<Sum>n\<in>(?S m). 1 / real n) \<ge> 1/2"
  13.123 -      by - (erule subst)
  13.124 -  }
  13.125 -  thus "0 < m \<longrightarrow> 1 / 2 \<le> (\<Sum>n\<in>(?S m). 1 / real n)" by simp
  13.126 -qed
  13.127 -
  13.128 -text {* We then show that the sum of a finite number of terms from the
  13.129 -harmonic series can be regrouped in increasing powers of 2. For
  13.130 -example: $1 + \frac{1}{2} + \frac{1}{3} + \frac{1}{4} + \frac{1}{5} +
  13.131 -\frac{1}{6} + \frac{1}{7} + \frac{1}{8} = 1 + (\frac{1}{2}) +
  13.132 -(\frac{1}{3} + \frac{1}{4}) + (\frac{1}{5} + \frac{1}{6} + \frac{1}{7}
  13.133 -+ \frac{1}{8})$. *}
  13.134 -
  13.135 -lemma harmonic_aux2 [rule_format]:
  13.136 -  "0<M \<Longrightarrow> (\<Sum>n\<in>{1..(2::nat)^M}. 1/real n) =
  13.137 -   (1 + (\<Sum>m\<in>{1..M}. \<Sum>n\<in>{(2::nat)^(m - 1)+1..2^m}. 1/real n))"
  13.138 -  (is "0<M \<Longrightarrow> ?LHS M = ?RHS M")
  13.139 -proof (induct M)
  13.140 -  case 0 show ?case by simp
  13.141 -next
  13.142 -  case (Suc M)
  13.143 -  have ant: "0 < Suc M" by fact
  13.144 -  {
  13.145 -    have suc: "?LHS (Suc M) = ?RHS (Suc M)"
  13.146 -    proof cases -- "show that LHS = c and RHS = c, and thus LHS = RHS"
  13.147 -      assume mz: "M=0"
  13.148 -      {
  13.149 -        then have
  13.150 -          "?LHS (Suc M) = ?LHS 1" by simp
  13.151 -        also have
  13.152 -          "\<dots> = (\<Sum>n\<in>{(1::nat)..2}. 1/real n)" by simp
  13.153 -        also have
  13.154 -          "\<dots> = ((\<Sum>n\<in>{Suc 1..2}. 1/real n) + 1/(real (1::nat)))"
  13.155 -          by (subst setsum_head)
  13.156 -             (auto simp: atLeastSucAtMost_greaterThanAtMost)
  13.157 -        also have
  13.158 -          "\<dots> = ((\<Sum>n\<in>{2..2::nat}. 1/real n) + 1/(real (1::nat)))"
  13.159 -          by (simp add: nat_number)
  13.160 -        also have
  13.161 -          "\<dots> =  1/(real (2::nat)) + 1/(real (1::nat))" by simp
  13.162 -        finally have
  13.163 -          "?LHS (Suc M) = 1/2 + 1" by simp
  13.164 -      }
  13.165 -      moreover
  13.166 -      {
  13.167 -        from mz have
  13.168 -          "?RHS (Suc M) = ?RHS 1" by simp
  13.169 -        also have
  13.170 -          "\<dots> = (\<Sum>n\<in>{((2::nat)^0)+1..2^1}. 1/real n) + 1"
  13.171 -          by simp
  13.172 -        also have
  13.173 -          "\<dots> = (\<Sum>n\<in>{2::nat..2}. 1/real n) + 1"
  13.174 -        proof -
  13.175 -          have "(2::nat)^0 = 1" by simp
  13.176 -          then have "(2::nat)^0+1 = 2" by simp
  13.177 -          moreover have "(2::nat)^1 = 2" by simp
  13.178 -          ultimately have "{((2::nat)^0)+1..2^1} = {2::nat..2}" by auto
  13.179 -          thus ?thesis by simp
  13.180 -        qed
  13.181 -        also have
  13.182 -          "\<dots> = 1/2 + 1"
  13.183 -          by simp
  13.184 -        finally have
  13.185 -          "?RHS (Suc M) = 1/2 + 1" by simp
  13.186 -      }
  13.187 -      ultimately show "?LHS (Suc M) = ?RHS (Suc M)" by simp
  13.188 -    next
  13.189 -      assume mnz: "M\<noteq>0"
  13.190 -      then have mgtz: "M>0" by simp
  13.191 -      with Suc have suc:
  13.192 -        "(?LHS M) = (?RHS M)" by blast
  13.193 -      have
  13.194 -        "(?LHS (Suc M)) =
  13.195 -         ((?LHS M) + (\<Sum>n\<in>{(2::nat)^M+1..2^(Suc M)}. 1 / real n))"
  13.196 -      proof -
  13.197 -        have
  13.198 -          "{1..(2::nat)^(Suc M)} =
  13.199 -           {1..(2::nat)^M}\<union>{(2::nat)^M+1..(2::nat)^(Suc M)}"
  13.200 -          by auto
  13.201 -        moreover have
  13.202 -          "{1..(2::nat)^M}\<inter>{(2::nat)^M+1..(2::nat)^(Suc M)} = {}"
  13.203 -          by auto
  13.204 -        moreover have
  13.205 -          "finite {1..(2::nat)^M}" and "finite {(2::nat)^M+1..(2::nat)^(Suc M)}"
  13.206 -          by auto
  13.207 -        ultimately show ?thesis
  13.208 -          by (auto intro: setsum_Un_disjoint)
  13.209 -      qed
  13.210 -      moreover
  13.211 -      {
  13.212 -        have
  13.213 -          "(?RHS (Suc M)) =
  13.214 -           (1 + (\<Sum>m\<in>{1..M}.  \<Sum>n\<in>{(2::nat)^(m - 1)+1..2^m}. 1/real n) +
  13.215 -           (\<Sum>n\<in>{(2::nat)^(Suc M - 1)+1..2^(Suc M)}. 1/real n))" by simp
  13.216 -        also have
  13.217 -          "\<dots> = (?RHS M) + (\<Sum>n\<in>{(2::nat)^M+1..2^(Suc M)}. 1/real n)"
  13.218 -          by simp
  13.219 -        also from suc have
  13.220 -          "\<dots> = (?LHS M) +  (\<Sum>n\<in>{(2::nat)^M+1..2^(Suc M)}. 1/real n)"
  13.221 -          by simp
  13.222 -        finally have
  13.223 -          "(?RHS (Suc M)) = \<dots>" by simp
  13.224 -      }
  13.225 -      ultimately show "?LHS (Suc M) = ?RHS (Suc M)" by simp
  13.226 -    qed
  13.227 -  }
  13.228 -  thus ?case by simp
  13.229 -qed
  13.230 -
  13.231 -text {* Using @{thm [source] harmonic_aux} and @{thm [source] harmonic_aux2} we now show
  13.232 -that each group sum is greater than or equal to $\frac{1}{2}$ and thus
  13.233 -the finite sum is bounded below by a value proportional to the number
  13.234 -of elements we choose. *}
  13.235 -
  13.236 -lemma harmonic_aux3 [rule_format]:
  13.237 -  shows "\<forall>(M::nat). (\<Sum>n\<in>{1..(2::nat)^M}. 1 / real n) \<ge> 1 + (real M)/2"
  13.238 -  (is "\<forall>M. ?P M \<ge> _")
  13.239 -proof (rule allI, cases)
  13.240 -  fix M::nat
  13.241 -  assume "M=0"
  13.242 -  then show "?P M \<ge> 1 + (real M)/2" by simp
  13.243 -next
  13.244 -  fix M::nat
  13.245 -  assume "M\<noteq>0"
  13.246 -  then have "M > 0" by simp
  13.247 -  then have
  13.248 -    "(?P M) =
  13.249 -     (1 + (\<Sum>m\<in>{1..M}. \<Sum>n\<in>{(2::nat)^(m - 1)+1..2^m}. 1/real n))"
  13.250 -    by (rule harmonic_aux2)
  13.251 -  also have
  13.252 -    "\<dots> \<ge> (1 + (\<Sum>m\<in>{1..M}. 1/2))"
  13.253 -  proof -
  13.254 -    let ?f = "(\<lambda>x. 1/2)"
  13.255 -    let ?g = "(\<lambda>x. (\<Sum>n\<in>{(2::nat)^(x - 1)+1..2^x}. 1/real n))"
  13.256 -    from harmonic_aux have "\<And>x. x\<in>{1..M} \<Longrightarrow> ?f x \<le> ?g x" by simp
  13.257 -    then have "(\<Sum>m\<in>{1..M}. ?g m) \<ge> (\<Sum>m\<in>{1..M}. ?f m)" by (rule setsum_mono)
  13.258 -    thus ?thesis by simp
  13.259 -  qed
  13.260 -  finally have "(?P M) \<ge> (1 + (\<Sum>m\<in>{1..M}. 1/2))" .
  13.261 -  moreover
  13.262 -  {
  13.263 -    have
  13.264 -      "(\<Sum>m\<in>{1..M}. (1::real)/2) = 1/2 * (\<Sum>m\<in>{1..M}. 1)"
  13.265 -      by auto
  13.266 -    also have
  13.267 -      "\<dots> = 1/2*(real (card {1..M}))"
  13.268 -      by (simp only: real_of_card[symmetric])
  13.269 -    also have
  13.270 -      "\<dots> = 1/2*(real M)" by simp
  13.271 -    also have
  13.272 -      "\<dots> = (real M)/2" by simp
  13.273 -    finally have "(\<Sum>m\<in>{1..M}. (1::real)/2) = (real M)/2" .
  13.274 -  }
  13.275 -  ultimately show "(?P M) \<ge> (1 + (real M)/2)" by simp
  13.276 -qed
  13.277 -
  13.278 -text {* The final theorem shows that as we take more and more elements
  13.279 -(see @{thm [source] harmonic_aux3}) we get an ever increasing sum. By assuming
  13.280 -the sum converges, the lemma @{thm [source] series_pos_less} ( @{thm
  13.281 -series_pos_less} ) states that each sum is bounded above by the
  13.282 -series' limit. This contradicts our first statement and thus we prove
  13.283 -that the harmonic series is divergent. *}
  13.284 -
  13.285 -theorem DivergenceOfHarmonicSeries:
  13.286 -  shows "\<not>summable (\<lambda>n. 1/real (Suc n))"
  13.287 -  (is "\<not>summable ?f")
  13.288 -proof -- "by contradiction"
  13.289 -  let ?s = "suminf ?f" -- "let ?s equal the sum of the harmonic series"
  13.290 -  assume sf: "summable ?f"
  13.291 -  then obtain n::nat where ndef: "n = nat \<lceil>2 * ?s\<rceil>" by simp
  13.292 -  then have ngt: "1 + real n/2 > ?s"
  13.293 -  proof -
  13.294 -    have "\<forall>n. 0 \<le> ?f n" by simp
  13.295 -    with sf have "?s \<ge> 0"
  13.296 -      by - (rule suminf_0_le, simp_all)
  13.297 -    then have cgt0: "\<lceil>2*?s\<rceil> \<ge> 0" by simp
  13.298 -
  13.299 -    from ndef have "n = nat \<lceil>(2*?s)\<rceil>" .
  13.300 -    then have "real n = real (nat \<lceil>2*?s\<rceil>)" by simp
  13.301 -    with cgt0 have "real n = real \<lceil>2*?s\<rceil>"
  13.302 -      by (auto dest: real_nat_eq_real)
  13.303 -    then have "real n \<ge> 2*(?s)" by simp
  13.304 -    then have "real n/2 \<ge> (?s)" by simp
  13.305 -    then show "1 + real n/2 > (?s)" by simp
  13.306 -  qed
  13.307 -
  13.308 -  obtain j where jdef: "j = (2::nat)^n" by simp
  13.309 -  have "\<forall>m\<ge>j. 0 < ?f m" by simp
  13.310 -  with sf have "(\<Sum>i\<in>{0..<j}. ?f i) < ?s" by (rule series_pos_less)
  13.311 -  then have "(\<Sum>i\<in>{1..<Suc j}. 1/(real i)) < ?s"
  13.312 -    apply -
  13.313 -    apply (subst(asm) setsum_shift_bounds_Suc_ivl [symmetric])
  13.314 -    by simp
  13.315 -  with jdef have
  13.316 -    "(\<Sum>i\<in>{1..< Suc ((2::nat)^n)}. 1 / (real i)) < ?s" by simp
  13.317 -  then have
  13.318 -    "(\<Sum>i\<in>{1..(2::nat)^n}. 1 / (real i)) < ?s"
  13.319 -    by (simp only: atLeastLessThanSuc_atLeastAtMost)
  13.320 -  moreover from harmonic_aux3 have
  13.321 -    "(\<Sum>i\<in>{1..(2::nat)^n}. 1 / (real i)) \<ge> 1 + real n/2" by simp
  13.322 -  moreover from ngt have "1 + real n/2 > ?s" by simp
  13.323 -  ultimately show False by simp
  13.324 -qed
  13.325 -
  13.326 -end
  13.327 \ No newline at end of file
    14.1 --- a/src/HOL/Complex/ex/MIR.thy	Wed Dec 03 09:53:58 2008 +0100
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,5933 +0,0 @@
    14.4 -(*  Title:      Complex/ex/MIR.thy
    14.5 -    Author:     Amine Chaieb
    14.6 -*)
    14.7 -
    14.8 -theory MIR
    14.9 -imports List Real Code_Integer Efficient_Nat
   14.10 -uses ("mirtac.ML")
   14.11 -begin
   14.12 -
   14.13 -section {* Quantifier elimination for @{text "\<real> (0, 1, +, floor, <)"} *}
   14.14 -
   14.15 -declare real_of_int_floor_cancel [simp del]
   14.16 -
   14.17 -primrec alluopairs:: "'a list \<Rightarrow> ('a \<times> 'a) list" where 
   14.18 -  "alluopairs [] = []"
   14.19 -| "alluopairs (x#xs) = (map (Pair x) (x#xs))@(alluopairs xs)"
   14.20 -
   14.21 -lemma alluopairs_set1: "set (alluopairs xs) \<le> {(x,y). x\<in> set xs \<and> y\<in> set xs}"
   14.22 -by (induct xs, auto)
   14.23 -
   14.24 -lemma alluopairs_set:
   14.25 -  "\<lbrakk>x\<in> set xs ; y \<in> set xs\<rbrakk> \<Longrightarrow> (x,y) \<in> set (alluopairs xs) \<or> (y,x) \<in> set (alluopairs xs) "
   14.26 -by (induct xs, auto)
   14.27 -
   14.28 -lemma alluopairs_ex:
   14.29 -  assumes Pc: "\<forall> x y. P x y = P y x"
   14.30 -  shows "(\<exists> x \<in> set xs. \<exists> y \<in> set xs. P x y) = (\<exists> (x,y) \<in> set (alluopairs xs). P x y)"
   14.31 -proof
   14.32 -  assume "\<exists>x\<in>set xs. \<exists>y\<in>set xs. P x y"
   14.33 -  then obtain x y where x: "x \<in> set xs" and y:"y \<in> set xs" and P: "P x y"  by blast
   14.34 -  from alluopairs_set[OF x y] P Pc show"\<exists>(x, y)\<in>set (alluopairs xs). P x y" 
   14.35 -    by auto
   14.36 -next
   14.37 -  assume "\<exists>(x, y)\<in>set (alluopairs xs). P x y"
   14.38 -  then obtain "x" and "y"  where xy:"(x,y) \<in> set (alluopairs xs)" and P: "P x y" by blast+
   14.39 -  from xy have "x \<in> set xs \<and> y\<in> set xs" using alluopairs_set1 by blast
   14.40 -  with P show "\<exists>x\<in>set xs. \<exists>y\<in>set xs. P x y" by blast
   14.41 -qed
   14.42 -
   14.43 -  (* generate a list from i to j*)
   14.44 -consts iupt :: "int \<times> int \<Rightarrow> int list"
   14.45 -recdef iupt "measure (\<lambda> (i,j). nat (j-i +1))" 
   14.46 -  "iupt (i,j) = (if j <i then [] else (i# iupt(i+1, j)))"
   14.47 -
   14.48 -lemma iupt_set: "set (iupt(i,j)) = {i .. j}"
   14.49 -proof(induct rule: iupt.induct)
   14.50 -  case (1 a b)
   14.51 -  show ?case
   14.52 -    using prems by (simp add: simp_from_to)
   14.53 -qed
   14.54 -
   14.55 -lemma nth_pos2: "0 < n \<Longrightarrow> (x#xs) ! n = xs ! (n - 1)"
   14.56 -using Nat.gr0_conv_Suc
   14.57 -by clarsimp
   14.58 -
   14.59 -
   14.60 -lemma myl: "\<forall> (a::'a::{pordered_ab_group_add}) (b::'a). (a \<le> b) = (0 \<le> b - a)" 
   14.61 -proof(clarify)
   14.62 -  fix x y ::"'a"
   14.63 -  have "(x \<le> y) = (x - y \<le> 0)" by (simp only: le_iff_diff_le_0[where a="x" and b="y"])
   14.64 -  also have "\<dots> = (- (y - x) \<le> 0)" by simp
   14.65 -  also have "\<dots> = (0 \<le> y - x)" by (simp only: neg_le_0_iff_le[where a="y-x"])
   14.66 -  finally show "(x \<le> y) = (0 \<le> y - x)" .
   14.67 -qed
   14.68 -
   14.69 -lemma myless: "\<forall> (a::'a::{pordered_ab_group_add}) (b::'a). (a < b) = (0 < b - a)" 
   14.70 -proof(clarify)
   14.71 -  fix x y ::"'a"
   14.72 -  have "(x < y) = (x - y < 0)" by (simp only: less_iff_diff_less_0[where a="x" and b="y"])
   14.73 -  also have "\<dots> = (- (y - x) < 0)" by simp
   14.74 -  also have "\<dots> = (0 < y - x)" by (simp only: neg_less_0_iff_less[where a="y-x"])
   14.75 -  finally show "(x < y) = (0 < y - x)" .
   14.76 -qed
   14.77 -
   14.78 -lemma myeq: "\<forall> (a::'a::{pordered_ab_group_add}) (b::'a). (a = b) = (0 = b - a)"
   14.79 -  by auto
   14.80 -
   14.81 -  (* Maybe should be added to the library \<dots> *)
   14.82 -lemma floor_int_eq: "(real n\<le> x \<and> x < real (n+1)) = (floor x = n)"
   14.83 -proof( auto)
   14.84 -  assume lb: "real n \<le> x"
   14.85 -    and ub: "x < real n + 1"
   14.86 -  have "real (floor x) \<le> x" by simp 
   14.87 -  hence "real (floor x) < real (n + 1) " using ub by arith
   14.88 -  hence "floor x < n+1" by simp
   14.89 -  moreover from lb have "n \<le> floor x" using floor_mono2[where x="real n" and y="x"] 
   14.90 -    by simp ultimately show "floor x = n" by simp
   14.91 -qed
   14.92 -
   14.93 -(* Periodicity of dvd *)
   14.94 -lemma dvd_period:
   14.95 -  assumes advdd: "(a::int) dvd d"
   14.96 -  shows "(a dvd (x + t)) = (a dvd ((x+ c*d) + t))"
   14.97 -  using advdd  
   14.98 -proof-
   14.99 -  {fix x k
  14.100 -    from inf_period(3)[OF advdd, rule_format, where x=x and k="-k"]  
  14.101 -    have " ((a::int) dvd (x + t)) = (a dvd (x+k*d + t))" by simp}
  14.102 -  hence "\<forall>x.\<forall>k. ((a::int) dvd (x + t)) = (a dvd (x+k*d + t))"  by simp
  14.103 -  then show ?thesis by simp
  14.104 -qed
  14.105 -
  14.106 -  (* The Divisibility relation between reals *)	
  14.107 -definition
  14.108 -  rdvd:: "real \<Rightarrow> real \<Rightarrow> bool" (infixl "rdvd" 50)
  14.109 -where
  14.110 -  rdvd_def: "x rdvd y \<longleftrightarrow> (\<exists>k\<Colon>int. y = x * real k)"
  14.111 -
  14.112 -lemma int_rdvd_real: 
  14.113 -  shows "real (i::int) rdvd x = (i dvd (floor x) \<and> real (floor x) = x)" (is "?l = ?r")
  14.114 -proof
  14.115 -  assume "?l" 
  14.116 -  hence th: "\<exists> k. x=real (i*k)" by (simp add: rdvd_def)
  14.117 -  hence th': "real (floor x) = x" by (auto simp del: real_of_int_mult)
  14.118 -  with th have "\<exists> k. real (floor x) = real (i*k)" by simp
  14.119 -  hence "\<exists> k. floor x = i*k" by (simp only: real_of_int_inject)
  14.120 -  thus ?r  using th' by (simp add: dvd_def) 
  14.121 -next
  14.122 -  assume "?r" hence "(i\<Colon>int) dvd \<lfloor>x\<Colon>real\<rfloor>" ..
  14.123 -  hence "\<exists> k. real (floor x) = real (i*k)" 
  14.124 -    by (simp only: real_of_int_inject) (simp add: dvd_def)
  14.125 -  thus ?l using prems by (simp add: rdvd_def)
  14.126 -qed
  14.127 -
  14.128 -lemma int_rdvd_iff: "(real (i::int) rdvd real t) = (i dvd t)"
  14.129 -by (auto simp add: rdvd_def dvd_def) (rule_tac x="k" in exI, simp only :real_of_int_mult[symmetric])
  14.130 -
  14.131 -
  14.132 -lemma rdvd_abs1: 
  14.133 -  "(abs (real d) rdvd t) = (real (d ::int) rdvd t)"
  14.134 -proof
  14.135 -  assume d: "real d rdvd t"
  14.136 -  from d int_rdvd_real have d2: "d dvd (floor t)" and ti: "real (floor t) = t" by auto
  14.137 -
  14.138 -  from iffD2[OF zdvd_abs1] d2 have "(abs d) dvd (floor t)" by blast
  14.139 -  with ti int_rdvd_real[symmetric] have "real (abs d) rdvd t" by blast 
  14.140 -  thus "abs (real d) rdvd t" by simp
  14.141 -next
  14.142 -  assume "abs (real d) rdvd t" hence "real (abs d) rdvd t" by simp
  14.143 -  with int_rdvd_real[where i="abs d" and x="t"] have d2: "abs d dvd floor t" and ti: "real (floor t) =t" by auto
  14.144 -  from iffD1[OF zdvd_abs1] d2 have "d dvd floor t" by blast
  14.145 -  with ti int_rdvd_real[symmetric] show "real d rdvd t" by blast
  14.146 -qed
  14.147 -
  14.148 -lemma rdvd_minus: "(real (d::int) rdvd t) = (real d rdvd -t)"
  14.149 -  apply (auto simp add: rdvd_def)
  14.150 -  apply (rule_tac x="-k" in exI, simp) 
  14.151 -  apply (rule_tac x="-k" in exI, simp)
  14.152 -done
  14.153 -
  14.154 -lemma rdvd_left_0_eq: "(0 rdvd t) = (t=0)"
  14.155 -by (auto simp add: rdvd_def)
  14.156 -
  14.157 -lemma rdvd_mult: 
  14.158 -  assumes knz: "k\<noteq>0"
  14.159 -  shows "(real (n::int) * real (k::int) rdvd x * real k) = (real n rdvd x)"
  14.160 -using knz by (simp add:rdvd_def)
  14.161 -
  14.162 -lemma rdvd_trans: assumes mn:"m rdvd n" and  nk:"n rdvd k" 
  14.163 -  shows "m rdvd k"
  14.164 -proof-
  14.165 -  from rdvd_def mn obtain c where nmc:"n = m * real (c::int)" by auto
  14.166 -  from rdvd_def nk obtain c' where nkc:"k = n * real (c'::int)" by auto
  14.167 -  hence "k = m * real (c * c')" using nmc by simp
  14.168 -  thus ?thesis using rdvd_def by blast
  14.169 -qed
  14.170 -
  14.171 -  (*********************************************************************************)
  14.172 -  (****                            SHADOW SYNTAX AND SEMANTICS                  ****)
  14.173 -  (*********************************************************************************)
  14.174 -
  14.175 -datatype num = C int | Bound nat | CN nat int num | Neg num | Add num num| Sub num num 
  14.176 -  | Mul int num | Floor num| CF int num num
  14.177 -
  14.178 -  (* A size for num to make inductive proofs simpler*)
  14.179 -primrec num_size :: "num \<Rightarrow> nat" where
  14.180 - "num_size (C c) = 1"
  14.181 -| "num_size (Bound n) = 1"
  14.182 -| "num_size (Neg a) = 1 + num_size a"
  14.183 -| "num_size (Add a b) = 1 + num_size a + num_size b"
  14.184 -| "num_size (Sub a b) = 3 + num_size a + num_size b"
  14.185 -| "num_size (CN n c a) = 4 + num_size a "
  14.186 -| "num_size (CF c a b) = 4 + num_size a + num_size b"
  14.187 -| "num_size (Mul c a) = 1 + num_size a"
  14.188 -| "num_size (Floor a) = 1 + num_size a"
  14.189 -
  14.190 -  (* Semantics of numeral terms (num) *)
  14.191 -primrec Inum :: "real list \<Rightarrow> num \<Rightarrow> real" where
  14.192 -  "Inum bs (C c) = (real c)"
  14.193 -| "Inum bs (Bound n) = bs!n"
  14.194 -| "Inum bs (CN n c a) = (real c) * (bs!n) + (Inum bs a)"
  14.195 -| "Inum bs (Neg a) = -(Inum bs a)"
  14.196 -| "Inum bs (Add a b) = Inum bs a + Inum bs b"
  14.197 -| "Inum bs (Sub a b) = Inum bs a - Inum bs b"
  14.198 -| "Inum bs (Mul c a) = (real c) * Inum bs a"
  14.199 -| "Inum bs (Floor a) = real (floor (Inum bs a))"
  14.200 -| "Inum bs (CF c a b) = real c * real (floor (Inum bs a)) + Inum bs b"
  14.201 -definition "isint t bs \<equiv> real (floor (Inum bs t)) = Inum bs t"
  14.202 -
  14.203 -lemma isint_iff: "isint n bs = (real (floor (Inum bs n)) = Inum bs n)"
  14.204 -by (simp add: isint_def)
  14.205 -
  14.206 -lemma isint_Floor: "isint (Floor n) bs"
  14.207 -  by (simp add: isint_iff)
  14.208 -
  14.209 -lemma isint_Mul: "isint e bs \<Longrightarrow> isint (Mul c e) bs"
  14.210 -proof-
  14.211 -  let ?e = "Inum bs e"
  14.212 -  let ?fe = "floor ?e"
  14.213 -  assume be: "isint e bs" hence efe:"real ?fe = ?e" by (simp add: isint_iff)
  14.214 -  have "real ((floor (Inum bs (Mul c e)))) = real (floor (real (c * ?fe)))" using efe by simp
  14.215 -  also have "\<dots> = real (c* ?fe)" by (simp only: floor_real_of_int) 
  14.216 -  also have "\<dots> = real c * ?e" using efe by simp
  14.217 -  finally show ?thesis using isint_iff by simp
  14.218 -qed
  14.219 -
  14.220 -lemma isint_neg: "isint e bs \<Longrightarrow> isint (Neg e) bs"
  14.221 -proof-
  14.222 -  let ?I = "\<lambda> t. Inum bs t"
  14.223 -  assume ie: "isint e bs"
  14.224 -  hence th: "real (floor (?I e)) = ?I e" by (simp add: isint_def)  
  14.225 -  have "real (floor (?I (Neg e))) = real (floor (- (real (floor (?I e)))))" by (simp add: th)
  14.226 -  also have "\<dots> = - real (floor (?I e))" by(simp add: floor_minus_real_of_int) 
  14.227 -  finally show "isint (Neg e) bs" by (simp add: isint_def th)
  14.228 -qed
  14.229 -
  14.230 -lemma isint_sub: 
  14.231 -  assumes ie: "isint e bs" shows "isint (Sub (C c) e) bs"
  14.232 -proof-
  14.233 -  let ?I = "\<lambda> t. Inum bs t"
  14.234 -  from ie have th: "real (floor (?I e)) = ?I e" by (simp add: isint_def)  
  14.235 -  have "real (floor (?I (Sub (C c) e))) = real (floor ((real (c -floor (?I e)))))" by (simp add: th)
  14.236 -  also have "\<dots> = real (c- floor (?I e))" by(simp add: floor_minus_real_of_int) 
  14.237 -  finally show "isint (Sub (C c) e) bs" by (simp add: isint_def th)
  14.238 -qed
  14.239 -
  14.240 -lemma isint_add: assumes
  14.241 -  ai:"isint a bs" and bi: "isint b bs" shows "isint (Add a b) bs"
  14.242 -proof-
  14.243 -  let ?a = "Inum bs a"
  14.244 -  let ?b = "Inum bs b"
  14.245 -  from ai bi isint_iff have "real (floor (?a + ?b)) = real (floor (real (floor ?a) + real (floor ?b)))" by simp
  14.246 -  also have "\<dots> = real (floor ?a) + real (floor ?b)" by simp
  14.247 -  also have "\<dots> = ?a + ?b" using ai bi isint_iff by simp
  14.248 -  finally show "isint (Add a b) bs" by (simp add: isint_iff)
  14.249 -qed
  14.250 -
  14.251 -lemma isint_c: "isint (C j) bs"
  14.252 -  by (simp add: isint_iff)
  14.253 -
  14.254 -
  14.255 -    (* FORMULAE *)
  14.256 -datatype fm  = 
  14.257 -  T| F| Lt num| Le num| Gt num| Ge num| Eq num| NEq num| Dvd int num| NDvd int num|
  14.258 -  NOT fm| And fm fm|  Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm
  14.259 -
  14.260 -
  14.261 -  (* A size for fm *)
  14.262 -fun fmsize :: "fm \<Rightarrow> nat" where
  14.263 - "fmsize (NOT p) = 1 + fmsize p"
  14.264 -| "fmsize (And p q) = 1 + fmsize p + fmsize q"
  14.265 -| "fmsize (Or p q) = 1 + fmsize p + fmsize q"
  14.266 -| "fmsize (Imp p q) = 3 + fmsize p + fmsize q"
  14.267 -| "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)"
  14.268 -| "fmsize (E p) = 1 + fmsize p"
  14.269 -| "fmsize (A p) = 4+ fmsize p"
  14.270 -| "fmsize (Dvd i t) = 2"
  14.271 -| "fmsize (NDvd i t) = 2"
  14.272 -| "fmsize p = 1"
  14.273 -  (* several lemmas about fmsize *)
  14.274 -lemma fmsize_pos: "fmsize p > 0"	
  14.275 -by (induct p rule: fmsize.induct) simp_all
  14.276 -
  14.277 -  (* Semantics of formulae (fm) *)
  14.278 -primrec Ifm ::"real list \<Rightarrow> fm \<Rightarrow> bool" where
  14.279 -  "Ifm bs T = True"
  14.280 -| "Ifm bs F = False"
  14.281 -| "Ifm bs (Lt a) = (Inum bs a < 0)"
  14.282 -| "Ifm bs (Gt a) = (Inum bs a > 0)"
  14.283 -| "Ifm bs (Le a) = (Inum bs a \<le> 0)"
  14.284 -| "Ifm bs (Ge a) = (Inum bs a \<ge> 0)"
  14.285 -| "Ifm bs (Eq a) = (Inum bs a = 0)"
  14.286 -| "Ifm bs (NEq a) = (Inum bs a \<noteq> 0)"
  14.287 -| "Ifm bs (Dvd i b) = (real i rdvd Inum bs b)"
  14.288 -| "Ifm bs (NDvd i b) = (\<not>(real i rdvd Inum bs b))"
  14.289 -| "Ifm bs (NOT p) = (\<not> (Ifm bs p))"
  14.290 -| "Ifm bs (And p q) = (Ifm bs p \<and> Ifm bs q)"
  14.291 -| "Ifm bs (Or p q) = (Ifm bs p \<or> Ifm bs q)"
  14.292 -| "Ifm bs (Imp p q) = ((Ifm bs p) \<longrightarrow> (Ifm bs q))"
  14.293 -| "Ifm bs (Iff p q) = (Ifm bs p = Ifm bs q)"
  14.294 -| "Ifm bs (E p) = (\<exists> x. Ifm (x#bs) p)"
  14.295 -| "Ifm bs (A p) = (\<forall> x. Ifm (x#bs) p)"
  14.296 -
  14.297 -consts prep :: "fm \<Rightarrow> fm"
  14.298 -recdef prep "measure fmsize"
  14.299 -  "prep (E T) = T"
  14.300 -  "prep (E F) = F"
  14.301 -  "prep (E (Or p q)) = Or (prep (E p)) (prep (E q))"
  14.302 -  "prep (E (Imp p q)) = Or (prep (E (NOT p))) (prep (E q))"
  14.303 -  "prep (E (Iff p q)) = Or (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))" 
  14.304 -  "prep (E (NOT (And p q))) = Or (prep (E (NOT p))) (prep (E(NOT q)))"
  14.305 -  "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))"
  14.306 -  "prep (E (NOT (Iff p q))) = Or (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))"
  14.307 -  "prep (E p) = E (prep p)"
  14.308 -  "prep (A (And p q)) = And (prep (A p)) (prep (A q))"
  14.309 -  "prep (A p) = prep (NOT (E (NOT p)))"
  14.310 -  "prep (NOT (NOT p)) = prep p"
  14.311 -  "prep (NOT (And p q)) = Or (prep (NOT p)) (prep (NOT q))"
  14.312 -  "prep (NOT (A p)) = prep (E (NOT p))"
  14.313 -  "prep (NOT (Or p q)) = And (prep (NOT p)) (prep (NOT q))"
  14.314 -  "prep (NOT (Imp p q)) = And (prep p) (prep (NOT q))"
  14.315 -  "prep (NOT (Iff p q)) = Or (prep (And p (NOT q))) (prep (And (NOT p) q))"
  14.316 -  "prep (NOT p) = NOT (prep p)"
  14.317 -  "prep (Or p q) = Or (prep p) (prep q)"
  14.318 -  "prep (And p q) = And (prep p) (prep q)"
  14.319 -  "prep (Imp p q) = prep (Or (NOT p) q)"
  14.320 -  "prep (Iff p q) = Or (prep (And p q)) (prep (And (NOT p) (NOT q)))"
  14.321 -  "prep p = p"
  14.322 -(hints simp add: fmsize_pos)
  14.323 -lemma prep: "\<And> bs. Ifm bs (prep p) = Ifm bs p"
  14.324 -by (induct p rule: prep.induct, auto)
  14.325 -
  14.326 -
  14.327 -  (* Quantifier freeness *)
  14.328 -fun qfree:: "fm \<Rightarrow> bool" where
  14.329 -  "qfree (E p) = False"
  14.330 -  | "qfree (A p) = False"
  14.331 -  | "qfree (NOT p) = qfree p" 
  14.332 -  | "qfree (And p q) = (qfree p \<and> qfree q)" 
  14.333 -  | "qfree (Or  p q) = (qfree p \<and> qfree q)" 
  14.334 -  | "qfree (Imp p q) = (qfree p \<and> qfree q)" 
  14.335 -  | "qfree (Iff p q) = (qfree p \<and> qfree q)"
  14.336 -  | "qfree p = True"
  14.337 -
  14.338 -  (* Boundedness and substitution *)
  14.339 -primrec numbound0 :: "num \<Rightarrow> bool" (* a num is INDEPENDENT of Bound 0 *) where
  14.340 -  "numbound0 (C c) = True"
  14.341 -  | "numbound0 (Bound n) = (n>0)"
  14.342 -  | "numbound0 (CN n i a) = (n > 0 \<and> numbound0 a)"
  14.343 -  | "numbound0 (Neg a) = numbound0 a"
  14.344 -  | "numbound0 (Add a b) = (numbound0 a \<and> numbound0 b)"
  14.345 -  | "numbound0 (Sub a b) = (numbound0 a \<and> numbound0 b)" 
  14.346 -  | "numbound0 (Mul i a) = numbound0 a"
  14.347 -  | "numbound0 (Floor a) = numbound0 a"
  14.348 -  | "numbound0 (CF c a b) = (numbound0 a \<and> numbound0 b)" 
  14.349 -
  14.350 -lemma numbound0_I:
  14.351 -  assumes nb: "numbound0 a"
  14.352 -  shows "Inum (b#bs) a = Inum (b'#bs) a"
  14.353 -  using nb by (induct a) (auto simp add: nth_pos2)
  14.354 -
  14.355 -lemma numbound0_gen: 
  14.356 -  assumes nb: "numbound0 t" and ti: "isint t (x#bs)"
  14.357 -  shows "\<forall> y. isint t (y#bs)"
  14.358 -using nb ti 
  14.359 -proof(clarify)
  14.360 -  fix y
  14.361 -  from numbound0_I[OF nb, where bs="bs" and b="y" and b'="x"] ti[simplified isint_def]
  14.362 -  show "isint t (y#bs)"
  14.363 -    by (simp add: isint_def)
  14.364 -qed
  14.365 -
  14.366 -primrec bound0:: "fm \<Rightarrow> bool" (* A Formula is independent of Bound 0 *) where
  14.367 -  "bound0 T = True"
  14.368 -  | "bound0 F = True"
  14.369 -  | "bound0 (Lt a) = numbound0 a"
  14.370 -  | "bound0 (Le a) = numbound0 a"
  14.371 -  | "bound0 (Gt a) = numbound0 a"
  14.372 -  | "bound0 (Ge a) = numbound0 a"
  14.373 -  | "bound0 (Eq a) = numbound0 a"
  14.374 -  | "bound0 (NEq a) = numbound0 a"
  14.375 -  | "bound0 (Dvd i a) = numbound0 a"
  14.376 -  | "bound0 (NDvd i a) = numbound0 a"
  14.377 -  | "bound0 (NOT p) = bound0 p"
  14.378 -  | "bound0 (And p q) = (bound0 p \<and> bound0 q)"
  14.379 -  | "bound0 (Or p q) = (bound0 p \<and> bound0 q)"
  14.380 -  | "bound0 (Imp p q) = ((bound0 p) \<and> (bound0 q))"
  14.381 -  | "bound0 (Iff p q) = (bound0 p \<and> bound0 q)"
  14.382 -  | "bound0 (E p) = False"
  14.383 -  | "bound0 (A p) = False"
  14.384 -
  14.385 -lemma bound0_I:
  14.386 -  assumes bp: "bound0 p"
  14.387 -  shows "Ifm (b#bs) p = Ifm (b'#bs) p"
  14.388 - using bp numbound0_I [where b="b" and bs="bs" and b'="b'"]
  14.389 -  by (induct p) (auto simp add: nth_pos2)
  14.390 -
  14.391 -primrec numsubst0:: "num \<Rightarrow> num \<Rightarrow> num" (* substitute a num into a num for Bound 0 *) where
  14.392 -  "numsubst0 t (C c) = (C c)"
  14.393 -  | "numsubst0 t (Bound n) = (if n=0 then t else Bound n)"
  14.394 -  | "numsubst0 t (CN n i a) = (if n=0 then Add (Mul i t) (numsubst0 t a) else CN n i (numsubst0 t a))"
  14.395 -  | "numsubst0 t (CF i a b) = CF i (numsubst0 t a) (numsubst0 t b)"
  14.396 -  | "numsubst0 t (Neg a) = Neg (numsubst0 t a)"
  14.397 -  | "numsubst0 t (Add a b) = Add (numsubst0 t a) (numsubst0 t b)"
  14.398 -  | "numsubst0 t (Sub a b) = Sub (numsubst0 t a) (numsubst0 t b)" 
  14.399 -  | "numsubst0 t (Mul i a) = Mul i (numsubst0 t a)"
  14.400 -  | "numsubst0 t (Floor a) = Floor (numsubst0 t a)"
  14.401 -
  14.402 -lemma numsubst0_I:
  14.403 -  shows "Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b#bs) a)#bs) t"
  14.404 -  by (induct t) (simp_all add: nth_pos2)
  14.405 -
  14.406 -lemma numsubst0_I':
  14.407 -  assumes nb: "numbound0 a"
  14.408 -  shows "Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b'#bs) a)#bs) t"
  14.409 -  by (induct t) (simp_all add: nth_pos2 numbound0_I[OF nb, where b="b" and b'="b'"])
  14.410 -
  14.411 -primrec subst0:: "num \<Rightarrow> fm \<Rightarrow> fm" (* substitue a num into a formula for Bound 0 *) where
  14.412 -  "subst0 t T = T"
  14.413 -  | "subst0 t F = F"
  14.414 -  | "subst0 t (Lt a) = Lt (numsubst0 t a)"
  14.415 -  | "subst0 t (Le a) = Le (numsubst0 t a)"
  14.416 -  | "subst0 t (Gt a) = Gt (numsubst0 t a)"
  14.417 -  | "subst0 t (Ge a) = Ge (numsubst0 t a)"
  14.418 -  | "subst0 t (Eq a) = Eq (numsubst0 t a)"
  14.419 -  | "subst0 t (NEq a) = NEq (numsubst0 t a)"
  14.420 -  | "subst0 t (Dvd i a) = Dvd i (numsubst0 t a)"
  14.421 -  | "subst0 t (NDvd i a) = NDvd i (numsubst0 t a)"
  14.422 -  | "subst0 t (NOT p) = NOT (subst0 t p)"
  14.423 -  | "subst0 t (And p q) = And (subst0 t p) (subst0 t q)"
  14.424 -  | "subst0 t (Or p q) = Or (subst0 t p) (subst0 t q)"
  14.425 -  | "subst0 t (Imp p q) = Imp (subst0 t p) (subst0 t q)"
  14.426 -  | "subst0 t (Iff p q) = Iff (subst0 t p) (subst0 t q)"
  14.427 -
  14.428 -lemma subst0_I: assumes qfp: "qfree p"
  14.429 -  shows "Ifm (b#bs) (subst0 a p) = Ifm ((Inum (b#bs) a)#bs) p"
  14.430 -  using qfp numsubst0_I[where b="b" and bs="bs" and a="a"]
  14.431 -  by (induct p) (simp_all add: nth_pos2 )
  14.432 -
  14.433 -consts
  14.434 -  decrnum:: "num \<Rightarrow> num" 
  14.435 -  decr :: "fm \<Rightarrow> fm"
  14.436 -
  14.437 -recdef decrnum "measure size"
  14.438 -  "decrnum (Bound n) = Bound (n - 1)"
  14.439 -  "decrnum (Neg a) = Neg (decrnum a)"
  14.440 -  "decrnum (Add a b) = Add (decrnum a) (decrnum b)"
  14.441 -  "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)"
  14.442 -  "decrnum (Mul c a) = Mul c (decrnum a)"
  14.443 -  "decrnum (Floor a) = Floor (decrnum a)"
  14.444 -  "decrnum (CN n c a) = CN (n - 1) c (decrnum a)"
  14.445 -  "decrnum (CF c a b) = CF c (decrnum a) (decrnum b)"
  14.446 -  "decrnum a = a"
  14.447 -
  14.448 -recdef decr "measure size"
  14.449 -  "decr (Lt a) = Lt (decrnum a)"
  14.450 -  "decr (Le a) = Le (decrnum a)"
  14.451 -  "decr (Gt a) = Gt (decrnum a)"
  14.452 -  "decr (Ge a) = Ge (decrnum a)"
  14.453 -  "decr (Eq a) = Eq (decrnum a)"
  14.454 -  "decr (NEq a) = NEq (decrnum a)"
  14.455 -  "decr (Dvd i a) = Dvd i (decrnum a)"
  14.456 -  "decr (NDvd i a) = NDvd i (decrnum a)"
  14.457 -  "decr (NOT p) = NOT (decr p)" 
  14.458 -  "decr (And p q) = And (decr p) (decr q)"
  14.459 -  "decr (Or p q) = Or (decr p) (decr q)"
  14.460 -  "decr (Imp p q) = Imp (decr p) (decr q)"
  14.461 -  "decr (Iff p q) = Iff (decr p) (decr q)"
  14.462 -  "decr p = p"
  14.463 -
  14.464 -lemma decrnum: assumes nb: "numbound0 t"
  14.465 -  shows "Inum (x#bs) t = Inum bs (decrnum t)"
  14.466 -  using nb by (induct t rule: decrnum.induct, simp_all add: nth_pos2)
  14.467 -
  14.468 -lemma decr: assumes nb: "bound0 p"
  14.469 -  shows "Ifm (x#bs) p = Ifm bs (decr p)"
  14.470 -  using nb 
  14.471 -  by (induct p rule: decr.induct, simp_all add: nth_pos2 decrnum)
  14.472 -
  14.473 -lemma decr_qf: "bound0 p \<Longrightarrow> qfree (decr p)"
  14.474 -by (induct p, simp_all)
  14.475 -
  14.476 -consts 
  14.477 -  isatom :: "fm \<Rightarrow> bool" (* test for atomicity *)
  14.478 -recdef isatom "measure size"
  14.479 -  "isatom T = True"
  14.480 -  "isatom F = True"
  14.481 -  "isatom (Lt a) = True"
  14.482 -  "isatom (Le a) = True"
  14.483 -  "isatom (Gt a) = True"
  14.484 -  "isatom (Ge a) = True"
  14.485 -  "isatom (Eq a) = True"
  14.486 -  "isatom (NEq a) = True"
  14.487 -  "isatom (Dvd i b) = True"
  14.488 -  "isatom (NDvd i b) = True"
  14.489 -  "isatom p = False"
  14.490 -
  14.491 -lemma numsubst0_numbound0: assumes nb: "numbound0 t"
  14.492 -  shows "numbound0 (numsubst0 t a)"
  14.493 -using nb by (induct a, auto)
  14.494 -
  14.495 -lemma subst0_bound0: assumes qf: "qfree p" and nb: "numbound0 t"
  14.496 -  shows "bound0 (subst0 t p)"
  14.497 -using qf numsubst0_numbound0[OF nb] by (induct p, auto)
  14.498 -
  14.499 -lemma bound0_qf: "bound0 p \<Longrightarrow> qfree p"
  14.500 -by (induct p, simp_all)
  14.501 -
  14.502 -
  14.503 -definition djf:: "('a \<Rightarrow> fm) \<Rightarrow> 'a \<Rightarrow> fm \<Rightarrow> fm" where
  14.504 -  "djf f p q = (if q=T then T else if q=F then f p else 
  14.505 -  (let fp = f p in case fp of T \<Rightarrow> T | F \<Rightarrow> q | _ \<Rightarrow> Or fp q))"
  14.506 -
  14.507 -definition evaldjf:: "('a \<Rightarrow> fm) \<Rightarrow> 'a list \<Rightarrow> fm" where
  14.508 -  "evaldjf f ps = foldr (djf f) ps F"
  14.509 -
  14.510 -lemma djf_Or: "Ifm bs (djf f p q) = Ifm bs (Or (f p) q)"
  14.511 -by (cases "q=T", simp add: djf_def,cases "q=F",simp add: djf_def) 
  14.512 -(cases "f p", simp_all add: Let_def djf_def) 
  14.513 -
  14.514 -lemma evaldjf_ex: "Ifm bs (evaldjf f ps) = (\<exists> p \<in> set ps. Ifm bs (f p))"
  14.515 -  by(induct ps, simp_all add: evaldjf_def djf_Or)
  14.516 -
  14.517 -lemma evaldjf_bound0: 
  14.518 -  assumes nb: "\<forall> x\<in> set xs. bound0 (f x)"
  14.519 -  shows "bound0 (evaldjf f xs)"
  14.520 -  using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) 
  14.521 -
  14.522 -lemma evaldjf_qf: 
  14.523 -  assumes nb: "\<forall> x\<in> set xs. qfree (f x)"
  14.524 -  shows "qfree (evaldjf f xs)"
  14.525 -  using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) 
  14.526 -
  14.527 -consts 
  14.528 -  disjuncts :: "fm \<Rightarrow> fm list" 
  14.529 -  conjuncts :: "fm \<Rightarrow> fm list"
  14.530 -recdef disjuncts "measure size"
  14.531 -  "disjuncts (Or p q) = (disjuncts p) @ (disjuncts q)"
  14.532 -  "disjuncts F = []"
  14.533 -  "disjuncts p = [p]"
  14.534 -
  14.535 -recdef conjuncts "measure size"
  14.536 -  "conjuncts (And p q) = (conjuncts p) @ (conjuncts q)"
  14.537 -  "conjuncts T = []"
  14.538 -  "conjuncts p = [p]"
  14.539 -lemma disjuncts: "(\<exists> q\<in> set (disjuncts p). Ifm bs q) = Ifm bs p"
  14.540 -by(induct p rule: disjuncts.induct, auto)
  14.541 -lemma conjuncts: "(\<forall> q\<in> set (conjuncts p). Ifm bs q) = Ifm bs p"
  14.542 -by(induct p rule: conjuncts.induct, auto)
  14.543 -
  14.544 -lemma disjuncts_nb: "bound0 p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). bound0 q"
  14.545 -proof-
  14.546 -  assume nb: "bound0 p"
  14.547 -  hence "list_all bound0 (disjuncts p)" by (induct p rule:disjuncts.induct,auto)
  14.548 -  thus ?thesis by (simp only: list_all_iff)
  14.549 -qed
  14.550 -lemma conjuncts_nb: "bound0 p \<Longrightarrow> \<forall> q\<in> set (conjuncts p). bound0 q"
  14.551 -proof-
  14.552 -  assume nb: "bound0 p"
  14.553 -  hence "list_all bound0 (conjuncts p)" by (induct p rule:conjuncts.induct,auto)
  14.554 -  thus ?thesis by (simp only: list_all_iff)
  14.555 -qed
  14.556 -
  14.557 -lemma disjuncts_qf: "qfree p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). qfree q"
  14.558 -proof-
  14.559 -  assume qf: "qfree p"
  14.560 -  hence "list_all qfree (disjuncts p)"
  14.561 -    by (induct p rule: disjuncts.induct, auto)
  14.562 -  thus ?thesis by (simp only: list_all_iff)
  14.563 -qed
  14.564 -lemma conjuncts_qf: "qfree p \<Longrightarrow> \<forall> q\<in> set (conjuncts p). qfree q"
  14.565 -proof-
  14.566 -  assume qf: "qfree p"
  14.567 -  hence "list_all qfree (conjuncts p)"
  14.568 -    by (induct p rule: conjuncts.induct, auto)
  14.569 -  thus ?thesis by (simp only: list_all_iff)
  14.570 -qed
  14.571 -
  14.572 -constdefs DJ :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm"
  14.573 -  "DJ f p \<equiv> evaldjf f (disjuncts p)"
  14.574 -
  14.575 -lemma DJ: assumes fdj: "\<forall> p q. f (Or p q) = Or (f p) (f q)"
  14.576 -  and fF: "f F = F"
  14.577 -  shows "Ifm bs (DJ f p) = Ifm bs (f p)"
  14.578 -proof-
  14.579 -  have "Ifm bs (DJ f p) = (\<exists> q \<in> set (disjuncts p). Ifm bs (f q))"
  14.580 -    by (simp add: DJ_def evaldjf_ex) 
  14.581 -  also have "\<dots> = Ifm bs (f p)" using fdj fF by (induct p rule: disjuncts.induct, auto)
  14.582 -  finally show ?thesis .
  14.583 -qed
  14.584 -
  14.585 -lemma DJ_qf: assumes 
  14.586 -  fqf: "\<forall> p. qfree p \<longrightarrow> qfree (f p)"
  14.587 -  shows "\<forall>p. qfree p \<longrightarrow> qfree (DJ f p) "
  14.588 -proof(clarify)
  14.589 -  fix  p assume qf: "qfree p"
  14.590 -  have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def)
  14.591 -  from disjuncts_qf[OF qf] have "\<forall> q\<in> set (disjuncts p). qfree q" .
  14.592 -  with fqf have th':"\<forall> q\<in> set (disjuncts p). qfree (f q)" by blast
  14.593 -  
  14.594 -  from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp
  14.595 -qed
  14.596 -
  14.597 -lemma DJ_qe: assumes qe: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))"
  14.598 -  shows "\<forall> bs p. qfree p \<longrightarrow> qfree (DJ qe p) \<and> (Ifm bs ((DJ qe p)) = Ifm bs (E p))"
  14.599 -proof(clarify)
  14.600 -  fix p::fm and bs
  14.601 -  assume qf: "qfree p"
  14.602 -  from qe have qth: "\<forall> p. qfree p \<longrightarrow> qfree (qe p)" by blast
  14.603 -  from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto
  14.604 -  have "Ifm bs (DJ qe p) = (\<exists> q\<in> set (disjuncts p). Ifm bs (qe q))"
  14.605 -    by (simp add: DJ_def evaldjf_ex)
  14.606 -  also have "\<dots> = (\<exists> q \<in> set(disjuncts p). Ifm bs (E q))" using qe disjuncts_qf[OF qf] by auto
  14.607 -  also have "\<dots> = Ifm bs (E p)" by (induct p rule: disjuncts.induct, auto)
  14.608 -  finally show "qfree (DJ qe p) \<and> Ifm bs (DJ qe p) = Ifm bs (E p)" using qfth by blast
  14.609 -qed
  14.610 -  (* Simplification *)
  14.611 -
  14.612 -  (* Algebraic simplifications for nums *)
  14.613 -consts bnds:: "num \<Rightarrow> nat list"
  14.614 -  lex_ns:: "nat list \<times> nat list \<Rightarrow> bool"
  14.615 -recdef bnds "measure size"
  14.616 -  "bnds (Bound n) = [n]"
  14.617 -  "bnds (CN n c a) = n#(bnds a)"
  14.618 -  "bnds (Neg a) = bnds a"
  14.619 -  "bnds (Add a b) = (bnds a)@(bnds b)"
  14.620 -  "bnds (Sub a b) = (bnds a)@(bnds b)"
  14.621 -  "bnds (Mul i a) = bnds a"
  14.622 -  "bnds (Floor a) = bnds a"
  14.623 -  "bnds (CF c a b) = (bnds a)@(bnds b)"
  14.624 -  "bnds a = []"
  14.625 -recdef lex_ns "measure (\<lambda> (xs,ys). length xs + length ys)"
  14.626 -  "lex_ns ([], ms) = True"
  14.627 -  "lex_ns (ns, []) = False"
  14.628 -  "lex_ns (n#ns, m#ms) = (n<m \<or> ((n = m) \<and> lex_ns (ns,ms))) "
  14.629 -constdefs lex_bnd :: "num \<Rightarrow> num \<Rightarrow> bool"
  14.630 -  "lex_bnd t s \<equiv> lex_ns (bnds t, bnds s)"
  14.631 -
  14.632 -consts 
  14.633 -  numgcdh:: "num \<Rightarrow> int \<Rightarrow> int"
  14.634 -  reducecoeffh:: "num \<Rightarrow> int \<Rightarrow> num"
  14.635 -  dvdnumcoeff:: "num \<Rightarrow> int \<Rightarrow> bool"
  14.636 -consts maxcoeff:: "num \<Rightarrow> int"
  14.637 -recdef maxcoeff "measure size"
  14.638 -  "maxcoeff (C i) = abs i"
  14.639 -  "maxcoeff (CN n c t) = max (abs c) (maxcoeff t)"
  14.640 -  "maxcoeff (CF c t s) = max (abs c) (maxcoeff s)"
  14.641 -  "maxcoeff t = 1"
  14.642 -
  14.643 -lemma maxcoeff_pos: "maxcoeff t \<ge> 0"
  14.644 -  apply (induct t rule: maxcoeff.induct, auto) 
  14.645 -  done
  14.646 -
  14.647 -recdef numgcdh "measure size"
  14.648 -  "numgcdh (C i) = (\<lambda>g. zgcd i g)"
  14.649 -  "numgcdh (CN n c t) = (\<lambda>g. zgcd c (numgcdh t g))"
  14.650 -  "numgcdh (CF c s t) = (\<lambda>g. zgcd c (numgcdh t g))"
  14.651 -  "numgcdh t = (\<lambda>g. 1)"
  14.652 -
  14.653 -definition
  14.654 -  numgcd :: "num \<Rightarrow> int"
  14.655 -where
  14.656 -  numgcd_def: "numgcd t = numgcdh t (maxcoeff t)"
  14.657 -
  14.658 -recdef reducecoeffh "measure size"
  14.659 -  "reducecoeffh (C i) = (\<lambda> g. C (i div g))"
  14.660 -  "reducecoeffh (CN n c t) = (\<lambda> g. CN n (c div g) (reducecoeffh t g))"
  14.661 -  "reducecoeffh (CF c s t) = (\<lambda> g. CF (c div g)  s (reducecoeffh t g))"
  14.662 -  "reducecoeffh t = (\<lambda>g. t)"
  14.663 -
  14.664 -definition
  14.665 -  reducecoeff :: "num \<Rightarrow> num"
  14.666 -where
  14.667 -  reducecoeff_def: "reducecoeff t =
  14.668 -  (let g = numgcd t in 
  14.669 -  if g = 0 then C 0 else if g=1 then t else reducecoeffh t g)"
  14.670 -
  14.671 -recdef dvdnumcoeff "measure size"
  14.672 -  "dvdnumcoeff (C i) = (\<lambda> g. g dvd i)"
  14.673 -  "dvdnumcoeff (CN n c t) = (\<lambda> g. g dvd c \<and> (dvdnumcoeff t g))"
  14.674 -  "dvdnumcoeff (CF c s t) = (\<lambda> g. g dvd c \<and> (dvdnumcoeff t g))"
  14.675 -  "dvdnumcoeff t = (\<lambda>g. False)"
  14.676 -
  14.677 -lemma dvdnumcoeff_trans: 
  14.678 -  assumes gdg: "g dvd g'" and dgt':"dvdnumcoeff t g'"
  14.679 -  shows "dvdnumcoeff t g"
  14.680 -  using dgt' gdg 
  14.681 -  by (induct t rule: dvdnumcoeff.induct, simp_all add: gdg zdvd_trans[OF gdg])
  14.682 -
  14.683 -declare zdvd_trans [trans add]
  14.684 -
  14.685 -lemma natabs0: "(nat (abs x) = 0) = (x = 0)"
  14.686 -by arith
  14.687 -
  14.688 -lemma numgcd0:
  14.689 -  assumes g0: "numgcd t = 0"
  14.690 -  shows "Inum bs t = 0"
  14.691 -proof-
  14.692 -  have "\<And>x. numgcdh t x= 0 \<Longrightarrow> Inum bs t = 0"
  14.693 -    by (induct t rule: numgcdh.induct, auto simp add: zgcd_def gcd_zero natabs0 max_def maxcoeff_pos)
  14.694 -  thus ?thesis using g0[simplified numgcd_def] by blast
  14.695 -qed
  14.696 -
  14.697 -lemma numgcdh_pos: assumes gp: "g \<ge> 0" shows "numgcdh t g \<ge> 0"
  14.698 -  using gp
  14.699 -  by (induct t rule: numgcdh.induct, auto simp add: zgcd_def)
  14.700 -
  14.701 -lemma numgcd_pos: "numgcd t \<ge>0"
  14.702 -  by (simp add: numgcd_def numgcdh_pos maxcoeff_pos)
  14.703 -
  14.704 -lemma reducecoeffh:
  14.705 -  assumes gt: "dvdnumcoeff t g" and gp: "g > 0" 
  14.706 -  shows "real g *(Inum bs (reducecoeffh t g)) = Inum bs t"
  14.707 -  using gt
  14.708 -proof(induct t rule: reducecoeffh.induct) 
  14.709 -  case (1 i) hence gd: "g dvd i" by simp
  14.710 -  from gp have gnz: "g \<noteq> 0" by simp
  14.711 -  from prems show ?case by (simp add: real_of_int_div[OF gnz gd])
  14.712 -next
  14.713 -  case (2 n c t)  hence gd: "g dvd c" by simp
  14.714 -  from gp have gnz: "g \<noteq> 0" by simp
  14.715 -  from prems show ?case by (simp add: real_of_int_div[OF gnz gd] ring_simps)
  14.716 -next
  14.717 -  case (3 c s t)  hence gd: "g dvd c" by simp
  14.718 -  from gp have gnz: "g \<noteq> 0" by simp
  14.719 -  from prems show ?case by (simp add: real_of_int_div[OF gnz gd] ring_simps) 
  14.720 -qed (auto simp add: numgcd_def gp)
  14.721 -consts ismaxcoeff:: "num \<Rightarrow> int \<Rightarrow> bool"
  14.722 -recdef ismaxcoeff "measure size"
  14.723 -  "ismaxcoeff (C i) = (\<lambda> x. abs i \<le> x)"
  14.724 -  "ismaxcoeff (CN n c t) = (\<lambda>x. abs c \<le> x \<and> (ismaxcoeff t x))"
  14.725 -  "ismaxcoeff (CF c s t) = (\<lambda>x. abs c \<le> x \<and> (ismaxcoeff t x))"
  14.726 -  "ismaxcoeff t = (\<lambda>x. True)"
  14.727 -
  14.728 -lemma ismaxcoeff_mono: "ismaxcoeff t c \<Longrightarrow> c \<le> c' \<Longrightarrow> ismaxcoeff t c'"
  14.729 -by (induct t rule: ismaxcoeff.induct, auto)
  14.730 -
  14.731 -lemma maxcoeff_ismaxcoeff: "ismaxcoeff t (maxcoeff t)"
  14.732 -proof (induct t rule: maxcoeff.induct)
  14.733 -  case (2 n c t)
  14.734 -  hence H:"ismaxcoeff t (maxcoeff t)" .
  14.735 -  have thh: "maxcoeff t \<le> max (abs c) (maxcoeff t)" by (simp add: le_maxI2)
  14.736 -  from ismaxcoeff_mono[OF H thh] show ?case by (simp add: le_maxI1)
  14.737 -next
  14.738 -  case (3 c t s) 
  14.739 -  hence H1:"ismaxcoeff s (maxcoeff s)" by auto
  14.740 -  have thh1: "maxcoeff s \<le> max \<bar>c\<bar> (maxcoeff s)" by (simp add: max_def)
  14.741 -  from ismaxcoeff_mono[OF H1 thh1] show ?case by (simp add: le_maxI1)
  14.742 -qed simp_all
  14.743 -
  14.744 -lemma zgcd_gt1: "zgcd i j > 1 \<Longrightarrow> ((abs i > 1 \<and> abs j > 1) \<or> (abs i = 0 \<and> abs j > 1) \<or> (abs i > 1 \<and> abs j = 0))"
  14.745 -  apply (unfold zgcd_def)
  14.746 -  apply (cases "i = 0", simp_all)
  14.747 -  apply (cases "j = 0", simp_all)
  14.748 -  apply (cases "abs i = 1", simp_all)
  14.749 -  apply (cases "abs j = 1", simp_all)
  14.750 -  apply auto
  14.751 -  done
  14.752 -lemma numgcdh0:"numgcdh t m = 0 \<Longrightarrow>  m =0"
  14.753 -  by (induct t rule: numgcdh.induct, auto simp add:zgcd0)
  14.754 -
  14.755 -lemma dvdnumcoeff_aux:
  14.756 -  assumes "ismaxcoeff t m" and mp:"m \<ge> 0" and "numgcdh t m > 1"
  14.757 -  shows "dvdnumcoeff t (numgcdh t m)"
  14.758 -using prems
  14.759 -proof(induct t rule: numgcdh.induct)
  14.760 -  case (2 n c t) 
  14.761 -  let ?g = "numgcdh t m"
  14.762 -  from prems have th:"zgcd c ?g > 1" by simp
  14.763 -  from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"]
  14.764 -  have "(abs c > 1 \<and> ?g > 1) \<or> (abs c = 0 \<and> ?g > 1) \<or> (abs c > 1 \<and> ?g = 0)" by simp
  14.765 -  moreover {assume "abs c > 1" and gp: "?g > 1" with prems
  14.766 -    have th: "dvdnumcoeff t ?g" by simp
  14.767 -    have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2)
  14.768 -    from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)}
  14.769 -  moreover {assume "abs c = 0 \<and> ?g > 1"
  14.770 -    with prems have th: "dvdnumcoeff t ?g" by simp
  14.771 -    have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2)
  14.772 -    from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)
  14.773 -    hence ?case by simp }
  14.774 -  moreover {assume "abs c > 1" and g0:"?g = 0" 
  14.775 -    from numgcdh0[OF g0] have "m=0". with prems   have ?case by simp }
  14.776 -  ultimately show ?case by blast
  14.777 -next
  14.778 -  case (3 c s t) 
  14.779 -  let ?g = "numgcdh t m"
  14.780 -  from prems have th:"zgcd c ?g > 1" by simp
  14.781 -  from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"]
  14.782 -  have "(abs c > 1 \<and> ?g > 1) \<or> (abs c = 0 \<and> ?g > 1) \<or> (abs c > 1 \<and> ?g = 0)" by simp
  14.783 -  moreover {assume "abs c > 1" and gp: "?g > 1" with prems
  14.784 -    have th: "dvdnumcoeff t ?g" by simp
  14.785 -    have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2)
  14.786 -    from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)}
  14.787 -  moreover {assume "abs c = 0 \<and> ?g > 1"
  14.788 -    with prems have th: "dvdnumcoeff t ?g" by simp
  14.789 -    have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2)
  14.790 -    from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)
  14.791 -    hence ?case by simp }
  14.792 -  moreover {assume "abs c > 1" and g0:"?g = 0" 
  14.793 -    from numgcdh0[OF g0] have "m=0". with prems   have ?case by simp }
  14.794 -  ultimately show ?case by blast
  14.795 -qed(auto simp add: zgcd_zdvd1)
  14.796 -
  14.797 -lemma dvdnumcoeff_aux2:
  14.798 -  assumes "numgcd t > 1" shows "dvdnumcoeff t (numgcd t) \<and> numgcd t > 0"
  14.799 -  using prems 
  14.800 -proof (simp add: numgcd_def)
  14.801 -  let ?mc = "maxcoeff t"
  14.802 -  let ?g = "numgcdh t ?mc"
  14.803 -  have th1: "ismaxcoeff t ?mc" by (rule maxcoeff_ismaxcoeff)
  14.804 -  have th2: "?mc \<ge> 0" by (rule maxcoeff_pos)
  14.805 -  assume H: "numgcdh t ?mc > 1"
  14.806 -  from dvdnumcoeff_aux[OF th1 th2 H]  show "dvdnumcoeff t ?g" .
  14.807 -qed
  14.808 -
  14.809 -lemma reducecoeff: "real (numgcd t) * (Inum bs (reducecoeff t)) = Inum bs t"
  14.810 -proof-
  14.811 -  let ?g = "numgcd t"
  14.812 -  have "?g \<ge> 0"  by (simp add: numgcd_pos)
  14.813 -  hence	"?g = 0 \<or> ?g = 1 \<or> ?g > 1" by auto
  14.814 -  moreover {assume "?g = 0" hence ?thesis by (simp add: numgcd0)} 
  14.815 -  moreover {assume "?g = 1" hence ?thesis by (simp add: reducecoeff_def)} 
  14.816 -  moreover { assume g1:"?g > 1"
  14.817 -    from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff t ?g" and g0: "?g > 0" by blast+
  14.818 -    from reducecoeffh[OF th1 g0, where bs="bs"] g1 have ?thesis 
  14.819 -      by (simp add: reducecoeff_def Let_def)} 
  14.820 -  ultimately show ?thesis by blast
  14.821 -qed
  14.822 -
  14.823 -lemma reducecoeffh_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeffh t g)"
  14.824 -by (induct t rule: reducecoeffh.induct, auto)
  14.825 -
  14.826 -lemma reducecoeff_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeff t)"
  14.827 -using reducecoeffh_numbound0 by (simp add: reducecoeff_def Let_def)
  14.828 -
  14.829 -consts
  14.830 -  simpnum:: "num \<Rightarrow> num"
  14.831 -  numadd:: "num \<times> num \<Rightarrow> num"
  14.832 -  nummul:: "num \<Rightarrow> int \<Rightarrow> num"
  14.833 -
  14.834 -recdef numadd "measure (\<lambda> (t,s). size t + size s)"
  14.835 -  "numadd (CN n1 c1 r1,CN n2 c2 r2) =
  14.836 -  (if n1=n2 then 
  14.837 -  (let c = c1 + c2
  14.838 -  in (if c=0 then numadd(r1,r2) else CN n1 c (numadd (r1,r2))))
  14.839 -  else if n1 \<le> n2 then CN n1 c1 (numadd (r1,CN n2 c2 r2))
  14.840 -  else (CN n2 c2 (numadd (CN n1 c1 r1,r2))))"
  14.841 -  "numadd (CN n1 c1 r1,t) = CN n1 c1 (numadd (r1, t))"  
  14.842 -  "numadd (t,CN n2 c2 r2) = CN n2 c2 (numadd (t,r2))" 
  14.843 -  "numadd (CF c1 t1 r1,CF c2 t2 r2) = 
  14.844 -   (if t1 = t2 then 
  14.845 -    (let c=c1+c2; s= numadd(r1,r2) in (if c=0 then s else CF c t1 s))
  14.846 -   else if lex_bnd t1 t2 then CF c1 t1 (numadd(r1,CF c2 t2 r2))
  14.847 -   else CF c2 t2 (numadd(CF c1 t1 r1,r2)))"
  14.848 -  "numadd (CF c1 t1 r1,C c) = CF c1 t1 (numadd (r1, C c))"
  14.849 -  "numadd (C c,CF c1 t1 r1) = CF c1 t1 (numadd (r1, C c))"
  14.850 -  "numadd (C b1, C b2) = C (b1+b2)"
  14.851 -  "numadd (a,b) = Add a b"
  14.852 -
  14.853 -lemma numadd[simp]: "Inum bs (numadd (t,s)) = Inum bs (Add t s)"
  14.854 -apply (induct t s rule: numadd.induct, simp_all add: Let_def)
  14.855 - apply (case_tac "c1+c2 = 0",case_tac "n1 \<le> n2", simp_all)
  14.856 -  apply (case_tac "n1 = n2", simp_all add: ring_simps)
  14.857 -  apply (simp only: left_distrib[symmetric])
  14.858 - apply simp
  14.859 -apply (case_tac "lex_bnd t1 t2", simp_all)
  14.860 - apply (case_tac "c1+c2 = 0")
  14.861 -  by (case_tac "t1 = t2", simp_all add: ring_simps left_distrib[symmetric] real_of_int_mult[symmetric] real_of_int_add[symmetric]del: real_of_int_mult real_of_int_add left_distrib)
  14.862 -
  14.863 -lemma numadd_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numadd (t,s))"
  14.864 -by (induct t s rule: numadd.induct, auto simp add: Let_def)
  14.865 -
  14.866 -recdef nummul "measure size"
  14.867 -  "nummul (C j) = (\<lambda> i. C (i*j))"
  14.868 -  "nummul (CN n c t) = (\<lambda> i. CN n (c*i) (nummul t i))"
  14.869 -  "nummul (CF c t s) = (\<lambda> i. CF (c*i) t (nummul s i))"
  14.870 -  "nummul (Mul c t) = (\<lambda> i. nummul t (i*c))"
  14.871 -  "nummul t = (\<lambda> i. Mul i t)"
  14.872 -
  14.873 -lemma nummul[simp]: "\<And> i. Inum bs (nummul t i) = Inum bs (Mul i t)"
  14.874 -by (induct t rule: nummul.induct, auto simp add: ring_simps)
  14.875 -
  14.876 -lemma nummul_nb[simp]: "\<And> i. numbound0 t \<Longrightarrow> numbound0 (nummul t i)"
  14.877 -by (induct t rule: nummul.induct, auto)
  14.878 -
  14.879 -constdefs numneg :: "num \<Rightarrow> num"
  14.880 -  "numneg t \<equiv> nummul t (- 1)"
  14.881 -
  14.882 -constdefs numsub :: "num \<Rightarrow> num \<Rightarrow> num"
  14.883 -  "numsub s t \<equiv> (if s = t then C 0 else numadd (s,numneg t))"
  14.884 -
  14.885 -lemma numneg[simp]: "Inum bs (numneg t) = Inum bs (Neg t)"
  14.886 -using numneg_def nummul by simp
  14.887 -
  14.888 -lemma numneg_nb[simp]: "numbound0 t \<Longrightarrow> numbound0 (numneg t)"
  14.889 -using numneg_def by simp
  14.890 -
  14.891 -lemma numsub[simp]: "Inum bs (numsub a b) = Inum bs (Sub a b)"
  14.892 -using numsub_def by simp
  14.893 -
  14.894 -lemma numsub_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numsub t s)"
  14.895 -using numsub_def by simp
  14.896 -
  14.897 -lemma isint_CF: assumes si: "isint s bs" shows "isint (CF c t s) bs"
  14.898 -proof-
  14.899 -  have cti: "isint (Mul c (Floor t)) bs" by (simp add: isint_Mul isint_Floor)
  14.900 -  
  14.901 -  have "?thesis = isint (Add (Mul c (Floor t)) s) bs" by (simp add: isint_def)
  14.902 -  also have "\<dots>" by (simp add: isint_add cti si)
  14.903 -  finally show ?thesis .
  14.904 -qed
  14.905 -
  14.906 -consts split_int:: "num \<Rightarrow> num\<times>num"
  14.907 -recdef split_int "measure num_size"
  14.908 -  "split_int (C c) = (C 0, C c)"
  14.909 -  "split_int (CN n c b) = 
  14.910 -     (let (bv,bi) = split_int b 
  14.911 -       in (CN n c bv, bi))"
  14.912 -  "split_int (CF c a b) = 
  14.913 -     (let (bv,bi) = split_int b 
  14.914 -       in (bv, CF c a bi))"
  14.915 -  "split_int a = (a,C 0)"
  14.916 -
  14.917 -lemma split_int:"\<And> tv ti. split_int t = (tv,ti) \<Longrightarrow> (Inum bs (Add tv ti) = Inum bs t) \<and> isint ti bs"
  14.918 -proof (induct t rule: split_int.induct)
  14.919 -  case (2 c n b tv ti)
  14.920 -  let ?bv = "fst (split_int b)"
  14.921 -  let ?bi = "snd (split_int b)"
  14.922 -  have "split_int b = (?bv,?bi)" by simp
  14.923 -  with prems(1) have b:"Inum bs (Add ?bv ?bi) = Inum bs b" and bii: "isint ?bi bs" by blast+
  14.924 -  from prems(2) have tibi: "ti = ?bi" by (simp add: Let_def split_def)
  14.925 -  from prems(2) b[symmetric] bii show ?case by (auto simp add: Let_def split_def)
  14.926 -next
  14.927 -  case (3 c a b tv ti) 
  14.928 -  let ?bv = "fst (split_int b)"
  14.929 -  let ?bi = "snd (split_int b)"
  14.930 -  have "split_int b = (?bv,?bi)" by simp
  14.931 -  with prems(1) have b:"Inum bs (Add ?bv ?bi) = Inum bs b" and bii: "isint ?bi bs" by blast+
  14.932 -  from prems(2) have tibi: "ti = CF c a ?bi" by (simp add: Let_def split_def)
  14.933 -  from prems(2) b[symmetric] bii show ?case by (auto simp add: Let_def split_def isint_Floor isint_add isint_Mul isint_CF)
  14.934 -qed (auto simp add: Let_def isint_iff isint_Floor isint_add isint_Mul split_def ring_simps)
  14.935 -
  14.936 -lemma split_int_nb: "numbound0 t \<Longrightarrow> numbound0 (fst (split_int t)) \<and> numbound0 (snd (split_int t)) "
  14.937 -by (induct t rule: split_int.induct, auto simp add: Let_def split_def)
  14.938 -
  14.939 -definition
  14.940 -  numfloor:: "num \<Rightarrow> num"
  14.941 -where
  14.942 -  numfloor_def: "numfloor t = (let (tv,ti) = split_int t in 
  14.943 -  (case tv of C i \<Rightarrow> numadd (tv,ti) 
  14.944 -  | _ \<Rightarrow> numadd(CF 1 tv (C 0),ti)))"
  14.945 -
  14.946 -lemma numfloor[simp]: "Inum bs (numfloor t) = Inum bs (Floor t)" (is "?n t = ?N (Floor t)")
  14.947 -proof-
  14.948 -  let ?tv = "fst (split_int t)"
  14.949 -  let ?ti = "snd (split_int t)"
  14.950 -  have tvti:"split_int t = (?tv,?ti)" by simp
  14.951 -  {assume H: "\<forall> v. ?tv \<noteq> C v"
  14.952 -    hence th1: "?n t = ?N (Add (Floor ?tv) ?ti)" 
  14.953 -      by (cases ?tv, auto simp add: numfloor_def Let_def split_def numadd)
  14.954 -    from split_int[OF tvti] have "?N (Floor t) = ?N (Floor(Add ?tv ?ti))" and tii:"isint ?ti bs" by simp+
  14.955 -    hence "?N (Floor t) = real (floor (?N (Add ?tv ?ti)))" by simp 
  14.956 -    also have "\<dots> = real (floor (?N ?tv) + (floor (?N ?ti)))"
  14.957 -      by (simp,subst tii[simplified isint_iff, symmetric]) simp
  14.958 -    also have "\<dots> = ?N (Add (Floor ?tv) ?ti)" by (simp add: tii[simplified isint_iff])
  14.959 -    finally have ?thesis using th1 by simp}
  14.960 -  moreover {fix v assume H:"?tv = C v" 
  14.961 -    from split_int[OF tvti] have "?N (Floor t) = ?N (Floor(Add ?tv ?ti))" and tii:"isint ?ti bs" by simp+
  14.962 -    hence "?N (Floor t) = real (floor (?N (Add ?tv ?ti)))" by simp 
  14.963 -    also have "\<dots> = real (floor (?N ?tv) + (floor (?N ?ti)))"
  14.964 -      by (simp,subst tii[simplified isint_iff, symmetric]) simp
  14.965 -    also have "\<dots> = ?N (Add (Floor ?tv) ?ti)" by (simp add: tii[simplified isint_iff])
  14.966 -    finally have ?thesis by (simp add: H numfloor_def Let_def split_def numadd) }
  14.967 -  ultimately show ?thesis by auto
  14.968 -qed
  14.969 -
  14.970 -lemma numfloor_nb[simp]: "numbound0 t \<Longrightarrow> numbound0 (numfloor t)"
  14.971 -  using split_int_nb[where t="t"]
  14.972 -  by (cases "fst(split_int t)" , auto simp add: numfloor_def Let_def split_def  numadd_nb)
  14.973 -
  14.974 -recdef simpnum "measure num_size"
  14.975 -  "simpnum (C j) = C j"
  14.976 -  "simpnum (Bound n) = CN n 1 (C 0)"
  14.977 -  "simpnum (Neg t) = numneg (simpnum t)"
  14.978 -  "simpnum (Add t s) = numadd (simpnum t,simpnum s)"
  14.979 -  "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)"
  14.980 -  "simpnum (Mul i t) = (if i = 0 then (C 0) else nummul (simpnum t) i)"
  14.981 -  "simpnum (Floor t) = numfloor (simpnum t)"
  14.982 -  "simpnum (CN n c t) = (if c=0 then simpnum t else CN n c (simpnum t))"
  14.983 -  "simpnum (CF c t s) = simpnum(Add (Mul c (Floor t)) s)"
  14.984 -
  14.985 -lemma simpnum_ci[simp]: "Inum bs (simpnum t) = Inum bs t"
  14.986 -by (induct t rule: simpnum.induct, auto)
  14.987 -
  14.988 -lemma simpnum_numbound0[simp]: 
  14.989 -  "numbound0 t \<Longrightarrow> numbound0 (simpnum t)"
  14.990 -by (induct t rule: simpnum.induct, auto)
  14.991 -
  14.992 -consts nozerocoeff:: "num \<Rightarrow> bool"
  14.993 -recdef nozerocoeff "measure size"
  14.994 -  "nozerocoeff (C c) = True"
  14.995 -  "nozerocoeff (CN n c t) = (c\<noteq>0 \<and> nozerocoeff t)"
  14.996 -  "nozerocoeff (CF c s t) = (c \<noteq> 0 \<and> nozerocoeff t)"
  14.997 -  "nozerocoeff (Mul c t) = (c\<noteq>0 \<and> nozerocoeff t)"
  14.998 -  "nozerocoeff t = True"
  14.999 -
 14.1000 -lemma numadd_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numadd (a,b))"
 14.1001 -by (induct a b rule: numadd.induct,auto simp add: Let_def)
 14.1002 -
 14.1003 -lemma nummul_nz : "\<And> i. i\<noteq>0 \<Longrightarrow> nozerocoeff a \<Longrightarrow> nozerocoeff (nummul a i)"
 14.1004 -  by (induct a rule: nummul.induct,auto simp add: Let_def numadd_nz)
 14.1005 -
 14.1006 -lemma numneg_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff (numneg a)"
 14.1007 -by (simp add: numneg_def nummul_nz)
 14.1008 -
 14.1009 -lemma numsub_nz: "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numsub a b)"
 14.1010 -by (simp add: numsub_def numneg_nz numadd_nz)
 14.1011 -
 14.1012 -lemma split_int_nz: "nozerocoeff t \<Longrightarrow> nozerocoeff (fst (split_int t)) \<and> nozerocoeff (snd (split_int t))"
 14.1013 -by (induct t rule: split_int.induct,auto simp add: Let_def split_def)
 14.1014 -
 14.1015 -lemma numfloor_nz: "nozerocoeff t \<Longrightarrow> nozerocoeff (numfloor t)"
 14.1016 -by (simp add: numfloor_def Let_def split_def)
 14.1017 -(cases "fst (split_int t)", simp_all add: split_int_nz numadd_nz)
 14.1018 -
 14.1019 -lemma simpnum_nz: "nozerocoeff (simpnum t)"
 14.1020 -by(induct t rule: simpnum.induct, auto simp add: numadd_nz numneg_nz numsub_nz nummul_nz numfloor_nz)
 14.1021 -
 14.1022 -lemma maxcoeff_nz: "nozerocoeff t \<Longrightarrow> maxcoeff t = 0 \<Longrightarrow> t = C 0"
 14.1023 -proof (induct t rule: maxcoeff.induct)
 14.1024 -  case (2 n c t)
 14.1025 -  hence cnz: "c \<noteq>0" and mx: "max (abs c) (maxcoeff t) = 0" by simp+
 14.1026 -  have "max (abs c) (maxcoeff t) \<ge> abs c" by (simp add: le_maxI1)
 14.1027 -  with cnz have "max (abs c) (maxcoeff t) > 0" by arith
 14.1028 -  with prems show ?case by simp
 14.1029 -next
 14.1030 -  case (3 c s t) 
 14.1031 -  hence cnz: "c \<noteq>0" and mx: "max (abs c) (maxcoeff t) = 0" by simp+
 14.1032 -  have "max (abs c) (maxcoeff t) \<ge> abs c" by (simp add: le_maxI1)
 14.1033 -  with cnz have "max (abs c) (maxcoeff t) > 0" by arith
 14.1034 -  with prems show ?case by simp
 14.1035 -qed auto
 14.1036 -
 14.1037 -lemma numgcd_nz: assumes nz: "nozerocoeff t" and g0: "numgcd t = 0" shows "t = C 0"
 14.1038 -proof-
 14.1039 -  from g0 have th:"numgcdh t (maxcoeff t) = 0" by (simp add: numgcd_def)
 14.1040 -  from numgcdh0[OF th]  have th:"maxcoeff t = 0" .
 14.1041 -  from maxcoeff_nz[OF nz th] show ?thesis .
 14.1042 -qed
 14.1043 -
 14.1044 -constdefs simp_num_pair:: "(num \<times> int) \<Rightarrow> num \<times> int"
 14.1045 -  "simp_num_pair \<equiv> (\<lambda> (t,n). (if n = 0 then (C 0, 0) else
 14.1046 -   (let t' = simpnum t ; g = numgcd t' in 
 14.1047 -      if g > 1 then (let g' = zgcd n g in 
 14.1048 -        if g' = 1 then (t',n) 
 14.1049 -        else (reducecoeffh t' g', n div g')) 
 14.1050 -      else (t',n))))"
 14.1051 -
 14.1052 -lemma simp_num_pair_ci:
 14.1053 -  shows "((\<lambda> (t,n). Inum bs t / real n) (simp_num_pair (t,n))) = ((\<lambda> (t,n). Inum bs t / real n) (t,n))"
 14.1054 -  (is "?lhs = ?rhs")
 14.1055 -proof-
 14.1056 -  let ?t' = "simpnum t"
 14.1057 -  let ?g = "numgcd ?t'"
 14.1058 -  let ?g' = "zgcd n ?g"
 14.1059 -  {assume nz: "n = 0" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
 14.1060 -  moreover
 14.1061 -  { assume nnz: "n \<noteq> 0"
 14.1062 -    {assume "\<not> ?g > 1" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
 14.1063 -    moreover
 14.1064 -    {assume g1:"?g>1" hence g0: "?g > 0" by simp
 14.1065 -      from zgcd0 g1 nnz have gp0: "?g' \<noteq> 0" by simp
 14.1066 -      hence g'p: "?g' > 0" using zgcd_pos[where i="n" and j="numgcd ?t'"] by arith
 14.1067 -      hence "?g'= 1 \<or> ?g' > 1" by arith
 14.1068 -      moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
 14.1069 -      moreover {assume g'1:"?g'>1"
 14.1070 -	from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff ?t' ?g" ..
 14.1071 -	let ?tt = "reducecoeffh ?t' ?g'"
 14.1072 -	let ?t = "Inum bs ?tt"
 14.1073 -	have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2)
 14.1074 -	have gpdd: "?g' dvd n" by (simp add: zgcd_zdvd1) 
 14.1075 -	have gpdgp: "?g' dvd ?g'" by simp
 14.1076 -	from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p] 
 14.1077 -	have th2:"real ?g' * ?t = Inum bs ?t'" by simp
 14.1078 -	from prems have "?lhs = ?t / real (n div ?g')" by (simp add: simp_num_pair_def Let_def)
 14.1079 -	also have "\<dots> = (real ?g' * ?t) / (real ?g' * (real (n div ?g')))" by simp
 14.1080 -	also have "\<dots> = (Inum bs ?t' / real n)"
 14.1081 -	  using real_of_int_div[OF gp0 gpdd] th2 gp0 by simp
 14.1082 -	finally have "?lhs = Inum bs t / real n" by simp
 14.1083 -	then have ?thesis using prems by (simp add: simp_num_pair_def)}
 14.1084 -      ultimately have ?thesis by blast}
 14.1085 -    ultimately have ?thesis by blast} 
 14.1086 -  ultimately show ?thesis by blast
 14.1087 -qed
 14.1088 -
 14.1089 -lemma simp_num_pair_l: assumes tnb: "numbound0 t" and np: "n >0" and tn: "simp_num_pair (t,n) = (t',n')"
 14.1090 -  shows "numbound0 t' \<and> n' >0"
 14.1091 -proof-
 14.1092 -    let ?t' = "simpnum t"
 14.1093 -  let ?g = "numgcd ?t'"
 14.1094 -  let ?g' = "zgcd n ?g"
 14.1095 -  {assume nz: "n = 0" hence ?thesis using prems by (simp add: Let_def simp_num_pair_def)}
 14.1096 -  moreover
 14.1097 -  { assume nnz: "n \<noteq> 0"
 14.1098 -    {assume "\<not> ?g > 1" hence ?thesis  using prems by (auto simp add: Let_def simp_num_pair_def)}
 14.1099 -    moreover
 14.1100 -    {assume g1:"?g>1" hence g0: "?g > 0" by simp
 14.1101 -      from zgcd0 g1 nnz have gp0: "?g' \<noteq> 0" by simp
 14.1102 -      hence g'p: "?g' > 0" using zgcd_pos[where i="n" and j="numgcd ?t'"] by arith
 14.1103 -      hence "?g'= 1 \<or> ?g' > 1" by arith
 14.1104 -      moreover {assume "?g'=1" hence ?thesis using prems 
 14.1105 -	  by (auto simp add: Let_def simp_num_pair_def)}
 14.1106 -      moreover {assume g'1:"?g'>1"
 14.1107 -	have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2)
 14.1108 -	have gpdd: "?g' dvd n" by (simp add: zgcd_zdvd1) 
 14.1109 -	have gpdgp: "?g' dvd ?g'" by simp
 14.1110 -	from zdvd_imp_le[OF gpdd np] have g'n: "?g' \<le> n" .
 14.1111 -	from zdiv_mono1[OF g'n g'p, simplified zdiv_self[OF gp0]]
 14.1112 -	have "n div ?g' >0" by simp
 14.1113 -	hence ?thesis using prems 
 14.1114 -	  by(auto simp add: simp_num_pair_def Let_def reducecoeffh_numbound0)}
 14.1115 -      ultimately have ?thesis by blast}
 14.1116 -    ultimately have ?thesis by blast} 
 14.1117 -  ultimately show ?thesis by blast
 14.1118 -qed
 14.1119 -
 14.1120 -consts not:: "fm \<Rightarrow> fm"
 14.1121 -recdef not "measure size"
 14.1122 -  "not (NOT p) = p"
 14.1123 -  "not T = F"
 14.1124 -  "not F = T"
 14.1125 -  "not (Lt t) = Ge t"
 14.1126 -  "not (Le t) = Gt t"
 14.1127 -  "not (Gt t) = Le t"
 14.1128 -  "not (Ge t) = Lt t"
 14.1129 -  "not (Eq t) = NEq t"
 14.1130 -  "not (NEq t) = Eq t"
 14.1131 -  "not (Dvd i t) = NDvd i t"
 14.1132 -  "not (NDvd i t) = Dvd i t"
 14.1133 -  "not (And p q) = Or (not p) (not q)"
 14.1134 -  "not (Or p q) = And (not p) (not q)"
 14.1135 -  "not p = NOT p"
 14.1136 -lemma not[simp]: "Ifm bs (not p) = Ifm bs (NOT p)"
 14.1137 -by (induct p) auto
 14.1138 -lemma not_qf[simp]: "qfree p \<Longrightarrow> qfree (not p)"
 14.1139 -by (induct p, auto)
 14.1140 -lemma not_nb[simp]: "bound0 p \<Longrightarrow> bound0 (not p)"
 14.1141 -by (induct p, auto)
 14.1142 -
 14.1143 -constdefs conj :: "fm \<Rightarrow> fm \<Rightarrow> fm"
 14.1144 -  "conj p q \<equiv> (if (p = F \<or> q=F) then F else if p=T then q else if q=T then p else 
 14.1145 -   if p = q then p else And p q)"
 14.1146 -lemma conj[simp]: "Ifm bs (conj p q) = Ifm bs (And p q)"
 14.1147 -by (cases "p=F \<or> q=F",simp_all add: conj_def) (cases p,simp_all)
 14.1148 -
 14.1149 -lemma conj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (conj p q)"
 14.1150 -using conj_def by auto 
 14.1151 -lemma conj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (conj p q)"
 14.1152 -using conj_def by auto 
 14.1153 -
 14.1154 -constdefs disj :: "fm \<Rightarrow> fm \<Rightarrow> fm"
 14.1155 -  "disj p q \<equiv> (if (p = T \<or> q=T) then T else if p=F then q else if q=F then p 
 14.1156 -       else if p=q then p else Or p q)"
 14.1157 -
 14.1158 -lemma disj[simp]: "Ifm bs (disj p q) = Ifm bs (Or p q)"
 14.1159 -by (cases "p=T \<or> q=T",simp_all add: disj_def) (cases p,simp_all)
 14.1160 -lemma disj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (disj p q)"
 14.1161 -using disj_def by auto 
 14.1162 -lemma disj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (disj p q)"
 14.1163 -using disj_def by auto 
 14.1164 -
 14.1165 -constdefs   imp :: "fm \<Rightarrow> fm \<Rightarrow> fm"
 14.1166 -  "imp p q \<equiv> (if (p = F \<or> q=T \<or> p=q) then T else if p=T then q else if q=F then not p 
 14.1167 -    else Imp p q)"
 14.1168 -lemma imp[simp]: "Ifm bs (imp p q) = Ifm bs (Imp p q)"
 14.1169 -by (cases "p=F \<or> q=T",simp_all add: imp_def)
 14.1170 -lemma imp_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (imp p q)"
 14.1171 -using imp_def by (cases "p=F \<or> q=T",simp_all add: imp_def)
 14.1172 -lemma imp_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (imp p q)"
 14.1173 -using imp_def by (cases "p=F \<or> q=T \<or> p=q",simp_all add: imp_def) 
 14.1174 -
 14.1175 -constdefs   iff :: "fm \<Rightarrow> fm \<Rightarrow> fm"
 14.1176 -  "iff p q \<equiv> (if (p = q) then T else if (p = not q \<or> not p = q) then F else 
 14.1177 -       if p=F then not q else if q=F then not p else if p=T then q else if q=T then p else 
 14.1178 -  Iff p q)"
 14.1179 -lemma iff[simp]: "Ifm bs (iff p q) = Ifm bs (Iff p q)"
 14.1180 -  by (unfold iff_def,cases "p=q", simp,cases "p=not q", simp add:not) 
 14.1181 -(cases "not p= q", auto simp add:not)
 14.1182 -lemma iff_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (iff p q)"
 14.1183 -  by (unfold iff_def,cases "p=q", auto)
 14.1184 -lemma iff_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (iff p q)"
 14.1185 -using iff_def by (unfold iff_def,cases "p=q", auto)
 14.1186 -
 14.1187 -consts check_int:: "num \<Rightarrow> bool"
 14.1188 -recdef check_int "measure size"
 14.1189 -  "check_int (C i) = True"
 14.1190 -  "check_int (Floor t) = True"
 14.1191 -  "check_int (Mul i t) = check_int t"
 14.1192 -  "check_int (Add t s) = (check_int t \<and> check_int s)"
 14.1193 -  "check_int (Neg t) = check_int t"
 14.1194 -  "check_int (CF c t s) = check_int s"
 14.1195 -  "check_int t = False"
 14.1196 -lemma check_int: "check_int t \<Longrightarrow> isint t bs"
 14.1197 -by (induct t, auto simp add: isint_add isint_Floor isint_Mul isint_neg isint_c isint_CF)
 14.1198 -
 14.1199 -lemma rdvd_left1_int: "real \<lfloor>t\<rfloor> = t \<Longrightarrow> 1 rdvd t"
 14.1200 -  by (simp add: rdvd_def,rule_tac x="\<lfloor>t\<rfloor>" in exI) simp
 14.1201 -
 14.1202 -lemma rdvd_reduce: 
 14.1203 -  assumes gd:"g dvd d" and gc:"g dvd c" and gp: "g > 0"
 14.1204 -  shows "real (d::int) rdvd real (c::int)*t = (real (d div g) rdvd real (c div g)*t)"
 14.1205 -proof
 14.1206 -  assume d: "real d rdvd real c * t"
 14.1207 -  from d rdvd_def obtain k where k_def: "real c * t = real d* real (k::int)" by auto
 14.1208 -  from gd dvd_def obtain kd where kd_def: "d = g * kd" by auto
 14.1209 -  from gc dvd_def obtain kc where kc_def: "c = g * kc" by auto
 14.1210 -  from k_def kd_def kc_def have "real g * real kc * t = real g * real kd * real k" by simp
 14.1211 -  hence "real kc * t = real kd * real k" using gp by simp
 14.1212 -  hence th:"real kd rdvd real kc * t" using rdvd_def by blast
 14.1213 -  from kd_def gp have th':"kd = d div g" by simp
 14.1214 -  from kc_def gp have "kc = c div g" by simp
 14.1215 -  with th th' show "real (d div g) rdvd real (c div g) * t" by simp
 14.1216 -next
 14.1217 -  assume d: "real (d div g) rdvd real (c div g) * t"
 14.1218 -  from gp have gnz: "g \<noteq> 0" by simp
 14.1219 -  thus "real d rdvd real c * t" using d rdvd_mult[OF gnz, where n="d div g" and x="real (c div g) * t"] real_of_int_div[OF gnz gd] real_of_int_div[OF gnz gc] by simp
 14.1220 -qed
 14.1221 -
 14.1222 -constdefs simpdvd:: "int \<Rightarrow> num \<Rightarrow> (int \<times> num)"
 14.1223 -  "simpdvd d t \<equiv> 
 14.1224 -   (let g = numgcd t in 
 14.1225 -      if g > 1 then (let g' = zgcd d g in 
 14.1226 -        if g' = 1 then (d, t) 
 14.1227 -        else (d div g',reducecoeffh t g')) 
 14.1228 -      else (d, t))"
 14.1229 -lemma simpdvd: 
 14.1230 -  assumes tnz: "nozerocoeff t" and dnz: "d \<noteq> 0"
 14.1231 -  shows "Ifm bs (Dvd (fst (simpdvd d t)) (snd (simpdvd d t))) = Ifm bs (Dvd d t)"
 14.1232 -proof-
 14.1233 -  let ?g = "numgcd t"
 14.1234 -  let ?g' = "zgcd d ?g"
 14.1235 -  {assume "\<not> ?g > 1" hence ?thesis by (simp add: Let_def simpdvd_def)}
 14.1236 -  moreover
 14.1237 -  {assume g1:"?g>1" hence g0: "?g > 0" by simp
 14.1238 -    from zgcd0 g1 dnz have gp0: "?g' \<noteq> 0" by simp
 14.1239 -    hence g'p: "?g' > 0" using zgcd_pos[where i="d" and j="numgcd t"] by arith
 14.1240 -    hence "?g'= 1 \<or> ?g' > 1" by arith
 14.1241 -    moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simpdvd_def)}
 14.1242 -    moreover {assume g'1:"?g'>1"
 14.1243 -      from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff t ?g" ..
 14.1244 -      let ?tt = "reducecoeffh t ?g'"
 14.1245 -      let ?t = "Inum bs ?tt"
 14.1246 -      have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2)
 14.1247 -      have gpdd: "?g' dvd d" by (simp add: zgcd_zdvd1) 
 14.1248 -      have gpdgp: "?g' dvd ?g'" by simp
 14.1249 -      from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p] 
 14.1250 -      have th2:"real ?g' * ?t = Inum bs t" by simp
 14.1251 -      from prems have "Ifm bs (Dvd (fst (simpdvd d t)) (snd(simpdvd d t))) = Ifm bs (Dvd (d div ?g') ?tt)"
 14.1252 -	by (simp add: simpdvd_def Let_def)
 14.1253 -      also have "\<dots> = (real d rdvd (Inum bs t))"
 14.1254 -	using rdvd_reduce[OF gpdd gpdgp g'p, where t="?t", simplified zdiv_self[OF gp0]] 
 14.1255 -	  th2[symmetric] by simp
 14.1256 -      finally have ?thesis by simp  }
 14.1257 -    ultimately have ?thesis by blast
 14.1258 -  }
 14.1259 -  ultimately show ?thesis by blast
 14.1260 -qed
 14.1261 -
 14.1262 -consts simpfm :: "fm \<Rightarrow> fm"
 14.1263 -recdef simpfm "measure fmsize"
 14.1264 -  "simpfm (And p q) = conj (simpfm p) (simpfm q)"
 14.1265 -  "simpfm (Or p q) = disj (simpfm p) (simpfm q)"
 14.1266 -  "simpfm (Imp p q) = imp (simpfm p) (simpfm q)"
 14.1267 -  "simpfm (Iff p q) = iff (simpfm p) (simpfm q)"
 14.1268 -  "simpfm (NOT p) = not (simpfm p)"
 14.1269 -  "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v < 0) then T else F 
 14.1270 -  | _ \<Rightarrow> Lt (reducecoeff a'))"
 14.1271 -  "simpfm (Le a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v \<le> 0)  then T else F | _ \<Rightarrow> Le (reducecoeff a'))"
 14.1272 -  "simpfm (Gt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v > 0)  then T else F | _ \<Rightarrow> Gt (reducecoeff a'))"
 14.1273 -  "simpfm (Ge a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v \<ge> 0)  then T else F | _ \<Rightarrow> Ge (reducecoeff a'))"
 14.1274 -  "simpfm (Eq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v = 0)  then T else F | _ \<Rightarrow> Eq (reducecoeff a'))"
 14.1275 -  "simpfm (NEq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v \<noteq> 0)  then T else F | _ \<Rightarrow> NEq (reducecoeff a'))"
 14.1276 -  "simpfm (Dvd i a) = (if i=0 then simpfm (Eq a)
 14.1277 -             else if (abs i = 1) \<and> check_int a then T
 14.1278 -             else let a' = simpnum a in case a' of C v \<Rightarrow> if (i dvd v)  then T else F | _ \<Rightarrow> (let (d,t) = simpdvd i a' in Dvd d t))"
 14.1279 -  "simpfm (NDvd i a) = (if i=0 then simpfm (NEq a) 
 14.1280 -             else if (abs i = 1) \<and> check_int a then F
 14.1281 -             else let a' = simpnum a in case a' of C v \<Rightarrow> if (\<not>(i dvd v)) then T else F | _ \<Rightarrow> (let (d,t) = simpdvd i a' in NDvd d t))"
 14.1282 -  "simpfm p = p"
 14.1283 -
 14.1284 -lemma simpfm[simp]: "Ifm bs (simpfm p) = Ifm bs p"
 14.1285 -proof(induct p rule: simpfm.induct)
 14.1286 -  case (6 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
 14.1287 -  {fix v assume "?sa = C v" hence ?case using sa by simp }
 14.1288 -  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
 14.1289 -    let ?g = "numgcd ?sa"
 14.1290 -    let ?rsa = "reducecoeff ?sa"
 14.1291 -    let ?r = "Inum bs ?rsa"
 14.1292 -    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
 14.1293 -    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
 14.1294 -    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
 14.1295 -    hence gp: "real ?g > 0" by simp
 14.1296 -    have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff)
 14.1297 -    with sa have "Inum bs a < 0 = (real ?g * ?r < real ?g * 0)" by simp
 14.1298 -    also have "\<dots> = (?r < 0)" using gp
 14.1299 -      by (simp only: mult_less_cancel_left) simp
 14.1300 -    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
 14.1301 -  ultimately show ?case by blast
 14.1302 -next
 14.1303 -  case (7 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
 14.1304 -  {fix v assume "?sa = C v" hence ?case using sa by simp }
 14.1305 -  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
 14.1306 -    let ?g = "numgcd ?sa"
 14.1307 -    let ?rsa = "reducecoeff ?sa"
 14.1308 -    let ?r = "Inum bs ?rsa"
 14.1309 -    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
 14.1310 -    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
 14.1311 -    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
 14.1312 -    hence gp: "real ?g > 0" by simp
 14.1313 -    have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff)
 14.1314 -    with sa have "Inum bs a \<le> 0 = (real ?g * ?r \<le> real ?g * 0)" by simp
 14.1315 -    also have "\<dots> = (?r \<le> 0)" using gp
 14.1316 -      by (simp only: mult_le_cancel_left) simp
 14.1317 -    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
 14.1318 -  ultimately show ?case by blast
 14.1319 -next
 14.1320 -  case (8 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
 14.1321 -  {fix v assume "?sa = C v" hence ?case using sa by simp }
 14.1322 -  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
 14.1323 -    let ?g = "numgcd ?sa"
 14.1324 -    let ?rsa = "reducecoeff ?sa"
 14.1325 -    let ?r = "Inum bs ?rsa"
 14.1326 -    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
 14.1327 -    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
 14.1328 -    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
 14.1329 -    hence gp: "real ?g > 0" by simp
 14.1330 -    have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff)
 14.1331 -    with sa have "Inum bs a > 0 = (real ?g * ?r > real ?g * 0)" by simp
 14.1332 -    also have "\<dots> = (?r > 0)" using gp
 14.1333 -      by (simp only: mult_less_cancel_left) simp
 14.1334 -    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
 14.1335 -  ultimately show ?case by blast
 14.1336 -next
 14.1337 -  case (9 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
 14.1338 -  {fix v assume "?sa = C v" hence ?case using sa by simp }
 14.1339 -  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
 14.1340 -    let ?g = "numgcd ?sa"
 14.1341 -    let ?rsa = "reducecoeff ?sa"
 14.1342 -    let ?r = "Inum bs ?rsa"
 14.1343 -    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
 14.1344 -    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
 14.1345 -    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
 14.1346 -    hence gp: "real ?g > 0" by simp
 14.1347 -    have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff)
 14.1348 -    with sa have "Inum bs a \<ge> 0 = (real ?g * ?r \<ge> real ?g * 0)" by simp
 14.1349 -    also have "\<dots> = (?r \<ge> 0)" using gp
 14.1350 -      by (simp only: mult_le_cancel_left) simp
 14.1351 -    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
 14.1352 -  ultimately show ?case by blast
 14.1353 -next
 14.1354 -  case (10 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
 14.1355 -  {fix v assume "?sa = C v" hence ?case using sa by simp }
 14.1356 -  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
 14.1357 -    let ?g = "numgcd ?sa"
 14.1358 -    let ?rsa = "reducecoeff ?sa"
 14.1359 -    let ?r = "Inum bs ?rsa"
 14.1360 -    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
 14.1361 -    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
 14.1362 -    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
 14.1363 -    hence gp: "real ?g > 0" by simp
 14.1364 -    have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff)
 14.1365 -    with sa have "Inum bs a = 0 = (real ?g * ?r = 0)" by simp
 14.1366 -    also have "\<dots> = (?r = 0)" using gp
 14.1367 -      by (simp add: mult_eq_0_iff)
 14.1368 -    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
 14.1369 -  ultimately show ?case by blast
 14.1370 -next
 14.1371 -  case (11 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
 14.1372 -  {fix v assume "?sa = C v" hence ?case using sa by simp }
 14.1373 -  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
 14.1374 -    let ?g = "numgcd ?sa"
 14.1375 -    let ?rsa = "reducecoeff ?sa"
 14.1376 -    let ?r = "Inum bs ?rsa"
 14.1377 -    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
 14.1378 -    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
 14.1379 -    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
 14.1380 -    hence gp: "real ?g > 0" by simp
 14.1381 -    have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff)
 14.1382 -    with sa have "Inum bs a \<noteq> 0 = (real ?g * ?r \<noteq> 0)" by simp
 14.1383 -    also have "\<dots> = (?r \<noteq> 0)" using gp
 14.1384 -      by (simp add: mult_eq_0_iff)
 14.1385 -    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
 14.1386 -  ultimately show ?case by blast
 14.1387 -next
 14.1388 -  case (12 i a)  let ?sa = "simpnum a"   have sa: "Inum bs ?sa = Inum bs a" by simp
 14.1389 -  have "i=0 \<or> (abs i = 1 \<and> check_int a) \<or> (i\<noteq>0 \<and> ((abs i \<noteq> 1) \<or> (\<not> check_int a)))" by auto
 14.1390 -  {assume "i=0" hence ?case using "12.hyps" by (simp add: rdvd_left_0_eq Let_def)}
 14.1391 -  moreover 
 14.1392 -  {assume ai1: "abs i = 1" and ai: "check_int a" 
 14.1393 -    hence "i=1 \<or> i= - 1" by arith
 14.1394 -    moreover {assume i1: "i = 1" 
 14.1395 -      from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] 
 14.1396 -      have ?case using i1 ai by simp }
 14.1397 -    moreover {assume i1: "i = - 1" 
 14.1398 -      from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] 
 14.1399 -	rdvd_abs1[where d="- 1" and t="Inum bs a"]
 14.1400 -      have ?case using i1 ai by simp }
 14.1401 -    ultimately have ?case by blast}
 14.1402 -  moreover   
 14.1403 -  {assume inz: "i\<noteq>0" and cond: "(abs i \<noteq> 1) \<or> (\<not> check_int a)"
 14.1404 -    {fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond
 14.1405 -	by (cases "abs i = 1", auto simp add: int_rdvd_iff) }
 14.1406 -    moreover {assume H:"\<not> (\<exists> v. ?sa = C v)" 
 14.1407 -      hence th: "simpfm (Dvd i a) = Dvd (fst (simpdvd i ?sa)) (snd (simpdvd i ?sa))" using inz cond by (cases ?sa, auto simp add: Let_def split_def)
 14.1408 -      from simpnum_nz have nz:"nozerocoeff ?sa" by simp
 14.1409 -      from simpdvd [OF nz inz] th have ?case using sa by simp}
 14.1410 -    ultimately have ?case by blast}
 14.1411 -  ultimately show ?case by blast
 14.1412 -next
 14.1413 -  case (13 i a)  let ?sa = "simpnum a"   have sa: "Inum bs ?sa = Inum bs a" by simp
 14.1414 -  have "i=0 \<or> (abs i = 1 \<and> check_int a) \<or> (i\<noteq>0 \<and> ((abs i \<noteq> 1) \<or> (\<not> check_int a)))" by auto
 14.1415 -  {assume "i=0" hence ?case using "13.hyps" by (simp add: rdvd_left_0_eq Let_def)}
 14.1416 -  moreover 
 14.1417 -  {assume ai1: "abs i = 1" and ai: "check_int a" 
 14.1418 -    hence "i=1 \<or> i= - 1" by arith
 14.1419 -    moreover {assume i1: "i = 1" 
 14.1420 -      from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] 
 14.1421 -      have ?case using i1 ai by simp }
 14.1422 -    moreover {assume i1: "i = - 1" 
 14.1423 -      from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] 
 14.1424 -	rdvd_abs1[where d="- 1" and t="Inum bs a"]
 14.1425 -      have ?case using i1 ai by simp }
 14.1426 -    ultimately have ?case by blast}
 14.1427 -  moreover   
 14.1428 -  {assume inz: "i\<noteq>0" and cond: "(abs i \<noteq> 1) \<or> (\<not> check_int a)"
 14.1429 -    {fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond
 14.1430 -	by (cases "abs i = 1", auto simp add: int_rdvd_iff) }
 14.1431 -    moreover {assume H:"\<not> (\<exists> v. ?sa = C v)" 
 14.1432 -      hence th: "simpfm (NDvd i a) = NDvd (fst (simpdvd i ?sa)) (snd (simpdvd i ?sa))" using inz cond 
 14.1433 -	by (cases ?sa, auto simp add: Let_def split_def)
 14.1434 -      from simpnum_nz have nz:"nozerocoeff ?sa" by simp
 14.1435 -      from simpdvd [OF nz inz] th have ?case using sa by simp}
 14.1436 -    ultimately have ?case by blast}
 14.1437 -  ultimately show ?case by blast
 14.1438 -qed (induct p rule: simpfm.induct, simp_all)
 14.1439 -
 14.1440 -lemma simpdvd_numbound0: "numbound0 t \<Longrightarrow> numbound0 (snd (simpdvd d t))"
 14.1441 -  by (simp add: simpdvd_def Let_def split_def reducecoeffh_numbound0)
 14.1442 -
 14.1443 -lemma simpfm_bound0[simp]: "bound0 p \<Longrightarrow> bound0 (simpfm p)"
 14.1444 -proof(induct p rule: simpfm.induct)
 14.1445 -  case (6 a) hence nb: "numbound0 a" by simp
 14.1446 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 14.1447 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
 14.1448 -next
 14.1449 -  case (7 a) hence nb: "numbound0 a" by simp
 14.1450 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 14.1451 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
 14.1452 -next
 14.1453 -  case (8 a) hence nb: "numbound0 a" by simp
 14.1454 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 14.1455 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
 14.1456 -next
 14.1457 -  case (9 a) hence nb: "numbound0 a" by simp
 14.1458 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 14.1459 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
 14.1460 -next
 14.1461 -  case (10 a) hence nb: "numbound0 a" by simp
 14.1462 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 14.1463 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
 14.1464 -next
 14.1465 -  case (11 a) hence nb: "numbound0 a" by simp
 14.1466 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 14.1467 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
 14.1468 -next
 14.1469 -  case (12 i a) hence nb: "numbound0 a" by simp
 14.1470 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 14.1471 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0 simpdvd_numbound0 split_def)
 14.1472 -next
 14.1473 -  case (13 i a) hence nb: "numbound0 a" by simp
 14.1474 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 14.1475 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0 simpdvd_numbound0 split_def)
 14.1476 -qed(auto simp add: disj_def imp_def iff_def conj_def)
 14.1477 -
 14.1478 -lemma simpfm_qf[simp]: "qfree p \<Longrightarrow> qfree (simpfm p)"
 14.1479 -by (induct p rule: simpfm.induct, auto simp add: Let_def)
 14.1480 -(case_tac "simpnum a",auto simp add: split_def Let_def)+
 14.1481 -
 14.1482 -
 14.1483 -  (* Generic quantifier elimination *)
 14.1484 -
 14.1485 -constdefs list_conj :: "fm list \<Rightarrow> fm"
 14.1486 -  "list_conj ps \<equiv> foldr conj ps T"
 14.1487 -lemma list_conj: "Ifm bs (list_conj ps) = (\<forall>p\<in> set ps. Ifm bs p)"
 14.1488 -  by (induct ps, auto simp add: list_conj_def)
 14.1489 -lemma list_conj_qf: " \<forall>p\<in> set ps. qfree p \<Longrightarrow> qfree (list_conj ps)"
 14.1490 -  by (induct ps, auto simp add: list_conj_def)
 14.1491 -lemma list_conj_nb: " \<forall>p\<in> set ps. bound0 p \<Longrightarrow> bound0 (list_conj ps)"
 14.1492 -  by (induct ps, auto simp add: list_conj_def)
 14.1493 -constdefs CJNB:: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm"
 14.1494 -  "CJNB f p \<equiv> (let cjs = conjuncts p ; (yes,no) = partition bound0 cjs
 14.1495 -                   in conj (decr (list_conj yes)) (f (list_conj no)))"
 14.1496 -
 14.1497 -lemma CJNB_qe: 
 14.1498 -  assumes qe: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))"
 14.1499 -  shows "\<forall> bs p. qfree p \<longrightarrow> qfree (CJNB qe p) \<and> (Ifm bs ((CJNB qe p)) = Ifm bs (E p))"
 14.1500 -proof(clarify)
 14.1501 -  fix bs p
 14.1502 -  assume qfp: "qfree p"
 14.1503 -  let ?cjs = "conjuncts p"
 14.1504 -  let ?yes = "fst (partition bound0 ?cjs)"
 14.1505 -  let ?no = "snd (partition bound0 ?cjs)"
 14.1506 -  let ?cno = "list_conj ?no"
 14.1507 -  let ?cyes = "list_conj ?yes"
 14.1508 -  have part: "partition bound0 ?cjs = (?yes,?no)" by simp
 14.1509 -  from partition_P[OF part] have "\<forall> q\<in> set ?yes. bound0 q" by blast 
 14.1510 -  hence yes_nb: "bound0 ?cyes" by (simp add: list_conj_nb) 
 14.1511 -  hence yes_qf: "qfree (decr ?cyes )" by (simp add: decr_qf)
 14.1512 -  from conjuncts_qf[OF qfp] partition_set[OF part] 
 14.1513 -  have " \<forall>q\<in> set ?no. qfree q" by auto
 14.1514 -  hence no_qf: "qfree ?cno"by (simp add: list_conj_qf)
 14.1515 -  with qe have cno_qf:"qfree (qe ?cno )" 
 14.1516 -    and noE: "Ifm bs (qe ?cno) = Ifm bs (E ?cno)" by blast+
 14.1517 -  from cno_qf yes_qf have qf: "qfree (CJNB qe p)" 
 14.1518 -    by (simp add: CJNB_def Let_def conj_qf split_def)
 14.1519 -  {fix bs
 14.1520 -    from conjuncts have "Ifm bs p = (\<forall>q\<in> set ?cjs. Ifm bs q)" by blast
 14.1521 -    also have "\<dots> = ((\<forall>q\<in> set ?yes. Ifm bs q) \<and> (\<forall>q\<in> set ?no. Ifm bs q))"
 14.1522 -      using partition_set[OF part] by auto
 14.1523 -    finally have "Ifm bs p = ((Ifm bs ?cyes) \<and> (Ifm bs ?cno))" using list_conj by simp}
 14.1524 -  hence "Ifm bs (E p) = (\<exists>x. (Ifm (x#bs) ?cyes) \<and> (Ifm (x#bs) ?cno))" by simp
 14.1525 -  also fix y have "\<dots> = (\<exists>x. (Ifm (y#bs) ?cyes) \<and> (Ifm (x#bs) ?cno))"
 14.1526 -    using bound0_I[OF yes_nb, where bs="bs" and b'="y"] by blast
 14.1527 -  also have "\<dots> = (Ifm bs (decr ?cyes) \<and> Ifm bs (E ?cno))"
 14.1528 -    by (auto simp add: decr[OF yes_nb])
 14.1529 -  also have "\<dots> = (Ifm bs (conj (decr ?cyes) (qe ?cno)))"
 14.1530 -    using qe[rule_format, OF no_qf] by auto
 14.1531 -  finally have "Ifm bs (E p) = Ifm bs (CJNB qe p)" 
 14.1532 -    by (simp add: Let_def CJNB_def split_def)
 14.1533 -  with qf show "qfree (CJNB qe p) \<and> Ifm bs (CJNB qe p) = Ifm bs (E p)" by blast
 14.1534 -qed
 14.1535 -
 14.1536 -consts qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm"
 14.1537 -recdef qelim "measure fmsize"
 14.1538 -  "qelim (E p) = (\<lambda> qe. DJ (CJNB qe) (qelim p qe))"
 14.1539 -  "qelim (A p) = (\<lambda> qe. not (qe ((qelim (NOT p) qe))))"
 14.1540 -  "qelim (NOT p) = (\<lambda> qe. not (qelim p qe))"
 14.1541 -  "qelim (And p q) = (\<lambda> qe. conj (qelim p qe) (qelim q qe))" 
 14.1542 -  "qelim (Or  p q) = (\<lambda> qe. disj (qelim p qe) (qelim q qe))" 
 14.1543 -  "qelim (Imp p q) = (\<lambda> qe. disj (qelim (NOT p) qe) (qelim q qe))"
 14.1544 -  "qelim (Iff p q) = (\<lambda> qe. iff (qelim p qe) (qelim q qe))"
 14.1545 -  "qelim p = (\<lambda> y. simpfm p)"
 14.1546 -
 14.1547 -lemma qelim_ci:
 14.1548 -  assumes qe_inv: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))"
 14.1549 -  shows "\<And> bs. qfree (qelim p qe) \<and> (Ifm bs (qelim p qe) = Ifm bs p)"
 14.1550 -using qe_inv DJ_qe[OF CJNB_qe[OF qe_inv]] 
 14.1551 -by(induct p rule: qelim.induct) 
 14.1552 -(auto simp del: simpfm.simps)
 14.1553 -
 14.1554 -
 14.1555 -text {* The @{text "\<int>"} Part *}
 14.1556 -text{* Linearity for fm where Bound 0 ranges over @{text "\<int>"} *}
 14.1557 -consts
 14.1558 -  zsplit0 :: "num \<Rightarrow> int \<times> num" (* splits the bounded from the unbounded part*)
 14.1559 -recdef zsplit0 "measure num_size"
 14.1560 -  "zsplit0 (C c) = (0,C c)"
 14.1561 -  "zsplit0 (Bound n) = (if n=0 then (1, C 0) else (0,Bound n))"
 14.1562 -  "zsplit0 (CN n c a) = zsplit0 (Add (Mul c (Bound n)) a)"
 14.1563 -  "zsplit0 (CF c a b) = zsplit0 (Add (Mul c (Floor a)) b)"
 14.1564 -  "zsplit0 (Neg a) = (let (i',a') =  zsplit0 a in (-i', Neg a'))"
 14.1565 -  "zsplit0 (Add a b) = (let (ia,a') =  zsplit0 a ; 
 14.1566 -                            (ib,b') =  zsplit0 b 
 14.1567 -                            in (ia+ib, Add a' b'))"
 14.1568 -  "zsplit0 (Sub a b) = (let (ia,a') =  zsplit0 a ; 
 14.1569 -                            (ib,b') =  zsplit0 b 
 14.1570 -                            in (ia-ib, Sub a' b'))"
 14.1571 -  "zsplit0 (Mul i a) = (let (i',a') =  zsplit0 a in (i*i', Mul i a'))"
 14.1572 -  "zsplit0 (Floor a) = (let (i',a') =  zsplit0 a in (i',Floor a'))"
 14.1573 -(hints simp add: Let_def)
 14.1574 -
 14.1575 -lemma zsplit0_I:
 14.1576 -  shows "\<And> n a. zsplit0 t = (n,a) \<Longrightarrow> (Inum ((real (x::int)) #bs) (CN 0 n a) = Inum (real x #bs) t) \<and> numbound0 a"
 14.1577 -  (is "\<And> n a. ?S t = (n,a) \<Longrightarrow> (?I x (CN 0 n a) = ?I x t) \<and> ?N a")
 14.1578 -proof(induct t rule: zsplit0.induct)
 14.1579 -  case (1 c n a) thus ?case by auto 
 14.1580 -next
 14.1581 -  case (2 m n a) thus ?case by (cases "m=0") auto
 14.1582 -next
 14.1583 -  case (3 n i a n a') thus ?case by auto
 14.1584 -next 
 14.1585 -  case (4 c a b n a') thus ?case by auto
 14.1586 -next
 14.1587 -  case (5 t n a)
 14.1588 -  let ?nt = "fst (zsplit0 t)"
 14.1589 -  let ?at = "snd (zsplit0 t)"
 14.1590 -  have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Neg ?at \<and> n=-?nt" using prems 
 14.1591 -    by (simp add: Let_def split_def)
 14.1592 -  from abj prems  have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
 14.1593 -  from th2[simplified] th[simplified] show ?case by simp
 14.1594 -next
 14.1595 -  case (6 s t n a)
 14.1596 -  let ?ns = "fst (zsplit0 s)"
 14.1597 -  let ?as = "snd (zsplit0 s)"
 14.1598 -  let ?nt = "fst (zsplit0 t)"
 14.1599 -  let ?at = "snd (zsplit0 t)"
 14.1600 -  have abjs: "zsplit0 s = (?ns,?as)" by simp 
 14.1601 -  moreover have abjt:  "zsplit0 t = (?nt,?at)" by simp 
 14.1602 -  ultimately have th: "a=Add ?as ?at \<and> n=?ns + ?nt" using prems 
 14.1603 -    by (simp add: Let_def split_def)
 14.1604 -  from abjs[symmetric] have bluddy: "\<exists> x y. (x,y) = zsplit0 s" by blast
 14.1605 -  from prems have "(\<exists> x y. (x,y) = zsplit0 s) \<longrightarrow> (\<forall>xa xb. zsplit0 t = (xa, xb) \<longrightarrow> Inum (real x # bs) (CN 0 xa xb) = Inum (real x # bs) t \<and> numbound0 xb)" by simp
 14.1606 -  with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
 14.1607 -  from abjs prems  have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \<and> ?N ?as" by blast
 14.1608 -  from th3[simplified] th2[simplified] th[simplified] show ?case 
 14.1609 -    by (simp add: left_distrib)
 14.1610 -next
 14.1611 -  case (7 s t n a)
 14.1612 -  let ?ns = "fst (zsplit0 s)"
 14.1613 -  let ?as = "snd (zsplit0 s)"
 14.1614 -  let ?nt = "fst (zsplit0 t)"
 14.1615 -  let ?at = "snd (zsplit0 t)"
 14.1616 -  have abjs: "zsplit0 s = (?ns,?as)" by simp 
 14.1617 -  moreover have abjt:  "zsplit0 t = (?nt,?at)" by simp 
 14.1618 -  ultimately have th: "a=Sub ?as ?at \<and> n=?ns - ?nt" using prems 
 14.1619 -    by (simp add: Let_def split_def)
 14.1620 -  from abjs[symmetric] have bluddy: "\<exists> x y. (x,y) = zsplit0 s" by blast
 14.1621 -  from prems have "(\<exists> x y. (x,y) = zsplit0 s) \<longrightarrow> (\<forall>xa xb. zsplit0 t = (xa, xb) \<longrightarrow> Inum (real x # bs) (CN 0 xa xb) = Inum (real x # bs) t \<and> numbound0 xb)" by simp
 14.1622 -  with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
 14.1623 -  from abjs prems  have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \<and> ?N ?as" by blast
 14.1624 -  from th3[simplified] th2[simplified] th[simplified] show ?case 
 14.1625 -    by (simp add: left_diff_distrib)
 14.1626 -next
 14.1627 -  case (8 i t n a)
 14.1628 -  let ?nt = "fst (zsplit0 t)"
 14.1629 -  let ?at = "snd (zsplit0 t)"
 14.1630 -  have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Mul i ?at \<and> n=i*?nt" using prems 
 14.1631 -    by (simp add: Let_def split_def)
 14.1632 -  from abj prems  have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
 14.1633 -  hence " ?I x (Mul i t) = (real i) * ?I x (CN 0 ?nt ?at)" by simp
 14.1634 -  also have "\<dots> = ?I x (CN 0 (i*?nt) (Mul i ?at))" by (simp add: right_distrib)
 14.1635 -  finally show ?case using th th2 by simp
 14.1636 -next
 14.1637 -  case (9 t n a)
 14.1638 -  let ?nt = "fst (zsplit0 t)"
 14.1639 -  let ?at = "snd (zsplit0 t)"
 14.1640 -  have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a= Floor ?at \<and> n=?nt" using prems 
 14.1641 -    by (simp add: Let_def split_def)
 14.1642 -  from abj prems  have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
 14.1643 -  hence na: "?N a" using th by simp
 14.1644 -  have th': "(real ?nt)*(real x) = real (?nt * x)" by simp
 14.1645 -  have "?I x (Floor t) = ?I x (Floor (CN 0 ?nt ?at))" using th2 by simp
 14.1646 -  also have "\<dots> = real (floor ((real ?nt)* real(x) + ?I x ?at))" by simp
 14.1647 -  also have "\<dots> = real (floor (?I x ?at + real (?nt* x)))" by (simp add: add_ac)
 14.1648 -  also have "\<dots> = real (floor (?I x ?at) + (?nt* x))" 
 14.1649 -    using floor_add[where x="?I x ?at" and a="?nt* x"] by simp 
 14.1650 -  also have "\<dots> = real (?nt)*(real x) + real (floor (?I x ?at))" by (simp add: add_ac)
 14.1651 -  finally have "?I x (Floor t) = ?I x (CN 0 n a)" using th by simp
 14.1652 -  with na show ?case by simp
 14.1653 -qed
 14.1654 -
 14.1655 -consts
 14.1656 -  iszlfm :: "fm \<Rightarrow> real list \<Rightarrow> bool"   (* Linearity test for fm *)
 14.1657 -  zlfm :: "fm \<Rightarrow> fm"       (* Linearity transformation for fm *)
 14.1658 -recdef iszlfm "measure size"
 14.1659 -  "iszlfm (And p q) = (\<lambda> bs. iszlfm p bs \<and> iszlfm q bs)" 
 14.1660 -  "iszlfm (Or p q) = (\<lambda> bs. iszlfm p bs \<and> iszlfm q bs)" 
 14.1661 -  "iszlfm (Eq  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
 14.1662 -  "iszlfm (NEq (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
 14.1663 -  "iszlfm (Lt  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
 14.1664 -  "iszlfm (Le  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
 14.1665 -  "iszlfm (Gt  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
 14.1666 -  "iszlfm (Ge  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
 14.1667 -  "iszlfm (Dvd i (CN 0 c e)) = 
 14.1668 -                 (\<lambda> bs. c>0 \<and> i>0 \<and> numbound0 e \<and> isint e bs)"
 14.1669 -  "iszlfm (NDvd i (CN 0 c e))= 
 14.1670 -                 (\<lambda> bs. c>0 \<and> i>0 \<and> numbound0 e \<and> isint e bs)"
 14.1671 -  "iszlfm p = (\<lambda> bs. isatom p \<and> (bound0 p))"
 14.1672 -
 14.1673 -lemma zlin_qfree: "iszlfm p bs \<Longrightarrow> qfree p"
 14.1674 -  by (induct p rule: iszlfm.induct) auto
 14.1675 -
 14.1676 -lemma iszlfm_gen:
 14.1677 -  assumes lp: "iszlfm p (x#bs)"
 14.1678 -  shows "\<forall> y. iszlfm p (y#bs)"
 14.1679 -proof
 14.1680 -  fix y
 14.1681 -  show "iszlfm p (y#bs)"
 14.1682 -    using lp
 14.1683 -  by(induct p rule: iszlfm.induct, simp_all add: numbound0_gen[rule_format, where x="x" and y="y"])
 14.1684 -qed
 14.1685 -
 14.1686 -lemma conj_zl[simp]: "iszlfm p bs \<Longrightarrow> iszlfm q bs \<Longrightarrow> iszlfm (conj p q) bs"
 14.1687 -  using conj_def by (cases p,auto)
 14.1688 -lemma disj_zl[simp]: "iszlfm p bs \<Longrightarrow> iszlfm q bs \<Longrightarrow> iszlfm (disj p q) bs"
 14.1689 -  using disj_def by (cases p,auto)
 14.1690 -lemma not_zl[simp]: "iszlfm p bs \<Longrightarrow> iszlfm (not p) bs"
 14.1691 -  by (induct p rule:iszlfm.induct ,auto)
 14.1692 -
 14.1693 -recdef zlfm "measure fmsize"
 14.1694 -  "zlfm (And p q) = conj (zlfm p) (zlfm q)"
 14.1695 -  "zlfm (Or p q) = disj (zlfm p) (zlfm q)"
 14.1696 -  "zlfm (Imp p q) = disj (zlfm (NOT p)) (zlfm q)"
 14.1697 -  "zlfm (Iff p q) = disj (conj (zlfm p) (zlfm q)) (conj (zlfm (NOT p)) (zlfm (NOT q)))"
 14.1698 -  "zlfm (Lt a) = (let (c,r) = zsplit0 a in 
 14.1699 -     if c=0 then Lt r else 
 14.1700 -     if c>0 then Or (Lt (CN 0 c (Neg (Floor (Neg r))))) (And (Eq (CN 0 c (Neg (Floor (Neg r))))) (Lt (Add (Floor (Neg r)) r))) 
 14.1701 -     else Or (Gt (CN 0 (-c) (Floor(Neg r)))) (And (Eq(CN 0 (-c) (Floor(Neg r)))) (Lt (Add (Floor (Neg r)) r))))"
 14.1702 -  "zlfm (Le a) = (let (c,r) = zsplit0 a in 
 14.1703 -     if c=0 then Le r else 
 14.1704 -     if c>0 then Or (Le (CN 0 c (Neg (Floor (Neg r))))) (And (Eq (CN 0 c (Neg (Floor (Neg r))))) (Lt (Add (Floor (Neg r)) r))) 
 14.1705 -     else Or (Ge (CN 0 (-c) (Floor(Neg r)))) (And (Eq(CN 0 (-c) (Floor(Neg r)))) (Lt (Add (Floor (Neg r)) r))))"
 14.1706 -  "zlfm (Gt a) = (let (c,r) = zsplit0 a in 
 14.1707 -     if c=0 then Gt r else 
 14.1708 -     if c>0 then Or (Gt (CN 0 c (Floor r))) (And (Eq (CN 0 c (Floor r))) (Lt (Sub (Floor r) r))) 
 14.1709 -     else Or (Lt (CN 0 (-c) (Neg (Floor r)))) (And (Eq(CN 0 (-c) (Neg (Floor r)))) (Lt (Sub (Floor r) r))))"
 14.1710 -  "zlfm (Ge a) = (let (c,r) = zsplit0 a in 
 14.1711 -     if c=0 then Ge r else 
 14.1712 -     if c>0 then Or (Ge (CN 0 c (Floor r))) (And (Eq (CN 0 c (Floor r))) (Lt (Sub (Floor r) r))) 
 14.1713 -     else Or (Le (CN 0 (-c) (Neg (Floor r)))) (And (Eq(CN 0 (-c) (Neg (Floor r)))) (Lt (Sub (Floor r) r))))"
 14.1714 -  "zlfm (Eq a) = (let (c,r) = zsplit0 a in 
 14.1715 -              if c=0 then Eq r else 
 14.1716 -      if c>0 then (And (Eq (CN 0 c (Neg (Floor (Neg r))))) (Eq (Add (Floor (Neg r)) r)))
 14.1717 -      else (And (Eq (CN 0 (-c) (Floor (Neg r)))) (Eq (Add (Floor (Neg r)) r))))"
 14.1718 -  "zlfm (NEq a) = (let (c,r) = zsplit0 a in 
 14.1719 -              if c=0 then NEq r else 
 14.1720 -      if c>0 then (Or (NEq (CN 0 c (Neg (Floor (Neg r))))) (NEq (Add (Floor (Neg r)) r)))
 14.1721 -      else (Or (NEq (CN 0 (-c) (Floor (Neg r)))) (NEq (Add (Floor (Neg r)) r))))"
 14.1722 -  "zlfm (Dvd i a) = (if i=0 then zlfm (Eq a) 
 14.1723 -  else (let (c,r) = zsplit0 a in 
 14.1724 -              if c=0 then Dvd (abs i) r else 
 14.1725 -      if c>0 then And (Eq (Sub (Floor r) r)) (Dvd (abs i) (CN 0 c (Floor r))) 
 14.1726 -      else And (Eq (Sub (Floor r) r)) (Dvd (abs i) (CN 0 (-c) (Neg (Floor r))))))"
 14.1727 -  "zlfm (NDvd i a) = (if i=0 then zlfm (NEq a) 
 14.1728 -  else (let (c,r) = zsplit0 a in 
 14.1729 -              if c=0 then NDvd (abs i) r else 
 14.1730 -      if c>0 then Or (NEq (Sub (Floor r) r)) (NDvd (abs i) (CN 0 c (Floor r))) 
 14.1731 -      else Or (NEq (Sub (Floor r) r)) (NDvd (abs i) (CN 0 (-c) (Neg (Floor r))))))"
 14.1732 -  "zlfm (NOT (And p q)) = disj (zlfm (NOT p)) (zlfm (NOT q))"
 14.1733 -  "zlfm (NOT (Or p q)) = conj (zlfm (NOT p)) (zlfm (NOT q))"
 14.1734 -  "zlfm (NOT (Imp p q)) = conj (zlfm p) (zlfm (NOT q))"
 14.1735 -  "zlfm (NOT (Iff p q)) = disj (conj(zlfm p) (zlfm(NOT q))) (conj (zlfm(NOT p)) (zlfm q))"
 14.1736 -  "zlfm (NOT (NOT p)) = zlfm p"
 14.1737 -  "zlfm (NOT T) = F"
 14.1738 -  "zlfm (NOT F) = T"
 14.1739 -  "zlfm (NOT (Lt a)) = zlfm (Ge a)"
 14.1740 -  "zlfm (NOT (Le a)) = zlfm (Gt a)"
 14.1741 -  "zlfm (NOT (Gt a)) = zlfm (Le a)"
 14.1742 -  "zlfm (NOT (Ge a)) = zlfm (Lt a)"
 14.1743 -  "zlfm (NOT (Eq a)) = zlfm (NEq a)"
 14.1744 -  "zlfm (NOT (NEq a)) = zlfm (Eq a)"
 14.1745 -  "zlfm (NOT (Dvd i a)) = zlfm (NDvd i a)"
 14.1746 -  "zlfm (NOT (NDvd i a)) = zlfm (Dvd i a)"
 14.1747 -  "zlfm p = p" (hints simp add: fmsize_pos)
 14.1748 -
 14.1749 -lemma split_int_less_real: 
 14.1750 -  "(real (a::int) < b) = (a < floor b \<or> (a = floor b \<and> real (floor b) < b))"
 14.1751 -proof( auto)
 14.1752 -  assume alb: "real a < b" and agb: "\<not> a < floor b"
 14.1753 -  from agb have "floor b \<le> a" by simp hence th: "b < real a + 1" by (simp only: floor_le_eq)
 14.1754 -  from floor_eq[OF alb th] show "a= floor b" by simp 
 14.1755 -next
 14.1756 -  assume alb: "a < floor b"
 14.1757 -  hence "real a < real (floor b)" by simp
 14.1758 -  moreover have "real (floor b) \<le> b" by simp ultimately show  "real a < b" by arith 
 14.1759 -qed
 14.1760 -
 14.1761 -lemma split_int_less_real': 
 14.1762 -  "(real (a::int) + b < 0) = (real a - real (floor(-b)) < 0 \<or> (real a - real (floor (-b)) = 0 \<and> real (floor (-b)) + b < 0))"
 14.1763 -proof- 
 14.1764 -  have "(real a + b <0) = (real a < -b)" by arith
 14.1765 -  with split_int_less_real[where a="a" and b="-b"] show ?thesis by arith  
 14.1766 -qed
 14.1767 -
 14.1768 -lemma split_int_gt_real': 
 14.1769 -  "(real (a::int) + b > 0) = (real a + real (floor b) > 0 \<or> (real a + real (floor b) = 0 \<and> real (floor b) - b < 0))"
 14.1770 -proof- 
 14.1771 -  have th: "(real a + b >0) = (real (-a) + (-b)< 0)" by arith
 14.1772 -  show ?thesis using myless[rule_format, where b="real (floor b)"] 
 14.1773 -    by (simp only:th split_int_less_real'[where a="-a" and b="-b"]) 
 14.1774 -    (simp add: ring_simps diff_def[symmetric],arith)
 14.1775 -qed
 14.1776 -
 14.1777 -lemma split_int_le_real: 
 14.1778 -  "(real (a::int) \<le> b) = (a \<le> floor b \<or> (a = floor b \<and> real (floor b) < b))"
 14.1779 -proof( auto)
 14.1780 -  assume alb: "real a \<le> b" and agb: "\<not> a \<le> floor b"
 14.1781 -  from alb have "floor (real a) \<le> floor b " by (simp only: floor_mono2) 
 14.1782 -  hence "a \<le> floor b" by simp with agb show "False" by simp
 14.1783 -next
 14.1784 -  assume alb: "a \<le> floor b"
 14.1785 -  hence "real a \<le> real (floor b)" by (simp only: floor_mono2)
 14.1786 -  also have "\<dots>\<le> b" by simp  finally show  "real a \<le> b" . 
 14.1787 -qed
 14.1788 -
 14.1789 -lemma split_int_le_real': 
 14.1790 -  "(real (a::int) + b \<le> 0) = (real a - real (floor(-b)) \<le> 0 \<or> (real a - real (floor (-b)) = 0 \<and> real (floor (-b)) + b < 0))"
 14.1791 -proof- 
 14.1792 -  have "(real a + b \<le>0) = (real a \<le> -b)" by arith
 14.1793 -  with split_int_le_real[where a="a" and b="-b"] show ?thesis by arith  
 14.1794 -qed
 14.1795 -
 14.1796 -lemma split_int_ge_real': 
 14.1797 -  "(real (a::int) + b \<ge> 0) = (real a + real (floor b) \<ge> 0 \<or> (real a + real (floor b) = 0 \<and> real (floor b) - b < 0))"
 14.1798 -proof- 
 14.1799 -  have th: "(real a + b \<ge>0) = (real (-a) + (-b) \<le> 0)" by arith
 14.1800 -  show ?thesis by (simp only: th split_int_le_real'[where a="-a" and b="-b"])
 14.1801 -    (simp add: ring_simps diff_def[symmetric],arith)
 14.1802 -qed
 14.1803 -
 14.1804 -lemma split_int_eq_real: "(real (a::int) = b) = ( a = floor b \<and> b = real (floor b))" (is "?l = ?r")
 14.1805 -by auto
 14.1806 -
 14.1807 -lemma split_int_eq_real': "(real (a::int) + b = 0) = ( a - floor (-b) = 0 \<and> real (floor (-b)) + b = 0)" (is "?l = ?r")
 14.1808 -proof-
 14.1809 -  have "?l = (real a = -b)" by arith
 14.1810 -  with split_int_eq_real[where a="a" and b="-b"] show ?thesis by simp arith
 14.1811 -qed
 14.1812 -
 14.1813 -lemma zlfm_I:
 14.1814 -  assumes qfp: "qfree p"
 14.1815 -  shows "(Ifm (real i #bs) (zlfm p) = Ifm (real i# bs) p) \<and> iszlfm (zlfm p) (real (i::int) #bs)"
 14.1816 -  (is "(?I (?l p) = ?I p) \<and> ?L (?l p)")
 14.1817 -using qfp
 14.1818 -proof(induct p rule: zlfm.induct)
 14.1819 -  case (5 a) 
 14.1820 -  let ?c = "fst (zsplit0 a)"
 14.1821 -  let ?r = "snd (zsplit0 a)"
 14.1822 -  have spl: "zsplit0 a = (?c,?r)" by simp
 14.1823 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 14.1824 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 14.1825 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 14.1826 -  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
 14.1827 -  moreover
 14.1828 -  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] 
 14.1829 -      by (cases "?r", simp_all add: Let_def split_def,case_tac "nat", simp_all)}
 14.1830 -  moreover
 14.1831 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Lt a))" 
 14.1832 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.1833 -    have "?I (Lt a) = (real (?c * i) + (?N ?r) < 0)" using Ia by (simp add: Let_def split_def)
 14.1834 -    also have "\<dots> = (?I (?l (Lt a)))" apply (simp only: split_int_less_real'[where a="?c*i" and b="?N ?r"]) by (simp add: Ia cp cnz Let_def split_def diff_def)
 14.1835 -    finally have ?case using l by simp}
 14.1836 -  moreover
 14.1837 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Lt a))" 
 14.1838 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.1839 -    have "?I (Lt a) = (real (?c * i) + (?N ?r) < 0)" using Ia by (simp add: Let_def split_def)
 14.1840 -    also from cn cnz have "\<dots> = (?I (?l (Lt a)))" by (simp only: split_int_less_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def diff_def[symmetric] add_ac, arith)
 14.1841 -    finally have ?case using l by simp}
 14.1842 -  ultimately show ?case by blast
 14.1843 -next
 14.1844 -  case (6 a)
 14.1845 -  let ?c = "fst (zsplit0 a)"
 14.1846 -  let ?r = "snd (zsplit0 a)"
 14.1847 -  have spl: "zsplit0 a = (?c,?r)" by simp
 14.1848 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 14.1849 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 14.1850 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 14.1851 -  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
 14.1852 -  moreover
 14.1853 -  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] 
 14.1854 -      by (cases "?r", simp_all add: Let_def split_def, case_tac "nat",simp_all)}
 14.1855 -  moreover
 14.1856 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Le a))" 
 14.1857 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.1858 -    have "?I (Le a) = (real (?c * i) + (?N ?r) \<le> 0)" using Ia by (simp add: Let_def split_def)
 14.1859 -    also have "\<dots> = (?I (?l (Le a)))" by (simp only: split_int_le_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia cp cnz Let_def split_def diff_def)
 14.1860 -    finally have ?case using l by simp}
 14.1861 -  moreover
 14.1862 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Le a))" 
 14.1863 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.1864 -    have "?I (Le a) = (real (?c * i) + (?N ?r) \<le> 0)" using Ia by (simp add: Let_def split_def)
 14.1865 -    also from cn cnz have "\<dots> = (?I (?l (Le a)))" by (simp only: split_int_le_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def diff_def[symmetric] add_ac ,arith)
 14.1866 -    finally have ?case using l by simp}
 14.1867 -  ultimately show ?case by blast
 14.1868 -next
 14.1869 -  case (7 a) 
 14.1870 -  let ?c = "fst (zsplit0 a)"
 14.1871 -  let ?r = "snd (zsplit0 a)"
 14.1872 -  have spl: "zsplit0 a = (?c,?r)" by simp
 14.1873 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 14.1874 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 14.1875 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 14.1876 -  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
 14.1877 -  moreover
 14.1878 -  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] 
 14.1879 -      by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)}
 14.1880 -  moreover
 14.1881 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Gt a))" 
 14.1882 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.1883 -    have "?I (Gt a) = (real (?c * i) + (?N ?r) > 0)" using Ia by (simp add: Let_def split_def)
 14.1884 -    also have "\<dots> = (?I (?l (Gt a)))" by (simp only: split_int_gt_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia cp cnz Let_def split_def diff_def)
 14.1885 -    finally have ?case using l by simp}
 14.1886 -  moreover
 14.1887 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Gt a))" 
 14.1888 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.1889 -    have "?I (Gt a) = (real (?c * i) + (?N ?r) > 0)" using Ia by (simp add: Let_def split_def)
 14.1890 -    also from cn cnz have "\<dots> = (?I (?l (Gt a)))" by (simp only: split_int_gt_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def diff_def[symmetric] add_ac, arith)
 14.1891 -    finally have ?case using l by simp}
 14.1892 -  ultimately show ?case by blast
 14.1893 -next
 14.1894 -  case (8 a)
 14.1895 -   let ?c = "fst (zsplit0 a)"
 14.1896 -  let ?r = "snd (zsplit0 a)"
 14.1897 -  have spl: "zsplit0 a = (?c,?r)" by simp
 14.1898 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 14.1899 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 14.1900 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 14.1901 -  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
 14.1902 -  moreover
 14.1903 -  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] 
 14.1904 -      by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)}
 14.1905 -  moreover
 14.1906 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Ge a))" 
 14.1907 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.1908 -    have "?I (Ge a) = (real (?c * i) + (?N ?r) \<ge> 0)" using Ia by (simp add: Let_def split_def)
 14.1909 -    also have "\<dots> = (?I (?l (Ge a)))" by (simp only: split_int_ge_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia cp cnz Let_def split_def diff_def)
 14.1910 -    finally have ?case using l by simp}
 14.1911 -  moreover
 14.1912 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Ge a))" 
 14.1913 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.1914 -    have "?I (Ge a) = (real (?c * i) + (?N ?r) \<ge> 0)" using Ia by (simp add: Let_def split_def)
 14.1915 -    also from cn cnz have "\<dots> = (?I (?l (Ge a)))" by (simp only: split_int_ge_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def diff_def[symmetric] add_ac, arith)
 14.1916 -    finally have ?case using l by simp}
 14.1917 -  ultimately show ?case by blast
 14.1918 -next
 14.1919 -  case (9 a)
 14.1920 -  let ?c = "fst (zsplit0 a)"
 14.1921 -  let ?r = "snd (zsplit0 a)"
 14.1922 -  have spl: "zsplit0 a = (?c,?r)" by simp
 14.1923 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 14.1924 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 14.1925 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 14.1926 -  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
 14.1927 -  moreover
 14.1928 -  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] 
 14.1929 -      by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)}
 14.1930 -  moreover
 14.1931 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Eq a))" 
 14.1932 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.1933 -    have "?I (Eq a) = (real (?c * i) + (?N ?r) = 0)" using Ia by (simp add: Let_def split_def)
 14.1934 -    also have "\<dots> = (?I (?l (Eq a)))" using cp cnz  by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia real_of_int_mult[symmetric] del: real_of_int_mult)
 14.1935 -    finally have ?case using l by simp}
 14.1936 -  moreover
 14.1937 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Eq a))" 
 14.1938 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.1939 -    have "?I (Eq a) = (real (?c * i) + (?N ?r) = 0)" using Ia by (simp add: Let_def split_def)
 14.1940 -    also from cn cnz have "\<dots> = (?I (?l (Eq a)))" by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia real_of_int_mult[symmetric] del: real_of_int_mult,arith)
 14.1941 -    finally have ?case using l by simp}
 14.1942 -  ultimately show ?case by blast
 14.1943 -next
 14.1944 -  case (10 a)
 14.1945 -  let ?c = "fst (zsplit0 a)"
 14.1946 -  let ?r = "snd (zsplit0 a)"
 14.1947 -  have spl: "zsplit0 a = (?c,?r)" by simp
 14.1948 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 14.1949 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 14.1950 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 14.1951 -  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
 14.1952 -  moreover
 14.1953 -  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] 
 14.1954 -      by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)}
 14.1955 -  moreover
 14.1956 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (NEq a))" 
 14.1957 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.1958 -    have "?I (NEq a) = (real (?c * i) + (?N ?r) \<noteq> 0)" using Ia by (simp add: Let_def split_def)
 14.1959 -    also have "\<dots> = (?I (?l (NEq a)))" using cp cnz  by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia real_of_int_mult[symmetric] del: real_of_int_mult)
 14.1960 -    finally have ?case using l by simp}
 14.1961 -  moreover
 14.1962 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (NEq a))" 
 14.1963 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.1964 -    have "?I (NEq a) = (real (?c * i) + (?N ?r) \<noteq> 0)" using Ia by (simp add: Let_def split_def)
 14.1965 -    also from cn cnz have "\<dots> = (?I (?l (NEq a)))" by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia real_of_int_mult[symmetric] del: real_of_int_mult,arith)
 14.1966 -    finally have ?case using l by simp}
 14.1967 -  ultimately show ?case by blast
 14.1968 -next
 14.1969 -  case (11 j a)
 14.1970 -  let ?c = "fst (zsplit0 a)"
 14.1971 -  let ?r = "snd (zsplit0 a)"
 14.1972 -  have spl: "zsplit0 a = (?c,?r)" by simp
 14.1973 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 14.1974 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 14.1975 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 14.1976 -  have "j=0 \<or> (j\<noteq>0 \<and> ?c = 0) \<or> (j\<noteq>0 \<and> ?c >0 \<and> ?c\<noteq>0) \<or> (j\<noteq> 0 \<and> ?c<0 \<and> ?c\<noteq>0)" by arith
 14.1977 -  moreover
 14.1978 -  {assume "j=0" hence z: "zlfm (Dvd j a) = (zlfm (Eq a))" by (simp add: Let_def) 
 14.1979 -    hence ?case using prems by (simp del: zlfm.simps add: rdvd_left_0_eq)}
 14.1980 -  moreover
 14.1981 -  {assume "?c=0" and "j\<noteq>0" hence ?case 
 14.1982 -      using zsplit0_I[OF spl, where x="i" and bs="bs"] rdvd_abs1[where d="j"]
 14.1983 -      by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)}
 14.1984 -  moreover
 14.1985 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" and jnz: "j\<noteq>0" hence l: "?L (?l (Dvd j a))" 
 14.1986 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.1987 -    have "?I (Dvd j a) = (real j rdvd (real (?c * i) + (?N ?r)))" 
 14.1988 -      using Ia by (simp add: Let_def split_def)
 14.1989 -    also have "\<dots> = (real (abs j) rdvd real (?c*i) + (?N ?r))" 
 14.1990 -      by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp
 14.1991 -    also have "\<dots> = ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \<and> 
 14.1992 -       (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r))))" 
 14.1993 -      by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac)
 14.1994 -    also have "\<dots> = (?I (?l (Dvd j a)))" using cp cnz jnz  
 14.1995 -      by (simp add: Let_def split_def int_rdvd_iff[symmetric]  
 14.1996 -	del: real_of_int_mult) (auto simp add: add_ac)
 14.1997 -    finally have ?case using l jnz  by simp }
 14.1998 -  moreover
 14.1999 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" and jnz: "j\<noteq>0" hence l: "?L (?l (Dvd j a))" 
 14.2000 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.2001 -    have "?I (Dvd j a) = (real j rdvd (real (?c * i) + (?N ?r)))" 
 14.2002 -      using Ia by (simp add: Let_def split_def)
 14.2003 -    also have "\<dots> = (real (abs j) rdvd real (?c*i) + (?N ?r))" 
 14.2004 -      by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp
 14.2005 -    also have "\<dots> = ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \<and> 
 14.2006 -       (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r))))" 
 14.2007 -      by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac)
 14.2008 -    also have "\<dots> = (?I (?l (Dvd j a)))" using cn cnz jnz
 14.2009 -      using rdvd_minus [where d="abs j" and t="real (?c*i + floor (?N ?r))", simplified, symmetric]
 14.2010 -      by (simp add: Let_def split_def int_rdvd_iff[symmetric]  
 14.2011 -	del: real_of_int_mult) (auto simp add: add_ac)
 14.2012 -    finally have ?case using l jnz by blast }
 14.2013 -  ultimately show ?case by blast
 14.2014 -next
 14.2015 -  case (12 j a)
 14.2016 -  let ?c = "fst (zsplit0 a)"
 14.2017 -  let ?r = "snd (zsplit0 a)"
 14.2018 -  have spl: "zsplit0 a = (?c,?r)" by simp
 14.2019 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 14.2020 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 14.2021 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 14.2022 -  have "j=0 \<or> (j\<noteq>0 \<and> ?c = 0) \<or> (j\<noteq>0 \<and> ?c >0 \<and> ?c\<noteq>0) \<or> (j\<noteq> 0 \<and> ?c<0 \<and> ?c\<noteq>0)" by arith
 14.2023 -  moreover
 14.2024 -  {assume "j=0" hence z: "zlfm (NDvd j a) = (zlfm (NEq a))" by (simp add: Let_def) 
 14.2025 -    hence ?case using prems by (simp del: zlfm.simps add: rdvd_left_0_eq)}
 14.2026 -  moreover
 14.2027 -  {assume "?c=0" and "j\<noteq>0" hence ?case 
 14.2028 -      using zsplit0_I[OF spl, where x="i" and bs="bs"] rdvd_abs1[where d="j"]
 14.2029 -      by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)}
 14.2030 -  moreover
 14.2031 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" and jnz: "j\<noteq>0" hence l: "?L (?l (NDvd j a))" 
 14.2032 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.2033 -    have "?I (NDvd j a) = (\<not> (real j rdvd (real (?c * i) + (?N ?r))))" 
 14.2034 -      using Ia by (simp add: Let_def split_def)
 14.2035 -    also have "\<dots> = (\<not> (real (abs j) rdvd real (?c*i) + (?N ?r)))" 
 14.2036 -      by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp
 14.2037 -    also have "\<dots> = (\<not> ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \<and> 
 14.2038 -       (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r)))))" 
 14.2039 -      by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac)
 14.2040 -    also have "\<dots> = (?I (?l (NDvd j a)))" using cp cnz jnz  
 14.2041 -      by (simp add: Let_def split_def int_rdvd_iff[symmetric]  
 14.2042 -	del: real_of_int_mult) (auto simp add: add_ac)
 14.2043 -    finally have ?case using l jnz  by simp }
 14.2044 -  moreover
 14.2045 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" and jnz: "j\<noteq>0" hence l: "?L (?l (NDvd j a))" 
 14.2046 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 14.2047 -    have "?I (NDvd j a) = (\<not> (real j rdvd (real (?c * i) + (?N ?r))))" 
 14.2048 -      using Ia by (simp add: Let_def split_def)
 14.2049 -    also have "\<dots> = (\<not> (real (abs j) rdvd real (?c*i) + (?N ?r)))" 
 14.2050 -      by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp
 14.2051 -    also have "\<dots> = (\<not> ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \<and> 
 14.2052 -       (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r)))))" 
 14.2053 -      by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac)
 14.2054 -    also have "\<dots> = (?I (?l (NDvd j a)))" using cn cnz jnz
 14.2055 -      using rdvd_minus [where d="abs j" and t="real (?c*i + floor (?N ?r))", simplified, symmetric]
 14.2056 -      by (simp add: Let_def split_def int_rdvd_iff[symmetric]  
 14.2057 -	del: real_of_int_mult) (auto simp add: add_ac)
 14.2058 -    finally have ?case using l jnz by blast }
 14.2059 -  ultimately show ?case by blast
 14.2060 -qed auto
 14.2061 -
 14.2062 -text{* plusinf : Virtual substitution of @{text "+\<infinity>"}
 14.2063 -       minusinf: Virtual substitution of @{text "-\<infinity>"}
 14.2064 -       @{text "\<delta>"} Compute lcm @{text "d| Dvd d  c*x+t \<in> p"}
 14.2065 -       @{text "d\<delta>"} checks if a given l divides all the ds above*}
 14.2066 -
 14.2067 -consts 
 14.2068 -  plusinf:: "fm \<Rightarrow> fm" 
 14.2069 -  minusinf:: "fm \<Rightarrow> fm"
 14.2070 -  \<delta> :: "fm \<Rightarrow> int" 
 14.2071 -  d\<delta> :: "fm \<Rightarrow> int \<Rightarrow> bool"
 14.2072 -
 14.2073 -recdef minusinf "measure size"
 14.2074 -  "minusinf (And p q) = conj (minusinf p) (minusinf q)" 
 14.2075 -  "minusinf (Or p q) = disj (minusinf p) (minusinf q)" 
 14.2076 -  "minusinf (Eq  (CN 0 c e)) = F"
 14.2077 -  "minusinf (NEq (CN 0 c e)) = T"
 14.2078 -  "minusinf (Lt  (CN 0 c e)) = T"
 14.2079 -  "minusinf (Le  (CN 0 c e)) = T"
 14.2080 -  "minusinf (Gt  (CN 0 c e)) = F"
 14.2081 -  "minusinf (Ge  (CN 0 c e)) = F"
 14.2082 -  "minusinf p = p"
 14.2083 -
 14.2084 -lemma minusinf_qfree: "qfree p \<Longrightarrow> qfree (minusinf p)"
 14.2085 -  by (induct p rule: minusinf.induct, auto)
 14.2086 -
 14.2087 -recdef plusinf "measure size"
 14.2088 -  "plusinf (And p q) = conj (plusinf p) (plusinf q)" 
 14.2089 -  "plusinf (Or p q) = disj (plusinf p) (plusinf q)" 
 14.2090 -  "plusinf (Eq  (CN 0 c e)) = F"
 14.2091 -  "plusinf (NEq (CN 0 c e)) = T"
 14.2092 -  "plusinf (Lt  (CN 0 c e)) = F"
 14.2093 -  "plusinf (Le  (CN 0 c e)) = F"
 14.2094 -  "plusinf (Gt  (CN 0 c e)) = T"
 14.2095 -  "plusinf (Ge  (CN 0 c e)) = T"
 14.2096 -  "plusinf p = p"
 14.2097 -
 14.2098 -recdef \<delta> "measure size"
 14.2099 -  "\<delta> (And p q) = zlcm (\<delta> p) (\<delta> q)" 
 14.2100 -  "\<delta> (Or p q) = zlcm (\<delta> p) (\<delta> q)" 
 14.2101 -  "\<delta> (Dvd i (CN 0 c e)) = i"
 14.2102 -  "\<delta> (NDvd i (CN 0 c e)) = i"
 14.2103 -  "\<delta> p = 1"
 14.2104 -
 14.2105 -recdef d\<delta> "measure size"
 14.2106 -  "d\<delta> (And p q) = (\<lambda> d. d\<delta> p d \<and> d\<delta> q d)" 
 14.2107 -  "d\<delta> (Or p q) = (\<lambda> d. d\<delta> p d \<and> d\<delta> q d)" 
 14.2108 -  "d\<delta> (Dvd i (CN 0 c e)) = (\<lambda> d. i dvd d)"
 14.2109 -  "d\<delta> (NDvd i (CN 0 c e)) = (\<lambda> d. i dvd d)"
 14.2110 -  "d\<delta> p = (\<lambda> d. True)"
 14.2111 -
 14.2112 -lemma delta_mono: 
 14.2113 -  assumes lin: "iszlfm p bs"
 14.2114 -  and d: "d dvd d'"
 14.2115 -  and ad: "d\<delta> p d"
 14.2116 -  shows "d\<delta> p d'"
 14.2117 -  using lin ad d
 14.2118 -proof(induct p rule: iszlfm.induct)
 14.2119 -  case (9 i c e)  thus ?case using d
 14.2120 -    by (simp add: zdvd_trans[where m="i" and n="d" and k="d'"])
 14.2121 -next
 14.2122 -  case (10 i c e) thus ?case using d
 14.2123 -    by (simp add: zdvd_trans[where m="i" and n="d" and k="d'"])
 14.2124 -qed simp_all
 14.2125 -
 14.2126 -lemma \<delta> : assumes lin:"iszlfm p bs"
 14.2127 -  shows "d\<delta> p (\<delta> p) \<and> \<delta> p >0"
 14.2128 -using lin
 14.2129 -proof (induct p rule: iszlfm.induct)
 14.2130 -  case (1 p q) 
 14.2131 -  let ?d = "\<delta> (And p q)"
 14.2132 -  from prems zlcm_pos have dp: "?d >0" by simp
 14.2133 -  have d1: "\<delta> p dvd \<delta> (And p q)" using prems by simp 
 14.2134 -   hence th: "d\<delta> p ?d" 
 14.2135 -     using delta_mono prems by (auto simp del: dvd_zlcm_self1)
 14.2136 -  have "\<delta> q dvd \<delta> (And p q)" using prems  by simp 
 14.2137 -  hence th': "d\<delta> q ?d" using delta_mono prems by (auto simp del: dvd_zlcm_self2)
 14.2138 -  from th th' dp show ?case by simp 
 14.2139 -next
 14.2140 -  case (2 p q)  
 14.2141 -  let ?d = "\<delta> (And p q)"
 14.2142 -  from prems zlcm_pos have dp: "?d >0" by simp
 14.2143 -  have "\<delta> p dvd \<delta> (And p q)" using prems by simp hence th: "d\<delta> p ?d" using delta_mono prems 
 14.2144 -    by (auto simp del: dvd_zlcm_self1)
 14.2145 -  have "\<delta> q dvd \<delta> (And p q)" using prems by simp hence th': "d\<delta> q ?d" using delta_mono prems by (auto simp del: dvd_zlcm_self2)
 14.2146 -  from th th' dp show ?case by simp 
 14.2147 -qed simp_all
 14.2148 -
 14.2149 -
 14.2150 -lemma minusinf_inf:
 14.2151 -  assumes linp: "iszlfm p (a # bs)"
 14.2152 -  shows "\<exists> (z::int). \<forall> x < z. Ifm ((real x)#bs) (minusinf p) = Ifm ((real x)#bs) p"
 14.2153 -  (is "?P p" is "\<exists> (z::int). \<forall> x < z. ?I x (?M p) = ?I x p")
 14.2154 -using linp
 14.2155 -proof (induct p rule: minusinf.induct)
 14.2156 -  case (1 f g)
 14.2157 -  from prems have "?P f" by simp
 14.2158 -  then obtain z1 where z1_def: "\<forall> x < z1. ?I x (?M f) = ?I x f" by blast
 14.2159 -  from prems have "?P g" by simp
 14.2160 -  then obtain z2 where z2_def: "\<forall> x < z2. ?I x (?M g) = ?I x g" by blast
 14.2161 -  let ?z = "min z1 z2"
 14.2162 -  from z1_def z2_def have "\<forall> x < ?z. ?I x (?M (And f g)) = ?I x (And f g)" by simp
 14.2163 -  thus ?case by blast
 14.2164 -next
 14.2165 -  case (2 f g)   from prems have "?P f" by simp
 14.2166 -  then obtain z1 where z1_def: "\<forall> x < z1. ?I x (?M f) = ?I x f" by blast
 14.2167 -  from prems have "?P g" by simp
 14.2168 -  then obtain z2 where z2_def: "\<forall> x < z2. ?I x (?M g) = ?I x g" by blast
 14.2169 -  let ?z = "min z1 z2"
 14.2170 -  from z1_def z2_def have "\<forall> x < ?z. ?I x (?M (Or f g)) = ?I x (Or f g)" by simp
 14.2171 -  thus ?case by blast
 14.2172 -next
 14.2173 -  case (3 c e) 
 14.2174 -  from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp
 14.2175 -  from prems have nbe: "numbound0 e" by simp
 14.2176 -  fix y
 14.2177 -  have "\<forall> x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Eq (CN 0 c e))) = ?I x (Eq (CN 0 c e))"
 14.2178 -  proof (simp add: less_floor_eq , rule allI, rule impI) 
 14.2179 -    fix x
 14.2180 -    assume A: "real x + (1\<Colon>real) \<le> - (Inum (y # bs) e / real c)"
 14.2181 -    hence th1:"real x < - (Inum (y # bs) e / real c)" by simp
 14.2182 -    with rcpos  have "(real c)*(real  x) < (real c)*(- (Inum (y # bs) e / real c))"
 14.2183 -      by (simp only:  real_mult_less_mono2[OF rcpos th1])
 14.2184 -    hence "real c * real x + Inum (y # bs) e \<noteq> 0"using rcpos  by simp
 14.2185 -    thus "real c * real x + Inum (real x # bs) e \<noteq> 0" 
 14.2186 -      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"]  by simp
 14.2187 -  qed
 14.2188 -  thus ?case by blast
 14.2189 -next
 14.2190 -  case (4 c e) 
 14.2191 -  from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp
 14.2192 -  from prems have nbe: "numbound0 e" by simp
 14.2193 -  fix y
 14.2194 -  have "\<forall> x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (NEq (CN 0 c e))) = ?I x (NEq (CN 0 c e))"
 14.2195 -  proof (simp add: less_floor_eq , rule allI, rule impI) 
 14.2196 -    fix x
 14.2197 -    assume A: "real x + (1\<Colon>real) \<le> - (Inum (y # bs) e / real c)"
 14.2198 -    hence th1:"real x < - (Inum (y # bs) e / real c)" by simp
 14.2199 -    with rcpos  have "(real c)*(real  x) < (real c)*(- (Inum (y # bs) e / real c))"
 14.2200 -      by (simp only:  real_mult_less_mono2[OF rcpos th1])
 14.2201 -    hence "real c * real x + Inum (y # bs) e \<noteq> 0"using rcpos  by simp
 14.2202 -    thus "real c * real x + Inum (real x # bs) e \<noteq> 0" 
 14.2203 -      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"]  by simp
 14.2204 -  qed
 14.2205 -  thus ?case by blast
 14.2206 -next
 14.2207 -  case (5 c e) 
 14.2208 -  from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp
 14.2209 -  from prems have nbe: "numbound0 e" by simp
 14.2210 -  fix y
 14.2211 -  have "\<forall> x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Lt (CN 0 c e))) = ?I x (Lt (CN 0 c e))"
 14.2212 -  proof (simp add: less_floor_eq , rule allI, rule impI) 
 14.2213 -    fix x
 14.2214 -    assume A: "real x + (1\<Colon>real) \<le> - (Inum (y # bs) e / real c)"
 14.2215 -    hence th1:"real x < - (Inum (y # bs) e / real c)" by simp
 14.2216 -    with rcpos  have "(real c)*(real  x) < (real c)*(- (Inum (y # bs) e / real c))"
 14.2217 -      by (simp only:  real_mult_less_mono2[OF rcpos th1])
 14.2218 -    thus "real c * real x + Inum (real x # bs) e < 0" 
 14.2219 -      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp
 14.2220 -  qed
 14.2221 -  thus ?case by blast
 14.2222 -next
 14.2223 -  case (6 c e) 
 14.2224 -  from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp
 14.2225 -  from prems have nbe: "numbound0 e" by simp
 14.2226 -  fix y
 14.2227 -  have "\<forall> x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Le (CN 0 c e))) = ?I x (Le (CN 0 c e))"
 14.2228 -  proof (simp add: less_floor_eq , rule allI, rule impI) 
 14.2229 -    fix x
 14.2230 -    assume A: "real x + (1\<Colon>real) \<le> - (Inum (y # bs) e / real c)"
 14.2231 -    hence th1:"real x < - (Inum (y # bs) e / real c)" by simp
 14.2232 -    with rcpos  have "(real c)*(real  x) < (real c)*(- (Inum (y # bs) e / real c))"
 14.2233 -      by (simp only:  real_mult_less_mono2[OF rcpos th1])
 14.2234 -    thus "real c * real x + Inum (real x # bs) e \<le> 0" 
 14.2235 -      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp
 14.2236 -  qed
 14.2237 -  thus ?case by blast
 14.2238 -next
 14.2239 -  case (7 c e) 
 14.2240 -  from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp
 14.2241 -  from prems have nbe: "numbound0 e" by simp
 14.2242 -  fix y
 14.2243 -  have "\<forall> x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Gt (CN 0 c e))) = ?I x (Gt (CN 0 c e))"
 14.2244 -  proof (simp add: less_floor_eq , rule allI, rule impI) 
 14.2245 -    fix x
 14.2246 -    assume A: "real x + (1\<Colon>real) \<le> - (Inum (y # bs) e / real c)"
 14.2247 -    hence th1:"real x < - (Inum (y # bs) e / real c)" by simp
 14.2248 -    with rcpos  have "(real c)*(real  x) < (real c)*(- (Inum (y # bs) e / real c))"
 14.2249 -      by (simp only:  real_mult_less_mono2[OF rcpos th1])
 14.2250 -    thus "\<not> (real c * real x + Inum (real x # bs) e>0)" 
 14.2251 -      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp
 14.2252 -  qed
 14.2253 -  thus ?case by blast
 14.2254 -next
 14.2255 -  case (8 c e) 
 14.2256 -  from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp
 14.2257 -  from prems have nbe: "numbound0 e" by simp
 14.2258 -  fix y
 14.2259 -  have "\<forall> x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Ge (CN 0 c e))) = ?I x (Ge (CN 0 c e))"
 14.2260 -  proof (simp add: less_floor_eq , rule allI, rule impI) 
 14.2261 -    fix x
 14.2262 -    assume A: "real x + (1\<Colon>real) \<le> - (Inum (y # bs) e / real c)"
 14.2263 -    hence th1:"real x < - (Inum (y # bs) e / real c)" by simp
 14.2264 -    with rcpos  have "(real c)*(real  x) < (real c)*(- (Inum (y # bs) e / real c))"
 14.2265 -      by (simp only:  real_mult_less_mono2[OF rcpos th1])
 14.2266 -    thus "\<not> real c * real x + Inum (real x # bs) e \<ge> 0" 
 14.2267 -      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp
 14.2268 -  qed
 14.2269 -  thus ?case by blast
 14.2270 -qed simp_all
 14.2271 -
 14.2272 -lemma minusinf_repeats:
 14.2273 -  assumes d: "d\<delta> p d" and linp: "iszlfm p (a # bs)"
 14.2274 -  shows "Ifm ((real(x - k*d))#bs) (minusinf p) = Ifm (real x #bs) (minusinf p)"
 14.2275 -using linp d
 14.2276 -proof(induct p rule: iszlfm.induct) 
 14.2277 -  case (9 i c e) hence nbe: "numbound0 e"  and id: "i dvd d" by simp+
 14.2278 -    hence "\<exists> k. d=i*k" by (simp add: dvd_def)
 14.2279 -    then obtain "di" where di_def: "d=i*di" by blast
 14.2280 -    show ?case 
 14.2281 -    proof(simp add: numbound0_I[OF nbe,where bs="bs" and b="real x - real k * real d" and b'="real x"] right_diff_distrib, rule iffI)
 14.2282 -      assume 
 14.2283 -	"real i rdvd real c * real x - real c * (real k * real d) + Inum (real x # bs) e"
 14.2284 -      (is "?ri rdvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri rdvd ?rt")
 14.2285 -      hence "\<exists> (l::int). ?rt = ?ri * (real l)" by (simp add: rdvd_def)
 14.2286 -      hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri*(real l)+?rc*(?rk * (real i) * (real di))" 
 14.2287 -	by (simp add: ring_simps di_def)
 14.2288 -      hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri*(real (l + c*k*di))"
 14.2289 -	by (simp add: ring_simps)
 14.2290 -      hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri* (real l)" by blast
 14.2291 -      thus "real i rdvd real c * real x + Inum (real x # bs) e" using rdvd_def by simp
 14.2292 -    next
 14.2293 -      assume 
 14.2294 -	"real i rdvd real c * real x + Inum (real x # bs) e" (is "?ri rdvd ?rc*?rx+?e")
 14.2295 -      hence "\<exists> (l::int). ?rc*?rx+?e = ?ri * (real l)" by (simp add: rdvd_def)
 14.2296 -      hence "\<exists> (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l) - real c * (real k * real d)" by simp
 14.2297 -      hence "\<exists> (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l) - real c * (real k * real i * real di)" by (simp add: di_def)
 14.2298 -      hence "\<exists> (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real (l - c*k*di))" by (simp add: ring_simps)
 14.2299 -      hence "\<exists> (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l)"
 14.2300 -	by blast
 14.2301 -      thus "real i rdvd real c * real x - real c * (real k * real d) + Inum (real x # bs) e" using rdvd_def by simp
 14.2302 -    qed
 14.2303 -next
 14.2304 -  case (10 i c e) hence nbe: "numbound0 e"  and id: "i dvd d" by simp+
 14.2305 -    hence "\<exists> k. d=i*k" by (simp add: dvd_def)
 14.2306 -    then obtain "di" where di_def: "d=i*di" by blast
 14.2307 -    show ?case 
 14.2308 -    proof(simp add: numbound0_I[OF nbe,where bs="bs" and b="real x - real k * real d" and b'="real x"] right_diff_distrib, rule iffI)
 14.2309 -      assume 
 14.2310 -	"real i rdvd real c * real x - real c * (real k * real d) + Inum (real x # bs) e"
 14.2311 -      (is "?ri rdvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri rdvd ?rt")
 14.2312 -      hence "\<exists> (l::int). ?rt = ?ri * (real l)" by (simp add: rdvd_def)
 14.2313 -      hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri*(real l)+?rc*(?rk * (real i) * (real di))" 
 14.2314 -	by (simp add: ring_simps di_def)
 14.2315 -      hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri*(real (l + c*k*di))"
 14.2316 -	by (simp add: ring_simps)
 14.2317 -      hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri* (real l)" by blast
 14.2318 -      thus "real i rdvd real c * real x + Inum (real x # bs) e" using rdvd_def by simp
 14.2319 -    next
 14.2320 -      assume 
 14.2321 -	"real i rdvd real c * real x + Inum (real x # bs) e" (is "?ri rdvd ?rc*?rx+?e")
 14.2322 -      hence "\<exists> (l::int). ?rc*?rx+?e = ?ri * (real l)" by (simp add: rdvd_def)
 14.2323 -      hence "\<exists> (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l) - real c * (real k * real d)" by simp
 14.2324 -      hence "\<exists> (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l) - real c * (real k * real i * real di)" by (simp add: di_def)
 14.2325 -      hence "\<exists> (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real (l - c*k*di))" by (simp add: ring_simps)
 14.2326 -      hence "\<exists> (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l)"
 14.2327 -	by blast
 14.2328 -      thus "real i rdvd real c * real x - real c * (real k * real d) + Inum (real x # bs) e" using rdvd_def by simp
 14.2329 -    qed
 14.2330 -qed (auto simp add: nth_pos2 numbound0_I[where bs="bs" and b="real(x - k*d)" and b'="real x"] simp del: real_of_int_mult real_of_int_diff)
 14.2331 -
 14.2332 -lemma minusinf_ex:
 14.2333 -  assumes lin: "iszlfm p (real (a::int) #bs)"
 14.2334 -  and exmi: "\<exists> (x::int). Ifm (real x#bs) (minusinf p)" (is "\<exists> x. ?P1 x")
 14.2335 -  shows "\<exists> (x::int). Ifm (real x#bs) p" (is "\<exists> x. ?P x")
 14.2336 -proof-
 14.2337 -  let ?d = "\<delta> p"
 14.2338 -  from \<delta> [OF lin] have dpos: "?d >0" by simp
 14.2339 -  from \<delta> [OF lin] have alld: "d\<delta> p ?d" by simp
 14.2340 -  from minusinf_repeats[OF alld lin] have th1:"\<forall> x k. ?P1 x = ?P1 (x - (k * ?d))" by simp
 14.2341 -  from minusinf_inf[OF lin] have th2:"\<exists> z. \<forall> x. x<z \<longrightarrow> (?P x = ?P1 x)" by blast
 14.2342 -  from minusinfinity [OF dpos th1 th2] exmi show ?thesis by blast
 14.2343 -qed
 14.2344 -
 14.2345 -lemma minusinf_bex:
 14.2346 -  assumes lin: "iszlfm p (real (a::int) #bs)"
 14.2347 -  shows "(\<exists> (x::int). Ifm (real x#bs) (minusinf p)) = 
 14.2348 -         (\<exists> (x::int)\<in> {1..\<delta> p}. Ifm (real x#bs) (minusinf p))"
 14.2349 -  (is "(\<exists> x. ?P x) = _")
 14.2350 -proof-
 14.2351 -  let ?d = "\<delta> p"
 14.2352 -  from \<delta> [OF lin] have dpos: "?d >0" by simp
 14.2353 -  from \<delta> [OF lin] have alld: "d\<delta> p ?d" by simp
 14.2354 -  from minusinf_repeats[OF alld lin] have th1:"\<forall> x k. ?P x = ?P (x - (k * ?d))" by simp
 14.2355 -  from periodic_finite_ex[OF dpos th1] show ?thesis by blast
 14.2356 -qed
 14.2357 -
 14.2358 -lemma dvd1_eq1: "x >0 \<Longrightarrow> (x::int) dvd 1 = (x = 1)" by auto
 14.2359 -
 14.2360 -consts 
 14.2361 -  a\<beta> :: "fm \<Rightarrow> int \<Rightarrow> fm" (* adjusts the coeffitients of a formula *)
 14.2362 -  d\<beta> :: "fm \<Rightarrow> int \<Rightarrow> bool" (* tests if all coeffs c of c divide a given l*)
 14.2363 -  \<zeta>  :: "fm \<Rightarrow> int" (* computes the lcm of all coefficients of x*)
 14.2364 -  \<beta> :: "fm \<Rightarrow> num list"
 14.2365 -  \<alpha> :: "fm \<Rightarrow> num list"
 14.2366 -
 14.2367 -recdef a\<beta> "measure size"
 14.2368 -  "a\<beta> (And p q) = (\<lambda> k. And (a\<beta> p k) (a\<beta> q k))" 
 14.2369 -  "a\<beta> (Or p q) = (\<lambda> k. Or (a\<beta> p k) (a\<beta> q k))" 
 14.2370 -  "a\<beta> (Eq  (CN 0 c e)) = (\<lambda> k. Eq (CN 0 1 (Mul (k div c) e)))"
 14.2371 -  "a\<beta> (NEq (CN 0 c e)) = (\<lambda> k. NEq (CN 0 1 (Mul (k div c) e)))"
 14.2372 -  "a\<beta> (Lt  (CN 0 c e)) = (\<lambda> k. Lt (CN 0 1 (Mul (k div c) e)))"
 14.2373 -  "a\<beta> (Le  (CN 0 c e)) = (\<lambda> k. Le (CN 0 1 (Mul (k div c) e)))"
 14.2374 -  "a\<beta> (Gt  (CN 0 c e)) = (\<lambda> k. Gt (CN 0 1 (Mul (k div c) e)))"
 14.2375 -  "a\<beta> (Ge  (CN 0 c e)) = (\<lambda> k. Ge (CN 0 1 (Mul (k div c) e)))"
 14.2376 -  "a\<beta> (Dvd i (CN 0 c e)) =(\<lambda> k. Dvd ((k div c)*i) (CN 0 1 (Mul (k div c) e)))"
 14.2377 -  "a\<beta> (NDvd i (CN 0 c e))=(\<lambda> k. NDvd ((k div c)*i) (CN 0 1 (Mul (k div c) e)))"
 14.2378 -  "a\<beta> p = (\<lambda> k. p)"
 14.2379 -
 14.2380 -recdef d\<beta> "measure size"
 14.2381 -  "d\<beta> (And p q) = (\<lambda> k. (d\<beta> p k) \<and> (d\<beta> q k))" 
 14.2382 -  "d\<beta> (Or p q) = (\<lambda> k. (d\<beta> p k) \<and> (d\<beta> q k))" 
 14.2383 -  "d\<beta> (Eq  (CN 0 c e)) = (\<lambda> k. c dvd k)"
 14.2384 -  "d\<beta> (NEq (CN 0 c e)) = (\<lambda> k. c dvd k)"
 14.2385 -  "d\<beta> (Lt  (CN 0 c e)) = (\<lambda> k. c dvd k)"
 14.2386 -  "d\<beta> (Le  (CN 0 c e)) = (\<lambda> k. c dvd k)"
 14.2387 -  "d\<beta> (Gt  (CN 0 c e)) = (\<lambda> k. c dvd k)"
 14.2388 -  "d\<beta> (Ge  (CN 0 c e)) = (\<lambda> k. c dvd k)"
 14.2389 -  "d\<beta> (Dvd i (CN 0 c e)) =(\<lambda> k. c dvd k)"
 14.2390 -  "d\<beta> (NDvd i (CN 0 c e))=(\<lambda> k. c dvd k)"
 14.2391 -  "d\<beta> p = (\<lambda> k. True)"
 14.2392 -
 14.2393 -recdef \<zeta> "measure size"
 14.2394 -  "\<zeta> (And p q) = zlcm (\<zeta> p) (\<zeta> q)" 
 14.2395 -  "\<zeta> (Or p q) = zlcm (\<zeta> p) (\<zeta> q)" 
 14.2396 -  "\<zeta> (Eq  (CN 0 c e)) = c"
 14.2397 -  "\<zeta> (NEq (CN 0 c e)) = c"
 14.2398 -  "\<zeta> (Lt  (CN 0 c e)) = c"
 14.2399 -  "\<zeta> (Le  (CN 0 c e)) = c"
 14.2400 -  "\<zeta> (Gt  (CN 0 c e)) = c"
 14.2401 -  "\<zeta> (Ge  (CN 0 c e)) = c"
 14.2402 -  "\<zeta> (Dvd i (CN 0 c e)) = c"
 14.2403 -  "\<zeta> (NDvd i (CN 0 c e))= c"
 14.2404 -  "\<zeta> p = 1"
 14.2405 -
 14.2406 -recdef \<beta> "measure size"
 14.2407 -  "\<beta> (And p q) = (\<beta> p @ \<beta> q)" 
 14.2408 -  "\<beta> (Or p q) = (\<beta> p @ \<beta> q)" 
 14.2409 -  "\<beta> (Eq  (CN 0 c e)) = [Sub (C -1) e]"
 14.2410 -  "\<beta> (NEq (CN 0 c e)) = [Neg e]"
 14.2411 -  "\<beta> (Lt  (CN 0 c e)) = []"
 14.2412 -  "\<beta> (Le  (CN 0 c e)) = []"
 14.2413 -  "\<beta> (Gt  (CN 0 c e)) = [Neg e]"
 14.2414 -  "\<beta> (Ge  (CN 0 c e)) = [Sub (C -1) e]"
 14.2415 -  "\<beta> p = []"
 14.2416 -
 14.2417 -recdef \<alpha> "measure size"
 14.2418 -  "\<alpha> (And p q) = (\<alpha> p @ \<alpha> q)" 
 14.2419 -  "\<alpha> (Or p q) = (\<alpha> p @ \<alpha> q)" 
 14.2420 -  "\<alpha> (Eq  (CN 0 c e)) = [Add (C -1) e]"
 14.2421 -  "\<alpha> (NEq (CN 0 c e)) = [e]"
 14.2422 -  "\<alpha> (Lt  (CN 0 c e)) = [e]"
 14.2423 -  "\<alpha> (Le  (CN 0 c e)) = [Add (C -1) e]"
 14.2424 -  "\<alpha> (Gt  (CN 0 c e)) = []"
 14.2425 -  "\<alpha> (Ge  (CN 0 c e)) = []"
 14.2426 -  "\<alpha> p = []"
 14.2427 -consts mirror :: "fm \<Rightarrow> fm"
 14.2428 -recdef mirror "measure size"
 14.2429 -  "mirror (And p q) = And (mirror p) (mirror q)" 
 14.2430 -  "mirror (Or p q) = Or (mirror p) (mirror q)" 
 14.2431 -  "mirror (Eq  (CN 0 c e)) = Eq (CN 0 c (Neg e))"
 14.2432 -  "mirror (NEq (CN 0 c e)) = NEq (CN 0 c (Neg e))"
 14.2433 -  "mirror (Lt  (CN 0 c e)) = Gt (CN 0 c (Neg e))"
 14.2434 -  "mirror (Le  (CN 0 c e)) = Ge (CN 0 c (Neg e))"
 14.2435 -  "mirror (Gt  (CN 0 c e)) = Lt (CN 0 c (Neg e))"
 14.2436 -  "mirror (Ge  (CN 0 c e)) = Le (CN 0 c (Neg e))"
 14.2437 -  "mirror (Dvd i (CN 0 c e)) = Dvd i (CN 0 c (Neg e))"
 14.2438 -  "mirror (NDvd i (CN 0 c e)) = NDvd i (CN 0 c (Neg e))"
 14.2439 -  "mirror p = p"
 14.2440 -
 14.2441 -lemma mirror\<alpha>\<beta>:
 14.2442 -  assumes lp: "iszlfm p (a#bs)"
 14.2443 -  shows "(Inum (real (i::int)#bs)) ` set (\<alpha> p) = (Inum (real i#bs)) ` set (\<beta> (mirror p))"
 14.2444 -using lp
 14.2445 -by (induct p rule: mirror.induct, auto)
 14.2446 -
 14.2447 -lemma mirror: 
 14.2448 -  assumes lp: "iszlfm p (a#bs)"
 14.2449 -  shows "Ifm (real (x::int)#bs) (mirror p) = Ifm (real (- x)#bs) p" 
 14.2450 -using lp
 14.2451 -proof(induct p rule: iszlfm.induct)
 14.2452 -  case (9 j c e)
 14.2453 -  have th: "(real j rdvd real c * real x - Inum (real x # bs) e) =
 14.2454 -       (real j rdvd - (real c * real x - Inum (real x # bs) e))"
 14.2455 -    by (simp only: rdvd_minus[symmetric])
 14.2456 -  from prems show  ?case
 14.2457 -    by (simp add: ring_simps th[simplified ring_simps]
 14.2458 -      numbound0_I[where bs="bs" and b'="real x" and b="- real x"])
 14.2459 -next
 14.2460 -    case (10 j c e)
 14.2461 -  have th: "(real j rdvd real c * real x - Inum (real x # bs) e) =
 14.2462 -       (real j rdvd - (real c * real x - Inum (real x # bs) e))"
 14.2463 -    by (simp only: rdvd_minus[symmetric])
 14.2464 -  from prems show  ?case
 14.2465 -    by (simp add: ring_simps th[simplified ring_simps]
 14.2466 -      numbound0_I[where bs="bs" and b'="real x" and b="- real x"])
 14.2467 -qed (auto simp add: numbound0_I[where bs="bs" and b="real x" and b'="- real x"] nth_pos2)
 14.2468 -
 14.2469 -lemma mirror_l: "iszlfm p (a#bs) \<Longrightarrow> iszlfm (mirror p) (a#bs)"
 14.2470 -by (induct p rule: mirror.induct, auto simp add: isint_neg)
 14.2471 -
 14.2472 -lemma mirror_d\<beta>: "iszlfm p (a#bs) \<and> d\<beta> p 1 
 14.2473 -  \<Longrightarrow> iszlfm (mirror p) (a#bs) \<and> d\<beta> (mirror p) 1"
 14.2474 -by (induct p rule: mirror.induct, auto simp add: isint_neg)
 14.2475 -
 14.2476 -lemma mirror_\<delta>: "iszlfm p (a#bs) \<Longrightarrow> \<delta> (mirror p) = \<delta> p"
 14.2477 -by (induct p rule: mirror.induct,auto)
 14.2478 -
 14.2479 -
 14.2480 -lemma mirror_ex: 
 14.2481 -  assumes lp: "iszlfm p (real (i::int)#bs)"
 14.2482 -  shows "(\<exists> (x::int). Ifm (real x#bs) (mirror p)) = (\<exists> (x::int). Ifm (real x#bs) p)"
 14.2483 -  (is "(\<exists> x. ?I x ?mp) = (\<exists> x. ?I x p)")
 14.2484 -proof(auto)
 14.2485 -  fix x assume "?I x ?mp" hence "?I (- x) p" using mirror[OF lp] by blast
 14.2486 -  thus "\<exists> x. ?I x p" by blast
 14.2487 -next
 14.2488 -  fix x assume "?I x p" hence "?I (- x) ?mp" 
 14.2489 -    using mirror[OF lp, where x="- x", symmetric] by auto
 14.2490 -  thus "\<exists> x. ?I x ?mp" by blast
 14.2491 -qed
 14.2492 -
 14.2493 -lemma \<beta>_numbound0: assumes lp: "iszlfm p bs"
 14.2494 -  shows "\<forall> b\<in> set (\<beta> p). numbound0 b"
 14.2495 -  using lp by (induct p rule: \<beta>.induct,auto)
 14.2496 -
 14.2497 -lemma d\<beta>_mono: 
 14.2498 -  assumes linp: "iszlfm p (a #bs)"
 14.2499 -  and dr: "d\<beta> p l"
 14.2500 -  and d: "l dvd l'"
 14.2501 -  shows "d\<beta> p l'"
 14.2502 -using dr linp zdvd_trans[where n="l" and k="l'", simplified d]
 14.2503 -by (induct p rule: iszlfm.induct) simp_all
 14.2504 -
 14.2505 -lemma \<alpha>_l: assumes lp: "iszlfm p (a#bs)"
 14.2506 -  shows "\<forall> b\<in> set (\<alpha> p). numbound0 b \<and> isint b (a#bs)"
 14.2507 -using lp
 14.2508 -by(induct p rule: \<alpha>.induct, auto simp add: isint_add isint_c)
 14.2509 -
 14.2510 -lemma \<zeta>: 
 14.2511 -  assumes linp: "iszlfm p (a #bs)"
 14.2512 -  shows "\<zeta> p > 0 \<and> d\<beta> p (\<zeta> p)"
 14.2513 -using linp
 14.2514 -proof(induct p rule: iszlfm.induct)
 14.2515 -  case (1 p q)
 14.2516 -  from prems have dl1: "\<zeta> p dvd zlcm (\<zeta> p) (\<zeta> q)" by simp
 14.2517 -  from prems have dl2: "\<zeta> q dvd zlcm (\<zeta> p) (\<zeta> q)" by simp
 14.2518 -  from prems d\<beta>_mono[where p = "p" and l="\<zeta> p" and l'="zlcm (\<zeta> p) (\<zeta> q)"] 
 14.2519 -    d\<beta>_mono[where p = "q" and l="\<zeta> q" and l'="zlcm (\<zeta> p) (\<zeta> q)"] 
 14.2520 -    dl1 dl2 show ?case by (auto simp add: zlcm_pos)
 14.2521 -next
 14.2522 -  case (2 p q)
 14.2523 -  from prems have dl1: "\<zeta> p dvd zlcm (\<zeta> p) (\<zeta> q)" by simp
 14.2524 -  from prems have dl2: "\<zeta> q dvd zlcm (\<zeta> p) (\<zeta> q)" by simp
 14.2525 -  from prems d\<beta>_mono[where p = "p" and l="\<zeta> p" and l'="zlcm (\<zeta> p) (\<zeta> q)"] 
 14.2526 -    d\<beta>_mono[where p = "q" and l="\<zeta> q" and l'="zlcm (\<zeta> p) (\<zeta> q)"] 
 14.2527 -    dl1 dl2 show ?case by (auto simp add: zlcm_pos)
 14.2528 -qed (auto simp add: zlcm_pos)
 14.2529 -
 14.2530 -lemma a\<beta>: assumes linp: "iszlfm p (a #bs)" and d: "d\<beta> p l" and lp: "l > 0"
 14.2531 -  shows "iszlfm (a\<beta> p l) (a #bs) \<and> d\<beta> (a\<beta> p l) 1 \<and> (Ifm (real (l * x) #bs) (a\<beta> p l) = Ifm ((real x)#bs) p)"
 14.2532 -using linp d
 14.2533 -proof (induct p rule: iszlfm.induct)
 14.2534 -  case (5 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+
 14.2535 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 14.2536 -    from cp have cnz: "c \<noteq> 0" by simp
 14.2537 -    have "c div c\<le> l div c"
 14.2538 -      by (simp add: zdiv_mono1[OF clel cp])
 14.2539 -    then have ldcp:"0 < l div c" 
 14.2540 -      by (simp add: zdiv_self[OF cnz])
 14.2541 -    have "c * (l div c) = c* (l div c) + l mod c" using d' zdvd_iff_zmod_eq_0[where m="c" and n="l"] by simp
 14.2542 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 14.2543 -      by simp
 14.2544 -    hence "(real l * real x + real (l div c) * Inum (real x # bs) e < (0\<Colon>real)) =
 14.2545 -          (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e < 0)"
 14.2546 -      by simp
 14.2547 -    also have "\<dots> = (real (l div c) * (real c * real x + Inum (real x # bs) e) < (real (l div c)) * 0)" by (simp add: ring_simps)
 14.2548 -    also have "\<dots> = (real c * real x + Inum (real x # bs) e < 0)"
 14.2549 -    using mult_less_0_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp
 14.2550 -  finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] be  isint_Mul[OF ei] by simp
 14.2551 -next
 14.2552 -  case (6 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+
 14.2553 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 14.2554 -    from cp have cnz: "c \<noteq> 0" by simp
 14.2555 -    have "c div c\<le> l div c"
 14.2556 -      by (simp add: zdiv_mono1[OF clel cp])
 14.2557 -    then have ldcp:"0 < l div c" 
 14.2558 -      by (simp add: zdiv_self[OF cnz])
 14.2559 -    have "c * (l div c) = c* (l div c) + l mod c" using d' zdvd_iff_zmod_eq_0[where m="c" and n="l"] by simp
 14.2560 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 14.2561 -      by simp
 14.2562 -    hence "(real l * real x + real (l div c) * Inum (real x # bs) e \<le> (0\<Colon>real)) =
 14.2563 -          (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e \<le> 0)"
 14.2564 -      by simp
 14.2565 -    also have "\<dots> = (real (l div c) * (real c * real x + Inum (real x # bs) e) \<le> (real (l div c)) * 0)" by (simp add: ring_simps)
 14.2566 -    also have "\<dots> = (real c * real x + Inum (real x # bs) e \<le> 0)"
 14.2567 -    using mult_le_0_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp
 14.2568 -  finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"]  be  isint_Mul[OF ei] by simp
 14.2569 -next
 14.2570 -  case (7 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+
 14.2571 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 14.2572 -    from cp have cnz: "c \<noteq> 0" by simp
 14.2573 -    have "c div c\<le> l div c"
 14.2574 -      by (simp add: zdiv_mono1[OF clel cp])
 14.2575 -    then have ldcp:"0 < l div c" 
 14.2576 -      by (simp add: zdiv_self[OF cnz])
 14.2577 -    have "c * (l div c) = c* (l div c) + l mod c" using d' zdvd_iff_zmod_eq_0[where m="c" and n="l"] by simp
 14.2578 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 14.2579 -      by simp
 14.2580 -    hence "(real l * real x + real (l div c) * Inum (real x # bs) e > (0\<Colon>real)) =
 14.2581 -          (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e > 0)"
 14.2582 -      by simp
 14.2583 -    also have "\<dots> = (real (l div c) * (real c * real x + Inum (real x # bs) e) > (real (l div c)) * 0)" by (simp add: ring_simps)
 14.2584 -    also have "\<dots> = (real c * real x + Inum (real x # bs) e > 0)"
 14.2585 -    using zero_less_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp
 14.2586 -  finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"]  be  isint_Mul[OF ei] by simp
 14.2587 -next
 14.2588 -  case (8 c e) hence cp: "c>0" and be: "numbound0 e"  and ei:"isint e (a#bs)" and d': "c dvd l" by simp+
 14.2589 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 14.2590 -    from cp have cnz: "c \<noteq> 0" by simp
 14.2591 -    have "c div c\<le> l div c"
 14.2592 -      by (simp add: zdiv_mono1[OF clel cp])
 14.2593 -    then have ldcp:"0 < l div c" 
 14.2594 -      by (simp add: zdiv_self[OF cnz])
 14.2595 -    have "c * (l div c) = c* (l div c) + l mod c" using d' zdvd_iff_zmod_eq_0[where m="c" and n="l"] by simp
 14.2596 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 14.2597 -      by simp
 14.2598 -    hence "(real l * real x + real (l div c) * Inum (real x # bs) e \<ge> (0\<Colon>real)) =
 14.2599 -          (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e \<ge> 0)"
 14.2600 -      by simp
 14.2601 -    also have "\<dots> = (real (l div c) * (real c * real x + Inum (real x # bs) e) \<ge> (real (l div c)) * 0)" by (simp add: ring_simps)
 14.2602 -    also have "\<dots> = (real c * real x + Inum (real x # bs) e \<ge> 0)"
 14.2603 -    using zero_le_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp
 14.2604 -  finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"]  be  isint_Mul[OF ei] by simp
 14.2605 -next
 14.2606 -  case (3 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+
 14.2607 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 14.2608 -    from cp have cnz: "c \<noteq> 0" by simp
 14.2609 -    have "c div c\<le> l div c"
 14.2610 -      by (simp add: zdiv_mono1[OF clel cp])
 14.2611 -    then have ldcp:"0 < l div c" 
 14.2612 -      by (simp add: zdiv_self[OF cnz])
 14.2613 -    have "c * (l div c) = c* (l div c) + l mod c" using d' zdvd_iff_zmod_eq_0[where m="c" and n="l"] by simp
 14.2614 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 14.2615 -      by simp
 14.2616 -    hence "(real l * real x + real (l div c) * Inum (real x # bs) e = (0\<Colon>real)) =
 14.2617 -          (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e = 0)"
 14.2618 -      by simp
 14.2619 -    also have "\<dots> = (real (l div c) * (real c * real x + Inum (real x # bs) e) = (real (l div c)) * 0)" by (simp add: ring_simps)
 14.2620 -    also have "\<dots> = (real c * real x + Inum (real x # bs) e = 0)"
 14.2621 -    using mult_eq_0_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp
 14.2622 -  finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"]  be  isint_Mul[OF ei] by simp
 14.2623 -next
 14.2624 -  case (4 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+
 14.2625 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 14.2626 -    from cp have cnz: "c \<noteq> 0" by simp
 14.2627 -    have "c div c\<le> l div c"
 14.2628 -      by (simp add: zdiv_mono1[OF clel cp])
 14.2629 -    then have ldcp:"0 < l div c" 
 14.2630 -      by (simp add: zdiv_self[OF cnz])
 14.2631 -    have "c * (l div c) = c* (l div c) + l mod c" using d' zdvd_iff_zmod_eq_0[where m="c" and n="l"] by simp
 14.2632 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 14.2633 -      by simp
 14.2634 -    hence "(real l * real x + real (l div c) * Inum (real x # bs) e \<noteq> (0\<Colon>real)) =
 14.2635 -          (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e \<noteq> 0)"
 14.2636 -      by simp
 14.2637 -    also have "\<dots> = (real (l div c) * (real c * real x + Inum (real x # bs) e) \<noteq> (real (l div c)) * 0)" by (simp add: ring_simps)
 14.2638 -    also have "\<dots> = (real c * real x + Inum (real x # bs) e \<noteq> 0)"
 14.2639 -    using zero_le_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp
 14.2640 -  finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"]  be  isint_Mul[OF ei] by simp
 14.2641 -next
 14.2642 -  case (9 j c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and jp: "j > 0" and d': "c dvd l" by simp+
 14.2643 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 14.2644 -    from cp have cnz: "c \<noteq> 0" by simp
 14.2645 -    have "c div c\<le> l div c"
 14.2646 -      by (simp add: zdiv_mono1[OF clel cp])
 14.2647 -    then have ldcp:"0 < l div c" 
 14.2648 -      by (simp add: zdiv_self[OF cnz])
 14.2649 -    have "c * (l div c) = c* (l div c) + l mod c" using d' zdvd_iff_zmod_eq_0[where m="c" and n="l"] by simp
 14.2650 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 14.2651 -      by simp
 14.2652 -    hence "(\<exists> (k::int). real l * real x + real (l div c) * Inum (real x # bs) e = (real (l div c) * real j) * real k) = (\<exists> (k::int). real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e = (real (l div c) * real j) * real k)"  by simp
 14.2653 -    also have "\<dots> = (\<exists> (k::int). real (l div c) * (real c * real x + Inum (real x # bs) e - real j * real k) = real (l div c)*0)" by (simp add: ring_simps)
 14.2654 -    also fix k have "\<dots> = (\<exists> (k::int). real c * real x + Inum (real x # bs) e - real j * real k = 0)"
 14.2655 -    using zero_le_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e - real j * real k"] ldcp by simp
 14.2656 -  also have "\<dots> = (\<exists> (k::int). real c * real x + Inum (real x # bs) e = real j * real k)" by simp
 14.2657 -  finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] rdvd_def  be  isint_Mul[OF ei] mult_strict_mono[OF ldcp jp ldcp ] by simp 
 14.2658 -next
 14.2659 -  case (10 j c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and jp: "j > 0" and d': "c dvd l" by simp+
 14.2660 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 14.2661 -    from cp have cnz: "c \<noteq> 0" by simp
 14.2662 -    have "c div c\<le> l div c"
 14.2663 -      by (simp add: zdiv_mono1[OF clel cp])
 14.2664 -    then have ldcp:"0 < l div c" 
 14.2665 -      by (simp add: zdiv_self[OF cnz])
 14.2666 -    have "c * (l div c) = c* (l div c) + l mod c" using d' zdvd_iff_zmod_eq_0[where m="c" and n="l"] by simp
 14.2667 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 14.2668 -      by simp
 14.2669 -    hence "(\<exists> (k::int). real l * real x + real (l div c) * Inum (real x # bs) e = (real (l div c) * real j) * real k) = (\<exists> (k::int). real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e = (real (l div c) * real j) * real k)"  by simp
 14.2670 -    also have "\<dots> = (\<exists> (k::int). real (l div c) * (real c * real x + Inum (real x # bs) e - real j * real k) = real (l div c)*0)" by (simp add: ring_simps)
 14.2671 -    also fix k have "\<dots> = (\<exists> (k::int). real c * real x + Inum (real x # bs) e - real j * real k = 0)"
 14.2672 -    using zero_le_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e - real j * real k"] ldcp by simp
 14.2673 -  also have "\<dots> = (\<exists> (k::int). real c * real x + Inum (real x # bs) e = real j * real k)" by simp
 14.2674 -  finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] rdvd_def  be  isint_Mul[OF ei]  mult_strict_mono[OF ldcp jp ldcp ] by simp
 14.2675 -qed (simp_all add: nth_pos2 numbound0_I[where bs="bs" and b="real (l * x)" and b'="real x"] isint_Mul del: real_of_int_mult)
 14.2676 -
 14.2677 -lemma a\<beta>_ex: assumes linp: "iszlfm p (a#bs)" and d: "d\<beta> p l" and lp: "l>0"
 14.2678 -  shows "(\<exists> x. l dvd x \<and> Ifm (real x #bs) (a\<beta> p l)) = (\<exists> (x::int). Ifm (real x#bs) p)"
 14.2679 -  (is "(\<exists> x. l dvd x \<and> ?P x) = (\<exists> x. ?P' x)")
 14.2680 -proof-
 14.2681 -  have "(\<exists> x. l dvd x \<and> ?P x) = (\<exists> (x::int). ?P (l*x))"
 14.2682 -    using unity_coeff_ex[where l="l" and P="?P", simplified] by simp
 14.2683 -  also have "\<dots> = (\<exists> (x::int). ?P' x)" using a\<beta>[OF linp d lp] by simp
 14.2684 -  finally show ?thesis  . 
 14.2685 -qed
 14.2686 -
 14.2687 -lemma \<beta>:
 14.2688 -  assumes lp: "iszlfm p (a#bs)"
 14.2689 -  and u: "d\<beta> p 1"
 14.2690 -  and d: "d\<delta> p d"
 14.2691 -  and dp: "d > 0"
 14.2692 -  and nob: "\<not>(\<exists>(j::int) \<in> {1 .. d}. \<exists> b\<in> (Inum (a#bs)) ` set(\<beta> p). real x = b + real j)"
 14.2693 -  and p: "Ifm (real x#bs) p" (is "?P x")
 14.2694 -  shows "?P (x - d)"
 14.2695 -using lp u d dp nob p
 14.2696 -proof(induct p rule: iszlfm.induct)
 14.2697 -  case (5 c e) hence c1: "c=1" and  bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+
 14.2698 -    with dp p c1 numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] prems
 14.2699 -    show ?case by (simp del: real_of_int_minus)
 14.2700 -next
 14.2701 -  case (6 c e)  hence c1: "c=1" and  bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+
 14.2702 -    with dp p c1 numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] prems
 14.2703 -    show ?case by (simp del: real_of_int_minus)
 14.2704 -next
 14.2705 -  case (7 c e) hence p: "Ifm (real x #bs) (Gt (CN 0 c e))" and c1: "c=1" and bn:"numbound0 e" and ie1:"isint e (a#bs)" using dvd1_eq1[where x="c"] by simp+
 14.2706 -    let ?e = "Inum (real x # bs) e"
 14.2707 -    from ie1 have ie: "real (floor ?e) = ?e" using isint_iff[where n="e" and bs="a#bs"]
 14.2708 -      numbound0_I[OF bn,where b="a" and b'="real x" and bs="bs"]
 14.2709 -      by (simp add: isint_iff)
 14.2710 -    {assume "real (x-d) +?e > 0" hence ?case using c1 
 14.2711 -      numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"]
 14.2712 -	by (simp del: real_of_int_minus)}
 14.2713 -    moreover
 14.2714 -    {assume H: "\<not> real (x-d) + ?e > 0" 
 14.2715 -      let ?v="Neg e"
 14.2716 -      have vb: "?v \<in> set (\<beta> (Gt (CN 0 c e)))" by simp
 14.2717 -      from prems(11)[simplified simp_thms Inum.simps \<beta>.simps set.simps bex_simps numbound0_I[OF bn,where b="a" and b'="real x" and bs="bs"]] 
 14.2718 -      have nob: "\<not> (\<exists> j\<in> {1 ..d}. real x =  - ?e + real j)" by auto 
 14.2719 -      from H p have "real x + ?e > 0 \<and> real x + ?e \<le> real d" by (simp add: c1)
 14.2720 -      hence "real (x + floor ?e) > real (0::int) \<and> real (x + floor ?e) \<le> real d"
 14.2721 -	using ie by simp
 14.2722 -      hence "x + floor ?e \<ge> 1 \<and> x + floor ?e \<le> d"  by simp
 14.2723 -      hence "\<exists> (j::int) \<in> {1 .. d}. j = x + floor ?e" by simp
 14.2724 -      hence "\<exists> (j::int) \<in> {1 .. d}. real x = real (- floor ?e + j)" 
 14.2725 -	by (simp only: real_of_int_inject) (simp add: ring_simps)
 14.2726 -      hence "\<exists> (j::int) \<in> {1 .. d}. real x = - ?e + real j" 
 14.2727 -	by (simp add: ie[simplified isint_iff])
 14.2728 -      with nob have ?case by auto}
 14.2729 -    ultimately show ?case by blast
 14.2730 -next
 14.2731 -  case (8 c e) hence p: "Ifm (real x #bs) (Ge (CN 0 c e))" and c1: "c=1" and bn:"numbound0 e" 
 14.2732 -    and ie1:"isint e (a #bs)" using dvd1_eq1[where x="c"] by simp+
 14.2733 -    let ?e = "Inum (real x # bs) e"
 14.2734 -    from ie1 have ie: "real (floor ?e) = ?e" using numbound0_I[OF bn,where b="real x" and b'="a" and bs="bs"] isint_iff[where n="e" and bs="(real x)#bs"]
 14.2735 -      by (simp add: isint_iff)
 14.2736 -    {assume "real (x-d) +?e \<ge> 0" hence ?case using  c1 
 14.2737 -      numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"]
 14.2738 -	by (simp del: real_of_int_minus)}
 14.2739 -    moreover
 14.2740 -    {assume H: "\<not> real (x-d) + ?e \<ge> 0" 
 14.2741 -      let ?v="Sub (C -1) e"
 14.2742 -      have vb: "?v \<in> set (\<beta> (Ge (CN 0 c e)))" by simp
 14.2743 -      from prems(11)[simplified simp_thms Inum.simps \<beta>.simps set.simps bex_simps numbound0_I[OF bn,where b="a" and b'="real x" and bs="bs"]] 
 14.2744 -      have nob: "\<not> (\<exists> j\<in> {1 ..d}. real x =  - ?e - 1 + real j)" by auto 
 14.2745 -      from H p have "real x + ?e \<ge> 0 \<and> real x + ?e < real d" by (simp add: c1)
 14.2746 -      hence "real (x + floor ?e) \<ge> real (0::int) \<and> real (x + floor ?e) < real d"
 14.2747 -	using ie by simp
 14.2748 -      hence "x + floor ?e +1 \<ge> 1 \<and> x + floor ?e + 1 \<le> d"  by simp
 14.2749 -      hence "\<exists> (j::int) \<in> {1 .. d}. j = x + floor ?e + 1" by simp
 14.2750 -      hence "\<exists> (j::int) \<in> {1 .. d}. x= - floor ?e - 1 + j" by (simp add: ring_simps)
 14.2751 -      hence "\<exists> (j::int) \<in> {1 .. d}. real x= real (- floor ?e - 1 + j)" 
 14.2752 -	by (simp only: real_of_int_inject)
 14.2753 -      hence "\<exists> (j::int) \<in> {1 .. d}. real x= - ?e - 1 + real j" 
 14.2754 -	by (simp add: ie[simplified isint_iff])
 14.2755 -      with nob have ?case by simp }
 14.2756 -    ultimately show ?case by blast
 14.2757 -next
 14.2758 -  case (3 c e) hence p: "Ifm (real x #bs) (Eq (CN 0 c e))" (is "?p x") and c1: "c=1" 
 14.2759 -    and bn:"numbound0 e" and ie1: "isint e (a #bs)" using dvd1_eq1[where x="c"] by simp+
 14.2760 -    let ?e = "Inum (real x # bs) e"
 14.2761 -    let ?v="(Sub (C -1) e)"
 14.2762 -    have vb: "?v \<in> set (\<beta> (Eq (CN 0 c e)))" by simp
 14.2763 -    from p have "real x= - ?e" by (simp add: c1) with prems(11) show ?case using dp
 14.2764 -      by simp (erule ballE[where x="1"],
 14.2765 -	simp_all add:ring_simps numbound0_I[OF bn,where b="real x"and b'="a"and bs="bs"])
 14.2766 -next
 14.2767 -  case (4 c e)hence p: "Ifm (real x #bs) (NEq (CN 0 c e))" (is "?p x") and c1: "c=1" 
 14.2768 -    and bn:"numbound0 e" and ie1: "isint e (a #bs)" using dvd1_eq1[where x="c"] by simp+
 14.2769 -    let ?e = "Inum (real x # bs) e"
 14.2770 -    let ?v="Neg e"
 14.2771 -    have vb: "?v \<in> set (\<beta> (NEq (CN 0 c e)))" by simp
 14.2772 -    {assume "real x - real d + Inum ((real (x -d)) # bs) e \<noteq> 0" 
 14.2773 -      hence ?case by (simp add: c1)}
 14.2774 -    moreover
 14.2775 -    {assume H: "real x - real d + Inum ((real (x -d)) # bs) e = 0"
 14.2776 -      hence "real x = - Inum ((real (x -d)) # bs) e + real d" by simp
 14.2777 -      hence "real x = - Inum (a # bs) e + real d"
 14.2778 -	by (simp add: numbound0_I[OF bn,where b="real x - real d"and b'="a"and bs="bs"])
 14.2779 -       with prems(11) have ?case using dp by simp}
 14.2780 -  ultimately show ?case by blast
 14.2781 -next 
 14.2782 -  case (9 j c e) hence p: "Ifm (real x #bs) (Dvd j (CN 0 c e))" (is "?p x") and c1: "c=1" 
 14.2783 -    and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+
 14.2784 -    let ?e = "Inum (real x # bs) e"
 14.2785 -    from prems have "isint e (a #bs)"  by simp 
 14.2786 -    hence ie: "real (floor ?e) = ?e" using isint_iff[where n="e" and bs="(real x)#bs"] numbound0_I[OF bn,where b="real x" and b'="a" and bs="bs"]
 14.2787 -      by (simp add: isint_iff)
 14.2788 -    from prems have id: "j dvd d" by simp
 14.2789 -    from c1 ie[symmetric] have "?p x = (real j rdvd real (x+ floor ?e))" by simp
 14.2790 -    also have "\<dots> = (j dvd x + floor ?e)" 
 14.2791 -      using int_rdvd_real[where i="j" and x="real (x+ floor ?e)"] by simp
 14.2792 -    also have "\<dots> = (j dvd x - d + floor ?e)" 
 14.2793 -      using dvd_period[OF id, where x="x" and c="-1" and t="floor ?e"] by simp
 14.2794 -    also have "\<dots> = (real j rdvd real (x - d + floor ?e))" 
 14.2795 -      using int_rdvd_real[where i="j" and x="real (x-d + floor ?e)",symmetric, simplified]
 14.2796 -      ie by simp
 14.2797 -    also have "\<dots> = (real j rdvd real x - real d + ?e)" 
 14.2798 -      using ie by simp
 14.2799 -    finally show ?case 
 14.2800 -      using numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] c1 p by simp
 14.2801 -next
 14.2802 -  case (10 j c e) hence p: "Ifm (real x #bs) (NDvd j (CN 0 c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+
 14.2803 -    let ?e = "Inum (real x # bs) e"
 14.2804 -    from prems have "isint e (a#bs)"  by simp 
 14.2805 -    hence ie: "real (floor ?e) = ?e" using numbound0_I[OF bn,where b="real x" and b'="a" and bs="bs"] isint_iff[where n="e" and bs="(real x)#bs"]
 14.2806 -      by (simp add: isint_iff)
 14.2807 -    from prems have id: "j dvd d" by simp
 14.2808 -    from c1 ie[symmetric] have "?p x = (\<not> real j rdvd real (x+ floor ?e))" by simp
 14.2809 -    also have "\<dots> = (\<not> j dvd x + floor ?e)" 
 14.2810 -      using int_rdvd_real[where i="j" and x="real (x+ floor ?e)"] by simp
 14.2811 -    also have "\<dots> = (\<not> j dvd x - d + floor ?e)" 
 14.2812 -      using dvd_period[OF id, where x="x" and c="-1" and t="floor ?e"] by simp
 14.2813 -    also have "\<dots> = (\<not> real j rdvd real (x - d + floor ?e))" 
 14.2814 -      using int_rdvd_real[where i="j" and x="real (x-d + floor ?e)",symmetric, simplified]
 14.2815 -      ie by simp
 14.2816 -    also have "\<dots> = (\<not> real j rdvd real x - real d + ?e)" 
 14.2817 -      using ie by simp
 14.2818 -    finally show ?case using numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] c1 p by simp
 14.2819 -qed (auto simp add: numbound0_I[where bs="bs" and b="real (x - d)" and b'="real x"] nth_pos2 simp del: real_of_int_diff)
 14.2820 -
 14.2821 -lemma \<beta>':   
 14.2822 -  assumes lp: "iszlfm p (a #bs)"
 14.2823 -  and u: "d\<beta> p 1"
 14.2824 -  and d: "d\<delta> p d"
 14.2825 -  and dp: "d > 0"
 14.2826 -  shows "\<forall> x. \<not>(\<exists>(j::int) \<in> {1 .. d}. \<exists> b\<in> set(\<beta> p). Ifm ((Inum (a#bs) b + real j) #bs) p) \<longrightarrow> Ifm (real x#bs) p \<longrightarrow> Ifm (real (x - d)#bs) p" (is "\<forall> x. ?b \<longrightarrow> ?P x \<longrightarrow> ?P (x - d)")
 14.2827 -proof(clarify)
 14.2828 -  fix x 
 14.2829 -  assume nb:"?b" and px: "?P x" 
 14.2830 -  hence nb2: "\<not>(\<exists>(j::int) \<in> {1 .. d}. \<exists> b\<in> (Inum (a#bs)) ` set(\<beta> p). real x = b + real j)"
 14.2831 -    by auto
 14.2832 -  from  \<beta>[OF lp u d dp nb2 px] show "?P (x -d )" .
 14.2833 -qed
 14.2834 -
 14.2835 -lemma \<beta>_int: assumes lp: "iszlfm p bs"
 14.2836 -  shows "\<forall> b\<in> set (\<beta> p). isint b bs"
 14.2837 -using lp by (induct p rule: iszlfm.induct) (auto simp add: isint_neg isint_sub)
 14.2838 -
 14.2839 -lemma cpmi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. x < z --> (P x = P1 x))
 14.2840 -==> ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D) 
 14.2841 -==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x-k*D))))
 14.2842 -==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (b::int) : B. P (b+j)))"
 14.2843 -apply(rule iffI)
 14.2844 -prefer 2
 14.2845 -apply(drule minusinfinity)
 14.2846 -apply assumption+
 14.2847 -apply(fastsimp)
 14.2848 -apply clarsimp
 14.2849 -apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x - k*D)")
 14.2850 -apply(frule_tac x = x and z=z in decr_lemma)
 14.2851 -apply(subgoal_tac "P1(x - (\<bar>x - z\<bar> + 1) * D)")
 14.2852 -prefer 2
 14.2853 -apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
 14.2854 -prefer 2 apply arith
 14.2855 - apply fastsimp
 14.2856 -apply(drule (1)  periodic_finite_ex)
 14.2857 -apply blast
 14.2858 -apply(blast dest:decr_mult_lemma)
 14.2859 -done
 14.2860 -
 14.2861 -
 14.2862 -theorem cp_thm:
 14.2863 -  assumes lp: "iszlfm p (a #bs)"
 14.2864 -  and u: "d\<beta> p 1"
 14.2865 -  and d: "d\<delta> p d"
 14.2866 -  and dp: "d > 0"
 14.2867 -  shows "(\<exists> (x::int). Ifm (real x #bs) p) = (\<exists> j\<in> {1.. d}. Ifm (real j #bs) (minusinf p) \<or> (\<exists> b \<in> set (\<beta> p). Ifm ((Inum (a#bs) b + real j) #bs) p))"
 14.2868 -  (is "(\<exists> (x::int). ?P (real x)) = (\<exists> j\<in> ?D. ?M j \<or> (\<exists> b\<in> ?B. ?P (?I b + real j)))")
 14.2869 -proof-
 14.2870 -  from minusinf_inf[OF lp] 
 14.2871 -  have th: "\<exists>(z::int). \<forall>x<z. ?P (real x) = ?M x" by blast
 14.2872 -  let ?B' = "{floor (?I b) | b. b\<in> ?B}"
 14.2873 -  from \<beta>_int[OF lp] isint_iff[where bs="a # bs"] have B: "\<forall> b\<in> ?B. real (floor (?I b)) = ?I b" by simp
 14.2874 -  from B[rule_format] 
 14.2875 -  have "(\<exists>j\<in>?D. \<exists>b\<in> ?B. ?P (?I b + real j)) = (\<exists>j\<in>?D. \<exists>b\<in> ?B. ?P (real (floor (?I b)) + real j))" 
 14.2876 -    by simp
 14.2877 -  also have "\<dots> = (\<exists>j\<in>?D. \<exists>b\<in> ?B. ?P (real (floor (?I b) + j)))" by simp
 14.2878 -  also have"\<dots> = (\<exists> j \<in> ?D. \<exists> b \<in> ?B'. ?P (real (b + j)))"  by blast
 14.2879 -  finally have BB': 
 14.2880 -    "(\<exists>j\<in>?D. \<exists>b\<in> ?B. ?P (?I b + real j)) = (\<exists> j \<in> ?D. \<exists> b \<in> ?B'. ?P (real (b + j)))" 
 14.2881 -    by blast 
 14.2882 -  hence th2: "\<forall> x. \<not> (\<exists> j \<in> ?D. \<exists> b \<in> ?B'. ?P (real (b + j))) \<longrightarrow> ?P (real x) \<longrightarrow> ?P (real (x - d))" using \<beta>'[OF lp u d dp] by blast
 14.2883 -  from minusinf_repeats[OF d lp]
 14.2884 -  have th3: "\<forall> x k. ?M x = ?M (x-k*d)" by simp
 14.2885 -  from cpmi_eq[OF dp th th2 th3] BB' show ?thesis by blast
 14.2886 -qed
 14.2887 -
 14.2888 -    (* Reddy and Loveland *)
 14.2889 -
 14.2890 -
 14.2891 -consts 
 14.2892 -  \<rho> :: "fm \<Rightarrow> (num \<times> int) list" (* Compute the Reddy and Loveland Bset*)
 14.2893 -  \<sigma>\<rho>:: "fm \<Rightarrow> num \<times> int \<Rightarrow> fm" (* Performs the modified substitution of Reddy and Loveland*)
 14.2894 -  \<alpha>\<rho> :: "fm \<Rightarrow> (num\<times>int) list"
 14.2895 -  a\<rho> :: "fm \<Rightarrow> int \<Rightarrow> fm"
 14.2896 -recdef \<rho> "measure size"
 14.2897 -  "\<rho> (And p q) = (\<rho> p @ \<rho> q)" 
 14.2898 -  "\<rho> (Or p q) = (\<rho> p @ \<rho> q)" 
 14.2899 -  "\<rho> (Eq  (CN 0 c e)) = [(Sub (C -1) e,c)]"
 14.2900 -  "\<rho> (NEq (CN 0 c e)) = [(Neg e,c)]"
 14.2901 -  "\<rho> (Lt  (CN 0 c e)) = []"
 14.2902 -  "\<rho> (Le  (CN 0 c e)) = []"
 14.2903 -  "\<rho> (Gt  (CN 0 c e)) = [(Neg e, c)]"
 14.2904 -  "\<rho> (Ge  (CN 0 c e)) = [(Sub (C (-1)) e, c)]"
 14.2905 -  "\<rho> p = []"
 14.2906 -
 14.2907 -recdef \<sigma>\<rho> "measure size"
 14.2908 -  "\<sigma>\<rho> (And p q) = (\<lambda> (t,k). And (\<sigma>\<rho> p (t,k)) (\<sigma>\<rho> q (t,k)))" 
 14.2909 -  "\<sigma>\<rho> (Or p q) = (\<lambda> (t,k). Or (\<sigma>\<rho> p (t,k)) (\<sigma>\<rho> q (t,k)))" 
 14.2910 -  "\<sigma>\<rho> (Eq  (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Eq (Add (Mul (c div k) t) e)) 
 14.2911 -                                            else (Eq (Add (Mul c t) (Mul k e))))"
 14.2912 -  "\<sigma>\<rho> (NEq (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (NEq (Add (Mul (c div k) t) e)) 
 14.2913 -                                            else (NEq (Add (Mul c t) (Mul k e))))"
 14.2914 -  "\<sigma>\<rho> (Lt  (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Lt (Add (Mul (c div k) t) e)) 
 14.2915 -                                            else (Lt (Add (Mul c t) (Mul k e))))"
 14.2916 -  "\<sigma>\<rho> (Le  (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Le (Add (Mul (c div k) t) e)) 
 14.2917 -                                            else (Le (Add (Mul c t) (Mul k e))))"
 14.2918 -  "\<sigma>\<rho> (Gt  (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Gt (Add (Mul (c div k) t) e)) 
 14.2919 -                                            else (Gt (Add (Mul c t) (Mul k e))))"
 14.2920 -  "\<sigma>\<rho> (Ge  (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Ge (Add (Mul (c div k) t) e)) 
 14.2921 -                                            else (Ge (Add (Mul c t) (Mul k e))))"
 14.2922 -  "\<sigma>\<rho> (Dvd i (CN 0 c e)) =(\<lambda> (t,k). if k dvd c then (Dvd i (Add (Mul (c div k) t) e)) 
 14.2923 -                                            else (Dvd (i*k) (Add (Mul c t) (Mul k e))))"
 14.2924 -  "\<sigma>\<rho> (NDvd i (CN 0 c e))=(\<lambda> (t,k). if k dvd c then (NDvd i (Add (Mul (c div k) t) e)) 
 14.2925 -                                            else (NDvd (i*k) (Add (Mul c t) (Mul k e))))"
 14.2926 -  "\<sigma>\<rho> p = (\<lambda> (t,k). p)"
 14.2927 -
 14.2928 -recdef \<alpha>\<rho> "measure size"
 14.2929 -  "\<alpha>\<rho> (And p q) = (\<alpha>\<rho> p @ \<alpha>\<rho> q)" 
 14.2930 -  "\<alpha>\<rho> (Or p q) = (\<alpha>\<rho> p @ \<alpha>\<rho> q)" 
 14.2931 -  "\<alpha>\<rho> (Eq  (CN 0 c e)) = [(Add (C -1) e,c)]"
 14.2932 -  "\<alpha>\<rho> (NEq (CN 0 c e)) = [(e,c)]"
 14.2933 -  "\<alpha>\<rho> (Lt  (CN 0 c e)) = [(e,c)]"
 14.2934 -  "\<alpha>\<rho> (Le  (CN 0 c e)) = [(Add (C -1) e,c)]"
 14.2935 -  "\<alpha>\<rho> p = []"
 14.2936 -
 14.2937 -    (* Simulates normal substituion by modifying the formula see correctness theorem *)
 14.2938 -
 14.2939 -recdef a\<rho> "measure size"
 14.2940 -  "a\<rho> (And p q) = (\<lambda> k. And (a\<rho> p k) (a\<rho> q k))" 
 14.2941 -  "a\<rho> (Or p q) = (\<lambda> k. Or (a\<rho> p k) (a\<rho> q k))" 
 14.2942 -  "a\<rho> (Eq (CN 0 c e)) = (\<lambda> k. if k dvd c then (Eq (CN 0 (c div k) e)) 
 14.2943 -                                           else (Eq (CN 0 c (Mul k e))))"
 14.2944 -  "a\<rho> (NEq (CN 0 c e)) = (\<lambda> k. if k dvd c then (NEq (CN 0 (c div k) e)) 
 14.2945 -                                           else (NEq (CN 0 c (Mul k e))))"
 14.2946 -  "a\<rho> (Lt (CN 0 c e)) = (\<lambda> k. if k dvd c then (Lt (CN 0 (c div k) e)) 
 14.2947 -                                           else (Lt (CN 0 c (Mul k e))))"
 14.2948 -  "a\<rho> (Le (CN 0 c e)) = (\<lambda> k. if k dvd c then (Le (CN 0 (c div k) e)) 
 14.2949 -                                           else (Le (CN 0 c (Mul k e))))"
 14.2950 -  "a\<rho> (Gt (CN 0 c e)) = (\<lambda> k. if k dvd c then (Gt (CN 0 (c div k) e)) 
 14.2951 -                                           else (Gt (CN 0 c (Mul k e))))"
 14.2952 -  "a\<rho> (Ge (CN 0 c e)) = (\<lambda> k. if k dvd c then (Ge (CN 0 (c div k) e)) 
 14.2953 -                                            else (Ge (CN 0 c (Mul k e))))"
 14.2954 -  "a\<rho> (Dvd i (CN 0 c e)) = (\<lambda> k. if k dvd c then (Dvd i (CN 0 (c div k) e)) 
 14.2955 -                                            else (Dvd (i*k) (CN 0 c (Mul k e))))"
 14.2956 -  "a\<rho> (NDvd i (CN 0 c e)) = (\<lambda> k. if k dvd c then (NDvd i (CN 0 (c div k) e)) 
 14.2957 -                                            else (NDvd (i*k) (CN 0 c (Mul k e))))"
 14.2958 -  "a\<rho> p = (\<lambda> k. p)"
 14.2959 -
 14.2960 -constdefs \<sigma> :: "fm \<Rightarrow> int \<Rightarrow> num \<Rightarrow> fm"
 14.2961 -  "\<sigma> p k t \<equiv> And (Dvd k t) (\<sigma>\<rho> p (t,k))"
 14.2962 -
 14.2963 -lemma \<sigma>\<rho>:
 14.2964 -  assumes linp: "iszlfm p (real (x::int)#bs)"
 14.2965 -  and kpos: "real k > 0"
 14.2966 -  and tnb: "numbound0 t"
 14.2967 -  and tint: "isint t (real x#bs)"
 14.2968 -  and kdt: "k dvd floor (Inum (b'#bs) t)"
 14.2969 -  shows "Ifm (real x#bs) (\<sigma>\<rho> p (t,k)) = 
 14.2970 -  (Ifm ((real ((floor (Inum (b'#bs) t)) div k))#bs) p)" 
 14.2971 -  (is "?I (real x) (?s p) = (?I (real ((floor (?N b' t)) div k)) p)" is "_ = (?I ?tk p)")
 14.2972 -using linp kpos tnb
 14.2973 -proof(induct p rule: \<sigma>\<rho>.induct)
 14.2974 -  case (3 c e) 
 14.2975 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.2976 -    {assume kdc: "k dvd c" 
 14.2977 -      from kpos have knz: "k\<noteq>0" by simp
 14.2978 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.2979 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 14.2980 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.2981 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 14.2982 -    moreover 
 14.2983 -    {assume "\<not> k dvd c"
 14.2984 -      from kpos have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 14.2985 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.2986 -      from prems have "?I (real x) (?s (Eq (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k = 0)"
 14.2987 -	using real_of_int_div[OF knz kdt]
 14.2988 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.2989 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 14.2990 -      also have "\<dots> = (?I ?tk (Eq (CN 0 c e)))" using nonzero_eq_divide_eq[OF knz', where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.2991 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 14.2992 -	by (simp add: ti)
 14.2993 -      finally have ?case . }
 14.2994 -    ultimately show ?case by blast 
 14.2995 -next
 14.2996 -  case (4 c e)  
 14.2997 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.2998 -    {assume kdc: "k dvd c" 
 14.2999 -      from kpos have knz: "k\<noteq>0" by simp
 14.3000 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.3001 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 14.3002 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3003 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 14.3004 -    moreover 
 14.3005 -    {assume "\<not> k dvd c"
 14.3006 -      from kpos have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 14.3007 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.3008 -      from prems have "?I (real x) (?s (NEq (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k \<noteq> 0)"
 14.3009 -	using real_of_int_div[OF knz kdt]
 14.3010 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3011 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 14.3012 -      also have "\<dots> = (?I ?tk (NEq (CN 0 c e)))" using nonzero_eq_divide_eq[OF knz', where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3013 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 14.3014 -	by (simp add: ti)
 14.3015 -      finally have ?case . }
 14.3016 -    ultimately show ?case by blast 
 14.3017 -next
 14.3018 -  case (5 c e) 
 14.3019 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.3020 -    {assume kdc: "k dvd c" 
 14.3021 -      from kpos have knz: "k\<noteq>0" by simp
 14.3022 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.3023 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 14.3024 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3025 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 14.3026 -    moreover 
 14.3027 -    {assume "\<not> k dvd c"
 14.3028 -      from kpos have knz: "k\<noteq>0" by simp
 14.3029 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.3030 -      from prems have "?I (real x) (?s (Lt (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k < 0)"
 14.3031 -	using real_of_int_div[OF knz kdt]
 14.3032 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3033 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 14.3034 -      also have "\<dots> = (?I ?tk (Lt (CN 0 c e)))" using pos_less_divide_eq[OF kpos, where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3035 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 14.3036 -	by (simp add: ti)
 14.3037 -      finally have ?case . }
 14.3038 -    ultimately show ?case by blast 
 14.3039 -next
 14.3040 -  case (6 c e)  
 14.3041 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.3042 -    {assume kdc: "k dvd c" 
 14.3043 -      from kpos have knz: "k\<noteq>0" by simp
 14.3044 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.3045 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 14.3046 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3047 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 14.3048 -    moreover 
 14.3049 -    {assume "\<not> k dvd c"
 14.3050 -      from kpos have knz: "k\<noteq>0" by simp
 14.3051 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.3052 -      from prems have "?I (real x) (?s (Le (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k \<le> 0)"
 14.3053 -	using real_of_int_div[OF knz kdt]
 14.3054 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3055 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 14.3056 -      also have "\<dots> = (?I ?tk (Le (CN 0 c e)))" using pos_le_divide_eq[OF kpos, where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3057 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 14.3058 -	by (simp add: ti)
 14.3059 -      finally have ?case . }
 14.3060 -    ultimately show ?case by blast 
 14.3061 -next
 14.3062 -  case (7 c e) 
 14.3063 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.3064 -    {assume kdc: "k dvd c" 
 14.3065 -      from kpos have knz: "k\<noteq>0" by simp
 14.3066 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.3067 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 14.3068 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3069 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 14.3070 -    moreover 
 14.3071 -    {assume "\<not> k dvd c"
 14.3072 -      from kpos have knz: "k\<noteq>0" by simp
 14.3073 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.3074 -      from prems have "?I (real x) (?s (Gt (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k > 0)"
 14.3075 -	using real_of_int_div[OF knz kdt]
 14.3076 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3077 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 14.3078 -      also have "\<dots> = (?I ?tk (Gt (CN 0 c e)))" using pos_divide_less_eq[OF kpos, where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3079 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 14.3080 -	by (simp add: ti)
 14.3081 -      finally have ?case . }
 14.3082 -    ultimately show ?case by blast 
 14.3083 -next
 14.3084 -  case (8 c e)  
 14.3085 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.3086 -    {assume kdc: "k dvd c" 
 14.3087 -      from kpos have knz: "k\<noteq>0" by simp
 14.3088 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.3089 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 14.3090 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3091 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 14.3092 -    moreover 
 14.3093 -    {assume "\<not> k dvd c"
 14.3094 -      from kpos have knz: "k\<noteq>0" by simp
 14.3095 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.3096 -      from prems have "?I (real x) (?s (Ge (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k \<ge> 0)"
 14.3097 -	using real_of_int_div[OF knz kdt]
 14.3098 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3099 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 14.3100 -      also have "\<dots> = (?I ?tk (Ge (CN 0 c e)))" using pos_divide_le_eq[OF kpos, where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3101 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 14.3102 -	by (simp add: ti)
 14.3103 -      finally have ?case . }
 14.3104 -    ultimately show ?case by blast 
 14.3105 -next
 14.3106 -  case (9 i c e)   from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.3107 -    {assume kdc: "k dvd c" 
 14.3108 -      from kpos have knz: "k\<noteq>0" by simp
 14.3109 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.3110 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 14.3111 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3112 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 14.3113 -    moreover 
 14.3114 -    {assume "\<not> k dvd c"
 14.3115 -      from kpos have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 14.3116 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.3117 -      from prems have "?I (real x) (?s (Dvd i (CN 0 c e))) = (real i * real k rdvd (real c * (?N (real x) t / real k) + ?N (real x) e)* real k)"
 14.3118 -	using real_of_int_div[OF knz kdt]
 14.3119 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3120 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 14.3121 -      also have "\<dots> = (?I ?tk (Dvd i (CN 0 c e)))" using rdvd_mult[OF knz, where n="i"] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3122 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 14.3123 -	by (simp add: ti)
 14.3124 -      finally have ?case . }
 14.3125 -    ultimately show ?case by blast 
 14.3126 -next
 14.3127 -  case (10 i c e)    from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.3128 -    {assume kdc: "k dvd c" 
 14.3129 -      from kpos have knz: "k\<noteq>0" by simp
 14.3130 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.3131 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 14.3132 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3133 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 14.3134 -    moreover 
 14.3135 -    {assume "\<not> k dvd c"
 14.3136 -      from kpos have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 14.3137 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 14.3138 -      from prems have "?I (real x) (?s (NDvd i (CN 0 c e))) = (\<not> (real i * real k rdvd (real c * (?N (real x) t / real k) + ?N (real x) e)* real k))"
 14.3139 -	using real_of_int_div[OF knz kdt]
 14.3140 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3141 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 14.3142 -      also have "\<dots> = (?I ?tk (NDvd i (CN 0 c e)))" using rdvd_mult[OF knz, where n="i"] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 14.3143 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 14.3144 -	by (simp add: ti)
 14.3145 -      finally have ?case . }
 14.3146 -    ultimately show ?case by blast 
 14.3147 -qed (simp_all add: nth_pos2 bound0_I[where bs="bs" and b="real ((floor (?N b' t)) div k)" and b'="real x"] numbound0_I[where bs="bs" and b="real ((floor (?N b' t)) div k)" and b'="real x"])
 14.3148 -
 14.3149 -
 14.3150 -lemma a\<rho>: 
 14.3151 -  assumes lp: "iszlfm p (real (x::int)#bs)" and kp: "real k > 0" 
 14.3152 -  shows "Ifm (real (x*k)#bs) (a\<rho> p k) = Ifm (real x#bs) p" (is "?I (x*k) (?f p k) = ?I x p")
 14.3153 -using lp bound0_I[where bs="bs" and b="real (x*k)" and b'="real x"] numbound0_I[where bs="bs" and b="real (x*k)" and b'="real x"]
 14.3154 -proof(induct p rule: a\<rho>.induct)
 14.3155 -  case (3 c e)  
 14.3156 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.3157 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 14.3158 -    {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 14.3159 -    moreover 
 14.3160 -    {assume nkdc: "\<not> k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] nonzero_eq_divide_eq[OF knz', where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: ring_simps)}
 14.3161 -    ultimately show ?case by blast 
 14.3162 -next
 14.3163 -  case (4 c e)   
 14.3164 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.3165 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 14.3166 -    {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 14.3167 -    moreover 
 14.3168 -    {assume nkdc: "\<not> k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] nonzero_eq_divide_eq[OF knz', where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: ring_simps)}
 14.3169 -    ultimately show ?case by blast 
 14.3170 -next
 14.3171 -  case (5 c e)   
 14.3172 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.3173 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 14.3174 -    {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 14.3175 -    moreover 
 14.3176 -    {assume nkdc: "\<not> k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] pos_less_divide_eq[OF kp, where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: ring_simps)}
 14.3177 -    ultimately show ?case by blast 
 14.3178 -next
 14.3179 -  case (6 c e)    
 14.3180 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.3181 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 14.3182 -    {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 14.3183 -    moreover 
 14.3184 -    {assume nkdc: "\<not> k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] pos_le_divide_eq[OF kp, where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: ring_simps)}
 14.3185 -    ultimately show ?case by blast 
 14.3186 -next
 14.3187 -  case (7 c e)    
 14.3188 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.3189 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 14.3190 -    {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 14.3191 -    moreover 
 14.3192 -    {assume nkdc: "\<not> k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] pos_divide_less_eq[OF kp, where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: ring_simps)}
 14.3193 -    ultimately show ?case by blast 
 14.3194 -next
 14.3195 -  case (8 c e)    
 14.3196 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.3197 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 14.3198 -    {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 14.3199 -    moreover 
 14.3200 -    {assume nkdc: "\<not> k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] pos_divide_le_eq[OF kp, where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: ring_simps)}
 14.3201 -    ultimately show ?case by blast 
 14.3202 -next
 14.3203 -  case (9 i c e)
 14.3204 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.3205 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 14.3206 -  {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 14.3207 -  moreover 
 14.3208 -  {assume "\<not> k dvd c"
 14.3209 -    hence "Ifm (real (x*k)#bs) (a\<rho> (Dvd i (CN 0 c e)) k) = 
 14.3210 -      (real i * real k rdvd (real c * real x + Inum (real x#bs) e) * real k)" 
 14.3211 -      using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] 
 14.3212 -      by (simp add: ring_simps)
 14.3213 -    also have "\<dots> = (Ifm (real x#bs) (Dvd i (CN 0 c e)))" by (simp add: rdvd_mult[OF knz, where n="i"])
 14.3214 -    finally have ?case . }
 14.3215 -  ultimately show ?case by blast 
 14.3216 -next
 14.3217 -  case (10 i c e) 
 14.3218 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 14.3219 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 14.3220 -  {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 14.3221 -  moreover 
 14.3222 -  {assume "\<not> k dvd c"
 14.3223 -    hence "Ifm (real (x*k)#bs) (a\<rho> (NDvd i (CN 0 c e)) k) = 
 14.3224 -      (\<not> (real i * real k rdvd (real c * real x + Inum (real x#bs) e) * real k))" 
 14.3225 -      using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] 
 14.3226 -      by (simp add: ring_simps)
 14.3227 -    also have "\<dots> = (Ifm (real x#bs) (NDvd i (CN 0 c e)))" by (simp add: rdvd_mult[OF knz, where n="i"])
 14.3228 -    finally have ?case . }
 14.3229 -  ultimately show ?case by blast 
 14.3230 -qed (simp_all add: nth_pos2)
 14.3231 -
 14.3232 -lemma a\<rho>_ex: 
 14.3233 -  assumes lp: "iszlfm p (real (x::int)#bs)" and kp: "k > 0"
 14.3234 -  shows "(\<exists> (x::int). real k rdvd real x \<and> Ifm (real x#bs) (a\<rho> p k)) = 
 14.3235 -  (\<exists> (x::int). Ifm (real x#bs) p)" (is "(\<exists> x. ?D x \<and> ?P' x) = (\<exists> x. ?P x)")
 14.3236 -proof-
 14.3237 -  have "(\<exists> x. ?D x \<and> ?P' x) = (\<exists> x. k dvd x \<and> ?P' x)" using int_rdvd_iff by simp
 14.3238 -  also have "\<dots> = (\<exists>x. ?P' (x*k))" using unity_coeff_ex[where P="?P'" and l="k", simplified]
 14.3239 -    by (simp add: ring_simps)
 14.3240 -  also have "\<dots> = (\<exists> x. ?P x)" using a\<rho> iszlfm_gen[OF lp] kp by auto
 14.3241 -  finally show ?thesis .
 14.3242 -qed
 14.3243 -
 14.3244 -lemma \<sigma>\<rho>': assumes lp: "iszlfm p (real (x::int)#bs)" and kp: "k > 0" and nb: "numbound0 t"
 14.3245 -  shows "Ifm (real x#bs) (\<sigma>\<rho> p (t,k)) = Ifm ((Inum (real x#bs) t)#bs) (a\<rho> p k)"
 14.3246 -using lp 
 14.3247 -by(induct p rule: \<sigma>\<rho>.induct, simp_all add: 
 14.3248 -  numbound0_I[OF nb, where bs="bs" and b="Inum (real x#bs) t" and b'="real x"] 
 14.3249 -  numbound0_I[where bs="bs" and b="Inum (real x#bs) t" and b'="real x"] 
 14.3250 -  bound0_I[where bs="bs" and b="Inum (real x#bs) t" and b'="real x"] nth_pos2 cong: imp_cong)
 14.3251 -
 14.3252 -lemma \<sigma>\<rho>_nb: assumes lp:"iszlfm p (a#bs)" and nb: "numbound0 t"
 14.3253 -  shows "bound0 (\<sigma>\<rho> p (t,k))"
 14.3254 -  using lp
 14.3255 -  by (induct p rule: iszlfm.induct, auto simp add: nb)
 14.3256 -
 14.3257 -lemma \<rho>_l:
 14.3258 -  assumes lp: "iszlfm p (real (i::int)#bs)"
 14.3259 -  shows "\<forall> (b,k) \<in> set (\<rho> p). k >0 \<and> numbound0 b \<and> isint b (real i#bs)"
 14.3260 -using lp by (induct p rule: \<rho>.induct, auto simp add: isint_sub isint_neg)
 14.3261 -
 14.3262 -lemma \<alpha>\<rho>_l:
 14.3263 -  assumes lp: "iszlfm p (real (i::int)#bs)"
 14.3264 -  shows "\<forall> (b,k) \<in> set (\<alpha>\<rho> p). k >0 \<and> numbound0 b \<and> isint b (real i#bs)"
 14.3265 -using lp isint_add [OF isint_c[where j="- 1"],where bs="real i#bs"]
 14.3266 - by (induct p rule: \<alpha>\<rho>.induct, auto)
 14.3267 -
 14.3268 -lemma zminusinf_\<rho>:
 14.3269 -  assumes lp: "iszlfm p (real (i::int)#bs)"
 14.3270 -  and nmi: "\<not> (Ifm (real i#bs) (minusinf p))" (is "\<not> (Ifm (real i#bs) (?M p))")
 14.3271 -  and ex: "Ifm (real i#bs) p" (is "?I i p")
 14.3272 -  shows "\<exists> (e,c) \<in> set (\<rho> p). real (c*i) > Inum (real i#bs) e" (is "\<exists> (e,c) \<in> ?R p. real (c*i) > ?N i e")
 14.3273 -  using lp nmi ex
 14.3274 -by (induct p rule: minusinf.induct, auto)
 14.3275 -
 14.3276 -
 14.3277 -lemma \<sigma>_And: "Ifm bs (\<sigma> (And p q) k t)  = Ifm bs (And (\<sigma> p k t) (\<sigma> q k t))"
 14.3278 -using \<sigma>_def by auto
 14.3279 -lemma \<sigma>_Or: "Ifm bs (\<sigma> (Or p q) k t)  = Ifm bs (Or (\<sigma> p k t) (\<sigma> q k t))"
 14.3280 -using \<sigma>_def by auto
 14.3281 -
 14.3282 -lemma \<rho>: assumes lp: "iszlfm p (real (i::int) #bs)"
 14.3283 -  and pi: "Ifm (real i#bs) p"
 14.3284 -  and d: "d\<delta> p d"
 14.3285 -  and dp: "d > 0"
 14.3286 -  and nob: "\<forall>(e,c) \<in> set (\<rho> p). \<forall> j\<in> {1 .. c*d}. real (c*i) \<noteq> Inum (real i#bs) e + real j"
 14.3287 -  (is "\<forall>(e,c) \<in> set (\<rho> p). \<forall> j\<in> {1 .. c*d}. _ \<noteq> ?N i e + _")
 14.3288 -  shows "Ifm (real(i - d)#bs) p"
 14.3289 -  using lp pi d nob
 14.3290 -proof(induct p rule: iszlfm.induct)
 14.3291 -  case (3 c e) hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)"
 14.3292 -    and pi: "real (c*i) = - 1 -  ?N i e + real (1::int)" and nob: "\<forall> j\<in> {1 .. c*d}. real (c*i) \<noteq> -1 - ?N i e + real j"
 14.3293 -    by simp+
 14.3294 -  from mult_strict_left_mono[OF dp cp]  have one:"1 \<in> {1 .. c*d}" by auto
 14.3295 -  from nob[rule_format, where j="1", OF one] pi show ?case by simp
 14.3296 -next
 14.3297 -  case (4 c e)  
 14.3298 -  hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)"
 14.3299 -    and nob: "\<forall> j\<in> {1 .. c*d}. real (c*i) \<noteq> - ?N i e + real j"
 14.3300 -    by simp+
 14.3301 -  {assume "real (c*i) \<noteq> - ?N i e + real (c*d)"
 14.3302 -    with numbound0_I[OF nb, where bs="bs" and b="real i - real d" and b'="real i"]
 14.3303 -    have ?case by (simp add: ring_simps)}
 14.3304 -  moreover
 14.3305 -  {assume pi: "real (c*i) = - ?N i e + real (c*d)"
 14.3306 -    from mult_strict_left_mono[OF dp cp] have d: "(c*d) \<in> {1 .. c*d}" by simp
 14.3307 -    from nob[rule_format, where j="c*d", OF d] pi have ?case by simp }
 14.3308 -  ultimately show ?case by blast
 14.3309 -next
 14.3310 -  case (5 c e) hence cp: "c > 0" by simp
 14.3311 -  from prems mult_strict_left_mono[OF dp cp, simplified real_of_int_less_iff[symmetric] 
 14.3312 -    real_of_int_mult]
 14.3313 -  show ?case using prems dp 
 14.3314 -    by (simp add: add: numbound0_I[where bs="bs" and b="real i - real d" and b'="real i"] 
 14.3315 -      ring_simps)
 14.3316 -next
 14.3317 -  case (6 c e)  hence cp: "c > 0" by simp
 14.3318 -  from prems mult_strict_left_mono[OF dp cp, simplified real_of_int_less_iff[symmetric] 
 14.3319 -    real_of_int_mult]
 14.3320 -  show ?case using prems dp 
 14.3321 -    by (simp add: add: numbound0_I[where bs="bs" and b="real i - real d" and b'="real i"] 
 14.3322 -      ring_simps)
 14.3323 -next
 14.3324 -  case (7 c e) hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)"
 14.3325 -    and nob: "\<forall> j\<in> {1 .. c*d}. real (c*i) \<noteq> - ?N i e + real j"
 14.3326 -    and pi: "real (c*i) + ?N i e > 0" and cp': "real c >0"
 14.3327 -    by simp+
 14.3328 -  let ?fe = "floor (?N i e)"
 14.3329 -  from pi cp have th:"(real i +?N i e / real c)*real c > 0" by (simp add: ring_simps)
 14.3330 -  from pi ei[simplified isint_iff] have "real (c*i + ?fe) > real (0::int)" by simp
 14.3331 -  hence pi': "c*i + ?fe > 0" by (simp only: real_of_int_less_iff[symmetric])
 14.3332 -  have "real (c*i) + ?N i e > real (c*d) \<or> real (c*i) + ?N i e \<le> real (c*d)" by auto
 14.3333 -  moreover
 14.3334 -  {assume "real (c*i) + ?N i e > real (c*d)" hence ?case
 14.3335 -      by (simp add: ring_simps 
 14.3336 -	numbound0_I[OF nb,where bs="bs" and b="real i - real d" and b'="real i"])} 
 14.3337 -  moreover 
 14.3338 -  {assume H:"real (c*i) + ?N i e \<le> real (c*d)"
 14.3339 -    with ei[simplified isint_iff] have "real (c*i + ?fe) \<le> real (c*d)" by simp
 14.3340 -    hence pid: "c*i + ?fe \<le> c*d" by (simp only: real_of_int_le_iff)
 14.3341 -    with pi' have "\<exists> j1\<in> {1 .. c*d}. c*i + ?fe = j1" by auto
 14.3342 -    hence "\<exists> j1\<in> {1 .. c*d}. real (c*i) = - ?N i e + real j1" 
 14.3343 -      by (simp only: diff_def[symmetric] real_of_int_mult real_of_int_add real_of_int_inject[symmetric] ei[simplified isint_iff] ring_simps)
 14.3344 -    with nob  have ?case by blast }
 14.3345 -  ultimately show ?case by blast
 14.3346 -next
 14.3347 -  case (8 c e)  hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)"
 14.3348 -    and nob: "\<forall> j\<in> {1 .. c*d}. real (c*i) \<noteq> - 1 - ?N i e + real j"
 14.3349 -    and pi: "real (c*i) + ?N i e \<ge> 0" and cp': "real c >0"
 14.3350 -    by simp+
 14.3351 -  let ?fe = "floor (?N i e)"
 14.3352 -  from pi cp have th:"(real i +?N i e / real c)*real c \<ge> 0" by (simp add: ring_simps)
 14.3353 -  from pi ei[simplified isint_iff] have "real (c*i + ?fe) \<ge> real (0::int)" by simp
 14.3354 -  hence pi': "c*i + 1 + ?fe \<ge> 1" by (simp only: real_of_int_le_iff[symmetric])
 14.3355 -  have "real (c*i) + ?N i e \<ge> real (c*d) \<or> real (c*i) + ?N i e < real (c*d)" by auto
 14.3356 -  moreover
 14.3357 -  {assume "real (c*i) + ?N i e \<ge> real (c*d)" hence ?case
 14.3358 -      by (simp add: ring_simps 
 14.3359 -	numbound0_I[OF nb,where bs="bs" and b="real i - real d" and b'="real i"])} 
 14.3360 -  moreover 
 14.3361 -  {assume H:"real (c*i) + ?N i e < real (c*d)"
 14.3362 -    with ei[simplified isint_iff] have "real (c*i + ?fe) < real (c*d)" by simp
 14.3363 -    hence pid: "c*i + 1 + ?fe \<le> c*d" by (simp only: real_of_int_le_iff)
 14.3364 -    with pi' have "\<exists> j1\<in> {1 .. c*d}. c*i + 1+ ?fe = j1" by auto
 14.3365 -    hence "\<exists> j1\<in> {1 .. c*d}. real (c*i) + 1= - ?N i e + real j1"
 14.3366 -      by (simp only: diff_def[symmetric] real_of_int_mult real_of_int_add real_of_int_inject[symmetric] ei[simplified isint_iff] ring_simps real_of_one) 
 14.3367 -    hence "\<exists> j1\<in> {1 .. c*d}. real (c*i) = (- ?N i e + real j1) - 1"
 14.3368 -      by (simp only: ring_simps diff_def[symmetric])
 14.3369 -        hence "\<exists> j1\<in> {1 .. c*d}. real (c*i) = - 1 - ?N i e + real j1"
 14.3370 -	  by (simp only: add_ac diff_def)
 14.3371 -    with nob  have ?case by blast }
 14.3372 -  ultimately show ?case by blast
 14.3373 -next
 14.3374 -  case (9 j c e)  hence p: "real j rdvd real (c*i) + ?N i e" (is "?p x") and cp: "c > 0" and bn:"numbound0 e"  by simp+
 14.3375 -    let ?e = "Inum (real i # bs) e"
 14.3376 -    from prems have "isint e (real i #bs)"  by simp 
 14.3377 -    hence ie: "real (floor ?e) = ?e" using isint_iff[where n="e" and bs="(real i)#bs"] numbound0_I[OF bn,where b="real i" and b'="real i" and bs="bs"]
 14.3378 -      by (simp add: isint_iff)
 14.3379 -    from prems have id: "j dvd d" by simp
 14.3380 -    from ie[symmetric] have "?p i = (real j rdvd real (c*i+ floor ?e))" by simp
 14.3381 -    also have "\<dots> = (j dvd c*i + floor ?e)" 
 14.3382 -      using int_rdvd_iff [where i="j" and t="c*i+ floor ?e"] by simp
 14.3383 -    also have "\<dots> = (j dvd c*i - c*d + floor ?e)" 
 14.3384 -      using dvd_period[OF id, where x="c*i" and c="-c" and t="floor ?e"] by simp
 14.3385 -    also have "\<dots> = (real j rdvd real (c*i - c*d + floor ?e))" 
 14.3386 -      using int_rdvd_iff[where i="j" and t="(c*i - c*d + floor ?e)",symmetric, simplified]
 14.3387 -      ie by simp
 14.3388 -    also have "\<dots> = (real j rdvd real (c*(i - d)) + ?e)" 
 14.3389 -      using ie by (simp add:ring_simps)
 14.3390 -    finally show ?case 
 14.3391 -      using numbound0_I[OF bn,where b="real i - real d" and b'="real i" and bs="bs"] p 
 14.3392 -      by (simp add: ring_simps)
 14.3393 -next
 14.3394 -  case (10 j c e)   hence p: "\<not> (real j rdvd real (c*i) + ?N i e)" (is "?p x") and cp: "c > 0" and bn:"numbound0 e"  by simp+
 14.3395 -    let ?e = "Inum (real i # bs) e"
 14.3396 -    from prems have "isint e (real i #bs)"  by simp 
 14.3397 -    hence ie: "real (floor ?e) = ?e" using isint_iff[where n="e" and bs="(real i)#bs"] numbound0_I[OF bn,where b="real i" and b'="real i" and bs="bs"]
 14.3398 -      by (simp add: isint_iff)
 14.3399 -    from prems have id: "j dvd d" by simp
 14.3400 -    from ie[symmetric] have "?p i = (\<not> (real j rdvd real (c*i+ floor ?e)))" by simp
 14.3401 -    also have "\<dots> = Not (j dvd c*i + floor ?e)" 
 14.3402 -      using int_rdvd_iff [where i="j" and t="c*i+ floor ?e"] by simp
 14.3403 -    also have "\<dots> = Not (j dvd c*i - c*d + floor ?e)" 
 14.3404 -      using dvd_period[OF id, where x="c*i" and c="-c" and t="floor ?e"] by simp
 14.3405 -    also have "\<dots> = Not (real j rdvd real (c*i - c*d + floor ?e))" 
 14.3406 -      using int_rdvd_iff[where i="j" and t="(c*i - c*d + floor ?e)",symmetric, simplified]
 14.3407 -      ie by simp
 14.3408 -    also have "\<dots> = Not (real j rdvd real (c*(i - d)) + ?e)" 
 14.3409 -      using ie by (simp add:ring_simps)
 14.3410 -    finally show ?case 
 14.3411 -      using numbound0_I[OF bn,where b="real i - real d" and b'="real i" and bs="bs"] p 
 14.3412 -      by (simp add: ring_simps)
 14.3413 -qed(auto simp add: numbound0_I[where bs="bs" and b="real i - real d" and b'="real i"] nth_pos2)
 14.3414 -
 14.3415 -lemma \<sigma>_nb: assumes lp: "iszlfm p (a#bs)" and nb: "numbound0 t"
 14.3416 -  shows "bound0 (\<sigma> p k t)"
 14.3417 -  using \<sigma>\<rho>_nb[OF lp nb] nb by (simp add: \<sigma>_def)
 14.3418 -  
 14.3419 -lemma \<rho>':   assumes lp: "iszlfm p (a #bs)"
 14.3420 -  and d: "d\<delta> p d"
 14.3421 -  and dp: "d > 0"
 14.3422 -  shows "\<forall> x. \<not>(\<exists> (e,c) \<in> set(\<rho> p). \<exists>(j::int) \<in> {1 .. c*d}. Ifm (a #bs) (\<sigma> p c (Add e (C j)))) \<longrightarrow> Ifm (real x#bs) p \<longrightarrow> Ifm (real (x - d)#bs) p" (is "\<forall> x. ?b x \<longrightarrow> ?P x \<longrightarrow> ?P (x - d)")
 14.3423 -proof(clarify)
 14.3424 -  fix x 
 14.3425 -  assume nob1:"?b x" and px: "?P x" 
 14.3426 -  from iszlfm_gen[OF lp, rule_format, where y="real x"] have lp': "iszlfm p (real x#bs)".
 14.3427 -  have nob: "\<forall>(e, c)\<in>set (\<rho> p). \<forall>j\<in>{1..c * d}. real (c * x) \<noteq> Inum (real x # bs) e + real j" 
 14.3428 -  proof(clarify)
 14.3429 -    fix e c j assume ecR: "(e,c) \<in> set (\<rho> p)" and jD: "j\<in> {1 .. c*d}"
 14.3430 -      and cx: "real (c*x) = Inum (real x#bs) e + real j"
 14.3431 -    let ?e = "Inum (real x#bs) e"
 14.3432 -    let ?fe = "floor ?e"
 14.3433 -    from \<rho>_l[OF lp'] ecR have ei:"isint e (real x#bs)" and cp:"c>0" and nb:"numbound0 e"
 14.3434 -      by auto
 14.3435 -    from numbound0_gen [OF nb ei, rule_format,where y="a"] have "isint e (a#bs)" .
 14.3436 -    from cx ei[simplified isint_iff] have "real (c*x) = real (?fe + j)" by simp
 14.3437 -    hence cx: "c*x = ?fe + j" by (simp only: real_of_int_inject)
 14.3438 -    hence cdej:"c dvd ?fe + j" by (simp add: dvd_def) (rule_tac x="x" in exI, simp)
 14.3439 -    hence "real c rdvd real (?fe + j)" by (simp only: int_rdvd_iff)
 14.3440 -    hence rcdej: "real c rdvd ?e + real j" by (simp add: ei[simplified isint_iff])
 14.3441 -    from cx have "(c*x) div c = (?fe + j) div c" by simp
 14.3442 -    with cp have "x = (?fe + j) div c" by simp
 14.3443 -    with px have th: "?P ((?fe + j) div c)" by auto
 14.3444 -    from cp have cp': "real c > 0" by simp
 14.3445 -    from cdej have cdej': "c dvd floor (Inum (real x#bs) (Add e (C j)))" by simp
 14.3446 -    from nb have nb': "numbound0 (Add e (C j))" by simp
 14.3447 -    have ji: "isint (C j) (real x#bs)" by (simp add: isint_def)
 14.3448 -    from isint_add[OF ei ji] have ei':"isint (Add e (C j)) (real x#bs)" .
 14.3449 -    from th \<sigma>\<rho>[where b'="real x", OF lp' cp' nb' ei' cdej',symmetric]
 14.3450 -    have "Ifm (real x#bs) (\<sigma>\<rho> p (Add e (C j), c))" by simp
 14.3451 -    with rcdej have th: "Ifm (real x#bs) (\<sigma> p c (Add e (C j)))" by (simp add: \<sigma>_def)
 14.3452 -    from th bound0_I[OF \<sigma>_nb[OF lp nb', where k="c"],where bs="bs" and b="real x" and b'="a"]
 14.3453 -    have "Ifm (a#bs) (\<sigma> p c (Add e (C j)))" by blast
 14.3454 -      with ecR jD nob1    show "False" by blast
 14.3455 -  qed
 14.3456 -  from \<rho>[OF lp' px d dp nob] show "?P (x -d )" . 
 14.3457 -qed
 14.3458 -
 14.3459 -
 14.3460 -lemma rl_thm: 
 14.3461 -  assumes lp: "iszlfm p (real (i::int)#bs)"
 14.3462 -  shows "(\<exists> (x::int). Ifm (real x#bs) p) = ((\<exists> j\<in> {1 .. \<delta> p}. Ifm (real j#bs) (minusinf p)) \<or> (\<exists> (e,c) \<in> set (\<rho> p). \<exists> j\<in> {1 .. c*(\<delta> p)}. Ifm (a#bs) (\<sigma> p c (Add e (C j)))))"
 14.3463 -  (is "(\<exists>(x::int). ?P x) = ((\<exists> j\<in> {1.. \<delta> p}. ?MP j)\<or>(\<exists> (e,c) \<in> ?R. \<exists> j\<in> _. ?SP c e j))" 
 14.3464 -    is "?lhs = (?MD \<or> ?RD)"  is "?lhs = ?rhs")
 14.3465 -proof-
 14.3466 -  let ?d= "\<delta> p"
 14.3467 -  from \<delta>[OF lp] have d:"d\<delta> p ?d" and dp: "?d > 0" by auto
 14.3468 -  { assume H:"?MD" hence th:"\<exists> (x::int). ?MP x" by blast
 14.3469 -    from H minusinf_ex[OF lp th] have ?thesis  by blast}
 14.3470 -  moreover
 14.3471 -  { fix e c j assume exR:"(e,c) \<in> ?R" and jD:"j\<in> {1 .. c*?d}" and spx:"?SP c e j"
 14.3472 -    from exR \<rho>_l[OF lp] have nb: "numbound0 e" and ei:"isint e (real i#bs)" and cp: "c > 0"
 14.3473 -      by auto
 14.3474 -    have "isint (C j) (real i#bs)" by (simp add: isint_iff)
 14.3475 -    with isint_add[OF numbound0_gen[OF nb ei,rule_format, where y="real i"]]
 14.3476 -    have eji:"isint (Add e (C j)) (real i#bs)" by simp
 14.3477 -    from nb have nb': "numbound0 (Add e (C j))" by simp
 14.3478 -    from spx bound0_I[OF \<sigma>_nb[OF lp nb', where k="c"], where bs="bs" and b="a" and b'="real i"]
 14.3479 -    have spx': "Ifm (real i # bs) (\<sigma> p c (Add e (C j)))" by blast
 14.3480 -    from spx' have rcdej:"real c rdvd (Inum (real i#bs) (Add e (C j)))" 
 14.3481 -      and sr:"Ifm (real i#bs) (\<sigma>\<rho> p (Add e (C j),c))" by (simp add: \<sigma>_def)+
 14.3482 -    from rcdej eji[simplified isint_iff] 
 14.3483 -    have "real c rdvd real (floor (Inum (real i#bs) (Add e (C j))))" by simp
 14.3484 -    hence cdej:"c dvd floor (Inum (real i#bs) (Add e (C j)))" by (simp only: int_rdvd_iff)
 14.3485 -    from cp have cp': "real c > 0" by simp
 14.3486 -    from \<sigma>\<rho>[OF lp cp' nb' eji cdej] spx' have "?P (\<lfloor>Inum (real i # bs) (Add e (C j))\<rfloor> div c)"
 14.3487 -      by (simp add: \<sigma>_def)
 14.3488 -    hence ?lhs by blast
 14.3489 -    with exR jD spx have ?thesis by blast}
 14.3490 -  moreover
 14.3491 -  { fix x assume px: "?P x" and nob: "\<not> ?RD"
 14.3492 -    from iszlfm_gen [OF lp,rule_format, where y="a"] have lp':"iszlfm p (a#bs)" .
 14.3493 -    from \<rho>'[OF lp' d dp, rule_format, OF nob] have th:"\<forall> x. ?P x \<longrightarrow> ?P (x - ?d)" by blast
 14.3494 -    from minusinf_inf[OF lp] obtain z where z:"\<forall> x<z. ?MP x = ?P x" by blast
 14.3495 -    have zp: "abs (x - z) + 1 \<ge> 0" by arith
 14.3496 -    from decr_lemma[OF dp,where x="x" and z="z"] 
 14.3497 -      decr_mult_lemma[OF dp th zp, rule_format, OF px] z have th:"\<exists> x. ?MP x" by auto
 14.3498 -    with minusinf_bex[OF lp] px nob have ?thesis by blast}
 14.3499 -  ultimately show ?thesis by blast
 14.3500 -qed
 14.3501 -
 14.3502 -lemma mirror_\<alpha>\<rho>:   assumes lp: "iszlfm p (a#bs)"
 14.3503 -  shows "(\<lambda> (t,k). (Inum (a#bs) t, k)) ` set (\<alpha>\<rho> p) = (\<lambda> (t,k). (Inum (a#bs) t,k)) ` set (\<rho> (mirror p))"
 14.3504 -using lp
 14.3505 -by (induct p rule: mirror.induct, simp_all add: split_def image_Un )
 14.3506 -  
 14.3507 -text {* The @{text "\<real>"} part*}
 14.3508 -
 14.3509 -text{* Linearity for fm where Bound 0 ranges over @{text "\<real>"}*}
 14.3510 -consts
 14.3511 -  isrlfm :: "fm \<Rightarrow> bool"   (* Linearity test for fm *)
 14.3512 -recdef isrlfm "measure size"
 14.3513 -  "isrlfm (And p q) = (isrlfm p \<and> isrlfm q)" 
 14.3514 -  "isrlfm (Or p q) = (isrlfm p \<and> isrlfm q)" 
 14.3515 -  "isrlfm (Eq  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
 14.3516 -  "isrlfm (NEq (CN 0 c e)) = (c>0 \<and> numbound0 e)"
 14.3517 -  "isrlfm (Lt  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
 14.3518 -  "isrlfm (Le  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
 14.3519 -  "isrlfm (Gt  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
 14.3520 -  "isrlfm (Ge  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
 14.3521 -  "isrlfm p = (isatom p \<and> (bound0 p))"
 14.3522 -
 14.3523 -constdefs fp :: "fm \<Rightarrow> int \<Rightarrow> num \<Rightarrow> int \<Rightarrow> fm"
 14.3524 -  "fp p n s j \<equiv> (if n > 0 then 
 14.3525 -            (And p (And (Ge (CN 0 n (Sub s (Add (Floor s) (C j)))))
 14.3526 -                        (Lt (CN 0 n (Sub s (Add (Floor s) (C (j+1))))))))
 14.3527 -            else 
 14.3528 -            (And p (And (Le (CN 0 (-n) (Add (Neg s) (Add (Floor s) (C j))))) 
 14.3529 -                        (Gt (CN 0 (-n) (Add (Neg s) (Add (Floor s) (C (j + 1)))))))))"
 14.3530 -
 14.3531 -  (* splits the bounded from the unbounded part*)
 14.3532 -consts rsplit0 :: "num \<Rightarrow> (fm \<times> int \<times> num) list" 
 14.3533 -recdef rsplit0 "measure num_size"
 14.3534 -  "rsplit0 (Bound 0) = [(T,1,C 0)]"
 14.3535 -  "rsplit0 (Add a b) = (let acs = rsplit0 a ; bcs = rsplit0 b 
 14.3536 -              in map (\<lambda> ((p,n,t),(q,m,s)). (And p q, n+m, Add t s)) [(a,b). a\<leftarrow>acs,b\<leftarrow>bcs])"
 14.3537 -  "rsplit0 (Sub a b) = rsplit0 (Add a (Neg b))"
 14.3538 -  "rsplit0 (Neg a) = map (\<lambda> (p,n,s). (p,-n,Neg s)) (rsplit0 a)"
 14.3539 -  "rsplit0 (Floor a) = foldl (op @) [] (map 
 14.3540 -      (\<lambda> (p,n,s). if n=0 then [(p,0,Floor s)]
 14.3541 -          else (map (\<lambda> j. (fp p n s j, 0, Add (Floor s) (C j))) (if n > 0 then iupt (0,n) else iupt(n,0))))
 14.3542 -       (rsplit0 a))"
 14.3543 -  "rsplit0 (CN 0 c a) = map (\<lambda> (p,n,s). (p,n+c,s)) (rsplit0 a)"
 14.3544 -  "rsplit0 (CN m c a) = map (\<lambda> (p,n,s). (p,n,CN m c s)) (rsplit0 a)"
 14.3545 -  "rsplit0 (CF c t s) = rsplit0 (Add (Mul c (Floor t)) s)"
 14.3546 -  "rsplit0 (Mul c a) = map (\<lambda> (p,n,s). (p,c*n,Mul c s)) (rsplit0 a)"
 14.3547 -  "rsplit0 t = [(T,0,t)]"
 14.3548 -
 14.3549 -lemma not_rl[simp]: "isrlfm p \<Longrightarrow> isrlfm (not p)"
 14.3550 -  by (induct p rule: isrlfm.induct, auto)
 14.3551 -lemma conj_rl[simp]: "isrlfm p \<Longrightarrow> isrlfm q \<Longrightarrow> isrlfm (conj p q)"
 14.3552 -  using conj_def by (cases p, auto)
 14.3553 -lemma disj_rl[simp]: "isrlfm p \<Longrightarrow> isrlfm q \<Longrightarrow> isrlfm (disj p q)"
 14.3554 -  using disj_def by (cases p, auto)
 14.3555 -
 14.3556 -
 14.3557 -lemma rsplit0_cs:
 14.3558 -  shows "\<forall> (p,n,s) \<in> set (rsplit0 t). 
 14.3559 -  (Ifm (x#bs) p \<longrightarrow>  (Inum (x#bs) t = Inum (x#bs) (CN 0 n s))) \<and> numbound0 s \<and> isrlfm p" 
 14.3560 -  (is "\<forall> (p,n,s) \<in> ?SS t. (?I p \<longrightarrow> ?N t = ?N (CN 0 n s)) \<and> _ \<and> _ ")
 14.3561 -proof(induct t rule: rsplit0.induct)
 14.3562 -  case (5 a) 
 14.3563 -  let ?p = "\<lambda> (p,n,s) j. fp p n s j"
 14.3564 -  let ?f = "(\<lambda> (p,n,s) j. (?p (p,n,s) j, (0::int),Add (Floor s) (C j)))"
 14.3565 -  let ?J = "\<lambda> n. if n>0 then iupt (0,n) else iupt (n,0)"
 14.3566 -  let ?ff=" (\<lambda> (p,n,s). if n= 0 then [(p,0,Floor s)] else map (?f (p,n,s)) (?J n))"
 14.3567 -  have int_cases: "\<forall> (i::int). i= 0 \<or> i < 0 \<or> i > 0" by arith
 14.3568 -  have U1: "(UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). set (?ff (p,n,s)))) = 
 14.3569 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). set [(p,0,Floor s)]))" by auto
 14.3570 -  have U2': "\<forall> (p,n,s) \<in> {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0}. 
 14.3571 -    ?ff (p,n,s) = map (?f(p,n,s)) (iupt(0,n))" by auto
 14.3572 -  hence U2: "(UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). set (?ff (p,n,s)))) = 
 14.3573 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). 
 14.3574 -    set (map (?f(p,n,s)) (iupt(0,n)))))"
 14.3575 -  proof-
 14.3576 -    fix M :: "('a\<times>'b\<times>'c) set" and f :: "('a\<times>'b\<times>'c) \<Rightarrow> 'd list" and g
 14.3577 -    assume "\<forall> (a,b,c) \<in> M. f (a,b,c) = g a b c"
 14.3578 -    thus "(UNION M (\<lambda> (a,b,c). set (f (a,b,c)))) = (UNION M (\<lambda> (a,b,c). set (g a b c)))"
 14.3579 -      by (auto simp add: split_def)
 14.3580 -  qed
 14.3581 -  have U3': "\<forall> (p,n,s) \<in> {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0}. ?ff (p,n,s) = map (?f(p,n,s)) (iupt(n,0))"
 14.3582 -    by auto
 14.3583 -  hence U3: "(UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s). set (?ff (p,n,s)))) = 
 14.3584 -    (UNION {(p,n,s). (p,n,s)\<in> ?SS a\<and>n<0} (\<lambda>(p,n,s). set (map (?f(p,n,s)) (iupt(n,0)))))"
 14.3585 -      proof-
 14.3586 -    fix M :: "('a\<times>'b\<times>'c) set" and f :: "('a\<times>'b\<times>'c) \<Rightarrow> 'd list" and g
 14.3587 -    assume "\<forall> (a,b,c) \<in> M. f (a,b,c) = g a b c"
 14.3588 -    thus "(UNION M (\<lambda> (a,b,c). set (f (a,b,c)))) = (UNION M (\<lambda> (a,b,c). set (g a b c)))"
 14.3589 -      by (auto simp add: split_def)
 14.3590 -  qed
 14.3591 -  have "?SS (Floor a) = UNION (?SS a) (\<lambda>x. set (?ff x))" 
 14.3592 -    by (auto simp add: foldl_conv_concat)
 14.3593 -  also have "\<dots> = UNION (?SS a) (\<lambda> (p,n,s). set (?ff (p,n,s)))" by auto
 14.3594 -  also have "\<dots> = 
 14.3595 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). set (?ff (p,n,s)))) Un 
 14.3596 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). set (?ff (p,n,s)))) Un 
 14.3597 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s). set (?ff (p,n,s)))))" 
 14.3598 -    using int_cases[rule_format] by blast
 14.3599 -  also have "\<dots> =  
 14.3600 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). set [(p,0,Floor s)])) Un 
 14.3601 -   (UNION {(p,n,s). (p,n,s)\<in> ?SS a\<and>n>0} (\<lambda>(p,n,s). set(map(?f(p,n,s)) (iupt(0,n))))) Un 
 14.3602 -   (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s). 
 14.3603 -    set (map (?f(p,n,s)) (iupt(n,0))))))" by (simp only: U1 U2 U3)
 14.3604 -  also have "\<dots> =  
 14.3605 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). {(p,0,Floor s)})) Un 
 14.3606 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). (?f(p,n,s)) ` {0 .. n})) Un 
 14.3607 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s). (?f(p,n,s)) ` {n .. 0})))"
 14.3608 -    by (simp only: set_map iupt_set set.simps)
 14.3609 -  also have "\<dots> =   
 14.3610 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). {(p,0,Floor s)})) Un 
 14.3611 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). {?f(p,n,s) j| j. j\<in> {0 .. n}})) Un 
 14.3612 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s).  {?f(p,n,s) j| j. j\<in> {n .. 0}})))" by blast
 14.3613 -  finally 
 14.3614 -  have FS: "?SS (Floor a) =   
 14.3615 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). {(p,0,Floor s)})) Un 
 14.3616 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). {?f(p,n,s) j| j. j\<in> {0 .. n}})) Un 
 14.3617 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s).  {?f(p,n,s) j| j. j\<in> {n .. 0}})))"    by blast
 14.3618 -  show ?case
 14.3619 -    proof(simp only: FS, clarsimp simp del: Ifm.simps Inum.simps, -)
 14.3620 -      fix p n s
 14.3621 -      let ?ths = "(?I p \<longrightarrow> (?N (Floor a) = ?N (CN 0 n s))) \<and> numbound0 s \<and> isrlfm p"
 14.3622 -      assume "(\<exists>ba. (p, 0, ba) \<in> set (rsplit0 a) \<and> n = 0 \<and> s = Floor ba) \<or>
 14.3623 -       (\<exists>ab ac ba.
 14.3624 -           (ab, ac, ba) \<in> set (rsplit0 a) \<and>
 14.3625 -           0 < ac \<and>
 14.3626 -           (\<exists>j. p = fp ab ac ba j \<and>
 14.3627 -                n = 0 \<and> s = Add (Floor ba) (C j) \<and> 0 \<le> j \<and> j \<le> ac)) \<or>
 14.3628 -       (\<exists>ab ac ba.
 14.3629 -           (ab, ac, ba) \<in> set (rsplit0 a) \<and>
 14.3630 -           ac < 0 \<and>
 14.3631 -           (\<exists>j. p = fp ab ac ba j \<and>
 14.3632 -                n = 0 \<and> s = Add (Floor ba) (C j) \<and> ac \<le> j \<and> j \<le> 0))"
 14.3633 -      moreover 
 14.3634 -      {fix s'
 14.3635 -	assume "(p, 0, s') \<in> ?SS a" and "n = 0" and "s = Floor s'"
 14.3636 -	hence ?ths using prems by auto}
 14.3637 -      moreover
 14.3638 -      {	fix p' n' s' j
 14.3639 -	assume pns: "(p', n', s') \<in> ?SS a" 
 14.3640 -	  and np: "0 < n'" 
 14.3641 -	  and p_def: "p = ?p (p',n',s') j" 
 14.3642 -	  and n0: "n = 0" 
 14.3643 -	  and s_def: "s = (Add (Floor s') (C j))" 
 14.3644 -	  and jp: "0 \<le> j" and jn: "j \<le> n'"
 14.3645 -	from prems pns have H:"(Ifm ((x\<Colon>real) # (bs\<Colon>real list)) p' \<longrightarrow>
 14.3646 -          Inum (x # bs) a = Inum (x # bs) (CN 0 n' s')) \<and>
 14.3647 -          numbound0 s' \<and> isrlfm p'" by blast
 14.3648 -	hence nb: "numbound0 s'" by simp
 14.3649 -	from H have nf: "isrlfm (?p (p',n',s') j)" using fp_def np by (simp add: numsub_nb)
 14.3650 -	let ?nxs = "CN 0 n' s'"
 14.3651 -	let ?l = "floor (?N s') + j"
 14.3652 -	from H 
 14.3653 -	have "?I (?p (p',n',s') j) \<longrightarrow> 
 14.3654 -	  (((?N ?nxs \<ge> real ?l) \<and> (?N ?nxs < real (?l + 1))) \<and> (?N a = ?N ?nxs ))" 
 14.3655 -	  by (simp add: fp_def np ring_simps numsub numadd numfloor)
 14.3656 -	also have "\<dots> \<longrightarrow> ((floor (?N ?nxs) = ?l) \<and> (?N a = ?N ?nxs ))"
 14.3657 -	  using floor_int_eq[where x="?N ?nxs" and n="?l"] by simp
 14.3658 -	moreover
 14.3659 -	have "\<dots> \<longrightarrow> (?N (Floor a) = ?N ((Add (Floor s') (C j))))" by simp
 14.3660 -	ultimately have "?I (?p (p',n',s') j) \<longrightarrow> (?N (Floor a) = ?N ((Add (Floor s') (C j))))"
 14.3661 -	  by blast
 14.3662 -	with s_def n0 p_def nb nf have ?ths by auto}
 14.3663 -      moreover
 14.3664 -      {fix p' n' s' j
 14.3665 -	assume pns: "(p', n', s') \<in> ?SS a" 
 14.3666 -	  and np: "n' < 0" 
 14.3667 -	  and p_def: "p = ?p (p',n',s') j" 
 14.3668 -	  and n0: "n = 0" 
 14.3669 -	  and s_def: "s = (Add (Floor s') (C j))" 
 14.3670 -	  and jp: "n' \<le> j" and jn: "j \<le> 0"
 14.3671 -	from prems pns have H:"(Ifm ((x\<Colon>real) # (bs\<Colon>real list)) p' \<longrightarrow>
 14.3672 -          Inum (x # bs) a = Inum (x # bs) (CN 0 n' s')) \<and>
 14.3673 -          numbound0 s' \<and> isrlfm p'" by blast
 14.3674 -	hence nb: "numbound0 s'" by simp
 14.3675 -	from H have nf: "isrlfm (?p (p',n',s') j)" using fp_def np by (simp add: numneg_nb)
 14.3676 -	let ?nxs = "CN 0 n' s'"
 14.3677 -	let ?l = "floor (?N s') + j"
 14.3678 -	from H 
 14.3679 -	have "?I (?p (p',n',s') j) \<longrightarrow> 
 14.3680 -	  (((?N ?nxs \<ge> real ?l) \<and> (?N ?nxs < real (?l + 1))) \<and> (?N a = ?N ?nxs ))" 
 14.3681 -	  by (simp add: np fp_def ring_simps numneg numfloor numadd numsub)
 14.3682 -	also have "\<dots> \<longrightarrow> ((floor (?N ?nxs) = ?l) \<and> (?N a = ?N ?nxs ))"
 14.3683 -	  using floor_int_eq[where x="?N ?nxs" and n="?l"] by simp
 14.3684 -	moreover
 14.3685 -	have "\<dots> \<longrightarrow> (?N (Floor a) = ?N ((Add (Floor s') (C j))))"  by simp
 14.3686 -	ultimately have "?I (?p (p',n',s') j) \<longrightarrow> (?N (Floor a) = ?N ((Add (Floor s') (C j))))"
 14.3687 -	  by blast
 14.3688 -	with s_def n0 p_def nb nf have ?ths by auto}
 14.3689 -      ultimately show ?ths by auto
 14.3690 -    qed
 14.3691 -next
 14.3692 -  case (3 a b) then show ?case
 14.3693 -  apply auto
 14.3694 -  apply (erule_tac x = "(aa, aaa, ba)" in ballE) apply simp_all
 14.3695 -  apply (erule_tac x = "(ab, ac, baa)" in ballE) apply simp_all
 14.3696 -  done
 14.3697 -qed (auto simp add: Let_def split_def ring_simps conj_rl)
 14.3698 -
 14.3699 -lemma real_in_int_intervals: 
 14.3700 -  assumes xb: "real m \<le> x \<and> x < real ((n::int) + 1)"
 14.3701 -  shows "\<exists> j\<in> {m.. n}. real j \<le> x \<and> x < real (j+1)" (is "\<exists> j\<in> ?N. ?P j")
 14.3702 -by (rule bexI[where P="?P" and x="floor x" and A="?N"]) 
 14.3703 -(auto simp add: floor_less_eq[where x="x" and a="n+1", simplified] xb[simplified] floor_mono2[where x="real m" and y="x", OF conjunct1[OF xb], simplified floor_real_of_int[where n="m"]])
 14.3704 -
 14.3705 -lemma rsplit0_complete:
 14.3706 -  assumes xp:"0 \<le> x" and x1:"x < 1"
 14.3707 -  shows "\<exists> (p,n,s) \<in> set (rsplit0 t). Ifm (x#bs) p" (is "\<exists> (p,n,s) \<in> ?SS t. ?I p")
 14.3708 -proof(induct t rule: rsplit0.induct)
 14.3709 -  case (2 a b) 
 14.3710 -  from prems have "\<exists> (pa,na,sa) \<in> ?SS a. ?I pa" by auto
 14.3711 -  then obtain "pa" "na" "sa" where pa: "(pa,na,sa)\<in> ?SS a \<and> ?I pa" by blast
 14.3712 -  from prems have "\<exists> (pb,nb,sb) \<in> ?SS b. ?I pb" by auto
 14.3713 -  then obtain "pb" "nb" "sb" where pb: "(pb,nb,sb)\<in> ?SS b \<and> ?I pb" by blast
 14.3714 -  from pa pb have th: "((pa,na,sa),(pb,nb,sb)) \<in> set[(x,y). x\<leftarrow>rsplit0 a, y\<leftarrow>rsplit0 b]"
 14.3715 -    by (auto)
 14.3716 -  let ?f="(\<lambda> ((p,n,t),(q,m,s)). (And p q, n+m, Add t s))"
 14.3717 -  from imageI[OF th, where f="?f"] have "?f ((pa,na,sa),(pb,nb,sb)) \<in> ?SS (Add a b)"
 14.3718 -    by (simp add: Let_def)
 14.3719 -  hence "(And pa pb, na +nb, Add sa sb) \<in> ?SS (Add a b)" by simp
 14.3720 -  moreover from pa pb have "?I (And pa pb)" by simp
 14.3721 -  ultimately show ?case by blast
 14.3722 -next
 14.3723 -  case (5 a) 
 14.3724 -  let ?p = "\<lambda> (p,n,s) j. fp p n s j"
 14.3725 -  let ?f = "(\<lambda> (p,n,s) j. (?p (p,n,s) j, (0::int),(Add (Floor s) (C j))))"
 14.3726 -  let ?J = "\<lambda> n. if n>0 then iupt (0,n) else iupt (n,0)"
 14.3727 -  let ?ff=" (\<lambda> (p,n,s). if n= 0 then [(p,0,Floor s)] else map (?f (p,n,s)) (?J n))"
 14.3728 -  have int_cases: "\<forall> (i::int). i= 0 \<or> i < 0 \<or> i > 0" by arith
 14.3729 -  have U1: "(UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). set (?ff (p,n,s)))) = (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). set [(p,0,Floor s)]))" by auto
 14.3730 -  have U2': "\<forall> (p,n,s) \<in> {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0}. ?ff (p,n,s) = map (?f(p,n,s)) (iupt(0,n))"
 14.3731 -    by auto
 14.3732 -  hence U2: "(UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). set (?ff (p,n,s)))) = (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). set (map (?f(p,n,s)) (iupt(0,n)))))"
 14.3733 -  proof-
 14.3734 -    fix M :: "('a\<times>'b\<times>'c) set" and f :: "('a\<times>'b\<times>'c) \<Rightarrow> 'd list" and g
 14.3735 -    assume "\<forall> (a,b,c) \<in> M. f (a,b,c) = g a b c"
 14.3736 -    thus "(UNION M (\<lambda> (a,b,c). set (f (a,b,c)))) = (UNION M (\<lambda> (a,b,c). set (g a b c)))"
 14.3737 -      by (auto simp add: split_def)
 14.3738 -  qed
 14.3739 -  have U3': "\<forall> (p,n,s) \<in> {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0}. ?ff (p,n,s) = map (?f(p,n,s)) (iupt(n,0))"
 14.3740 -    by auto
 14.3741 -  hence U3: "(UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s). set (?ff (p,n,s)))) = (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s). set (map (?f(p,n,s)) (iupt(n,0)))))"
 14.3742 -  proof-
 14.3743 -    fix M :: "('a\<times>'b\<times>'c) set" and f :: "('a\<times>'b\<times>'c) \<Rightarrow> 'd list" and g
 14.3744 -    assume "\<forall> (a,b,c) \<in> M. f (a,b,c) = g a b c"
 14.3745 -    thus "(UNION M (\<lambda> (a,b,c). set (f (a,b,c)))) = (UNION M (\<lambda> (a,b,c). set (g a b c)))"
 14.3746 -      by (auto simp add: split_def)
 14.3747 -  qed
 14.3748 -
 14.3749 -  have "?SS (Floor a) = UNION (?SS a) (\<lambda>x. set (?ff x))" by (auto simp add: foldl_conv_concat) 
 14.3750 -  also have "\<dots> = UNION (?SS a) (\<lambda> (p,n,s). set (?ff (p,n,s)))" by auto
 14.3751 -  also have "\<dots> = 
 14.3752 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). set (?ff (p,n,s)))) Un 
 14.3753 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). set (?ff (p,n,s)))) Un 
 14.3754 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s). set (?ff (p,n,s)))))" 
 14.3755 -    using int_cases[rule_format] by blast
 14.3756 -  also have "\<dots> =  
 14.3757 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). set [(p,0,Floor s)])) Un 
 14.3758 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). set (map (?f(p,n,s)) (iupt(0,n))))) Un 
 14.3759 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s). set (map (?f(p,n,s)) (iupt(n,0))))))" by (simp only: U1 U2 U3)
 14.3760 -  also have "\<dots> =  
 14.3761 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). {(p,0,Floor s)})) Un 
 14.3762 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). (?f(p,n,s)) ` {0 .. n})) Un 
 14.3763 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s). (?f(p,n,s)) ` {n .. 0})))"
 14.3764 -    by (simp only: set_map iupt_set set.simps)
 14.3765 -  also have "\<dots> =   
 14.3766 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). {(p,0,Floor s)})) Un 
 14.3767 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). {?f(p,n,s) j| j. j\<in> {0 .. n}})) Un 
 14.3768 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s).  {?f(p,n,s) j| j. j\<in> {n .. 0}})))" by blast
 14.3769 -  finally 
 14.3770 -  have FS: "?SS (Floor a) =   
 14.3771 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). {(p,0,Floor s)})) Un 
 14.3772 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). {?f(p,n,s) j| j. j\<in> {0 .. n}})) Un 
 14.3773 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s).  {?f(p,n,s) j| j. j\<in> {n .. 0}})))"    by blast
 14.3774 -  from prems have "\<exists> (p,n,s) \<in> ?SS a. ?I p" by auto
 14.3775 -  then obtain "p" "n" "s" where pns: "(p,n,s) \<in> ?SS a \<and> ?I p" by blast
 14.3776 -  let ?N = "\<lambda> t. Inum (x#bs) t"
 14.3777 -  from rsplit0_cs[rule_format] pns have ans:"(?N a = ?N (CN 0 n s)) \<and> numbound0 s \<and> isrlfm p"
 14.3778 -    by auto
 14.3779 -  
 14.3780 -  have "n=0 \<or> n >0 \<or> n <0" by arith
 14.3781 -  moreover {assume "n=0" hence ?case using pns by (simp only: FS) auto }
 14.3782 -  moreover
 14.3783 -  {
 14.3784 -    assume np: "n > 0"
 14.3785 -    from real_of_int_floor_le[where r="?N s"] have "?N (Floor s) \<le> ?N s" by simp
 14.3786 -    also from mult_left_mono[OF xp] np have "?N s \<le> real n * x + ?N s" by simp
 14.3787 -    finally have "?N (Floor s) \<le> real n * x + ?N s" .
 14.3788 -    moreover
 14.3789 -    {from mult_strict_left_mono[OF x1] np 
 14.3790 -      have "real n *x + ?N s < real n + ?N s" by simp
 14.3791 -      also from real_of_int_floor_add_one_gt[where r="?N s"] 
 14.3792 -      have "\<dots> < real n + ?N (Floor s) + 1" by simp
 14.3793 -      finally have "real n *x + ?N s < ?N (Floor s) + real (n+1)" by simp}
 14.3794 -    ultimately have "?N (Floor s) \<le> real n *x + ?N s\<and> real n *x + ?N s < ?N (Floor s) + real (n+1)" by simp
 14.3795 -    hence th: "0 \<le> real n *x + ?N s - ?N (Floor s) \<and> real n *x + ?N s - ?N (Floor s) < real (n+1)" by simp
 14.3796 -    from real_in_int_intervals th have  "\<exists> j\<in> {0 .. n}. real j \<le> real n *x + ?N s - ?N (Floor s)\<and> real n *x + ?N s - ?N (Floor s) < real (j+1)" by simp
 14.3797 -    
 14.3798 -    hence "\<exists> j\<in> {0 .. n}. 0 \<le> real n *x + ?N s - ?N (Floor s) - real j \<and> real n *x + ?N s - ?N (Floor s) - real (j+1) < 0"
 14.3799 -      by(simp only: myl[rule_format, where b="real n * x + Inum (x # bs) s - Inum (x # bs) (Floor s)"] less_iff_diff_less_0[where a="real n *x + ?N s - ?N (Floor s)"]) 
 14.3800 -    hence "\<exists> j\<in> {0.. n}. ?I (?p (p,n,s) j)"
 14.3801 -      using pns by (simp add: fp_def np ring_simps numsub numadd)
 14.3802 -    then obtain "j" where j_def: "j\<in> {0 .. n} \<and> ?I (?p (p,n,s) j)" by blast
 14.3803 -    hence "\<exists>x \<in> {?p (p,n,s) j |j. 0\<le> j \<and> j \<le> n }. ?I x" by auto
 14.3804 -    hence ?case using pns 
 14.3805 -      by (simp only: FS,simp add: bex_Un) 
 14.3806 -    (rule disjI2, rule disjI1,rule exI [where x="p"],
 14.3807 -      rule exI [where x="n"],rule exI [where x="s"],simp_all add: np)
 14.3808 -  }
 14.3809 -  moreover
 14.3810 -  { assume nn: "n < 0" hence np: "-n >0" by simp
 14.3811 -    from real_of_int_floor_le[where r="?N s"] have "?N (Floor s) + 1 > ?N s" by simp
 14.3812 -    moreover from mult_left_mono_neg[OF xp] nn have "?N s \<ge> real n * x + ?N s" by simp
 14.3813 -    ultimately have "?N (Floor s) + 1 > real n * x + ?N s" by arith 
 14.3814 -    moreover
 14.3815 -    {from mult_strict_left_mono_neg[OF x1, where c="real n"] nn
 14.3816 -      have "real n *x + ?N s \<ge> real n + ?N s" by simp 
 14.3817 -      moreover from real_of_int_floor_le[where r="?N s"]  have "real n + ?N s \<ge> real n + ?N (Floor s)" by simp
 14.3818 -      ultimately have "real n *x + ?N s \<ge> ?N (Floor s) + real n" 
 14.3819 -	by (simp only: ring_simps)}
 14.3820 -    ultimately have "?N (Floor s) + real n \<le> real n *x + ?N s\<and> real n *x + ?N s < ?N (Floor s) + real (1::int)" by simp
 14.3821 -    hence th: "real n \<le> real n *x + ?N s - ?N (Floor s) \<and> real n *x + ?N s - ?N (Floor s) < real (1::int)" by simp
 14.3822 -    have th1: "\<forall> (a::real). (- a > 0) = (a < 0)" by auto
 14.3823 -    have th2: "\<forall> (a::real). (0 \<ge> - a) = (a \<ge> 0)" by auto
 14.3824 -    from real_in_int_intervals th  have  "\<exists> j\<in> {n .. 0}. real j \<le> real n *x + ?N s - ?N (Floor s)\<and> real n *x + ?N s - ?N (Floor s) < real (j+1)" by simp
 14.3825 -    
 14.3826 -    hence "\<exists> j\<in> {n .. 0}. 0 \<le> real n *x + ?N s - ?N (Floor s) - real j \<and> real n *x + ?N s - ?N (Floor s) - real (j+1) < 0"
 14.3827 -      by(simp only: myl[rule_format, where b="real n * x + Inum (x # bs) s - Inum (x # bs) (Floor s)"] less_iff_diff_less_0[where a="real n *x + ?N s - ?N (Floor s)"]) 
 14.3828 -    hence "\<exists> j\<in> {n .. 0}. 0 \<ge> - (real n *x + ?N s - ?N (Floor s) - real j) \<and> - (real n *x + ?N s - ?N (Floor s) - real (j+1)) > 0" by (simp only: th1[rule_format] th2[rule_format])
 14.3829 -    hence "\<exists> j\<in> {n.. 0}. ?I (?p (p,n,s) j)"
 14.3830 -      using pns by (simp add: fp_def nn diff_def add_ac mult_ac numfloor numadd numneg
 14.3831 -	del: diff_less_0_iff_less diff_le_0_iff_le) 
 14.3832 -    then obtain "j" where j_def: "j\<in> {n .. 0} \<and> ?I (?p (p,n,s) j)" by blast
 14.3833 -    hence "\<exists>x \<in> {?p (p,n,s) j |j. n\<le> j \<and> j \<le> 0 }. ?I x" by auto
 14.3834 -    hence ?case using pns 
 14.3835 -      by (simp only: FS,simp add: bex_Un)
 14.3836 -    (rule disjI2, rule disjI2,rule exI [where x="p"],
 14.3837 -      rule exI [where x="n"],rule exI [where x="s"],simp_all add: nn)
 14.3838 -  }
 14.3839 -  ultimately show ?case by blast
 14.3840 -qed (auto simp add: Let_def split_def)
 14.3841 -
 14.3842 -    (* Linearize a formula where Bound 0 ranges over [0,1) *)
 14.3843 -
 14.3844 -constdefs rsplit :: "(int \<Rightarrow> num \<Rightarrow> fm) \<Rightarrow> num \<Rightarrow> fm"
 14.3845 -  "rsplit f a \<equiv> foldr disj (map (\<lambda> (\<phi>, n, s). conj \<phi> (f n s)) (rsplit0 a)) F"
 14.3846 -
 14.3847 -lemma foldr_disj_map: "Ifm bs (foldr disj (map f xs) F) = (\<exists> x \<in> set xs. Ifm bs (f x))"
 14.3848 -by(induct xs, simp_all)
 14.3849 -
 14.3850 -lemma foldr_conj_map: "Ifm bs (foldr conj (map f xs) T) = (\<forall> x \<in> set xs. Ifm bs (f x))"
 14.3851 -by(induct xs, simp_all)
 14.3852 -
 14.3853 -lemma foldr_disj_map_rlfm: 
 14.3854 -  assumes lf: "\<forall> n s. numbound0 s \<longrightarrow> isrlfm (f n s)"
 14.3855 -  and \<phi>: "\<forall> (\<phi>,n,s) \<in> set xs. numbound0 s \<and> isrlfm \<phi>"
 14.3856 -  shows "isrlfm (foldr disj (map (\<lambda> (\<phi>, n, s). conj \<phi> (f n s)) xs) F)"
 14.3857 -using lf \<phi> by (induct xs, auto)
 14.3858 -
 14.3859 -lemma rsplit_ex: "Ifm bs (rsplit f a) = (\<exists> (\<phi>,n,s) \<in> set (rsplit0 a). Ifm bs (conj \<phi> (f n s)))"
 14.3860 -using foldr_disj_map[where xs="rsplit0 a"] rsplit_def by (simp add: split_def)
 14.3861 -
 14.3862 -lemma rsplit_l: assumes lf: "\<forall> n s. numbound0 s \<longrightarrow> isrlfm (f n s)"
 14.3863 -  shows "isrlfm (rsplit f a)"
 14.3864 -proof-
 14.3865 -  from rsplit0_cs[where t="a"] have th: "\<forall> (\<phi>,n,s) \<in> set (rsplit0 a). numbound0 s \<and> isrlfm \<phi>" by blast
 14.3866 -  from foldr_disj_map_rlfm[OF lf th] rsplit_def show ?thesis by simp
 14.3867 -qed
 14.3868 -
 14.3869 -lemma rsplit: 
 14.3870 -  assumes xp: "x \<ge> 0" and x1: "x < 1"
 14.3871 -  and f: "\<forall> a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \<and> numbound0 s \<longrightarrow> (Ifm (x#bs) (f n s) = Ifm (x#bs) (g a))"
 14.3872 -  shows "Ifm (x#bs) (rsplit f a) = Ifm (x#bs) (g a)"
 14.3873 -proof(auto)
 14.3874 -  let ?I = "\<lambda>x p. Ifm (x#bs) p"
 14.3875 -  let ?N = "\<lambda> x t. Inum (x#bs) t"
 14.3876 -  assume "?I x (rsplit f a)"
 14.3877 -  hence "\<exists> (\<phi>,n,s) \<in> set (rsplit0 a). ?I x (And \<phi> (f n s))" using rsplit_ex by simp
 14.3878 -  then obtain "\<phi>" "n" "s" where fnsS:"(\<phi>,n,s) \<in> set (rsplit0 a)" and "?I x (And \<phi> (f n s))" by blast
 14.3879 -  hence \<phi>: "?I x \<phi>" and fns: "?I x (f n s)" by auto
 14.3880 -  from rsplit0_cs[where t="a" and bs="bs" and x="x", rule_format, OF fnsS] \<phi> 
 14.3881 -  have th: "(?N x a = ?N x (CN 0 n s)) \<and> numbound0 s" by auto
 14.3882 -  from f[rule_format, OF th] fns show "?I x (g a)" by simp
 14.3883 -next
 14.3884 -  let ?I = "\<lambda>x p. Ifm (x#bs) p"
 14.3885 -  let ?N = "\<lambda> x t. Inum (x#bs) t"
 14.3886 -  assume ga: "?I x (g a)"
 14.3887 -  from rsplit0_complete[OF xp x1, where bs="bs" and t="a"] 
 14.3888 -  obtain "\<phi>" "n" "s" where fnsS:"(\<phi>,n,s) \<in> set (rsplit0 a)" and fx: "?I x \<phi>" by blast
 14.3889 -  from rsplit0_cs[where t="a" and x="x" and bs="bs"] fnsS fx
 14.3890 -  have ans: "?N x a = ?N x (CN 0 n s)" and nb: "numbound0 s" by auto
 14.3891 -  with ga f have "?I x (f n s)" by auto
 14.3892 -  with rsplit_ex fnsS fx show "?I x (rsplit f a)" by auto
 14.3893 -qed
 14.3894 -
 14.3895 -definition lt :: "int \<Rightarrow> num \<Rightarrow> fm" where
 14.3896 -  lt_def: "lt c t = (if c = 0 then (Lt t) else if c > 0 then (Lt (CN 0 c t)) 
 14.3897 -                        else (Gt (CN 0 (-c) (Neg t))))"
 14.3898 -
 14.3899 -definition  le :: "int \<Rightarrow> num \<Rightarrow> fm" where
 14.3900 -  le_def: "le c t = (if c = 0 then (Le t) else if c > 0 then (Le (CN 0 c t)) 
 14.3901 -                        else (Ge (CN 0 (-c) (Neg t))))"
 14.3902 -
 14.3903 -definition  gt :: "int \<Rightarrow> num \<Rightarrow> fm" where
 14.3904 -  gt_def: "gt c t = (if c = 0 then (Gt t) else if c > 0 then (Gt (CN 0 c t)) 
 14.3905 -                        else (Lt (CN 0 (-c) (Neg t))))"
 14.3906 -
 14.3907 -definition  ge :: "int \<Rightarrow> num \<Rightarrow> fm" where
 14.3908 -  ge_def: "ge c t = (if c = 0 then (Ge t) else if c > 0 then (Ge (CN 0 c t)) 
 14.3909 -                        else (Le (CN 0 (-c) (Neg t))))"
 14.3910 -
 14.3911 -definition  eq :: "int \<Rightarrow> num \<Rightarrow> fm" where
 14.3912 -  eq_def: "eq c t = (if c = 0 then (Eq t) else if c > 0 then (Eq (CN 0 c t)) 
 14.3913 -                        else (Eq (CN 0 (-c) (Neg t))))"
 14.3914 -
 14.3915 -definition neq :: "int \<Rightarrow> num \<Rightarrow> fm" where
 14.3916 -  neq_def: "neq c t = (if c = 0 then (NEq t) else if c > 0 then (NEq (CN 0 c t)) 
 14.3917 -                        else (NEq (CN 0 (-c) (Neg t))))"
 14.3918 -
 14.3919 -lemma lt_mono: "\<forall> a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \<and> numbound0 s \<longrightarrow> Ifm (x#bs) (lt n s) = Ifm (x#bs) (Lt a)"
 14.3920 -  (is "\<forall> a n s . ?N a = ?N (CN 0 n s) \<and> _\<longrightarrow> ?I (lt n s) = ?I (Lt a)")
 14.3921 -proof(clarify)
 14.3922 -  fix a n s
 14.3923 -  assume H: "?N a = ?N (CN 0 n s)"
 14.3924 -  show "?I (lt n s) = ?I (Lt a)" using H by (cases "n=0", (simp add: lt_def))
 14.3925 -  (cases "n > 0", simp_all add: lt_def ring_simps myless[rule_format, where b="0"])
 14.3926 -qed
 14.3927 -
 14.3928 -lemma lt_l: "isrlfm (rsplit lt a)"
 14.3929 -  by (rule rsplit_l[where f="lt" and a="a"], auto simp add: lt_def,
 14.3930 -    case_tac s, simp_all, case_tac "nat", simp_all)
 14.3931 -
 14.3932 -lemma le_mono: "\<forall> a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \<and> numbound0 s \<longrightarrow> Ifm (x#bs) (le n s) = Ifm (x#bs) (Le a)" (is "\<forall> a n s. ?N a = ?N (CN 0 n s) \<and> _ \<longrightarrow> ?I (le n s) = ?I (Le a)")
 14.3933 -proof(clarify)
 14.3934 -  fix a n s
 14.3935 -  assume H: "?N a = ?N (CN 0 n s)"
 14.3936 -  show "?I (le n s) = ?I (Le a)" using H by (cases "n=0", (simp add: le_def))
 14.3937 -  (cases "n > 0", simp_all add: le_def ring_simps myl[rule_format, where b="0"])
 14.3938 -qed
 14.3939 -
 14.3940 -lemma le_l: "isrlfm (rsplit le a)"
 14.3941 -  by (rule rsplit_l[where f="le" and a="a"], auto simp add: le_def) 
 14.3942 -(case_tac s, simp_all, case_tac "nat",simp_all)
 14.3943 -
 14.3944 -lemma gt_mono: "\<forall> a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \<and> numbound0 s \<longrightarrow> Ifm (x#bs) (gt n s) = Ifm (x#bs) (Gt a)" (is "\<forall> a n s. ?N a = ?N (CN 0 n s) \<and> _ \<longrightarrow> ?I (gt n s) = ?I (Gt a)")
 14.3945 -proof(clarify)
 14.3946 -  fix a n s
 14.3947 -  assume H: "?N a = ?N (CN 0 n s)"
 14.3948 -  show "?I (gt n s) = ?I (Gt a)" using H by (cases "n=0", (simp add: gt_def))
 14.3949 -  (cases "n > 0", simp_all add: gt_def ring_simps myless[rule_format, where b="0"])
 14.3950 -qed
 14.3951 -lemma gt_l: "isrlfm (rsplit gt a)"
 14.3952 -  by (rule rsplit_l[where f="gt" and a="a"], auto simp add: gt_def) 
 14.3953 -(case_tac s, simp_all, case_tac "nat", simp_all)
 14.3954 -
 14.3955 -lemma ge_mono: "\<forall> a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \<and> numbound0 s \<longrightarrow> Ifm (x#bs) (ge n s) = Ifm (x#bs) (Ge a)" (is "\<forall> a n s . ?N a = ?N (CN 0 n s) \<and> _ \<longrightarrow> ?I (ge n s) = ?I (Ge a)")
 14.3956 -proof(clarify)
 14.3957 -  fix a n s 
 14.3958 -  assume H: "?N a = ?N (CN 0 n s)"
 14.3959 -  show "?I (ge n s) = ?I (Ge a)" using H by (cases "n=0", (simp add: ge_def))
 14.3960 -  (cases "n > 0", simp_all add: ge_def ring_simps myl[rule_format, where b="0"])
 14.3961 -qed
 14.3962 -lemma ge_l: "isrlfm (rsplit ge a)"
 14.3963 -  by (rule rsplit_l[where f="ge" and a="a"], auto simp add: ge_def) 
 14.3964 -(case_tac s, simp_all, case_tac "nat", simp_all)
 14.3965 -
 14.3966 -lemma eq_mono: "\<forall> a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \<and> numbound0 s \<longrightarrow> Ifm (x#bs) (eq n s) = Ifm (x#bs) (Eq a)" (is "\<forall> a n s. ?N a = ?N (CN 0 n s) \<and> _ \<longrightarrow> ?I (eq n s) = ?I (Eq a)")
 14.3967 -proof(clarify)
 14.3968 -  fix a n s 
 14.3969 -  assume H: "?N a = ?N (CN 0 n s)"
 14.3970 -  show "?I (eq n s) = ?I (Eq a)" using H by (auto simp add: eq_def ring_simps)
 14.3971 -qed
 14.3972 -lemma eq_l: "isrlfm (rsplit eq a)"
 14.3973 -  by (rule rsplit_l[where f="eq" and a="a"], auto simp add: eq_def) 
 14.3974 -(case_tac s, simp_all, case_tac"nat", simp_all)
 14.3975 -
 14.3976 -lemma neq_mono: "\<forall> a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \<and> numbound0 s \<longrightarrow> Ifm (x#bs) (neq n s) = Ifm (x#bs) (NEq a)" (is "\<forall> a n s. ?N a = ?N (CN 0 n s) \<and> _ \<longrightarrow> ?I (neq n s) = ?I (NEq a)")
 14.3977 -proof(clarify)
 14.3978 -  fix a n s bs
 14.3979 -  assume H: "?N a = ?N (CN 0 n s)"
 14.3980 -  show "?I (neq n s) = ?I (NEq a)" using H by (auto simp add: neq_def ring_simps)
 14.3981 -qed
 14.3982 -
 14.3983 -lemma neq_l: "isrlfm (rsplit neq a)"
 14.3984 -  by (rule rsplit_l[where f="neq" and a="a"], auto simp add: neq_def) 
 14.3985 -(case_tac s, simp_all, case_tac"nat", simp_all)
 14.3986 -
 14.3987 -lemma small_le: 
 14.3988 -  assumes u0:"0 \<le> u" and u1: "u < 1"
 14.3989 -  shows "(-u \<le> real (n::int)) = (0 \<le> n)"
 14.3990 -using u0 u1  by auto
 14.3991 -
 14.3992 -lemma small_lt: 
 14.3993 -  assumes u0:"0 \<le> u" and u1: "u < 1"
 14.3994 -  shows "(real (n::int) < real (m::int) - u) = (n < m)"
 14.3995 -using u0 u1  by auto
 14.3996 -
 14.3997 -lemma rdvd01_cs: 
 14.3998 -  assumes up: "u \<ge> 0" and u1: "u<1" and np: "real n > 0"
 14.3999 -  shows "(real (i::int) rdvd real (n::int) * u - s) = (\<exists> j\<in> {0 .. n - 1}. real n * u = s - real (floor s) + real j \<and> real i rdvd real (j - floor s))" (is "?lhs = ?rhs")
 14.4000 -proof-
 14.4001 -  let ?ss = "s - real (floor s)"
 14.4002 -  from real_of_int_floor_add_one_gt[where r="s", simplified myless[rule_format,where a="s"]] 
 14.4003 -    real_of_int_floor_le[where r="s"]  have ss0:"?ss \<ge> 0" and ss1:"?ss < 1" 
 14.4004 -    by (auto simp add: myl[rule_format, where b="s", symmetric] myless[rule_format, where a="?ss"])
 14.4005 -  from np have n0: "real n \<ge> 0" by simp
 14.4006 -  from mult_left_mono[OF up n0] mult_strict_left_mono[OF u1 np] 
 14.4007 -  have nu0:"real n * u - s \<ge> -s" and nun:"real n * u -s < real n - s" by auto  
 14.4008 -  from int_rdvd_real[where i="i" and x="real (n::int) * u - s"] 
 14.4009 -  have "real i rdvd real n * u - s = 
 14.4010 -    (i dvd floor (real n * u -s) \<and> (real (floor (real n * u - s)) = real n * u - s ))" 
 14.4011 -    (is "_ = (?DE)" is "_ = (?D \<and> ?E)") by simp
 14.4012 -  also have "\<dots> = (?DE \<and> real(floor (real n * u - s) + floor s)\<ge> -?ss 
 14.4013 -    \<and> real(floor (real n * u - s) + floor s)< real n - ?ss)" (is "_=(?DE \<and>real ?a \<ge> _ \<and> real ?a < _)")
 14.4014 -    using nu0 nun  by auto
 14.4015 -  also have "\<dots> = (?DE \<and> ?a \<ge> 0 \<and> ?a < n)" by(simp only: small_le[OF ss0 ss1] small_lt[OF ss0 ss1])
 14.4016 -  also have "\<dots> = (?DE \<and> (\<exists> j\<in> {0 .. (n - 1)}. ?a = j))" by simp
 14.4017 -  also have "\<dots> = (?DE \<and> (\<exists> j\<in> {0 .. (n - 1)}. real (\<lfloor>real n * u - s\<rfloor>) = real j - real \<lfloor>s\<rfloor> ))"
 14.4018 -    by (simp only: ring_simps real_of_int_diff[symmetric] real_of_int_inject del: real_of_int_diff)
 14.4019 -  also have "\<dots> = ((\<exists> j\<in> {0 .. (n - 1)}. real n * u - s = real j - real \<lfloor>s\<rfloor> \<and> real i rdvd real n * u - s))" using int_rdvd_iff[where i="i" and t="\<lfloor>real n * u - s\<rfloor>"]
 14.4020 -    by (auto cong: conj_cong)
 14.4021 -  also have "\<dots> = ?rhs" by(simp cong: conj_cong) (simp add: ring_simps )
 14.4022 -  finally show ?thesis .
 14.4023 -qed
 14.4024 -
 14.4025 -definition
 14.4026 -  DVDJ:: "int \<Rightarrow> int \<Rightarrow> num \<Rightarrow> fm"
 14.4027 -where
 14.4028 -  DVDJ_def: "DVDJ i n s = (foldr disj (map (\<lambda> j. conj (Eq (CN 0 n (Add s (Sub (Floor (Neg s)) (C j))))) (Dvd i (Sub (C j) (Floor (Neg s))))) (iupt(0,n - 1))) F)"
 14.4029 -
 14.4030 -definition
 14.4031 -  NDVDJ:: "int \<Rightarrow> int \<Rightarrow> num \<Rightarrow> fm"
 14.4032 -where
 14.4033 -  NDVDJ_def: "NDVDJ i n s = (foldr conj (map (\<lambda> j. disj (NEq (CN 0 n (Add s (Sub (Floor (Neg s)) (C j))))) (NDvd i (Sub (C j) (Floor (Neg s))))) (iupt(0,n - 1))) T)"
 14.4034 -
 14.4035 -lemma DVDJ_DVD: 
 14.4036 -  assumes xp:"x\<ge> 0" and x1: "x < 1" and np:"real n > 0"
 14.4037 -  shows "Ifm (x#bs) (DVDJ i n s) = Ifm (x#bs) (Dvd i (CN 0 n s))"
 14.4038 -proof-
 14.4039 -  let ?f = "\<lambda> j. conj (Eq(CN 0 n (Add s (Sub(Floor (Neg s)) (C j))))) (Dvd i (Sub (C j) (Floor (Neg s))))"
 14.4040 -  let ?s= "Inum (x#bs) s"
 14.4041 -  from foldr_disj_map[where xs="iupt(0,n - 1)" and bs="x#bs" and f="?f"]
 14.4042 -  have "Ifm (x#bs) (DVDJ i n s) = (\<exists> j\<in> {0 .. (n - 1)}. Ifm (x#bs) (?f j))" 
 14.4043 -    by (simp add: iupt_set np DVDJ_def del: iupt.simps)
 14.4044 -  also have "\<dots> = (\<exists> j\<in> {0 .. (n - 1)}. real n * x = (- ?s) - real (floor (- ?s)) + real j \<and> real i rdvd real (j - floor (- ?s)))" by (simp add: ring_simps diff_def[symmetric])
 14.4045 -  also from rdvd01_cs[OF xp x1 np, where i="i" and s="-?s"] 
 14.4046 -  have "\<dots> = (real i rdvd real n * x - (-?s))" by simp
 14.4047 -  finally show ?thesis by simp
 14.4048 -qed
 14.4049 -
 14.4050 -lemma NDVDJ_NDVD: 
 14.4051 -  assumes xp:"x\<ge> 0" and x1: "x < 1" and np:"real n > 0"
 14.4052 -  shows "Ifm (x#bs) (NDVDJ i n s) = Ifm (x#bs) (NDvd i (CN 0 n s))"
 14.4053 -proof-
 14.4054 -  let ?f = "\<lambda> j. disj(NEq(CN 0 n (Add s (Sub (Floor (Neg s)) (C j))))) (NDvd i (Sub (C j) (Floor(Neg s))))"
 14.4055 -  let ?s= "Inum (x#bs) s"
 14.4056 -  from foldr_conj_map[where xs="iupt(0,n - 1)" and bs="x#bs" and f="?f"]
 14.4057 -  have "Ifm (x#bs) (NDVDJ i n s) = (\<forall> j\<in> {0 .. (n - 1)}. Ifm (x#bs) (?f j))" 
 14.4058 -    by (simp add: iupt_set np NDVDJ_def del: iupt.simps)
 14.4059 -  also have "\<dots> = (\<not> (\<exists> j\<in> {0 .. (n - 1)}. real n * x = (- ?s) - real (floor (- ?s)) + real j \<and> real i rdvd real (j - floor (- ?s))))" by (simp add: ring_simps diff_def[symmetric])
 14.4060 -  also from rdvd01_cs[OF xp x1 np, where i="i" and s="-?s"] 
 14.4061 -  have "\<dots> = (\<not> (real i rdvd real n * x - (-?s)))" by simp
 14.4062 -  finally show ?thesis by simp
 14.4063 -qed  
 14.4064 -
 14.4065 -lemma foldr_disj_map_rlfm2: 
 14.4066 -  assumes lf: "\<forall> n . isrlfm (f n)"
 14.4067 -  shows "isrlfm (foldr disj (map f xs) F)"
 14.4068 -using lf by (induct xs, auto)
 14.4069 -lemma foldr_And_map_rlfm2: 
 14.4070 -  assumes lf: "\<forall> n . isrlfm (f n)"
 14.4071 -  shows "isrlfm (foldr conj (map f xs) T)"
 14.4072 -using lf by (induct xs, auto)
 14.4073 -
 14.4074 -lemma DVDJ_l: assumes ip: "i >0" and np: "n>0" and nb: "numbound0 s"
 14.4075 -  shows "isrlfm (DVDJ i n s)"
 14.4076 -proof-
 14.4077 -  let ?f="\<lambda>j. conj (Eq (CN 0 n (Add s (Sub (Floor (Neg s)) (C j)))))
 14.4078 -                         (Dvd i (Sub (C j) (Floor (Neg s))))"
 14.4079 -  have th: "\<forall> j. isrlfm (?f j)" using nb np by auto
 14.4080 -  from DVDJ_def foldr_disj_map_rlfm2[OF th] show ?thesis by simp 
 14.4081 -qed
 14.4082 -
 14.4083 -lemma NDVDJ_l: assumes ip: "i >0" and np: "n>0" and nb: "numbound0 s"
 14.4084 -  shows "isrlfm (NDVDJ i n s)"
 14.4085 -proof-
 14.4086 -  let ?f="\<lambda>j. disj (NEq (CN 0 n (Add s (Sub (Floor (Neg s)) (C j)))))
 14.4087 -                      (NDvd i (Sub (C j) (Floor (Neg s))))"
 14.4088 -  have th: "\<forall> j. isrlfm (?f j)" using nb np by auto
 14.4089 -  from NDVDJ_def foldr_And_map_rlfm2[OF th] show ?thesis by auto
 14.4090 -qed
 14.4091 -
 14.4092 -definition DVD :: "int \<Rightarrow> int \<Rightarrow> num \<Rightarrow> fm" where
 14.4093 -  DVD_def: "DVD i c t =
 14.4094 -  (if i=0 then eq c t else 
 14.4095 -  if c = 0 then (Dvd i t) else if c >0 then DVDJ (abs i) c t else DVDJ (abs i) (-c) (Neg t))"
 14.4096 -
 14.4097 -definition  NDVD :: "int \<Rightarrow> int \<Rightarrow> num \<Rightarrow> fm" where
 14.4098 -  "NDVD i c t =
 14.4099 -  (if i=0 then neq c t else 
 14.4100 -  if c = 0 then (NDvd i t) else if c >0 then NDVDJ (abs i) c t else NDVDJ (abs i) (-c) (Neg t))"
 14.4101 -
 14.4102 -lemma DVD_mono: 
 14.4103 -  assumes xp: "0\<le> x" and x1: "x < 1" 
 14.4104 -  shows "\<forall> a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \<and> numbound0 s \<longrightarrow> Ifm (x#bs) (DVD i n s) = Ifm (x#bs) (Dvd i a)"
 14.4105 -  (is "\<forall> a n s. ?N a = ?N (CN 0 n s) \<and> _ \<longrightarrow> ?I (DVD i n s) = ?I (Dvd i a)")
 14.4106 -proof(clarify)
 14.4107 -  fix a n s 
 14.4108 -  assume H: "?N a = ?N (CN 0 n s)" and nb: "numbound0 s"
 14.4109 -  let ?th = "?I (DVD i n s) = ?I (Dvd i a)"
 14.4110 -  have "i=0 \<or> (i\<noteq>0 \<and> n=0) \<or> (i\<noteq>0 \<and> n < 0) \<or> (i\<noteq>0 \<and> n > 0)" by arith
 14.4111 -  moreover {assume iz: "i=0" hence ?th using eq_mono[rule_format, OF conjI[OF H nb]] 
 14.4112 -      by (simp add: DVD_def rdvd_left_0_eq)}
 14.4113 -  moreover {assume inz: "i\<noteq>0" and "n=0" hence ?th by (simp add: H DVD_def) } 
 14.4114 -  moreover {assume inz: "i\<noteq>0" and "n<0" hence ?th 
 14.4115 -      by (simp add: DVD_def H DVDJ_DVD[OF xp x1] rdvd_abs1 
 14.4116 -	rdvd_minus[where d="i" and t="real n * x + Inum (x # bs) s"]) } 
 14.4117 -  moreover {assume inz: "i\<noteq>0" and "n>0" hence ?th by (simp add:DVD_def H DVDJ_DVD[OF xp x1] rdvd_abs1)}
 14.4118 -  ultimately show ?th by blast
 14.4119 -qed
 14.4120 -
 14.4121 -lemma NDVD_mono:   assumes xp: "0\<le> x" and x1: "x < 1" 
 14.4122 -  shows "\<forall> a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \<and> numbound0 s \<longrightarrow> Ifm (x#bs) (NDVD i n s) = Ifm (x#bs) (NDvd i